Skip to content

Commit

Permalink
fixed code climate
Browse files Browse the repository at this point in the history
  • Loading branch information
nidhi-soni1104 committed Mar 11, 2024
1 parent 52c1c5d commit 5024303
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
4 changes: 0 additions & 4 deletions app/lib/payment_gateways/payment_gateway_crypt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ def update_billing_details(payment_method, billing_address)
}
end

def reset_stripe_api_key
Stripe.api_key = nil
end

def handle_stripe_error(stripe_error)
report_error("Failed to update billing address on Stripe: #{stripe_error.message}")
false
Expand Down
13 changes: 5 additions & 8 deletions app/lib/payment_gateways/stripe_crypt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ def customer
def update_billing_address(billing_address)
begin
Stripe.api_key = api_key # Set actual Stripe secret key

latest_payment_method_id = latest_payment_method_id_for_customer
return true unless latest_payment_method_id.present?

payment_method = retrieve_payment_method(latest_payment_method_id)

update_billing_details(payment_method, billing_address)
payment_method.save
rescue Stripe::StripeError => stripe_error
Expand All @@ -57,15 +54,12 @@ def update_billing_address(billing_address)
def find_or_create_customer
customer_id = payment_detail.credit_card_auth_code
return create_customer if customer_id.blank?

retrieve_customer(customer_id)
end

def retrieve_customer(customer_id)
customer = Stripe::Customer.retrieve(customer_id, api_key)

return create_customer if customer.nil? || customer.deleted?

return create_customer if customer&.deleted?
customer
rescue Stripe::InvalidRequestError
create_customer
Expand All @@ -77,7 +71,6 @@ def create_customer
email: user.email,
metadata: { '3scale_account_reference' => buyer_reference }
}

Stripe::Customer.create(customer_params, api_key).tap do |stripe_customer|
payment_detail.update(credit_card_auth_code: stripe_customer.id)
end
Expand All @@ -87,6 +80,10 @@ def api_key
payment_gateway_options.fetch(:login)
end

def reset_stripe_api_key
Stripe.api_key = nil
end

def latest_payment_method_id_for_customer
latest_payment_method = Stripe::PaymentMethod.list(
customer: customer.id,
Expand Down

0 comments on commit 5024303

Please sign in to comment.