Merge pull request #5597 from luisramos0/bo_stripe_payments

[Spree 2.1] Make backoffice stripe payments work in rails 4
This commit is contained in:
Luis Ramos
2020-06-18 14:50:27 +01:00
committed by GitHub
4 changed files with 38 additions and 15 deletions

View File

@@ -84,7 +84,11 @@ module Spree
source_params = params.delete(:payment_source)[params[:payment][:payment_method_id]]
params[:payment][:source_attributes] = source_params
end
params.require(:payment).permit(:amount, :payment_method_id, :source_attributes)
params.require(:payment).permit(
:amount, :payment_method_id,
source_attributes: ::PermittedAttributes::PaymentSource.attributes
)
end
def load_data

View File

@@ -13,24 +13,13 @@ module PermittedAttributes
:existing_card_id, :shipping_method_id,
payments_attributes: [
:payment_method_id,
source_attributes: payment_source_attributes
source_attributes: PermittedAttributes::PaymentSource.attributes
],
ship_address_attributes: PermittedAttributes::Address.attributes,
bill_address_attributes: PermittedAttributes::Address.attributes
],
payment_source: payment_source_attributes
payment_source: PermittedAttributes::PaymentSource.attributes
)
end
private
def payment_source_attributes
[
:gateway_payment_profile_id, :cc_type, :last_digits,
:month, :year, :first_name, :last_name,
:number, :verification_value,
:save_requested_by_customer
]
end
end
end

View File

@@ -0,0 +1,14 @@
# frozen_string_literal: true
module PermittedAttributes
class PaymentSource
def self.attributes
[
:gateway_payment_profile_id, :cc_type, :last_digits,
:month, :year, :first_name, :last_name,
:number, :verification_value,
:save_requested_by_customer
]
end
end
end

View File

@@ -92,11 +92,27 @@ describe Spree::Admin::PaymentsController, type: :controller do
context "where both payment.process! and payment.authorize! work" do
before do
allow_any_instance_of(Spree::Payment).to receive(:authorize!) do |payment|
payment.update_attribute :state, "pending"
payment.update state: "pending"
end
allow_any_instance_of(Spree::Payment).to receive(:process!).and_return(true)
end
it "makes a payment with the provided card details" do
source_attributes = {
gateway_payment_profile_id: "pm_123",
cc_type: "visa",
last_digits: "4242",
month: "4",
year: "2100"
}
spree_post :create, payment: params.merge({ source_attributes: source_attributes }),
order_id: order.number
payment = order.reload.payments.last
expect(payment.source.attributes.transform_keys(&:to_sym)).to include source_attributes
end
it "redirects to list of payments with success flash" do
spree_post :create, payment: params, order_id: order.number