mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-04 22:16:08 +00:00
Add stripe as payment method
This commit is contained in:
committed by
Matt-Yorkley
parent
fc6fba4fe9
commit
e89caf7a0d
@@ -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
|
||||
|
||||
@@ -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 }
|
||||
|
||||
23
app/views/split_checkout/payment/_stripe.html.haml
Normal file
23
app/views/split_checkout/payment/_stripe.html.haml
Normal 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" }
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user