1. Go to this page and download the library: Download myanmyanpay/mmpay-php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use MMPay\MMPay;
class PaymentWebhookController extends Controller
{
public function handle(Request $request)
{
$mmpayx = new MMPay([
'appId' => config('services.mmpay.app_id'),
'publishableKey' => config('services.mmpay.publish_key'),
'secretKey' => config('services.mmpay.secret_key'),
'apiBaseUrl' => 'https://api.myanmyanpay.com'
]);
$mmpayx->onTxCreate(function ($tx) {
\Log::info("Payment Created for order: " . $tx['orderId']);
// Verify Source of truth here if you are using browser mmpayx showPaymentModal()
});
// Attach listeners
$mmpayx->onTxSuccess(function ($tx) {
// Update your database order status here
\Log::info("Payment Successful for order: " . $tx['orderId']);
});
$mmpayx->onTxFail(function ($tx) {
\Log::error("Payment Failed for order: " . $tx['orderId']);
});
$mmpayx->onTxCancel(function ($tx) {
\Log::info("Payment Cancelled for order: " . $tx['orderId']);
});
$mmpayx->onTxExpire(function ($tx) {
\Log::info("Payment Expired for order: " . $tx['orderId']);
});
$mmpayx->onHeartbeat(function ($tx) {
\Log::info("Already Sent Event Coming in Again: " . $tx['orderId']);
});
// Get headers and raw body
$nonce = $request->header('X-Mmpay-Nonce');
$signature = $request->header('X-Mmpay-Signature');
$payload = $request->getContent();
// Listen triggers the events
$mmpayx->listen($payload, $nonce, $signature);
return response()->json(['received' => true], 200);
}
}
try {
$sdk->pay($params);
} catch (\Exception $e) {
// Log the error for debugging
error_log($e->getMessage());
// Return a user-friendly message
echo "We could not process your payment at this time.";
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.