【问题标题】:How to pass data to Stripe checkout with Rails and HAML?如何使用 Rails 和 HAML 将数据传递给 Stripe 结账?
【发布时间】:2015-07-14 22:33:22
【问题描述】:

我有一个包含名字、姓氏、电子邮件和电话的注册表单,然后是“使用卡条纹结帐付款”按钮。用户填写表格后,Stripe Checkout 会要求提供电子邮件地址。如何让用户在表单中输入电子邮件地址以自动填写 Stripe Checkout 中的电子邮件地址字段。

这是我当前的代码:

        .field
          = f.label :"Email:"
          = f.text_field :email
        %br  
        .actions
          %script.stripe-button{ src: "https://checkout.stripe.com/checkout.js",
                data: {email: "thisemail@carriesover.com", amount: @level.price*100, description: @level.name, key: Rails.application.secrets.stripe_publishable_key}}

如果我在 Stripe Checkout 脚本中对电子邮件地址进行硬编码,它就可以工作。我可以使用 jQuery 传递它吗?如果有,怎么做?

【问题讨论】:

  • 如果你在同一页面的 JS 中得到它,那么你不能这样。您需要使用自定义结帐(stripe.com/docs/checkout#integration-custom)并在handler.open()email 参数中传递电子邮件
  • @koopajah 谢谢!看起来它打破了这条线:@registration = Registration.new registration_params.merge(email: stripe_params["stripeEmail"])不确定stripe_params []来自哪里。
  • 如果您使用自定义结帐,您会在 token() 回调中获得令牌,此时您必须将令牌 ID 和用户通过电子邮件发送到您的服务器

标签: ruby-on-rails haml stripe-payments


【解决方案1】:

我是这样做的:

    = javascript_include_tag "https://checkout.stripe.com/v2/checkout.js",
      :class => "stripe-button",
      :"data-key" => "#{Rails.configuration.stripe[:publishable_key]}",
      :"data-description" => "charged upon appointment confirmation",
      :"data-amount" => total.to_s,
      :"data-image" => 'https://s3-us-west-2.amazonaws.com/xx
      :"data-label" => "Request Appointment",
      :"data-panel-label" => "Pre-Authorize",
      :"data-name" => "Pre-Authorize Payment",
      :"data-email" => @current_user.email

希望对你有所帮助。

【讨论】:

    猜你喜欢
    • 2013-02-08
    • 2015-03-31
    • 2021-11-08
    • 2011-09-30
    • 2016-04-12
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多