Friday, November 28, 2014

Stripe Payment Gateway


Stripe is the one of the payment gateway to charge amount from credit card. Currently we are using Authorize.Net gateway. When we use Authorize.Net gateway, sometime it gets failure, by this time we can switch the Stripe Payment gateway.

Steps to Implement  Stripe

Step1 :

Let’s start by adding the latest Stripe.NET library to our project using NuGet.

Step2 :

Next Step to the Stripe site to register for a free account and get your API keys

To use Stripe on your site you will need to reference the stripe.dll in your controller or where your code will be running e.g. on the razor page etc.

Step3 :

Add your Stripe public key to the web.config as per below:

       <add key="StripeApiKey" value="Your Public Key" />

Note make sure you replace the StripeApiKey value with your public key.Because this key is used in stripe.dll

StripeApiKey  - This splling should not be change.

Step4 :

       StripeTokenCreateOptions myToken = new StripeTokenCreateOptions();

                myToken.CardAddressCountry = "USA";
                myToken.CardAddressLine1 = "Suite 200";
                myToken.CardAddressLine2 = "";
                myToken.CardAddressCity = "Alden";
                myToken.CardAddressZip = "60001";
                myToken.CardCvc = "123";
                myToken.CardExpirationMonth = "07";
                myToken.CardExpirationYear = "2018";
                myToken.CardName = "Join";
                myToken.CardNumber = "4111555588887777";

                    StripeTokenService tokenService = new StripeTokenService();
                    StripeToken stripeToken = tokenService.Create(myToken);   //Here we got token from stripe.

                    string _stripeToken = stripeToken.Id;

                    StripeChargeCreateOptions myCharge = new StripeChargeCreateOptions();
                    myCharge.Amount = Convert.ToInt32(creditCard.ChargeAmount*100);
                    myCharge.Currency = "usd";  //usd means US Doller. If we want indian rupee we can use "inr"
                    myCharge.Description = creditCard.Description;
                    myCharge.TokenId = _stripeToken;

                    StripeChargeService chargeService = new StripeChargeService();
                    StripeCharge stripeCharge = chargeService.Create(myCharge); //Here charge the amount from Creditcard

No comments:

Post a Comment