Categories

How to create a new payment plugin

Example based on Adyen PayByLink plugin
https://docs.adyen.com/checkout/pay-by-link

 

1. Firstly, create a basic plugin structure according to documentation
https://docs.grandnode.com/how-to-create-base-plugin-3

2. Your main plugin class should inherit from BasePlugin (like all plugins) and implement the IPaymentMethod interface.interface

3. Prepare and configure the plugin.

In most cases, our payment plugins are required to store additional information like specific API key/Company name e.g.
Best place to store it is settings.
So, let’s create settings for our plugin
settings

If we have settings, we will want to allow the administrator to fill settings by payment method configure.

You should override method GetConfigurationPageUrl()

configuration

then in Admin-> Local plugins, you will see the button Configure. It will redirect to override PageUrl (notice than you must create a controller with action responsible for handle configuration, usually some form to fill and save to settings). 

configure button

Example of controller configure

congiure controller

 

4.Payment processing

The methods described are derived from IPaymentPlugin
-Set type of payment method and RecurringPaymentType.

Recurring

Available Recurring Payment types:
- NotSupported
- Manual
- Automatic  (payment is processed on payment gateway site)

Available payment method types:
- Unknown
- Standard (all payment information is entered on the site)
- Redirection (a customer is redirected to a third-party site in order to complete the payment)
- Button (button in cart, one of our payment plugin is based on Button type Paypal Express Checkout)
- Set supported action (it usually depends on your payment method provider)

types

Sometimes you will want to block certain payment methods depends on the order product.
For instance. You sell cars, but you want to be able to pay only in cash in the store.
So you can check product category or other criteria and hide your payment method

hide payment method

This method allows you to add additional fees to order. For example, your provider charges 1% if the price is over $2000, so you can factor that in (or you have your own reason for calculating fee)

additional fee

Return payment method description

payment description method

It will be displayed at the checkout

description at the checkout

If you choose a payment method and click Continue button, will display payment method View Component. 

First, assign ViewComponent by setting a name.

view component name

In view component, you return View, and can also pass the model.

view component return view

A view can be simple HTML with a description or with inputs to filled by user

payment information

If you used form (HTML inputs with name attribute ) in the previous step, you can fetch data passed by a user by this method 

getpaymentinfor

You can pass to result some error if they occurred

processpaymentresult

In this method, you can redirect to the payment provider.

In the Ayden case, I use Adyen API to create payment links.
Firstly check than the link is exist

link exists

If so send the request to API

request to api

try catch

If there is no error use IHttpContextAccessor to redirect to the payment provider site.

 

5. Retry Payment, and refund

Give information that Retry payment is allowed or not

can reprocess

If the user has not completed the payment, he can use the retry button. Method PostProcessPayment will be triggered again.

In Adyen I first check than previous link is expired, If yes generate new and redirect to the provider site.
If the payment status is PAID you can refund.

refund admin panel

It will invoke the Refund method

refund method

6.Webhooks

Most of the payment providers use webhooks to notify that payment status has changed.

To handle this:
-Create a controller with action dedicated to handling notification
-Register your action URL in provider site

 

Important! You should always validate notification request, to be ensure that is from your payment provider

web hook

back to top