0% found this document useful (0 votes)
318 views10 pages

Bagisto Paystack Integration

The document summarizes the steps taken to integrate the Paystack payment gateway into the Bagisto e-commerce platform. It describes creating a custom Paystack package by duplicating the existing PayPal package files and modifying them. Key steps included registering the Paystack package and payment method, adding configuration files, creating Paystack controller and model files, and implementing the Paystack API to initialize transactions, verify payments, and redirect to success/cancel routes. Pseudocode outlines the integration process of collecting customer details, making API calls to Paystack to initialize and verify transactions, and conditionally redirecting based on the response.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
318 views10 pages

Bagisto Paystack Integration

The document summarizes the steps taken to integrate the Paystack payment gateway into the Bagisto e-commerce platform. It describes creating a custom Paystack package by duplicating the existing PayPal package files and modifying them. Key steps included registering the Paystack package and payment method, adding configuration files, creating Paystack controller and model files, and implementing the Paystack API to initialize transactions, verify payments, and redirect to success/cancel routes. Pseudocode outlines the integration process of collecting customer details, making API calls to Paystack to initialize and verify transactions, and conditionally redirecting based on the response.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Smooth Capital

TECHNICAL
DOCUMENTATION
Oluwatobi Odekunle,

Lead Developer.
Payment Integration
A payment gateway is a merchant service provided by an e-commerce application
service provider that authorizes credit card or direct payments processing for e-
businesses, online retailers, bricks and clicks, or traditional brick and mortar.

Bagisto Payment Package


Bagisto comes with a payment package that handles all the configurations needed to
add a new payment gateway to the application. This payment package contains the
following folder structure:

src/
config/
Paymentmethods.php
System.php
facades/
payment.php
Http/
Helpers.php
Payment/
CashOnDelivery.php
MoneyTransfer.php
Payment.php
Providers/
PaymentServiceProviders.php
Payment.php
Composer.json

You do not have to update this package except you want to add a new payment
gateway eg. Paystack.

For your new payment method e.g Paystack to show on the front end, you have to do
some configurations. All these configurations are done inside the config folder
(Paymentmetods.php and system.php) are the files you need to update to register your
payment method.
Follow the below tutorial to create a new payment method.

Create a new payment method

Bagisto PayPal Package


Bagisto comes with Paypal integration as the default payment method, this package
helped me in configuring my own payment method because you have to follow the way
paypay is being structured to actually get it to work. PayPal is a package written by
WebKul for making payment easier. You can disconnect the paypal from showing at the
front end by going to the payment package above and remove its properties.

Laravel-Paystack Library Used


In order to add a new payment method to the bagisto application, I ran through several
options before selecting paystack as my payment method which I found one of the best
laravel package for connecting paystack to any laravel application. This library is
created by Prosper Otemuyiwa which I found after several searches on Google.

I followed the instructions on how to use the library to connect my application with
paystack but unfortunately I could not get it done just because the way WebKul
structured their payment method (PayPal) is different and you have to follow their own
way of creating a package just like PayPal in order to get it to work. The main reason is
to not break the exisiting code.

I tried creating a package with the files gotten from the library but could not get it done
until I developed my own package from scratch.
A new created Paystack Package
Yes, I had to create a new package called Paystack which is now part of WebKul
packages and configured it to work with the application without breaking any code yet.

Step By Step Procudures


1. Created a new package called Paystack using the manual way (I duplicated the
PayPal package and rename it to avoid mistakes).

2. Registered the package: Inside the config folder, a file named app.php and I
registed the package by adding this to providers:
Webkul\Paystack\Providers\PaystackServiceProvider::class,
3. Updated the composer.json file by modifying the autoload property:
"autoload": {

"psr-4": {

"Webkul\\Paystack\\": "src/"

},

4. Updated the composer.json by regitering the service provider:


"extra": {

"laravel": {

"providers": [

"Webkul\\Paystack\\Providers\\PaystackServiceProvider"

],
"aliases": {}

},

5. Registered the payment method to work with payment package and


also to display at the frontend of the app. I added the below to the
config/paymentmethods.php file.

'paystack_standard' => [

'code' => 'paystack_standard',

'title' => 'Paystack Standard',

'description' => 'Paystack Standard',

'class' => 'Webkul\Paystack\Payment\Standard',

'sandbox' => true,

'active' => true,

'business_account' => '[email protected]',

'sort' => 4,

],

6. I added the below to the config/system.php file for configuration.

[
'key' => 'sales.paymentmethods.paystack_standard',

'name' => 'admin::app.admin.system.paystack-standard',

'sort' => 4,

'fields' => [

'name' => 'title',

'title' => 'admin::app.admin.system.title',

'type' => 'text',

'validation' => 'required',

'channel_based' => false,

'locale_based' => true,

], [

'name' => 'description',

'title' => 'admin::app.admin.system.description',

'type' => 'textarea',

'channel_based' => false,

'locale_based' => true,

], [

'name' => 'business_account',


'title' => 'admin::app.admin.system.business-account',

'type' => 'select',

'type' => 'text',

'validation' => 'required',

], [

'name' => 'active',

'title' => 'admin::app.admin.system.status',

'type' => 'boolean',

'validation' => 'required',

'channel_based' => false,

'locale_based' => true

], [

'name' => 'sandbox',

'title' => 'admin::app.admin.system.sandbox',

'type' => 'boolean',

'validation' => 'required',

'channel_based' => false,

'locale_based' => true,

], [
'name' => 'sort',

'title' => 'admin::app.admin.system.sort_order',

'type' => 'select',

'options' => [

'title' => '1',

'value' => 1,

], [

'title' => '2',

'value' => 2,

], [

'title' => '3',

'value' => 3,

], [

'title' => '4',


'value' => 4,
],
],
]
]
],

7. Inside the Paystack Http folder, I created both Controller.php and


StandardCotroller.php
8. Inside the Paystaack Http folder, I registered all the routes needed e.g
/success, /callback, /cancel, /redirect
9. Inside the Paystack payment folder, I created an abstract Paystack class that
extends the Payment class.
10. Inside the Paystack payment folder, I created an Standard class that extends the
Paystack class (the abstract one created).
11. Inside the Paystack providers folder, I created PaystackServiceProvider.php that
was registered inside the config/app.php file.
12. Inside the Paystack resources folder, I created standard-redirect.blade.php file
and this is the page that the user would be redirected to after clicking Paystack
Standard as the payment method.
Paystack Integration (Pseudo code)
After all the above steps, the following algorithm was followed inside the standard-
redirect.blade.php file:-

1. Register with paystack (the test mode)


2. Got all the necessary information needed (test secret key, pubic key etc)
3. Got the paystack api endpoint (https://api.paystack.co/transaction/initialize)
4. Extract all the information of the customer submitted from the Standard class
created to a variable.<?php $paystackStandard = app('Webkul\Paystack\
Payment\Standard') ?>

5. Calculated the total amount : ($fields['grand_total'] + $fields['shipping'])


6. Converted the amount to naira: ($fields['grand_total'] + $fields['shipping']) * 100;
7. Added the result to the amount property of the object extracted.
8. Added some information to the metadata property
9. Encoded the object using json_encode($fields)
10. Started the connection using curl_init()
11. Set the necessary options needed eg. url, post data, httpheader etc using
curl_setopt
12. Added the test secret key to the httpheader.
13. Executed the post using curl_exec($connection)
14. Checked for error using curl_error($connection)
15. Decoded the response using: json_decode
16. Checked for success code from the response object
17. Verified the transaction using https://api.paystack.co/transaction/verify/
18. If error occured redirected back to /cancel route created
19. If no error, redirected back to /success route created.

You might also like