From fdf660585a7e1bf82a714ad6f7a4f795f70a2fd2 Mon Sep 17 00:00:00 2001 From: kolbaa Date: Wed, 23 Jan 2019 01:48:43 +0300 Subject: [PATCH 1/5] Initial customization for Spree 3.0.0 --- app/helpers/spree/quad_pay_helper.rb | 4 +++- .../spree/billing_integration/quad_pay_checkout.rb | 4 +++- app/models/spree/order_decorator.rb | 10 ++++++---- config/routes.rb | 5 +++-- lib/active_merchant/billing/quad_pay_api.rb | 4 +++- lib/tasks/quad_pay_tasks.rake | 5 ++++- 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app/helpers/spree/quad_pay_helper.rb b/app/helpers/spree/quad_pay_helper.rb index f2e2dce..1e02aec 100644 --- a/app/helpers/spree/quad_pay_helper.rb +++ b/app/helpers/spree/quad_pay_helper.rb @@ -2,8 +2,10 @@ module Spree module QuadPayHelper QUADPAY_WIDGET_URL_BASE = "https://widgets.quadpay.com" + # NOTE: customize line 8 for Spree 3.0.0-stable + # Spree::BillingIntegration::QuadPayCheckout.available_on_front_end.exists?(active: true) def quadpay_active_on_front_end? - Spree::BillingIntegration::QuadPayCheckout.available_on_front_end.exists?(active: true) + Spree::BillingIntegration::QuadPayCheckout.exists?(active: true) end def display_quadpay_widget_on_product_page? diff --git a/app/models/spree/billing_integration/quad_pay_checkout.rb b/app/models/spree/billing_integration/quad_pay_checkout.rb index ef25a4f..cb24a39 100644 --- a/app/models/spree/billing_integration/quad_pay_checkout.rb +++ b/app/models/spree/billing_integration/quad_pay_checkout.rb @@ -83,6 +83,8 @@ def auto_capture? true end + # NOTE: Add phone to params via order.phone field. + # See line 96. def build_order_params(order) billing_address = order.billing_address shipping_address = order.shipping_address @@ -91,7 +93,7 @@ def build_order_params(order) 'description': "Order ##{order.number}", 'amount': number_to_currency(order.total.to_f, unit: ''), 'consumer': { - 'phoneNumber': billing_address.phone, + 'phoneNumber': order.phone, 'givenNames': billing_address.first_name, 'surname': billing_address.last_name, 'email': order.email diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 354dd5c..37be3f8 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -1,11 +1,13 @@ Spree::Order.class_eval do def available_payment_methods - qpm_ids = Spree::BillingIntegration::QuadPayCheckout.active.ids - @available_payment_methods ||= + # NOTE: Customize for Spree 3.0.0 + # See lines 5,6,8,10 + qpm_ids = Spree::BillingIntegration::QuadPayCheckout.where(active: true).ids + @available_payment_methods ||= if qpm_ids.any? && (self.total < Spree::Config.quad_pay_min_amount.to_f || self.total > Spree::Config.quad_pay_max_amount.to_f) - Spree::PaymentMethod.available_on_front_end.where.not(id: qpm_ids) + Spree::PaymentMethod.available.where.not(id: qpm_ids) else - Spree::PaymentMethod.available_on_front_end + Spree::PaymentMethod.available end end end diff --git a/config/routes.rb b/config/routes.rb index 732f88f..dca4e98 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,8 +6,9 @@ get :quadpay_confirm end end - - namespace :admin, path: Spree.admin_path do + # NOTE: Make routes working for our project + # Removed path parameter for namespace below. + namespace :admin do resources :quad_pay_settings, :only => [] do collection do get :edit diff --git a/lib/active_merchant/billing/quad_pay_api.rb b/lib/active_merchant/billing/quad_pay_api.rb index a9761c3..22caecf 100644 --- a/lib/active_merchant/billing/quad_pay_api.rb +++ b/lib/active_merchant/billing/quad_pay_api.rb @@ -22,10 +22,12 @@ def auth_end_point end end + # NOTE: Fixed depreceted base url for test mode. + # See line 30 def auth_audience @auth_audience ||= if @test_mode - 'https://auth-dev.quadpay.com' + 'https://api-ut.quadpay.com' else 'https://auth.quadpay.com' end diff --git a/lib/tasks/quad_pay_tasks.rake b/lib/tasks/quad_pay_tasks.rake index 7381755..471d05b 100644 --- a/lib/tasks/quad_pay_tasks.rake +++ b/lib/tasks/quad_pay_tasks.rake @@ -1,6 +1,9 @@ +# NOTE: Customization for Spree 3.0.0 +# Stop using available_on_frontend method, using just where(active: true) +# See line 5 namespace :quad_pay_tasks do task sync_orders: :environment do - qpms = Spree::BillingIntegration::QuadPayCheckout.available_on_front_end.active + qpms = Spree::BillingIntegration::QuadPayCheckout.where(active: true) if qpm = qpms.first quad_pay_payments = quad_pay_payments(qpms) quad_pay_payments.each do |payment| From 563dd11d58f0d567a6f448acca348de2929f690e Mon Sep 17 00:00:00 2001 From: kolbaa Date: Wed, 23 Jan 2019 01:56:52 +0300 Subject: [PATCH 2/5] Fix dependencies --- spree_quad_pay.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spree_quad_pay.gemspec b/spree_quad_pay.gemspec index db5c2be..d4e10e4 100644 --- a/spree_quad_pay.gemspec +++ b/spree_quad_pay.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |s| s.require_path = 'lib' s.requirements << 'none' - spree_version = '>= 3.2.0', '< 4.0' + spree_version = '>= 3.0.0', '< 4.0' s.add_dependency 'spree_core', spree_version s.add_development_dependency 'capybara', '~> 2.6' From 73ba6052d7431c244eb4e06b9fa041aa57619c4e Mon Sep 17 00:00:00 2001 From: kolbaa Date: Wed, 23 Jan 2019 21:39:35 +0300 Subject: [PATCH 3/5] Use not deprecated api endpoints --- lib/active_merchant/billing/quad_pay_api.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/active_merchant/billing/quad_pay_api.rb b/lib/active_merchant/billing/quad_pay_api.rb index 22caecf..4795a23 100644 --- a/lib/active_merchant/billing/quad_pay_api.rb +++ b/lib/active_merchant/billing/quad_pay_api.rb @@ -27,7 +27,7 @@ def auth_end_point def auth_audience @auth_audience ||= if @test_mode - 'https://api-ut.quadpay.com' + 'https://auth-dev.quadpay.com' else 'https://auth.quadpay.com' end @@ -36,7 +36,7 @@ def auth_audience def base_url @base_url ||= if @test_mode - 'https://api-ci.quadpay.com' + 'https://api-ut.quadpay.com' else 'https://api.quadpay.com' end From ea4ed0d7fe3425904c4555cb93d875eeb8fcdaf1 Mon Sep 17 00:00:00 2001 From: kolbaa Date: Wed, 30 Jan 2019 13:24:29 +0300 Subject: [PATCH 4/5] Fix undefined method for array --- app/models/spree/order_decorator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 37be3f8..4377e49 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -5,9 +5,9 @@ def available_payment_methods qpm_ids = Spree::BillingIntegration::QuadPayCheckout.where(active: true).ids @available_payment_methods ||= if qpm_ids.any? && (self.total < Spree::Config.quad_pay_min_amount.to_f || self.total > Spree::Config.quad_pay_max_amount.to_f) - Spree::PaymentMethod.available.where.not(id: qpm_ids) + Spree::PaymentMethod.where(active: true).where.not(id: qpm_ids) else - Spree::PaymentMethod.available + Spree::PaymentMethod.where(active: true) end end end From 8ee516770a0eed34d549a85b13eb340f3f054120 Mon Sep 17 00:00:00 2001 From: kolbaa Date: Tue, 26 Feb 2019 17:18:33 +0300 Subject: [PATCH 5/5] Add callback url --- app/models/spree/billing_integration/quad_pay_checkout.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/spree/billing_integration/quad_pay_checkout.rb b/app/models/spree/billing_integration/quad_pay_checkout.rb index cb24a39..80e7137 100644 --- a/app/models/spree/billing_integration/quad_pay_checkout.rb +++ b/app/models/spree/billing_integration/quad_pay_checkout.rb @@ -84,7 +84,8 @@ def auto_capture? end # NOTE: Add phone to params via order.phone field. - # See line 96. + # Add Callback url. See line + # See line 97. def build_order_params(order) billing_address = order.billing_address shipping_address = order.shipping_address @@ -115,7 +116,8 @@ def build_order_params(order) 'items': line_item_as_json(order), 'merchant': { 'redirectConfirmUrl': "#{site_url}/orders/quadpay_confirm", - 'redirectCancelUrl': "#{site_url}/orders/quadpay_cancel" + 'redirectCancelUrl': "#{site_url}/orders/quadpay_cancel", + 'statusCallbackUrl': "#{site_url}/orders/quadpay_callback" }, 'merchantReference': order.number, 'taxAmount': number_to_currency(order.tax_total, unit: ''),