我是支付集成的新手。我需要在我的php页面集成MasterCard支付网关服务。我有一个用于PAY的按钮,一旦点击,我就会重定向到下面的页面。我有以下代码:
<script type="text/javascript">
function errorCallback(error) {
console.log(JSON.stringify(error));
}
function cancelCallback() {
console.log('Payment cancelled');
}
Checkout.configure({
merchant: 'test001000000052',
order: {
amount: 100,
currency: 'AED',
description: 'Ordered goods',
id: '123'
},
interaction: {
merchant: {
name: 'test',
address: {
line1: '200 Sample St',
line2: '1234 Example Town'
},
cancelUrl:'10.0.1.100/?load=parents/online_payment'
}
}
});
</script>
</head>
<body>
<input type="button" value="Pay with Lightbox" onclick="Checkout.showLightbox();" />
<input type="button" value="Pay with Payment Page" onclick="Checkout.showPaymentPage();" />
</body>
当我单击任一按钮时,我在控制台中得到以下错误消息。
XHR failed loading: POST "https://eu-gateway.mastercard.com/api/page/version/51/pay".
{"cause":"INVALID_REQUEST","explanation":"Invalid credentials."}我正确地使用了merchantID,可能是我漏掉了什么。我随身带着用户名和密码,不知道在哪里添加这些参数。请帮帮我
发布于 2021-01-13 02:29:48
您应该创建一个会话,然后打开结帐页面或lightbox
创建会话变量
$session_request = [
'apiOperation' => "CREATE_CHECKOUT_SESSION",
'interaction' => [
'operation' => "PURCHASE",
'returnUrl' => "<return url>",
],
'order' => [
'amount' => <amount>,
'currency' => '<Currency Code like USD>',
'description' => 'Full Payment',
'id' => <transaction reference>,
],
'userId' => <customer ID>,
];调用以下函数将会话数据发送到万事达卡服务器
/**
* @param $inputs
* @param $link
* @param $username
* @param $password
* @param string $type
*
* @return \Exception|\GuzzleHttp\Exception\ClientException|\GuzzleHttp\Exception\RequestException|mixed|string
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public static function postJsonRequestWithToken( $inputs, $link, $username, $password, $type = "assoc" ) {
try {
$client = new Client();
$response = $client->post( $link, [
'body' => json_encode( $inputs ),
'auth' => [
$username,
$password,
],
] );
$statusCode = $response->getStatusCode();
$body = $response->getBody()->getContents();
if ( $type == 'json' ) {
return $body;
}
if ( $type == 'object' ) {
return json_decode( $body );
}
if ( $type == 'assoc' ) {
return json_decode( $body, true );
}
return json_decode( $body );
} catch( ClientException $e ) {
//return json_decode( $e->getResponse()->getBody(), true );
return $e;
} catch( RequestException $e ) {
//return json_decode( $e->getResponse()->getBody(), true );
return $e;
}
/*} catch( RequestException $e ) {
echo Psr7\str($e->getRequest());
if ($e->hasResponse()) {
echo Psr7\str($e->getResponse());
}
}*/
}发布于 2020-04-29 20:59:07
有两种情况1.当您收到商家ID时。他们应该已经共享了一个文档链接,请参阅该链接。大多数情况下,checkout.js文件路径是错误的。2.在进行API调用时需要进行基本的用户身份验证,并传入用户名和密码。您可以从管理面板生成密码
发布于 2021-06-09 07:11:35
static public function initPaymentSession($amount,$orderID,$description,$currency = 'EGP')
{
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://banquemisr.gateway.mastercard.com/api/nvp/version/60');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "apiOperation=CREATE_CHECKOUT_SESSION&apiPassword=xxxxxxxxxxxxxxx&apiUsername=merchant.xxxxxxxxx&merchant=xxxxxxxxx&interaction.operation=PURCHASE&order.id=$orderID&order.amount=$amount&order.currency=EGP");
$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);
}
if (curl_errno($ch)) {
return 'Error:' . curl_error($ch);
}
curl_close($ch);
if ($result){
$res1 = explode('&session.id=', $result);
$res2 = explode('&', $res1[1]);
return $res2[0];
}
}https://stackoverflow.com/questions/55007085
复制相似问题