How to Integrate Cybersource Payment Gateway Extension in Bagisto

Updated 8 August 2024

If you want to accept payments all over the world, and you need a reliable solution to handle them all, Cybersource Global Payment Gateway is the answer. In a single integration, you can accept payments online and in-store across the world, and in over 50 currencies.

Building a Cybersource Payment Gateway Extension in Bagisto Step-by-Step Tutorial.

Cybersource Global Payment Gateway is the solution that enables you to take credit and debit card payments online around the world. It processes each transaction securely from start to finish, and all in just a few seconds.

1) Module Setup

So in the installation of Bagisto, you will get the directory name Webkul which contains the packages for Bagisto.  Create a directory named  CyberSource & src inside the Webkul folder at the root of the Bagisto installation. packages directory is the container of all namespaces of packages. A namespace or vendor name is a group of entities or classes that are separated from classes of other namespaces with the same name so they don’t conflict. Every extension or package that we will develop should be kept in the same namespace to avoid conflict between classes with the same name.

Now add the below code inside the “autoload psr-4” in the  composer.json file as shown below.

Now register in the provider array with the array merge function in the config/app.php file which is presented in the root directory of Bagisto.

In the config/bagisto-vite.php file, add the following line under the ‘viters’ section:

Go to app/Http/Middleware/VerifyCsrfToken.php file and add the following line under ‘$except’ variables.

2) Providers

In the src folder, create a folder named Providers. Inside that folder, create a file named CyberSourceServiceProvider.php. Make sure to create the file name according to your module name. Now the structure will look like this.

CyberSourceServiceProvider.php

Run the below command to register the package in the root directory of Bagisto.

3) Custom Configuration

To create a custom configuration for your application, you just need to create a system.php file in the Config folder of your package.

Inside the file, you can include the code below.

system.php

Now create a paymentmethods.php file in the Config folder of your package.

Inside the file, you can include the code below.

paymentmethods.php

So now after this, the structure will look like this as shown in the below image.

Load Configuration from Package 

Now we need to merge these custom config also, in the respective service provider.

4) Routes

Create a Routes folder inside packages /Webkul/CyberSource/src/ and create 2 files named front-routes.php and web.php. To learn in detail about Routes, you can visit the Laravel documentation here.

front-routes.php

web.php

Now add the below code inside the boot method of the respective service provider to register the routes.

So now after this, the structure will look like this as shown in the below image.

5) Controllers

To learn in detail about Controllers, you can visit the Laravel documentation here

Create an Http folder in the packages/Webkul/CyberSource/src path. Inside the Http folder, create another folder named Controllers. Inside the Controllers folder, we need to create two files named Controller.php and CyberSourceController.php. The directory structure will look like this.

Controller.php

CyberSourceController.php

6) Payment

Now create a Payment folder and create a file CyberSource.php inside this.

Inside the file, you can include the code below.

7) Views

Create a Resources folder in the packages/Webkul/CyberSource/src path. Inside the Resources folder, create another folder named views. Now inside the views folder, we need to create a file by the name of cyber-source-redirect.blade.php.

cyber-source-redirect.blade.php :-

So now after this, the structure will look like this as shown in the below image.

 

Load Views From Package

Now we need to register our views in the service provider’s boot method. Open the file packages/Webkul/CyberSource/src/Providers/CyberSourceServiceProvider.php and update it as follows.

8) Localization

So, let’s create a language file for our package. Create a lang folder in the packages/Webkul/CyberSource/src/Resources path. Inside the lang folder, you create different folders for language translations. For example, you create a folder for English (‘en’), Hindi (‘hi’), etc. For now, let’s create a folder named en (representing the language code). Inside the en folder, create a file named app.php for language translations.

app.php

Load Translations From Package

Now register the language file in the service provider in the boot method.

Now the structure and file will look like this.

9) Frontend

So you can select a new payment method and proceed with placing an order.

Thanks for reading this blog. I hope you’ll get an idea of how to create a custom stock notification package. Please share your reviews on this, which will support me to write more.

You can directly get the code from the GitHub CyberSource Payment Gateway repository

Additionally, you can also Hire Laravel Developers to help you with your project requirements and ensure the successful implementation of your ideas.

vrCEoWZEkMs
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project




    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home