用 React 替换 javascript Paypal 按钮 .render() 调用

问题描述 投票:0回答:0

我可以使用此代码制作基于 javascript 的贝宝购买按钮(未显示 API 密钥

src
变量)

paypal.Buttons().render('#paypal-button-container');
  paypal.Buttons({
    createOrder: function (data, actions) {
      // This function sets up the details of the transaction, including the amount and line item details.
      return actions.order.create({
        purchase_units: [{
          amount: {
            value: '0.01'
          }
        }]
      });
    }
  }).render('#paypal-button-container');
  paypal.Buttons({
    createOrder: function (data, actions) {
      // This function sets up the details of the transaction, including the amount and line item details.
      return actions.order.create({
        purchase_units: [{
          amount: {
            value: '0.01'
          }
        }]
      });
    },
    onApprove: function (data, actions) {
      // This function captures the funds from the transaction.
      return actions.order.capture().then(function (details) {
        // This function shows a transaction success message to your buyer.
        alert('Transaction completed by ' + details.payer.name.given_name);
      });
    }
  }).render('#paypal-button-container');

我想使用 React 渲染这些按钮。

  render() {
    return (

      <button className="empty-cart-button" onClick={this.handleEmptyCart}>Empty Cart</button>
      <div className="paypal-buttons-container">
        <div id="paypal-button"></div>
      </div>
    );
  }

如何在 React Render 函数中正确渲染这些内容?

javascript html reactjs paypal e-commerce
© www.soinside.com 2019 - 2024. All rights reserved.