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

Move 'shipping_preference' preference under PaypalOrder#to_json #152

Merged
merged 4 commits into from
Nov 22, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,11 @@ SolidusPaypalCommercePlatform.addPayment = function(paypal_amount, payment_metho
})
}

SolidusPaypalCommercePlatform.updateAddress = function(response) {
var updated_address = response.purchase_units[0].shipping.address
SolidusPaypalCommercePlatform.updateAddress = function(response) {
var shipping = response.purchase_units[0].shipping;
if (!shipping) return Promise.resolve({});

var updated_address = shipping.address;
return Spree.ajax({
url: '/solidus_paypal_commerce_platform/update_address',
method: 'POST',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def javascript_sdk_url(order: nil, currency: nil)
currency: currency
}

parameters[:shipping_preference] = 'NO_SHIPPING' if step_names.exclude? 'delivery'
parameters['enable-funding'] = 'venmo' if venmo_standalone_enabled?

if !Rails.env.production? && options[:force_buyer_country].present?
Expand Down
17 changes: 16 additions & 1 deletion app/models/solidus_paypal_commerce_platform/paypal_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def to_json(intent)
{
intent: intent,
purchase_units: purchase_units,
payer: (payer if @order.bill_address)
payer: (payer if @order.bill_address),
application_context: application_context
}
end

Expand Down Expand Up @@ -109,5 +110,19 @@ def price(amount)
value: amount
}
end

def application_context
{
shipping_preference: require_shipping? ? 'SET_PROVIDED_ADDRESS' : 'NO_SHIPPING'
}
end

def require_shipping?
step_names.include? :delivery
end

def step_names
@order ? @order.checkout_steps.map(&:to_sym) : ::Spree::Order.checkout_steps.keys
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,6 @@ def Struct(data) # rubocop:disable Naming/MethodName
end
end

context 'when checkout_steps does not include "delivery"' do
it 'disables autocommit' do
allow(order).to receive(:checkout_steps).and_return([:address, :confirm, :payment])
expect(url.query.split("&")).to include("shipping_preference=NO_SHIPPING")
end
end

context 'when messaging is turned on' do
it 'includes messaging component' do
paypal_payment_method.preferences.update(display_credit_messaging: true)
Expand Down
22 changes: 22 additions & 0 deletions spec/models/solidus_paypal_commerce_platform/paypal_order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@
payer: hash_including(name: { given_name: 'Johnny', surname: 'Vonny Doey' })
)
end

context 'when checkout_steps does not include "delivery"' do
let(:old_checkout_flow) { Spree::Order.checkout_flow }

before do
old_checkout_flow

Spree::Order.class_eval do
remove_checkout_step :delivery
end
end

after do
Spree::Order.checkout_flow(&old_checkout_flow)
end

it 'disable shipping requirements' do
expect(to_json).to match hash_including(
application_context: hash_including(shipping_preference: 'NO_SHIPPING')
)
end
end
end

private
Expand Down