Example based on Adyen PayByLink plugin
1. Firstly, create a basic plugin structure according to documentation
2. Your main plugin class should inherit from BasePlugin (like all plugins) and implement the IPaymentMethod 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
If we have settings, we will want to allow the administrator to fill settings by payment method configure.
You should override method GetConfigurationPageUrl()
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).
Example of controller configure
The methods described are derived from IPaymentPlugin
-Set type of payment method and RecurringPaymentType.
Available Recurring Payment types:
- Automatic (payment is processed on payment gateway site)
Available payment method types:
- 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)
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
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)
Return payment method description
It will be displayed 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.
In view component, you return View, and can also pass the model.
A view can be simple HTML with a description or with inputs to filled by user
If you used form (HTML inputs with name attribute ) in the previous step, you can fetch data passed by a user by this method
You can pass to result some error if they occurred
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
If so send the request to API
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
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.
It will invoke the Refund method
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