Luehang / react-paypal-button-v2

An easy and simple to use React button component to implement PayPal Checkout with Smart Payment Buttons V2 (Version 2).
https://luehangs.site/lue_hang/projects/react-paypal-button-v2
MIT License
274 stars 81 forks source link

For subscription use case, address shows up even when shippingPreference="NO_SHIPPING" specified #91

Open yxwu opened 3 years ago

yxwu commented 3 years ago

Seems shippingPreference="NO_SHIPPING" doesn't work for subscription case, screenshot attached.

Screen Shot 2020-12-12 at 1 44 08 AM

faceyoga-dev commented 3 years ago

I am getting the same behaviour. For now, I am hoping that this is only in sandbox.

Furthermore, NO_SHIPPING is the implicit default for that prop... According to docs we don't even have to specify that prop.

nanukn commented 3 years ago

This is working for us:

        return actions.subscription.create({
            'plan_id': <plan_id>,
            application_context: {
                shipping_preference: 'NO_SHIPPING'
            }
        });
    };

or if you are using the example:

import { PayPalButton } from "react-paypal-button-v2";

export default class Example Component {
  render() {
    return (
      <PayPalButton
        options={{vault: true}}
        createSubscription={(data, actions) => {
          return actions.subscription.create({
            plan_id: 'P-XXXXXXXXXXXXXXXXXXXXXXXX',
            application_context: {
                shipping_preference: 'NO_SHIPPING'
            }
          });
        }}
        onApprove={(data, actions) => {
          // Capture the funds from the transaction
          return actions.subscription.get().then(function(details) {
            // Show a success message to your buyer
            alert("Subscription completed");

            // OPTIONAL: Call your server to save the subscription
            return fetch("/paypal-subscription-complete", {
              method: "post",
              body: JSON.stringify({
                orderID: data.orderID,
                subscriptionID: data.subscriptionID
              })
            });
          });
        }}
      />
    );
  }
}