【问题标题】:Paypal PHP API SDK - Set Email Address for person purchasingPaypal PHP API SDK - 为购买人设置电子邮件地址
【发布时间】:2018-12-11 18:14:37
【问题描述】:

我想为购买产品的人设置电子邮件地址。这是我到目前为止所得到的(根据文档):

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

$amount = new \PayPal\Api\Amount();
$amount->setTotal($order['totals']['grand']);
$amount->setCurrency('GBP');

$itemList = new \PayPal\Api\ItemList();

$shipping_address = new \PayPal\Api\ShippingAddress();
$shipping_address->setRecipientName($order['shipping']['name']);
$shipping_address->setLine1($order['billing']['add1']);
$shipping_address->setLine2($order['billing']['add2']);
$shipping_address->setCity($order['shipping']['add3']);
$shipping_address->setPostalCode($order['shipping']['postcode']);
$shipping_address->setCountryCode(countryData($order['shipping']['countryID'],"code"));
$shipping_address->setPhone($order['shipping']['telephone']);
$itemList->setShippingAddress($shipping_address);

$transaction = new \PayPal\Api\Transaction();
$transaction->setAmount($amount)->setItemList($itemList);

$redirectUrls = new \PayPal\Api\RedirectUrls();
$redirectUrls   ->setReturnUrl("https://example.com/shop/thank-you/")
                ->setCancelUrl("https://example.com/shop/cancelled/");

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

try {
    $payment->create($apiContext);
    predump(json_decode($payment));

    echo "\n\n<a href='".$payment->getApprovalLink()."'>Redirect user to approval_url</a>\n";
}
catch (\PayPal\Exception\PayPalConnectionException $ex) {
    // This will print the detailed information on the exception.
    //REALLY HELPFUL FOR DEBUGGING
    echo $ex->getData();
}

据我从 Paypal 发布的大量文档以及谷歌搜索的许多不同页面中收集到的信息,我想在 Payer() ($payer) 类中设置电子邮件地址 - 我该怎么做这样做?

请帮忙。

【问题讨论】:

    标签: php api paypal sdk


    【解决方案1】:

    我认为您正在寻找PayerInfo,这应该可以:

    $payerInfo = new \PayPal\Api\PayerInfo();
    $payerInfo ->setEmail('example@email.com');
    
    $payer = new \PayPal\Api\Payer();
    $payer  ->setPaymentMethod('paypal');
    $payer ->setPayerInfo($payerInfo);
    

    【讨论】:

    • 谢谢。无论我搜索什么,我都无法在任何地方找到它。我知道这也很容易!我讨厌他们的文档哈哈。
    • 是的,我记得当我不得不在 C# 中实现它时的痛苦!不客气:)
    猜你喜欢
    • 1970-01-01
    • 2016-10-04
    • 2017-06-18
    • 2014-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    相关资源
    最近更新 更多