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

BubbaLovesCheese

Active member
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
                    ],
                ],
            ],
 
Back
Top Bottom