2017-04-05 45 views
-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); 
+0

請解決您的問題,你的代碼是不明確的。 –

回答

1

如果您使用REST API將信用卡數據保存到Vault中,要執行付款,您需要使用REST API。 Magento有不同的設置。

如果要使用保管庫,您需要使用下面的例子

curl -v https://api.sandbox.paypal.com/v1/payments/payment \ 
 
-H "Content-Type:application/json" \ 
 
-H "Authorization: Bearer Access-Token" \ 
 
-d '{ 
 
    "id":"CPPAY-13U467758H032001PKPIFQZI", 
 
    "intent":"sale", 
 
    "payer":{ 
 
    "payment_method":"credit_card", 
 
    "funding_instruments":[ 
 
     { 
 
     "credit_card_token":{ 
 
      "credit_card_id":"CARD-1MD19612EW4364010KGFNJQI", 
 
      "external_customer_id":"joe_shopper408-334-8890" 
 
     } 
 
     } 
 
    ] 
 
    }, 
 
    "transactions":[ 
 
    { 
 
     "amount":{ 
 
     "total":"6.70", 
 
     "currency":"USD" 
 
     }, 
 
     "description":"Payment by vaulted credit card." 
 
    } 
 
    ] 
 
}'

相關問題