fix rubocop warnings

This commit is contained in:
Andy Brett
2020-11-19 13:44:41 -08:00
parent 3d47ad7e33
commit a466886a32
5 changed files with 23 additions and 25 deletions

View File

@@ -13,9 +13,8 @@ module Api
client_secret = RecurringPayments.setup_for(@customer) if params[:customer][:allow_charges]
if @customer.update(params[:customer])
@customer.gateway_recurring_payment_client_secret = client_secret
@customer.gateway_shop_id = @customer.enterprise.stripe_account&.stripe_user_id
if @customer.update(customer_params)
add_recurring_payment_info(@customer, client_secret)
render json: @customer, serializer: CustomerSerializer, status: :ok
else
invalid_resource!(@customer)
@@ -25,5 +24,14 @@ module Api
def customer_params
params.require(:customer).permit(:code, :email, :enterprise_id, :allow_charges)
end
private
def add_recurring_payment_info(customer, client_secret)
return unless client_secret
customer.gateway_recurring_payment_client_secret = client_secret
customer.gateway_shop_id = customer.enterprise.stripe_account&.stripe_user_id
end
end
end

View File

@@ -47,22 +47,19 @@ module Spree
# NOTE: the name of this method is determined by Spree::Payment::Processing
def charge_offline(money, creditcard, gateway_options)
options = basic_options(gateway_options)
customer_id, payment_method_id =
customer, payment_method =
Stripe::CreditCardCloner.new.find_or_clone(creditcard, stripe_account_id)
options[:customer] = customer_id
options[:off_session] = true
provider.purchase(money, payment_method_id, options)
options = basic_options(gateway_options).merge(customer: customer, off_session: true)
provider.purchase(money, payment_method, options)
rescue Stripe::StripeError => e
failed_activemerchant_billing_response(e.message)
end
# NOTE: the name of this method is determined by Spree::Payment::Processing
def authorize(money, creditcard, gateway_options)
authorize_response = provider.authorize(*options_for_authorize(money,
creditcard,
gateway_options))
authorize_response =
provider.authorize(*options_for_authorize(money, creditcard, gateway_options))
Stripe::AuthorizeResponsePatcher.new(authorize_response).call!
rescue Stripe::StripeError => e
failed_activemerchant_billing_response(e.message)

View File

@@ -15,10 +15,8 @@ module Spree
raise Core::GatewayError, Spree.t(:payment_method_not_supported)
end
if offline
charge_offline!
elsif payment_method.auto_capture?
purchase!
if payment_method.auto_capture?
purchase!(offline)
else
authorize!
end
@@ -29,14 +27,9 @@ module Spree
gateway_action(source, :authorize, :pend)
end
def purchase!
def purchase!(offline = false)
started_processing!
gateway_action(source, :purchase, :complete)
end
def charge_offline!
started_processing!
gateway_action(source, :charge_offline, :complete)
gateway_action(source, offline ? :charge_offline : :purchase, :complete)
end
def capture!

View File

@@ -9,7 +9,7 @@ class RecurringPayments
Stripe::CreditCardCloner.new.find_or_clone(card, stripe_account)
setup_intent = Stripe::SetupIntent.create(
{ payment_method: payment_method_id, customer: customer_id },
{ stripe_account: stripe_account }
stripe_account: stripe_account
)
setup_intent.client_secret
end

View File

@@ -73,7 +73,7 @@ module Stripe
loop do
response = Stripe::Customer.list({ email: email, starting_after: starting_after },
{ stripe_account: connected_account_id })
stripe_account: connected_account_id)
customers += response.data
break unless response.has_more
@@ -88,7 +88,7 @@ module Stripe
loop do
options = { customer: customer_id, type: 'card', starting_after: starting_after }
response = Stripe::PaymentMethod.list(options, { stripe_account: connected_account_id })
response = Stripe::PaymentMethod.list(options, stripe_account: connected_account_id)
payment_methods += response.data
break unless response.has_more