Skip to content

Commit

Permalink
Refactor based on feedback
Browse files Browse the repository at this point in the history
31 tests, 88 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
  • Loading branch information
aenand committed Aug 1, 2023
1 parent 3db9f4e commit f660e64
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions lib/active_merchant/billing/gateways/rapyd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ def verify(credit_card, options = {})
def store(payment, options = {})
post = {}
add_payment(post, payment, options)
phone = options.dig(:billing_address, :phone) .gsub(/\D/, '') unless options[:billing_address].nil?
post[:phone_number] = phone || options.dig(:customer, :phone_number)
post[:email] = options[:email] || options.dig(:customer, :email)
post[:name] = "#{payment.first_name} #{payment.last_name}" unless payment.is_a?(String)
post[:addresses] = [address(options)]
add_customer_object(post, payment, options, 'store')
add_metadata(post, options)
add_ewallet(post, options)
add_payment_fields(post, options)
Expand Down Expand Up @@ -111,7 +107,6 @@ def add_auth_purchase(post, money, payment, options)
add_ewallet(post, options)
add_payment_fields(post, options)
add_payment_urls(post, options)
add_customer_id(post, options)
end

def add_address(post, creditcard, options)
Expand Down Expand Up @@ -217,13 +212,25 @@ def add_payment_urls(post, options)
post[:error_payment_url] = options[:error_payment_url] if options[:error_payment_url]
end

def add_customer_object(post, payment, options)
phone = options.dig(:billing_address, :phone) .gsub(/\D/, '') unless options[:billing_address].nil?
post[:phone_number] = phone || options.dig(:customer, :phone_number)
post[:email] = options[:email] || options.dig(:customer, :email)
post[:customer] = {}
post[:customer][:name] = "#{payment.first_name} #{payment.last_name}" unless payment.is_a?(String)
post[:customer][:addresses] = [address(options)]
def add_customer_object(post, payment, options, action = '')
post[:phone_number] = options.dig(:billing_address, :phone) .gsub(/\D/, '') unless options[:billing_address].nil?
post[:email] = options[:email]
return add_customer_id(post, options) if options[:customer_id]

if action == 'store'
post.merge!(customer_fields(payment, options))
else
post[:customer] = customer_fields(payment, options)
end
end

def customer_fields(payment, options)
return if options[:customer_id]

customer_data = {}
customer_data[:name] = "#{payment.first_name} #{payment.last_name}" unless payment.is_a?(String)
customer_data[:addresses] = [address(options)]
customer_data
end

def address(options)
Expand Down

0 comments on commit f660e64

Please sign in to comment.