XF 2.3 This is how to prevent Paypal asking for a shipping address via REST API

BubbaLovesCheese

Active member
Licensed customer
If you only sell User Upgrades, and you do NOT sell physical items, then you can prevent the newest Paypal Rest API from asking for a shipping address.

Just add this code 'shipping_preference' => 'NO_SHIPPING' just after Line 237 in your /src/XF/Payment/PayPalRest.php file on your server.

PHP:
protected function getSubscriptionParams(string $planId, PurchaseRequest $purchaseRequest, Purchase $purchase): array
{
    return [
        'plan_id' => $planId,
        'quantity' => '1',
        'custom_id' => $purchaseRequest->request_key,
        'application_context' => [
            'return_url' => $purchase->returnUrl,
            'cancel_url' => $purchase->cancelUrl,
            'shipping_preference' => 'NO_SHIPPING', // Prevents Paypal asking for shipping address. Add to line 238
        ],
    ];
}
 
Update. Sorry, the above works for removing address when you have subscription.... and the code below works for removing addresses for 1-time purchases.

I use BOTH in my code.

Just add this code 'shipping_preference' = 'NO_SHIPPING' just around Line 264

PHP:
            'payment_source' => [
                'paypal' => [
                    'experience_context' => [
                        'payment_method_preference' => 'IMMEDIATE_PAYMENT_REQUIRED',
                        'user_action' => 'PAY_NOW',
                        'return_url' => $purchase->returnUrl,
                        'cancel_url' => $purchase->cancelUrl,
                        'shipping_preference' => 'NO_SHIPPING',    // Prevents PayPal from requesting a shipping address for 1-time purchases
                    ],
                ],
            ],
 
Hi all, just to touch base on this again. I have recently set up PayPal REST on my site to take over from PayPal legacy. It is now asking everyone for a shipping address and is giving me alerts when I log in to PayPal to ship the items. Does the above need redoing every time we update XenForo?

Have XenForo addressed this issue within the admin UI and I can't find it?

Thank you in advance! G.
 
Back
Top Bottom