react-paypal-button-v2 无法授权付款

react-paypal-button-v2 cannot authorize payment

我正在尝试授权付款并稍后获取资金。基本上,我想暂停客户卡上的资金。然后处理订单,最后在订单准备好时捕获金额。我按照贝宝指南去做了:https://developer.paypal.com/docs/business/checkout/add-capabilities/authorization/ 但是,无论我尝试过什么,我 总是最终“捕获”全部金额 而不是搁置。 我正在为贝宝按钮使用 react-paypal-button-v2 这是我的代码:

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

const addPayPalScript = () => {
    const script = document.createElement("script");
    script.type = "text/javascript";
    script.src =
      "https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID&intent=authorize";
    //script.src = "https://www.paypal.com/sdk/js";
    script.async = true;
    script.onload = () => {
      setSdkReady(true);
    };
    document.body.appendChild(script);
  };
  useEffect(() => {
   
      if (!window.paypal) {
        addPayPalScript();
        setSdkReady(true);
      } else {
        setSdkReady(true);
      }
    }
  }, []);

return  {!sdkReady ? (
                    <Loader />
                  ) : (
                    <PayPalButton
                       amount={100}         
                      onSuccess={successPaymentHandler}

                    />
                  )}

我也试过以下方法:

const addPayPalScript = () => {
    const script = document.createElement("script");
    script.type = "text/javascript";
    script.src =
      "https://www.paypal.com/sdk/js";
    script.async = true;
    script.onload = () => {
      setSdkReady(true);
    };
    document.body.appendChild(script);
  };
 const initialOptions = {
    clientId:
      MyPaypalID,
    intent: "authorize",
  };

return  {!sdkReady ? (
                    <Loader />
                  ) : (
                    <PayPalButton
                       amount={100}         
                      onSuccess={successPaymentHandler}
    options={initialOptions}

                    />
                  )}

使用官方 react-paypal-js 并指定执行 actions.order.authorize() 而不是默认捕获的 onApprove 函数。