Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR for view changes of customization quadpay-spree for spree 3.0.0 stable #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/helpers/spree/quad_pay_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
8 changes: 6 additions & 2 deletions app/models/spree/billing_integration/quad_pay_checkout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def auto_capture?
true
end

# NOTE: Add phone to params via order.phone field.
# Add Callback url. See line
# See line 97.
def build_order_params(order)
billing_address = order.billing_address
shipping_address = order.shipping_address
Expand All @@ -91,7 +94,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
Expand All @@ -113,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: ''),
Expand Down
10 changes: 6 additions & 4 deletions app/models/spree/order_decorator.rb
Original file line number Diff line number Diff line change
@@ -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.where(active: true).where.not(id: qpm_ids)
else
Spree::PaymentMethod.available_on_front_end
Spree::PaymentMethod.where(active: true)
end
end
end
5 changes: 3 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/active_merchant/billing/quad_pay_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ 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
Expand All @@ -34,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
Expand Down
5 changes: 4 additions & 1 deletion lib/tasks/quad_pay_tasks.rake
Original file line number Diff line number Diff line change
@@ -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|
Expand Down
2 changes: 1 addition & 1 deletion spree_quad_pay.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down