is it possible to get buyer's address while using PayPal's Checkout PHP SDK?
anysoll
Contributor
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
Jun-28-2022
05:20 AM
I have this code for processing PayPal payments on my website :
$environment = new \PayPalCheckoutSdk\Core\SandboxEnvironment(PAYPAL_ID, PAYPAL_SECRET); $client = new \PayPalCheckoutSdk\Core\PayPalHttpClient($environment); $authorizationId = $_POST['authorizationId']; $request = new \PayPalCheckoutSdk\Payments\AuthorizationsGetRequest($authorizationId); $authorizationResponse = $client->execute($request); $orderId = $authorizationResponse->result->supplementary_data->related_ids->order_id; $request = new OrdersGetRequest($orderId); $orderResponse = $client->execute($request); var_dump($orderResponse->result->payer->address);
When I var_dump the address sdtObject I get only this
public 'address' => object(stdClass)[74] public 'country_code' => string 'FR' (length=2)
I am trying to get the buyer's shipping information after completing the order to store their address in my database because they are buying as a "guest".
That happens even when you pay with Card option of PayPal although they ask you to put in your shipping address.
The order is created like this
$order = json_encode([ 'purchase_units' => [ [ 'description' => 'some desc...', 'items' => array_map(function ($product) { return [ 'name' => $product['name'] . " (n°" . $product['num'] . " | " . strtoupper($product['language']) . ")", 'quantity' => $_SESSION['cart'][$product['id']], 'unit_amount' => [ 'value' => number_format((float)$product['price'], 2, '.', ''), 'currency_code' => 'USD', ] ]; }, $products), 'amount' => [ 'currency_code' => 'USD', 'value' => $total > 200 ? $total : $total + 8, 'breakdown' => [ 'item_total' => [ 'currency_code' => 'USD', 'value' => $total ], 'shipping' => [ 'currency_code' => 'USD', 'value' => $total > 200 ? '0.00' : '8.00', ] ] ] ] ] ]);
And is then passed like this to the PayPal's JS SDK :
paypal.Buttons({ createOrder: (data, actions) => { return actions.order.create(<?= $order; ?>); }, onApprove: async (data, actions) => { const authorization = await actions.order.authorize() const authorizationId = authorization.purchase_units[0].payments.authorizations[0].id const response = await fetch('<?= base_url('cart/process'); ?>', { method: 'post', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ authorizationId }) }) let responseText = await response.text(); $('.site-content').html(responseText); }, onCancel: function(data, actions) { alert("Order cancelled successfully!"); }, onError: function(err) { console.log(err); } }).render('#paypal-button-container');
The intent of the order which is created is authorize
Can someone help me ?
Labels:
- Labels:
-
REST SDK
0 REPLIES 0

Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
Related Content
- where does paypal payments go to if there is no linked phone or email to the seller ? in PayPal Payments Standard
- Is it possible to make payments in RON (Romanian Leu) through PayPal? in REST APIs
- My PayPal is not allowing me to receive or send requests. in PayPal Payments Standard
- "System error. Please try again later" when connecting to paypal sandbox account with my android app in Sandbox Environment
- [WooCommerce PayPal Payments] - Required phone country code, different than the cards country code. in PayPal Payments Standard