MPGS Hosted checkout integration for Lunar
Supported action
- purchase
Not supported (PR welcome)
- refund
- authorize/capture
You can install the package via composer:
composer require wychoong/lunarphp-mpgs
You can publish the config file with:
php artisan vendor:publish --tag="lunarphp-mpgs-config"
Set the driver in config/lunar/payments.php
<?php
return [
// ...
'types' => [
'card' => [
'driver' => 'stripe',
'authorized' => 'payment-received', # or any status key configured in lunar.orders.statuses
],
],
];
###Add your MPGS credentials
Set your MPGS_ variable in .env
MPGS_MERCHANT_ID=
MPGS_API_PASSWORD=
MPGS_VERSION=
We use closure to return the data you want to pass to the api
use \WyChoong\Mpgs\Facades\Mpgs;
// in service provider `boot` method
Mpgs::initiateCheckoutUsing(function ($cart, $amount, $currency): array {
if (!$order = $cart->order) {
$order = $cart->createOrder();
}
$reference = $order->reference . date('Ymdhis');
return [
// refer to the api spec for Initiate Checkout params
'order' => [
'id' => $reference,
'currency' => $currency,
'amount' => $amount,
'description' => "Payment for #" . $order->reference,
'reference' => $reference,
],
'transaction' => [
'reference' => $reference,
],
'interaction' => [
'merchant' => [
'name' => 'Lunar store',
],
'displayControl' => [
'billingAddress' => 'HIDE',
]
]
];
});
use \WyChoong\Mpgs\Facades\Mpgs;
Mpgs::createIntent(\Lunar\Models\Cart $cart);
This method will initiate a checkout session to be used by checkout.js
Latest session and order.id are stored in cart's meta
'meta' => [
'payment_intent' => `session`,
'order_id' => `order.id`,
],
This package only provide basic blade components to interact with MPGS,, publish the views to fit your storefront design
php artisan vendor:publish --tag="lunarphp-mpgs-views"
In the your checkout page
@mpgsScripts
@if ($paymentType == 'card')
<livewire:mpgs.payment :cart="$cart" />
@endif
The component will handle the success payment for you. To redirect or add handling after payment verified, set your route or listen to livewire event
// config/lunar-mpgs.php
'route' => [
'payment-success' => null,
'payment-failed' => null,
]
// livewire events
'mpgsPaymentSuccess'
'mpgsPaymentFailed'
- support capture/refund if applicable
- implement omnipay-mpgs adapter
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.