• Asp.net MVC集成stripe支付


    1、注册Stripe账号 https://stripe.com

    初始时账号是TEST模式,需要激活账号才能进入LIVE模式;点击 "Your Account" -> "Account Settings",出现如下弹出框:

    如果是TEST模式,请使用Test Secret Key和Test Publishable Key,否则请使用LIVE相关的两个Key;具体如何使用,请继续往下看

    2、安装Stripe

    使用NuGet安装Stripe,通过搜索会找到Stripe和Stripe.net两个,请安装Stripe。具体过程略过!

    可以到https://github.com/nberardi/stripe-dotnet下载源码看看

    3、集成支付

    <form action="/ChargeController/Charge"
        <script src="https://checkout.stripe.com/checkout.js" type="text/javascript"
            data-key="your-test-publishable-key"
            data-image="your-website-image,size 128*128"
            data-name="Demo Site"
            data-description="2 widgets (£20.00)"
            data-currency="GBP"
            data-amount="2500" />
    </form>
    

     将以上Script嵌入到form中,form中会出现一个;当然,你也可以根据需要使用自定义的按钮,具体请看Stripe官网文档。

     点击按钮,在弹出的支付信息填写Dialog中,填写正确后,会产生一个stripeToken,连同form的其它内容一起POST到ChargeController/Charge

    4、执行支付

            [HttpPost]
            public ActionResult Charge(FormCollection form)
            {
                string token = form["stripeToken"];
                string email = form["stripeEmail"];
    
                string apiKey = "sk_test_xxxxxxxxxxxxxxx";
                var stripeClient = new Stripe.StripeClient(apiKey);
    
                dynamic response = stripeClient.CreateChargeWithToken(2000, token, "NOK", email);
                if (response.IsError == false && response.Paid)
                {
                    // success
                    string id = response.Id;//支付Id
                    bool livemode = response.LiveMode;//支付模式
                    long created = response.Created;//支付时间
                    string status = response.Status;//支付状态
                    object source = response.Source;//支付源(信用卡等)
                    string source_id = response.Source.Id;//卡Id
                    string source_last4 = response.Source.Last4;//卡后四位
                    string source_brand = response.Source.Brand;//卡品牌(Visa等)
                    string source_funding = response.Source.Funding;//资金(Creadit等)
                    int source_exp_month = response.Source.Exp_Month; //卡过期月份
                    int source_exp_year = response.Source.Exp_Year;//卡过期年份
                    string source_name = response.Source.Name;//支付人邮箱名
                    return RedirectToAction("Index", "Home");
                }
                return View();
            }     
    

     到此就完成了一个支付流程,相比paypal,觉得还是方便的多了!

  • 相关阅读:
    问题 A: C#抽象类Vehicles
    最短路练习
    BFS
    poj 1083 Moving Tables
    组合数
    hdu 1443 Joseph【约瑟夫环】
    poj 2449 Remmarguts' Date【第K短路】
    hdu 1695 GCD 【莫比乌斯函数】
    hdu 2178 猜数字
    bzoj 2440 完全平方数 【莫比乌斯函数】
  • 原文地址:https://www.cnblogs.com/liu2008hz/p/4331839.html
Copyright © 2020-2023  润新知