ASP. NET MVC Integrated stripe payment

Source: Internet
Author: User

1, registered stripe account https://stripe.com

Initial account is the test mode, need to activate the account to enter the live mode, click "Your Accounts", "Accounts Settings", the following pop-up box appears:

If it is test mode, use Test Secret key and test publishable key, otherwise use live-related two key, and how to use it, keep looking down

2, installation Stripe

With NuGet installed stripe, search will find stripe and stripe.net two, please install stripe. Specific process Skip!

can go to https://github.com/nberardi/stripe-dotnet download source to see

3. Integrated Payment

<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>

Embed the above script in the form, one in the form, and, of course, you can use the custom button as needed, see the stripe official website.

Click the button, fill in the dialog in the pop-up payment information, fill in the correct, will produce a stripetoken, together with the other contents of the form to post to Chargecontroller/charge

4. Execution of payment

        [HttpPost] public actionresult Charge (formcollection form) {String token = form["Stripet            Oken "];            string email = form["Stripeemail"];            String ApiKey = "Sk_test_xxxxxxxxxxxxxxx";            var stripeclient = new Stripe.stripeclient (ApiKey);            Dynamic response = Stripeclient.createchargewithtoken ($, token, "NOK", email); if (response. IsError = = False && response. Paid) {//success String id = response. id;//Payment ID BOOL Livemode = response. livemode;//Payment mode Long created = response. created;//payment Time String status = Response. status;//Payment Status Object Source = Response. source;//Payment Source (credit card, etc.) string source_id = Response. source.id;//Card Id String source_last4 = Response. source.last4;//card after four bit string source_brand = response. source.brand;//Card Brand (visa, etc.) string source_funding = ReSponse. source.funding;//funds (Creadit, etc.) int source_exp_month = response. Source.exp_month; Card expiration Month int source_exp_year = response. source.exp_year;//card expiration Year string source_name = Response.            source.name;//payer's mailbox name return redirecttoaction ("Index", "Home");        } return View ();      }

This is the completion of a payment process, compared to PayPal, I think it is more convenient!

ASP. NET MVC Integrated stripe payment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.