You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native WebView集成PayPal:商品详情无法传递致金额固定1美元求助

React Native WebView 集成 PayPal 金额无法正确传递的排查方案
  • 检查PayPal表单的金额参数绑定
    确保WebView加载的PayPal支付表单中,金额字段(如amount)是动态绑定你传入的商品金额,而非固定写死的1.00。如果是静态HTML字符串,注入时要替换固定值,示例:

    const paymentHtml = `
      <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
        <input type="hidden" name="cmd" value="_xclick">
        <input type="hidden" name="business" value="你的PayPal商家邮箱">
        <input type="hidden" name="item_name" value="${你的商品名称}">
        <input type="hidden" name="amount" value="${你的商品金额}">
        <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - 安全便捷的在线支付方式!">
      </form>
    `;
    

    务必确认你的商品金额是正确数值,未被硬编码覆盖。

  • 验证WebView的参数注入时机
    如果用injectJavaScript传递参数到WebView页面,要等待页面加载完成后再执行注入,避免DOM元素未渲染导致修改失效。示例:

    <WebView
      source={{ uri: '你的PayPal表单页面地址' }}
      onLoadEnd={() => {
        this.webView.injectJavaScript(`
          document.querySelector('input[name="amount"]').value = "${你的商品金额}";
          true;
        `);
      }}
      ref={ref => (this.webView = ref)}
    />
    
  • 排查PayPal REST API的订单参数(若使用API模式)
    若通过REST API创建订单后跳转支付,要保证创建订单时purchase_units内的amount参数正确:

    // 创建订单API请求示例
    fetch('https://api-m.sandbox.paypal.com/v2/checkout/orders', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer ' + 你的访问令牌
      },
      body: JSON.stringify({
        intent: 'CAPTURE',
        purchase_units: [{
          amount: {
            currency_code: 'USD',
            value: 你的商品金额 // 如"29.99",注意是字符串格式
          }
        }]
      })
    })
    

    订单创建成功后,将返回的id传入WebView支付页面,确保金额与订单一致。

  • 清除WebView缓存
    若WebView缓存旧页面内容,会导致新参数不生效。可设置cacheEnabled={false},或在URL后添加随机参数(如?t=${Date.now()})强制刷新。

  • 检查PayPal商家后台配置
    极少数情况,商家账户的默认金额设置会覆盖传入值,登录PayPal商家后台确认无固定金额配置。

内容的提问来源于stack exchange,提问作者Mahmoud Zoabi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 03:25:18