【问题标题】:How to pre-populate email in the Stripe payments dialog popup如何在 Stripe 付款对话框弹出窗口中预填充电子邮件
【发布时间】:2016-02-08 23:20:42
【问题描述】:

我似乎找不到在条带支付弹出窗口中预填充电子邮件地址的方法。然而这个周末我在使用条纹支付的网站上注册了两个帐户,我意识到这些网站已经在条纹对话框 iframe 框中预先填充了我的电子邮件。所以我知道一定有办法,但我不确定如何做到这一点。文档没有定义该属性。 有人能解释一下这是如何使用 javascript API 和基本的 Stripe 对话框完成的吗?

【问题讨论】:

    标签: stripe-payments


    【解决方案1】:

    如果您使用的是Simple Checkout,您可以像这样传递data-email 中的电子邮件:

    <form action="/charge" method="POST">
      <script
        src="https://checkout.stripe.com/checkout.js" class="stripe-button"
        data-key="pk_test_6pRNASCoBOKtIshFeQd4XMUh"
        data-image="/img/documentation/checkout/marketplace.png"
        data-name="Stripe.com"
        data-description="2 widgets"
        data-amount="2000"
        data-email="customer@email.com"
        data-locale="auto">
      </script>
    </form>
    

    如果您使用Custom Checkout,则将email 参数中的电子邮件传递给handler.open()

    handler.open({
      name: 'Stripe.com',
      description: '2 widgets',
      amount: 2000,
      email: "customer@email.com"
    });
    

    【讨论】:

    • 是否可以使用 Stripe Apple Pay 预填充电子邮件?
    • 可能很高兴知道,如果您传递无效的电子邮件地址(例如“admin”),它根本不会被预填充。
    • 不要忘记倒数第二行末尾的逗号。 (就像我刚才所做的那样)
    【解决方案2】:

    如果您想使用 js 动态设置电子邮件(对于 Simple Checkout ),您必须动态创建整个脚本元素以确保它正确加载。可以这样做:

    //create our stipe script element
    var stripescript = document.createElement('script'); //create script element
    
    //dynamicaly load stripe checkout attributes
    stripescript.setAttribute('src','https://checkout.stripe.com/checkout.js');
    stripescript.setAttribute("data-key","[YOUR STRIPE TOKEN]" )  
    stripescript.setAttribute("data-amount","90" )  
    stripescript.setAttribute("data-locale","auto")  
    stripescript.setAttribute("class","stripe-button")  
    stripescript.setAttribute("data-billing-address",true)  
    stripescript.setAttribute("data-panel-label","Update")  
    stripescript.setAttribute("data-currency","gbp")  
    // any other attributes you want to add stripescript.setAttribute("[name]","[value]") 
    
    //insert script element inside of div or an other element
    document.getElementById('[ID OF ELEMENT YOU WANT TO PUT THE FORM INTO]').appendChild(stripescript);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-12
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 2012-01-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多