微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在Paypal SDK中更改币种

如何解决在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加载行上的货币匹配。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。