wychoong / lunarphp-mpgs
MPGS payment adapter for Lunar
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.5
- illuminate/contracts: ^9.0 | ^10.0
- illuminate/support: ^9.0 | ^10.0
- livewire/livewire: ^2.0
- lunarphp/core: ^0.3.0-alpha.2
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
This package is auto-updated.
Last update: 2024-11-09 06:21:56 UTC
README
MPGS Hosted checkout integration for Lunar
Supported action
- purchase
Not supported (PR welcome)
- refund
- authorize/capture
Installation
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"
Enable the driver
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=
Setup
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', ] ] ]; });
Backend Usage
Creating a PaymentIntent
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`, ],
Storefront Usage
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"
Set up the scripts and payment component
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'
Roadmap
- support capture/refund if applicable
- implement omnipay-mpgs adapter
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.