码迷,mamicode.com
首页 > Web开发 > 详细

Asp.net MVC集成stripe支付

时间:2015-03-12 12:50:22      阅读:308      评论:0      收藏:0      [点我收藏+]

标签:

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,觉得还是方便的多了!

 

Asp.net MVC集成stripe支付

标签:

原文地址:http://www.cnblogs.com/liu2008hz/p/4331839.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!