I am trying to integrate the hosted checkout with MasterCard.
guide:
https://ap-gateway.mastercard.com/api/documentation/integrationGuidelines/index.html?locale=en_US
after complete ACS Emulator page, It's return "Your transactions was unsuccessful" error.
How can I fix this error?
<?php
$orderid = "13441568";
$merchant = "XXXXX";
$apipassword = "XXXXX";
$returnUrl = "http://localhost/mpgs";
$currency = "USD";
$amount ="10.00";
$apiUsername= "merchant.xxx";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://test-gateway.mastercard.com/api/nvp/version/51");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "apiOperation=CREATE_CHECKOUT_SESSION&apiPassword=$apipassword&interaction.returnUrl=$returnUrl&apiUsername=$apiUsername&merchant=$merchant&order.id=$orderid&order.amount=$amount&order.currency=$currency");
$headers = array();
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if(curl_errno($ch)) {
echo 'ERROR:'. curl_error($ch);
}
curl_close($ch);
$sessionid = explode("=", explode("&", $result)[2])[1];
?>
<script
src="https://test-gateway.mastercard.com/checkout/version/51/checkout.js"
data-error="errorCallback"
data-cancel="http://localhost/mpgs"
></script>
<script type="text/javascript">
function errorCallback() {
alert("Error: "+ JSON.stringify(error));
window.location.href = "http://localhost/mpgs";
}
Checkout.configure({
merchant: '<?php echo $merchant ?>',
order: {
amount: function () {
return <?php echo $amount ?>;
},
currency: '<?php echo $currency ?>',
description: 'Order Goods',
id: '<?php echo $orderid ?>'
},
interaction: {
merchant: {
name: "XXX",
address: {
line1: '',
line2: ''
}
}
},
session: {
id: '<?php echo $sessionid ?>'
}
});
Checkout.showPaymentPage();
</script>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…