PayPal SDK:使用PayPal账户支付时没有服务器响应

问题描述:

我已经搜索了100次文档和this tutorial,但无法弄清楚如何使用PayPal账户而不是信用卡来完成支付过程。我已经获得了信用卡付款,没有问题。PayPal SDK:使用PayPal账户支付时没有服务器响应

在上述的教程,这是说,我应该想到做一个OAuth凭证后,从服务器的JSON响应:

$sdkConfig = array(
    "mode" => "sandbox" 
); 

$cred = new OAuthTokenCredential("clientID","clientSecret", $sdkConfig); 

我得到绝对尽管歌厅没有服务器响应“200 OK”来自服务器的状态。

起初我有我的代码中设置了像一堆其他教程:

$apiContext = new ApiContext(
     new OAuthTokenCredential(
       'clientID',  // ClientID 
       'clientSecret'  // ClientSecret 
     ) 
); 

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

$item1 = new Item(); 
$item1->setName("Donation squares."); 
$item1->setCurrency('USD'); 
$item1->setQuantity(1); 
$item1->setPrice(1); 

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

$amountDetails = new Details(); 
$amountDetails->setSubtotal('7.41'); 
$amountDetails->setTax('0.03'); 
$amountDetails->setShipping('0.03'); 

$amount = new Amount(); 
$amount->setCurrency('USD'); 
$amount->setTotal('7.47'); 
$amount->setDetails($amountDetails); 

$transaction = new Transaction(); 
$transaction->setAmount($amount); 
$transaction->setDescription('This is the payment transaction description.'); 

$redirectUrls = new RedirectUrls(); 
$redirectUrls->setReturnUrl("https://devtools-paypal.com/guide/pay_paypal/php?success=true"); 
$redirectUrls->setCancelUrl("https://devtools-paypal.com/guide/pay_paypal/php?cancel=true"); 

$payment = new Payment(); 
$payment->setIntent('sale'); 
$payment->setPayer($payer); 
$payment->setRedirectUrls($redirectUrls); 
$payment->setTransactions(array($transaction)); 

try{ 
    $payment->create($apiContext); 
} catch(Exception $e){ 
    echo $e 
    exit(1); 
} 

这一切都不作品无论是 - 没有任何来自服务器的响应。

回答/评论 你不应该在寻找JSON响应。如果付款成功创建,则应通过运行生成批准网址

$payment->getApprovalLink(); 

用户然后按照此链接完成他/她的付款。

您可能有兴趣在PayPal-PHP-SDK中关注非常simple instruction,它解释how to make calls using PayPal PHP SDK。我知道你已经经历了这个,并且正在寻找如何使用PayPal创建付款。

我不确定你是否知道这一点,但PayPal-PHP-SDK附带很多samples,你可以运行just one simple command(如果你有PHP 5.4或更高版本)。第一个样本中的一个具有用于进行PayPal呼叫的说明和代码。

有两个步骤涉及到。

  1. 创建一项付款。收到一个approval_url链接,用于要求用户通过任何浏览器完成PayPal流程。

  2. 一旦用户在PayPal网站上接受付款,它将被重定向回您的网站,在那里执行付款。

这两个代码样本都提供herehere

让我知道这是否有帮助,并且您还有其他问题。我会很乐意提供帮助。

enter image description here

+0

@ JAY-特尔 - 贝宝我得到PHP致命错误:类 'ResultPrinter' 未找到(因为添加的代码示例)。仅供参考,我通过作曲家安装了这个软件,并使用require __DIR__。 '/../vendor/autoload.php';在文件顶部 – Ravioli87 2015-04-01 20:23:35

+0

这是正确的。您可以删除结果打印机行,因为它仅用于样本。用您选择的任何回声声明替换它。 – 2015-04-01 20:37:52