I hope that now you know how to create a package, if not refer to Package development.
Bagisto eases the task of creating payment methods so a novice developer or professional developer can easily create payment methods. As the diversity of payment methods provide the options to customer for payment when they proceed to checkout. On another perspective, multiple payment methods are a great strategy to reach out to the global marketplace.
In this article, we will understand how to create a payment method with just the following steps:
Steps to create a payment method
Create respective Directory Structure to create your payment method.
Within Config folder, it contain’s application’s configuration files. Let’s just create two files as system.php and paymentmethods.php
- Inside the file, you can include the code below as shown in image
<?php return [ [ 'key' => 'sales.paymentmethods.paypal_standard', 'name' => 'admin::app.admin.system.paypal-standard', 'sort' => 3, '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, ], ], ] ] ] ]
Explanation for the keys:
key: these values provided are unique and concatenated with ‘.’ (dot) operator. After the creation of two nested, other keys written are display in the browser in the form of accordion
name: these keys accept the value as a placeholder of your configuration. Generally, in bagisto, we consider writing it using translation.
sort: these keys accept the sort position for the configuration menu.
fields these keys accept the array for the value of the custom configuration.
<?php return [ 'paypal_standard' => [ 'code' => 'paypal_standard', 'title' => 'Paypal Standard', 'description' => 'Paypal Standard', 'class' => 'Webkul\Paypal\Payment\Standard', 'sandbox' => true, 'active' => true, 'sort' => 3, ] ];
Explanation for the keys:
- code: a text to represent payment method
- title: in this field, the name of payment method is specified
- description: a brief description of the payment method.
- class: this field includes the class namespace where all functions of payment method are written
- sandbox: this is a custom option of boolean type
- active: this field accepts true/false to enable or disable the module.
- sort: these keys accept the sort position for the payment.
Within Database folder, the migration and seeder(if needed) files are stored.
Within Providers folder all of the service providers for your application. Service providers bootstrap your application by binding services in the service container, registering events, or performing any other tasks to prepare your application for incoming requests.
Here, in our case, we have created two providers files i.e.,
EventServiceProvider : In this file, events included with your application provides a convenient place to register all of your application’s event listeners.
PaymentServiceProvider : In this file, you may register all your configuration, language, and routes within register and boot methods.
Within Models folder, the models are stored for the application.
Within Payment folder, write the code needed to operate your payment method
Within Repositories folder, create a file as HelloWorldRepository.php which must extend repository class
Within Http folder, define your routes and controller application.
Within Listeners folder, this folder includes listener files to listen to respective events.