Reputation: 5007
I want to set the email address for the person buying the product. This is what I've got so far (as per the documentation):
$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();
}
As far as I can gather from the shitshow of documentation that Paypal put out, and from the many various pages from googling, I want to set the email address in the Payer() ($payer
) class - how do I do that?
Please help.
Upvotes: 1
Views: 616
Reputation: 7129
I think you're looking for PayerInfo, this should work:
$payerInfo = new \PayPal\Api\PayerInfo();
$payerInfo ->setEmail('[email protected]');
$payer = new \PayPal\Api\Payer();
$payer ->setPaymentMethod('paypal');
$payer ->setPayerInfo($payerInfo);
Upvotes: 2