在Paypal SDK中更改币种

问题描述

我正在尝试使用JavaScript / React连接到PayPal

我已经建立了流程,但只承认美元。 我一直在尝试遵循在线提供的建议,这些建议一直很有效,但一直无法使其与其他货币(例如GBP)一起使用

const dispatch = usedispatch();
  useEffect(() => {
    const addPayPalScript = async () => {
      const { data } = await Axios.get('/api/config/paypal');
      const script = document.createElement('script');
      script.type = 'text/javascript';
      script.src = "https://www.paypal.com/sdk/js?client-id='myclientid'&currency=GBP";
      
      script.async = true;
      script.onload = () => {
        setSdkReady(true);
      };
      document.body.appendChild(script);
    };

然后当我按下按钮时

<PayPalButton 
  amount={order.totalPrice}
  onSuccess={successpaymentHandler}
></PayPalButton> 

我也将货币作为order.currency的字段。

错误来自 意外的货币:USD传递至order.create。请确保您在Paypal脚本标记中传递/ sdk / js?currency = USD。 至 意外的货币:GBP传递给order.create。请确保您在Paypal脚本标记中传递了/ sdk / js?currency = GBP。

解决方法

使用https://github.com/Luehang/react-paypal-button-v2#large_blue_diamond-props

有一个“货币”参数,例如

<PayPalButton 
    amount={order.totalPrice}
    currency="GBP"
    onSuccess={successPaymentHandler}
></PayPalButton> 

这是创建订单时的货币(如果在抽象中的代码中指定),则需要与SDK加载行上的货币匹配。