From 1c19d239af7e7e0f0515de9f8b34bde61a6e0c36 Mon Sep 17 00:00:00 2001 From: jaredmurphy Date: Mon, 4 Mar 2019 12:47:41 -0500 Subject: [PATCH 1/4] use order.outstanding_balance to include store credit payments --- app/controllers/spree/affirm_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/spree/affirm_controller.rb b/app/controllers/spree/affirm_controller.rb index c53f31b..8502185 100644 --- a/app/controllers/spree/affirm_controller.rb +++ b/app/controllers/spree/affirm_controller.rb @@ -54,7 +54,7 @@ def confirm _affirm_payment = order.payments.create!({ payment_method: payment_method, - amount: order.total, + amount: order.outstanding_balance, source: _affirm_checkout }) From e4db04530dcf37d5f603eb9cee4041022a7238f0 Mon Sep 17 00:00:00 2001 From: jaredmurphy Date: Mon, 4 Mar 2019 13:31:59 -0500 Subject: [PATCH 2/4] update affirm partial to use outstanding_balance in order to include store credit --- app/views/spree/checkout/payment/_affirm.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/spree/checkout/payment/_affirm.html.erb b/app/views/spree/checkout/payment/_affirm.html.erb index 993edd7..52e1932 100644 --- a/app/views/spree/checkout/payment/_affirm.html.erb +++ b/app/views/spree/checkout/payment/_affirm.html.erb @@ -20,7 +20,7 @@ set the shared checkout data \*****************************************************/ affirm.checkout({ - total: <%= (@order.total * 100).to_i %>, + total: <%= (@order.outstanding_balance * 100).to_i %>, currency: "USD", tax_amount: <%= (@order.additional_tax_total * 100).to_i %>, order_id: "<%= @order.number %>", From 21f6fbe9afc87f9041f66932fbc65177187da4e5 Mon Sep 17 00:00:00 2001 From: jaredmurphy Date: Mon, 4 Mar 2019 16:50:23 -0500 Subject: [PATCH 3/4] Revert "Include store credit" --- app/controllers/spree/affirm_controller.rb | 2 +- app/views/spree/checkout/payment/_affirm.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/spree/affirm_controller.rb b/app/controllers/spree/affirm_controller.rb index 8502185..c53f31b 100644 --- a/app/controllers/spree/affirm_controller.rb +++ b/app/controllers/spree/affirm_controller.rb @@ -54,7 +54,7 @@ def confirm _affirm_payment = order.payments.create!({ payment_method: payment_method, - amount: order.outstanding_balance, + amount: order.total, source: _affirm_checkout }) diff --git a/app/views/spree/checkout/payment/_affirm.html.erb b/app/views/spree/checkout/payment/_affirm.html.erb index 52e1932..993edd7 100644 --- a/app/views/spree/checkout/payment/_affirm.html.erb +++ b/app/views/spree/checkout/payment/_affirm.html.erb @@ -20,7 +20,7 @@ set the shared checkout data \*****************************************************/ affirm.checkout({ - total: <%= (@order.outstanding_balance * 100).to_i %>, + total: <%= (@order.total * 100).to_i %>, currency: "USD", tax_amount: <%= (@order.additional_tax_total * 100).to_i %>, order_id: "<%= @order.number %>", From 0055d63a2c1c1ee5d98a35f011186c17db49fd61 Mon Sep 17 00:00:00 2001 From: hf2186 Date: Sat, 30 Mar 2019 14:12:06 -0400 Subject: [PATCH 4/4] Look up state w/ country to prevent ambiguity --- app/controllers/spree/affirm_controller.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/spree/affirm_controller.rb b/app/controllers/spree/affirm_controller.rb index c53f31b..3cfb17d 100644 --- a/app/controllers/spree/affirm_controller.rb +++ b/app/controllers/spree/affirm_controller.rb @@ -91,11 +91,14 @@ def completion_route(order) def generate_spree_address(affirm_address) # find the state and country in spree - _state = Spree::State.find_by_abbr(affirm_address["address"]["region1_code"]) or - Spree::State.find_by_name(affirm_address["address"]["region1_code"]) _country = Spree::Country.find_by_iso3(affirm_address["address"]["country_code"]) or Spree::Country.find_by_iso(affirm_address["address"]["country_code"]) + + _state = Spree::State.find_by(abbr: affirm_address["address"]["region1_code"], country: _country) or + Spree::State.find_by_abbr(affirm_address["address"]["region1_code"]) or + Spree::State.find_by_name(affirm_address["address"]["region1_code"]) + # try to get the name from first and last _firstname = affirm_address["name"]["first"] if affirm_address["name"]["first"].present? _lastname = affirm_address["name"]["last"] if affirm_address["name"]["last"].present?