【问题标题】:Issue with Payment method selection when I add Braintree Drop-in UI in Spree Store当我在 Spree Store 中添加 Braintree Drop-in UI 时,付款方式选择出现问题
【发布时间】:2015-08-31 13:42:14
【问题描述】:

当客户选择 Braintree 作为付款方式时,我正在尝试实施扩展以适应 Braintree 的插入式 UI。如果我将 Braintree js 代码添加到 _gateway.html.erb 中,那么所有其他付款方式都将停止工作。如果我选择除了braintree 之外的任何其他方法并单击“保存并继续”,那么什么也不会发生。 “保存并继续”按钮被禁用。

我已经覆盖了 spree/frontend/app/views/spree/checkout/_gateway.html.erb。

<% if payment_method.name == "Braintree" %>

 <div id="dropin"></div>

<% else %>
<div class="well clearfix">

  <%= image_tag 'credit_cards/credit_card.gif', :id => 'credit-card-image', :class => 'pull-right', :width => '170', :height => '28' %>
  <% param_prefix = "payment_source[#{payment_method.id}]" %>

  <p class="field">
    <%= label_tag "name_on_card_#{payment_method.id}" do %>
      <%= Spree.t(:name_on_card) %><abbr class="required" title="required">*</abbr>
    <% end %>
    <%= text_field_tag "#{param_prefix}[name]", "#{@order.billing_firstname} #{@order.billing_lastname}", { id: "name_on_card_#{payment_method.id}", :class => 'form-control required'} %>
  </p>

  <p class="field" data-hook="card_number">
    <%= label_tag "card_number" do %>
      <%= Spree.t(:card_number) %><abbr class="required" title="required">*</abbr>
    <% end %>
    <% options_hash = Rails.env.production? ? {:autocomplete => 'off'} : {} %>
    <%= text_field_tag "#{param_prefix}[number]", '', options_hash.merge(:id => 'card_number', :class => 'form-control required cardNumber', :size => 19, :maxlength => 19, :autocomplete => "off") %>
    &nbsp;
    <span id="card_type" style="display:none;">
      ( <span id="looks_like" ><%= Spree.t(:card_type_is) %> <span id="type"></span></span>
        <span id="unrecognized"><%= Spree.t(:unrecognized_card_type) %></span>
      )
    </span>
  </p>
  <div class="row">
    <div class="col-md-8 field" data-hook="card_expiration">
      <%= label_tag "card_expiry" do %>
        <%= Spree.t(:expiration) %><abbr class="required" title="required">*</abbr>
      <% end %>
      <%= text_field_tag "#{param_prefix}[expiry]", '', :id => 'card_expiry', :class => "form-control required cardExpiry", :placeholder => "MM / YY" %>
    </div>
    <div class="col-md-4 field" data-hook="card_code">
      <%= label_tag "card_code" do %>
        <%= Spree.t(:card_code) %><abbr class="required" title="required">*</abbr>
      <% end %>
      <%= text_field_tag "#{param_prefix}[verification_value]", '', options_hash.merge(:id => 'card_code', :class => 'form-control required cardCode', :size => 5) %>
      <%= link_to "(#{Spree.t(:what_is_this)})", spree.content_path('cvv'), :target => '_blank', "data-hook" => "cvv_link", :id => "cvv_link" %>
    </div>
  </div>

  <%= hidden_field_tag "#{param_prefix}[cc_type]", '', :id => "cc_type", :class => 'ccType' %>
</div>

<% end %>
<%= @client_token = Braintree::ClientToken.generate %>
<script type="text/javascript">
braintree.setup("<%=@client_token%>", 'dropin', {
      container: 'dropin'
    });
</script>

【问题讨论】:

    标签: javascript ruby-on-rails spree braintree


    【解决方案1】:

    我在布伦特里工作。如果您没有在对braintree.setup 的调用中指定form 选项,braintree.js 会将其行为附加到最近的父表单元素。由于您的braintree 容器的父表单看起来与其他结帐流程使用的表单相同,因此braintree.js 确实会劫持提交按钮的调用(无论使用的支付流程如何)。我建议创建两个单独的表单元素,并将braintree 使用的那个的id 传递给braintree.setup 调用。

    braintree.setup("<%=@client_token%>", 'dropin', {
        container: ‘dropin’,
        form: ‘braintree_checkout'
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-30
      • 2016-01-05
      • 2019-11-05
      • 2017-12-25
      • 1970-01-01
      • 2015-05-10
      • 2015-07-12
      相关资源
      最近更新 更多