-1
我已使用以下休息腳本將信用卡添加到保險庫中。如何在不使用PNREF(網關令牌)的情況下使用PayPal付費流程的信用卡進行支付?
如何使用此信用卡在magento結帳頁面上進行付款?
$clientId="XXXXXXXXXXXXXXXXXXXXX";
$secret='XXXXXXXXXXXXXXXXXXXXXXX';
$ipnexec = curl_init();
curl_setopt($ipnexec, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token"); // test url
curl_setopt($ipnexec, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ipnexec, CURLOPT_POST, true);
curl_setopt($ipnexec, CURLOPT_USERPWD, $clientId.":".$secret);
curl_setopt($ipnexec, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
//curl_setopt($ipnexec, CURLOPT_POSTFIELDS, $req);
//curl_setopt($ipnexec, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ipnexec, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ipnexec, CURLOPT_TIMEOUT, 30);
$ipnresult = curl_exec($ipnexec);
$result = json_decode($ipnresult);
if(!isset($result->access_token))
{
$this->messageManager->addErrorMessage(
__('Invalid Card data, please try again!')
);
return $this->_redirect('vault/cards/listaction');
}
//print_r($result);
//die;
//echo "<pre>";
$access_token = $result->access_token;
//die($access_token);
//print_r($result->access_token);
//$token_type = $result->token_type;
curl_close($ipnexec);
$scope = "https://api.sandbox.paypal.com/v1/vault/credit-cards";
$ch = curl_init();
//curl_setopt($ch, CURLOPT_HTTPHEADER, 1);
$data = '
{
"external_customer_id":"'.$customer_id.'",
"external_card_id":"'.$external_card_id.'",
"payer_id":"'.$payer_id.'",
"type":"visa",
"cvv2" : "'.$cvv2.'",
"number":"'.str_replace(" ","",$number).'",
"expire_month":"'.$expire_month.'",
"expire_year":"'.$expire_year.'",
"first_name":"'.$first_name.'",
"last_name":"'.$last_name.'"
}
';
curl_setopt($ch, CURLOPT_URL,$scope);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:
application/json","Authorization: Bearer ".$access_token));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
if(empty($result))die("Error: No response.");
else
{
$json = json_decode($result);
//echo "<pre>";
//print_r($json);
//die;
if(!isset($json->payer_id))
{
$this->messageManager->addErrorMessage(
__('Invalid Card data, please try again!')
);
return $this->_redirect('vault/cards/listaction');
}
}
curl_close($ch);
請解決您的問題,你的代碼是不明確的。 –