Payment Gateway

Payment Gateway Service Class

php artisan payable:gateway Paypal

This will generate Paypal class implementing PaymentGatewayInterface located in app\PaymentGateway implementing 5 methods :-


pay(float $amount, $return_url, $purchase_order_id, $purchase_order_name);

Accepts 4 arguments:-

  • amount(float): Payment amount to be processed via payment gateway

  • return_url : Payment gateway redirect url

  • product_id

  • product_name

Responsible for payment process requests to payment gateway


initiate(float $amount, $return_url, ?array $arguments = null)

Accepts 3 arguments:-

  • amount(float): Payment amount to be processed via payment gateway

  • return_url : Payment gateway redirect url

  • arguments(array) : Any additional data needed for the transaction process

Responsible for payment process requests to payment gateway


inquiry($transaction_id, ?array $arguments = null) : array

Accepts 2 arguments:-

  • transaction_id: Uniquely identifiable key given by payment gateway vendor

  • arguments(array) : Any additional data needed for the inquiry process

Responsible for lookup requests for payment transactions to verify their authenticity


isSuccess(array $inquiry, ?array $arguments = null): bool

Accepts 2 arguments:-

  • inquiry: Array response from inquiry method

  • arguments(array) : Any additional data needed for the isSuccess process

Responsible for verifying transaction success status


requestedAmount(array $inquiry, ?array $arguments = null): float

Accepts 2 arguments:-

  • inquiry: Array response from inquiry method

  • arguments(array) : Any additional data needed for the isSuccess process

Responsible for returning requested amount to be processed in payment gateway

Payment Gateway

This class accepts payment gateway service class and is responsible for initiating and processing payment from the gateway to registering verified payment to the database

__construct(PaymentGatewayInterface $gateway, $model)

Accepts 2 arguments:-

  • Payment gateway service class (Paypal instance for example)

  • Model instance which has HasPayable trait


pay(float $amount, $return_url, $product_id = null, $product_name = null)

Accepts 3 arguments:-

  • Amount to be processed

  • product_id(optional) if left empty takes model instance id ($model->id)

  • product_name (optional) if left empty takes the model instance name ($model->name)

Responsible for payment process requests to payment gateway


process($transaction_id, ?array $arguments = null): Payment

Accepts 2 arguments:-

  • transaction_id: Uniquely identifiable key given by payment gateway vendor

  • arguments(array) : Any additional data needed for the inquiry process

Responsible for verifying payment status and registering payments.

  • Register a transaction

  • Register a payment

  • Register payment history

Example Walk Through

Creating payment generator

Generate Paypal payment gateway using the payment gateway generator command

Controller to handle checkout and verification

Routes to handle checkout and verification

Some of the premade payment gateways

Esewa

Khalti

Fonepay

Last updated