2017-07-30 59 views
0

我跟着官方說明:https://www.paypalobjects.com/digitalassets/c/website/marketing/emea/de/de/paypal-plus-center/PayPal_PLUS_integration_guide.pdf如何獲得PayPal Plus集成的approvalURL?

08.整合的PayPal PLUS

並呈現支付牆必須 創建付款資源。相應的API調用是「創建支付」。當創建付款資源數量爲 時,必須提交貨幣和物品詳細信息 。

..好吧。理解。所以我需要創建一個付款,抓取Url,然後我可以最終呈現PayPalPlus-Object。

我跟着https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/payments/CreatePaymentUsingPayPal.php作爲示例腳本和一個例子。但我無法收到任何$ payment-> getApprovalLink()

我完全錯了嗎?

哪個示例可以用來創建付款並呈現PayPal +的東西?

回答

0
<?php 
require '../vendor/autoload.php'; 
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'xxx',  // ClientID 
'xxx'  // ClientSecret 
) 
); 

$apiContext->setConfig(
array(
'mode' => 'sandbox' 
) 
); 

$item1 = new \PayPal\Api\Item(); 
$item1->setName('Test item') 
->setCurrency('USD') 
->setQuantity(1) 
->setPrice(1); 

$itemList = new \PayPal\Api\ItemList(); 
$itemList->setItems(array($item1)); 

$payer = new \PayPal\Api\Payer(); 
$payer->setPaymentMethod('paypal'); 

$amount = new \PayPal\Api\Amount(); 
$amount->setCurrency('USD'); 
$amount->setTotal('1'); 

$transaction = new \PayPal\Api\Transaction(); 
$transaction->setAmount($amount); 
$transaction->setItemList($itemList); 
//$transaction->setInvoiceNumber(uniqid()); 
//$transaction->setDescription('Description'); 

$redirectUrl = new \PayPal\Api\RedirectUrls(); 
$redirectUrl->setReturnUrl('http://localhost'); 
$redirectUrl->setCancelUrl('http://localhost'); 

$payment = new \PayPal\Api\Payment(); 
$payment->setIntent('sale'); 
$payment->setPayer($payer); 
$payment->setRedirectUrls($redirectUrl); 
$payment->setTransactions(array($transaction)); 

$payment = $payment->create($apiContext); 

$approvalUrl = $payment->getApprovalLink(); 

echo $approvalUrl;