How to solve this error "cause":"INVALID_REQUEST","explanation":"Invalid request" in mastercard payment gateway (mpgs)

5.6k views Asked by At

I am trying to integrate my site with mastercard gateway payment (mpgs) , i follow up the documentation , i select the Hosted Checkout method, see the documentation from here

I request a checkout session by this code :

$orderid = $_POST['order_id'];
$merchant = $_POST['merchant']; //       
$apiPassword = $_POST['api_password'];//           
$amount=$_POST['amount'];
$currency=$_POST['currency'];

$ch = curl_init();  
curl_setopt($ch, CURLOPT_URL, "https://test-gateway.mastercard.com/api/nvp/version/58");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST , 1);
curl_setopt($ch, CURLOPT_POSTFIELDS , 
"apiOperation=CREATE_CHECKOUT_SESSION&apiPassword=$apiPassword&apiUsername=merchant.$merchant&merchant=$merchant&interaction.operation=AUTHORIZE&order.id=$orderid&order.amount=$amount&order.currency=$currency");

$arr = array('sessionid' => $sessionid);

echo json_encode($arr);

And this request is works very well and get the sessionid successfully,

But when execute this checkout code, the error appear in JavaScript console like this : {"cause":"INVALID_REQUEST","explanation":"Invalid request","supportCode":"PVIRB4OXUZI6G","result":"ERROR"}

And here is the code:

                 Checkout.configure({
                  merchant: $("#merchant").val(),
                  order:{
                      amount: function(){
                        return $("#amount").val(); 
                      },
                      currency: $("#currency").val(),
                      description: $("#order_description").val(),
                      id: $("#order_id").val()
                  },
                  session: { 
                    id: sessionid
                    },
                  interaction: {
                        merchant: {
                            name:  $("#merchant").val(),
                            address: {
                                line1:  $("#address1").val(),
                                line2:  $("#address2").val()           
                            }    
                        }
                   }
                });
Checkout.showLightbox();
  • I am sure that the amount,currency and orderId are the same in the two requests.
  • I have checked out this question in stackoverflow too (here), but did not find the solution .
  • I am sure that the apiPassword is correct because the sessionid return successfully from the first request

And to start the payment process i am calling : Checkout.showLightbox();

and the pop up should be appear but unfortunately it does not appear.

Any Help Please ?

1

There are 1 answers

1
Ali Abu Harb On BEST ANSWER

I solved the problem , the problem was due to this link :

https://test-gateway.mastercard.com/api/nvp/version/58"

YOH should ask your bank to provide you with merchant administration portal and link.

in my case the link is :

https://test-bop.mtf.gateway.mastercard.com/api/nvp/version/58"