Friday, November 28, 2014

Stripe Payment Gateway

Indroduction


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. 


https://cmatskas.com/content/images/2014/Jan/AddNugetPackage_PNG.png


Step2 :

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

https://dashboard.stripe.com/register

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.

https://cmatskas.com/content/images/2014/Jan/StripeApiKey_PNG.png


Step3 :

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

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

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

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