How to use PayPal's Express In-Context Checkout with ReactJS?

前端 未结 1 688
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-10 08:49

I\'m following this PayPal tutorial about how to generate a PayPal button, but nothing works. The code it provides to make the button appear mysteriously worked only once fo

相关标签:
1条回答
  • 2020-12-10 09:26

    You could create your own PayPal Button component.

    class PayPalButton extends React.Component {
      constructor() {
        super();
        // you can take this value from a config.js module for example.
        this.merchantId = '6XF3MPZBZV6HU';
      }
    
      componentDidMount() {
        let container = this.props.id;
        let merchantId = this.merchantId;
        window.paypalCheckoutReady = function() {
          paypal.checkout.setup(merchantId, {
            locale: 'en_US',
            environment: 'sandbox',
            container: container,
          });
        }
      }
    
      render() {
        return(
          <a id={this.props.id} href="/checkout" />
        );
      }
    }
    
    ReactDOM.render(<PayPalButton id="button" />, document.getElementById('View'));
    

    Working example on JSFiddle.

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