PayPal React shows extra buttons after changing amount

后端 未结 1 569
我在风中等你
我在风中等你 2021-01-28 15:39

WITHOUT react-paypal-button-v2 ~~~has an ovehead of 60KB

Similar question here but they suggest react-paypal-button-v2

I\'m Tryin

相关标签:
1条回答
  • 2021-01-28 16:34

    Something like:

    useEffect(() => {
        if(window.myButton) window.myButton.close();
        window.myButton = window.paypal
          .Buttons({
            createOrder: (data, actions) => {
              return actions.order.create({
                purchase_units: [
                  {
                    description: "test",
                    amount: {
                      currency_code: "USD",
                      value: props.price
                    }
                  }
                ]
              });
            },
            onApprove: async (data, actions) => {
              const order = await actions.order.capture();
              console.log(order);
            },
            onError: err => {
              setError(err);
              console.error(err);
            }
          });
        window.myButton.render(paypalRef.current);
    

    However, you do not actually need to re-render the button on price change!

    You can do value: document.getElementById('...').value or similar (whatever function call you need)

    0 讨论(0)
提交回复
热议问题