n
nE-commerce applications require user-friendly mechanisms for payment. Payment processing on the Web is a big industry and there are myriad services and providers allowing you to process credit cards and bank cards over Internet connections.
n
n
nIntroduction
nIf you are developing an e-commerce application or you already have one running on .net platform and you require some payment gateway integration, then this article will guide you on how you can integrate Paystack payment gateway.
nnn
nnnIf you are getting to know or hear about Paystack for the first time, then I advise that you visit their website here for full introduction.
n
n
nHow Paystack works
nPaystack, like every other payment gateway works the same way in an e-commerce applications.
nThe process goes like this:
n
- n
- User picks items in the web site
- User fills our order info
- User accepts the order and final amount
- User gets redirected to a Paystack secure payment page
- On success Paystack redirects back to site’s callback url
n
n
n
n
n
n
nA walk through of the process
n
n
n
n
nnn
nnn
n
n
n
n
nBelow is the screen shot of the sample app on the usage of the plugin on my github page:
n
n
| Screen shot of the sample mini e-commerce app on my github |
n
n
nHow to use the Paystack.Net.SDK plugin
n
n
n
nnn
nnn
nSearch for Paystack.Net.SDK or alternatively, click here to view the plugin for all optional versions. You can also install the plugin directly from the package manager console by running this command.
n
n
Install-Package Paystack.Net.SDK -Version 1.0.2
n
nThe plugin which I will continue supporting and adding more feature allows you to perform almost all the actions provided by Paystack like:
n
- n
- Transactions
- Customers
- Subaccounts
- Plans
- Subscriptions
- Transfers
n
n
n
n
n
n
n
n
n
nnn
nnn
n
nTransactions Initialization
nYou can easily perform transaction initialization with the plugin like so:
n
nUsing Statements
n
n
using Paystack.Net.SDK.Transactions;nusing PaystackSampleWebApp.Models.DataModel;nusing PaystackSampleWebApp.Models.Interfaces;nusing PaystackSampleWebApp.Models.ViewModels;n
n
n
public async TaskInitializePayment(PaystackCustomerModel model)n {n string secretKey = ConfigurationManager.AppSettings["PaystackSecret"];n var paystackTransactionAPI = new PaystackTransaction(secretKey);n var response = await paystackTransactionAPI.InitializeTransaction(model.email, model.amount, model.firstName, model.lastName, "http://localhost:17869/order/callback");n //Note that callback url is optionaln if (response.status == true)n {n return Json(new {error=false,result= response }, JsonRequestBehavior.AllowGet);n }n return Json(new { error = true, result = response }, JsonRequestBehavior.AllowGet);nn }n
n
nI just instantiated the PaystackTransaction and the pass the secret key that can be found in https://dashboard.paystack.com/#/settings/developer
nnn
nnn
n
nTransaction Verification
nVerification can also be done simple like so:
n
n
[Route("order/callback")]n public async Task Index()n {n string secretKey = ConfigurationManager.AppSettings["PaystackSecret"];n var paystackTransactionAPI = new PaystackTransaction(secretKey);n var tranxRef = HttpContext.Request.QueryString["reference"];n if (tranxRef != null)n {n var response = await paystackTransactionAPI.VerifyTransaction(tranxRef);n if (response.status)n {n return View(response);n }n }nn return View("PaymentError");n }n
n
n
n
nSamples
nI’ve spent a fair amount of time talking about how to use my plugin for easy integration in this article, because I think it’s important to keep things in the perspective of a real application environment. I do hope that the code shown was not too specific and easily understandable in the context of the Paystack integration.nnn
nnI’ve provided a really simple sample project that demonstrates the basic concepts I’ve described here along with the code to the helper classes mentioned, which you can run and play around with. Just remember to use small order amounts.
n
nYou can download the sample app from here.
n
nIf you have any questions or bug report please let me know.
n
nHappy New Year in Advance and happy coding.
n
nSource Code
