Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

MasterCard payment with php

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?

enter image description here

<?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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try to use this card: Mastercard 5123450000000008 use any 3gisit from cvv , and any valid expire date


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...