简体   繁体   English

paypal 订阅按钮未显示在手机上

[英]paypal subscription buttons are not showing on phones

I'm using Paypal at 4 different places in the app 3 subscriptions and one single payment.我在应用程序的 4 个不同位置使用 Paypal 3 个订阅和一次付款。

everything works on a desktop, but subscription buttons are not showing on mobiles.一切都在桌面上运行,但订阅按钮没有显示在手机上。

I feel that the problem is in importing the library, is anything wrong with this import?我觉得问题出在导入库,这个导入有什么问题吗?

no errors of any kind, I checked and found PayPal is loaded on phone, but buttons don't show.没有任何错误,我检查并发现 PayPal 已加载到手机上,但按钮不显示。


 <script
src=`https://www.paypal.com/sdk/js?clientid=${process.env.PAYPAL_CLIENT_ID}
&currency=GBP&disable-funding=credit,card&vault=true&intent=subscription`
></script>

so the problem was that buttons are being removed because the paypalButton.close() is being called when the state render (don't exactly know why).所以问题是按钮被删除了,因为在 state 渲染时调用了paypalButton.close() (不知道为什么)。

please see this issue for more info about the problem:请参阅此问题以获取有关该问题的更多信息:

https://github.com/paypal/paypal-checkout-components/issues/1506 https://github.com/paypal/paypal-checkout-components/issues/1506

solved by sleeping 1 second before rendering, I don't know why, but this has solved the problem.通过在渲染前休眠 1 秒解决,我不知道为什么,但这已经解决了问题。

so my code is:所以我的代码是:

sleep function:睡眠 function:

 function sleep(ms) {
     return new Promise((resolve) => setTimeout(resolve, ms));
  }

paypa;支付宝; button component:按钮组件:

 const paypalRef = useRef();
 
// options
 const btnOptions = {
    createSubscription: function (data, actions) {
      return actions.subscription.create({
        plan_id: planID,
      });
    },
    onApprove: function (data, actions) {
      alert(data.subscriptionID);
    },
  };

 // effect, make sure to listen to Paypal library load
  useEffect(() => {
    (async () => {
        await sleep(1000)  // sleep second before rendering. <---------------------- solution here;
      if (paypalRef.current) {
        btn = window.paypal.Buttons(btnOptions);
        btn.render(paypalRef.current);
      }
    })();
  }, [window.paypal]);


  return <div className={styles.paypal_btn} ref={paypalRef}></div>;




声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM