Warning: Undefined array key "action" in /www/wwwroot/mpay.onemiracles.com/examples/index.php on line 19

Warning: Undefined array key "action" in /www/wwwroot/mpay.onemiracles.com/examples/index.php on line 48

Warning: Undefined array key "action" in /www/wwwroot/mpay.onemiracles.com/examples/index.php on line 67
M Pay SDK Example - ຕົວຢ່າງການນຳໃຊ້

M Pay SDK Examples

ຕົວຢ່າງການນຳໃຊ້ M Pay SDK ສຳລັບ PHP ແລະ JavaScript

1. PHP SDK - ສ້າງການຊຳລະເງິນ

PHP Code:
$payment = $mpay->createPayment([
  'amount' => 50000,
  'currency' => 'LAK',
  'reference' => 'ORDER_001',
  'description' => 'ຊື້ສິນຄ້າຈາກຮ້ານ ABC'
]);

2. JavaScript SDK - ສ້າງການຊຳລະເງິນ (Frontend)

JavaScript Code:
const mpay = new MPayJS({ publicKey: 'pk_test_xxx', sandbox: true });
mpay.createPayment({
  amount: 25000,
  currency: 'LAK',
  reference: 'ORDER_002',
  description: 'ຊື້ອາຫານອອນລາຍ'
});

3. ກວດສອບສະຖານະການຊຳລະເງິນ

4. Webhook Integration

ຕົວຢ່າງການຈັດການ Webhook ເພື່ອຮັບແຈ້ງເຕືອນການຊຳລະເງິນ:

Webhook URL: https://yoursite.com/webhook

PHP Code:
$webhookData = json_decode(file_get_contents('php://input'), true);
if ($mpay->verifyWebhookSignature($webhookData, $_SERVER['HTTP_X_MPAY_SIGNATURE'])) {
  // ປັບປຸງສະຖານະການສັ່ງຊື້
  if ($webhookData['event'] === 'payment.completed') {
    // ອັບເດດສະຖານະເປັນ "ຊຳລະແລ້ວ"
  }
}
ຫມາຍເຫດ: ໃນການນຳໃຊ້ແທ້ຈິງ, ທ່ານຕ້ອງໃສ່ Merchant ID, API Key ແລະ Secret Key ທີ່ຖືກຕ້ອງ