Paypal付款执行

时间:2016-02-28 11:28:13

标签: php laravel paypal paypal-sandbox paypal-rest-sdk

我正在使用信用卡创建PayPal应用程序。它正在以批准的状态成功创建付款。

$addr = new Address();
$addr->setLine1($street);
$addr->setCity($city);
$addr->setPostalCode(zip);
$addr->setState($state);
$addr->setCountryCode($code);

$card = new CreditCard();
$card->setNumber($number);
$card->setType($type);
$card->setExpireMonth($m);
$card->setExpireYear($y);
$card->setCvv2($cvv);
$card->setFirstName($fname);
$card->setLastName($lname);
$card->setBillingAddress($addr);

$fi = new FundingInstrument();
$fi->setCreditCard($card);

$payer = new Payer();
$payer->setPaymentMethod('credit_card');
$payer->setFundingInstruments(array($fi));

$amountDetails = new Details();
$amountDetails->setSubtotal('100');
$amountDetails->setTax('10');
$amountDetails->setShipping('10');

$amount = new Amount();
$amount->setCurrency('JPY');
$amount->setTotal('120');
$amount->setDetails($amountDetails);

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

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

$payment->create($this->_api_context);

现在我正在尝试执行此付款以完成交易,但我无法找到付款人ID。这个付款人ID是什么?我从哪里得到它?

$payer_id = ?;
$paymentExecution = new PaymentExecution();
$paymentExecution->setPayerId($payer_id);
$payment->execute($paymentExecution, $this->_api_context);

2 个答案:

答案 0 :(得分:1)

您将从“创建付款”的返回网址(GET方法)获得 payer_id 。查看Paypal REST API Reference了解更多详情

答案 1 :(得分:1)

信用卡付款是一个步骤,在此过程中付款 $payment->execute($paymentExecution, $this->_api_context);已获批准。

因此不需要执行步骤(var myVar = "my info"; var myVar2 = "my other info"; $.post("myscript.php", { info1: myVar, info2: myVar2 }, function(answer) { // answer will contain whatever the PHP script printed // in this example answer will be "success" alert(answer); } ); )。此外,在这种情况下,我们不需要付款人ID。