The library offers easy access to Moneymour APIs
A composer package is available on Packagist
$ composer install moneymour/api-client-phpuseMoneymour\ApiClientasMoneymourApiClient;
class ApiClient {
// Get the following information from https://merchant.sandbox.moneymour.com// For production: https://merchant.moneymour.comconstPRIVATE_KEY = '<YOUR_PRIVATE_KEY>';
constMERCHANT_ID = '<YOUR_MERCHANT_ID>';
constMERCHANT_SECRET = '<YOUR_MERCHANT_SECRET>';
// Build the client$signatureFactory = newSignatureFactory(self::PRIVATE_KEY);$client = newMoneymourApiClient(
self::MERCHANT_ID,
self::MERCHANT_SECRET,
$signatureFactory,
MoneymourApiClient::ENVIRONMENT_SANDBOX// or ENVIRONMENT_PRODUCTION when you get ready
);
// Request payload$payload = [
'orderId' => '123456', // the order id in your system'amount' => '1080', // must be >= 300 and <= 2000'email' => 'customer@merchant.com',
'phoneNumber' => '+393334444555', // must include +39'products' => [ // the list of products in the cart
[
'name' => 'iPhone 7',
'type' => 'Electronics',
'price' => '500',
'quantity' => 2,
'discount' => 0
],
[
'name' => 'MacBook Pro Charger',
'type' => 'Electronics',
'price' => '80',
'quantity' => 1,
'discount' => 0
]
]
];
// Perform the request$response = $client->request($payload);
// Output example in JSON formatprint json_encode($res, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE) . "\n";
/* { "status": "accepted", "amount": 1080, "phoneNumber": "+393334444555", "orderId": "123456", "products": [ { "name": "iPhone 7", "type": "Electronics", "price": "500", "price": "2", "discount": 0 }, { "name": "MacBook Pro Charger", "type": "Electronics", "price": "80", "price": "1", "discount": 0 } ] } */
}Moneymour APIs allow only one pending request at a time. If you get a 403 error having message Duplicated request please cancel the current pending request using the Moneymour app for iOS or Android.
$factory = newSignatureFactory(self::PRIVATE_KEY);
$factory->verify(
$signature, // http request header "Signature"$expiresAt, // http request header "Expires-at"$body, // http request body
MoneymourApiClient::ENVIRONMENT_SANDBOX// or ENVIRONMENT_PRODUCTION when you get ready
); // return true or false