Question

My Request to Pay Script

  • 11 March 2024
  • 1 reply
  • 21 views

<?php
require 'vendor/autoload.php';

use FannyPack\Momo\Products\Collection;
// use FannyPack\Momo\Products\Disbursement;
// use FannyPack\Momo\Products\Remittance;

use Ramsey\Uuid\Uuid;


$xReferenceId = Uuid::uuid4()->toString();

$options = [
'callbackHost' => 'sandbox.momodeveloper.mtn.com',
'subscriptionKey' => 'mygenerated_subs_key',
'xReferenceId' => get_uuid(),
];
$options['baseUrl'] = 'https://sandbox.momodeveloper.mtn.com';
$product = Collection::create($options);
$product->createApiUser();
$apiKey = $product->createApiKey();

$options['apiKey'] = $apiKey->getApiKey();
$product = Collection::create($options);
$token = $product->getToken();
$options['accessToken'] = $token->getAccessToken();

$product = Collection::create($options);

// Example externalId generation
$externalId = Uuid::uuid4()->toString();
$product->requestToPay($xReferenceId, '46733123453', '1000', 'EUR', 'Payment for order #123', 'Thank you for shopping with us!');


function get_uuid()
{
return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),

// 16 bits for "time_mid"
mt_rand(0, 0xffff),

// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand(0, 0x0fff) | 0x4000,

// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand(0, 0x3fff) | 0x8000,

// 48 bits for "node"
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0xffff)
);
}


Here’s the error i’m getting 
I need help. Thank you in advance


1 reply

Userlevel 1
<?php
require 'vendor/autoload.php';

use FannyPack\Momo\Products\Collection;
// use FannyPack\Momo\Products\Disbursement;
// use FannyPack\Momo\Products\Remittance;

use Ramsey\Uuid\Uuid;


$xReferenceId = Uuid::uuid4()->toString();

$options = [
'callbackHost' => 'sandbox.momodeveloper.mtn.com',
'subscriptionKey' => 'mygenerated_subs_key',
'xReferenceId' => get_uuid(),
];
$options['baseUrl'] = 'https://sandbox.momodeveloper.mtn.com';
$product = Collection::create($options);
$product->createApiUser();
$apiKey = $product->createApiKey();

$options['apiKey'] = $apiKey->getApiKey();
$product = Collection::create($options);
$token = $product->getToken();
$options['accessToken'] = $token->getAccessToken();

$product = Collection::create($options);

// Example externalId generation
$externalId = Uuid::uuid4()->toString();
$product->requestToPay($xReferenceId, '46733123453', '1000', 'EUR', 'Payment for order #123', 'Thank you for shopping with us!');


function get_uuid()
{
return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),

// 16 bits for "time_mid"
mt_rand(0, 0xffff),

// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand(0, 0x0fff) | 0x4000,

// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand(0, 0x3fff) | 0x8000,

// 48 bits for "node"
mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0xffff)
);
}


Here’s the error i’m getting 
I need help. Thank you in advance

 

You can try below checks. 

1. Confirm token is actually generated.
2. Remove special characters in'Payment for order #123', 'Thank you for shopping with us!'
3. Callback URL must have protocol e.g http://test.api.com
4. Confirm your xReferenceId is a UUID version 4.

Reply