1. Go to this page and download the library: Download hakhant/myanmar-payments 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/ */
hakhant / myanmar-payments example snippets
use Hakhant\Payments\Application\PaymentManager;
use Hakhant\Payments\Domain\Enums\Provider;
public function checkout(PaymentManager $payments)
{
$gateway = $payments->provider(Provider::KBZPAY);
// String values still work too:
// $gateway = $payments->provider('kbzpay');
}
use Hakhant\Payments\Application\PaymentManager;
use Hakhant\Payments\Domain\DTO\PaymentRequest;
use Hakhant\Payments\Domain\Enums\Provider;
public function checkout(PaymentManager $payments)
{
return $payments->createPayment(
new PaymentRequest(
merchantReference: 'INV-1001',
amount: 10000,
currency: 'MMK',
callbackUrl: 'https://example.com/payments/callback',
redirectUrl: 'https://example.com/payments/return',
),
Provider::KBZPAY,
);
}
if ($payments->supportsMmqr(Provider::AYA)) {
// Show MMQR option in the UI
}
use Hakhant\Payments\Application\PaymentManager;
use Hakhant\Payments\Domain\DTO\PaymentRequest;
use Hakhant\Payments\Domain\Enums\Provider;
public function checkout(PaymentManager $payments)
{
$response = $payments->provider(Provider::TWOC2P)->createPayment(
new PaymentRequest(
merchantReference: 'INV-1001',
amount: 10000,
currency: 'MMK',
callbackUrl: 'https://example.com/payments/callback',
redirectUrl: 'https://example.com/payments/return',
metadata: ['description' => 'Order INV-1001']
)
);
return redirect()->away((string) $response->paymentUrl);
}
use Hakhant\Payments\Application\PaymentManager;
use Hakhant\Payments\Domain\Enums\Provider;
public function status(string $transactionId, PaymentManager $payments): array
{
$response = $payments->queryStatus($transactionId, Provider::TWOC2P);
return [
'transaction_id' => $response->transactionId,
'status' => $response->status->value,
'provider' => $response->provider,
];
}
use Hakhant\Payments\Application\PaymentManager;
use Hakhant\Payments\Domain\DTO\RefundRequest;
use Hakhant\Payments\Domain\Enums\Provider;
public function refund(string $transactionId, PaymentManager $payments): array
{
$response = $payments->refund(new RefundRequest(
transactionId: $transactionId,
amount: 10000,
reason: 'Customer requested cancellation',
metadata: [
'refund_request_no' => 'REFUND-REQ-1001',
],
), Provider::KBZPAY);
return [
'refund_id' => $response->refundId,
'status' => $response->status->value,
];
}
use Hakhant\Payments\Application\PaymentManager;
use Hakhant\Payments\Domain\DTO\CallbackPayload;
use Hakhant\Payments\Domain\Enums\Provider;
use Illuminate\Http\Request;
public function webhook(Request $request, PaymentManager $payments)
{
$payload = new CallbackPayload(
payload: ['payload' => (string) $request->input('payload', '')],
signature: '',
timestamp: $request->integer('timestamp'),
);
$valid = $payments->verifyCallback($payload, Provider::TWOC2P);
abort_unless($valid, 401, 'Invalid signature');
return response()->json(['ok' => true]);
}
use Hakhant\Payments\Application\UseCases\CreateMmqr;
use Hakhant\Payments\Domain\DTO\MmqrRequest;
use Hakhant\Payments\Domain\Enums\Provider;
public function createMmqr(CreateMmqr $createMmqr): array
{
$response = $createMmqr->handle(new MmqrRequest(
merchantReference: 'MMQR-1001',
amount: 10000,
currency: 'MMK',
notifyUrl: 'https://example.com/payments/mmqr/callback',
metadata: ['invoice_no' => 'INV-1001'],
), Provider::AYA);
return [
'transaction_id' => $response->transactionId,
'status' => $response->status->value,
'qr_code' => $response->qrCode,
'qr_image' => $response->qrImage,
];
}
use Hakhant\Payments\Domain\DTO\PaymentRequest;
use Hakhant\Payments\Domain\Enums\Provider;
use Hakhant\Payments\Facades\MyanmarPayments;
$response = MyanmarPayments::createPayment(
new PaymentRequest(
merchantReference: 'INV-2001',
amount: 25000,
currency: 'MMK',
callbackUrl: 'https://example.com/payments/callback',
redirectUrl: 'https://example.com/payments/return'
),
Provider::KBZPAY,
);