贝宝支付执行

Paypal Payment Execution

我正在使用信用卡创建一个 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);

您将从 "Create a payment" 的 return URL(GET 方法)获得 payer_id。查看 Paypal REST API Reference 了解更多详情

信用卡付款是一步过程,付款时 $payment->create($this->_api_context); 已获批准。

所以不需要执行步骤($payment->execute($paymentExecution, $this->_api_context);)。此外,在这种情况下我们不需要付款人 ID。