From 9fa4bad0b45e30da7e9e414d392961135d7c093f Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Mon, 13 Jan 2020 17:48:01 +0000 Subject: [PATCH] Add stripe SCA checkotu payment template and move stripe object definition to it and the other stripe template We need to set the stripe object with the stripe account id to work with the payment intents api but we cannot set it to work with the stripe charges api This makes the two payment methods incompatible: a given enterprise cannot use both the old stripe integration and this new one at the same time. --- app/views/checkout/_payment.html.haml | 5 ----- .../spree/checkout/payment/_stripe.html.haml | 5 +++++ .../checkout/payment/_stripe_sca.html.haml | 22 +++++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 app/views/spree/checkout/payment/_stripe_sca.html.haml diff --git a/app/views/checkout/_payment.html.haml b/app/views/checkout/_payment.html.haml index fdbd103203..928578158f 100644 --- a/app/views/checkout/_payment.html.haml +++ b/app/views/checkout/_payment.html.haml @@ -1,8 +1,3 @@ -- content_for :injection_data do - - if Stripe.publishable_key - :javascript - angular.module('Darkswarm').value("stripeObject", Stripe("#{Stripe.publishable_key}")) - %fieldset#payment %ng-form{"ng-controller" => "PaymentCtrl", name: "payment"} diff --git a/app/views/spree/checkout/payment/_stripe.html.haml b/app/views/spree/checkout/payment/_stripe.html.haml index eace9f00a7..2929b90d3e 100644 --- a/app/views/spree/checkout/payment/_stripe.html.haml +++ b/app/views/spree/checkout/payment/_stripe.html.haml @@ -1,3 +1,8 @@ +- content_for :injection_data do + - if Stripe.publishable_key + :javascript + angular.module('Darkswarm').value("stripeObject", Stripe("#{Stripe.publishable_key}")) + .row{ "ng-show" => "savedCreditCards.length > 0" } .small-12.columns %h6= t('.used_saved_card') diff --git a/app/views/spree/checkout/payment/_stripe_sca.html.haml b/app/views/spree/checkout/payment/_stripe_sca.html.haml new file mode 100644 index 0000000000..00ded42afe --- /dev/null +++ b/app/views/spree/checkout/payment/_stripe_sca.html.haml @@ -0,0 +1,22 @@ +- content_for :injection_data do + - if Stripe.publishable_key + :javascript + angular.module('Darkswarm').value("stripeObject", Stripe("#{Stripe.publishable_key}", { stripeAccount: "#{StripeAccount.find_by_enterprise_id(payment_method.preferred_enterprise_id).andand.stripe_user_id}" })) + +.row{ "ng-show" => "savedCreditCards.length > 0" } + .small-12.columns + %h6= t('.used_saved_card') + %select{ name: "selected_card", required: false, ng: { model: "secrets.selected_card", options: "card.id as card.formatted for card in savedCreditCards" } } + %option{ value: "" }= "{{ secrets.selected_card ? '#{t('.enter_new_card')}' : '#{t('.choose_one')}' }}" + + %h6{ ng: { if: '!secrets.selected_card' } } + = t('.or_enter_new_card') + +%div{ ng: { if: '!secrets.selected_card' } } + %stripe-elements + + - if spree_current_user + .row + .small-12.columns.text-right + = check_box_tag 'secrets.save_requested_by_customer', '1', false, 'ng-model' => 'secrets.save_requested_by_customer' + = label_tag 'secrets.save_requested_by_customer', t('.remember_this_card')