Add stripe as payment method

This commit is contained in:
Jean-Baptiste Bellet
2021-11-25 12:00:45 +01:00
committed by Matt-Yorkley
parent fc6fba4fe9
commit e89caf7a0d
4 changed files with 35 additions and 2 deletions

View File

@@ -13,7 +13,7 @@ module CheckoutCallbacks
prepend_before_action :require_order_cycle
prepend_before_action :require_distributor_chosen
before_action :load_order, :associate_user, :load_saved_addresses
before_action :load_order, :associate_user, :load_saved_addresses, :load_saved_credit_cards
before_action :load_shipping_methods, :load_countries, if: -> { params[:step] == "details" }
before_action :ensure_order_not_completed
@@ -41,6 +41,11 @@ module CheckoutCallbacks
@order.ship_address ||= finder.ship_address
end
def load_saved_credit_cards
@saved_credit_cards = spree_current_user ? spree_current_user.credit_cards.with_payment_profile.all : []
@selected_card = nil
end
def load_shipping_methods
@shipping_methods = Spree::ShippingMethod.for_distributor(@order.distributor).order(:name)
end
@@ -89,4 +94,5 @@ module CheckoutCallbacks
def check_authorization
authorize!(:edit, current_order, session[:access_token])
end
end

View File

@@ -22,7 +22,7 @@
.paymentmethod-description.panel
#{payment_method.description}
.paymentmethod-form
- if payment_method.method_type == "gateway"
- if payment_method.method_type == "gateway" || payment_method.method_type == "stripe"
= render partial: "split_checkout/payment/#{payment_method.method_type}", locals: { payment_method: payment_method, f: f }
- else
= render partial: "spree/checkout/payment/#{payment_method.method_type}", :locals => { payment_method: payment_method }

View File

@@ -0,0 +1,23 @@
- content_for :injection_data do
- if Stripe.publishable_key
:javascript
angular.module('Darkswarm').value("stripeObject", Stripe("#{Stripe.publishable_key}"))
- if @saved_credit_cards.length > 0
.checkout-input
%label
= t('split_checkout.step2.form.stripe.use_saved_card')
= select_tag :card, options_for_select(@saved_credit_cards.map {|cc| [ cc.id, "#{cc.brand} #{cc.number}" ] }, @selected_card)
.checkout-input
- if @saved_credit_cards.length > 0
%label
= t('split_checkout.step2.form.stripe.use_new_card')
%stripe-elements
- if spree_current_user
.checkout-input
= check_box_tag :save_card, {id: "save_card", name: "save_card", checked: false, value: "1"}
= label :save_card, t('split_checkout.step2.form.stripe.save_card'), { for: "save_card" }

View File

@@ -1737,6 +1737,10 @@ en:
card_year:
label: Year
placeholder: 2020
stripe:
use_saved_card: Use saved card
use_new_card: or use a new card
save_card: Save card for future use
explaination: You can review and confirm your order in the next step which includes the final costs.
submit: Next - Order summary
cancel: Back to Your details