Skip to content

Commit

Permalink
Merge pull request #117 from solidusio-contrib/update_for_solidus_3_0
Browse files Browse the repository at this point in the history
Update extension for Solidus 3.0
  • Loading branch information
aldesantis authored Feb 6, 2021
2 parents 8937ef4 + 8fdbea9 commit 7a70553
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 29 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ RSpec/VerifiedDoubles:
# Sometimes you really need an "anything" double
IgnoreSymbolicNames: true

Rspec/Naming/VariableNumber:
# PayPal uses snake_case, we use normal_case ¯\_(ツ)_/¯
Enabled: false

Style/FrozenStringLiteralComment:
Exclude:
- spec/**/*
Expand Down
39 changes: 19 additions & 20 deletions app/models/solidus_paypal_commerce_platform/paypal_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def simulate_update(paypal_address)
end

def update(paypal_address)
formatted_address = format_address(paypal_address)
formatted_address = address_attributes(paypal_address[:updated_address], paypal_address[:recipient])
new_address = @order.ship_address.dup || ::Spree::Address.new
new_address.assign_attributes(formatted_address)

Expand Down Expand Up @@ -51,36 +51,35 @@ def find_state(state_name, country)
end

def format_simulated_address(paypal_address)
country = ::Spree::Country.find_by(iso: paypal_address[:country_code])
# Also adds fake information for a few fields, so validations can run
# Adds fake information for a few fields, so validations can run
paypal_address[:address_line_1] = "123 Fake St."

::Spree::Address.new(
city: paypal_address[:city],
state: find_state(paypal_address[:state], country),
state_name: paypal_address[:state],
zipcode: paypal_address[:postal_code],
country: country,
address1: "123 Fake St.",
phone: "123456789",
firstname: "Fake"
address_attributes(paypal_address, { name: { given_name: "Fake" } })
)
end

def format_address(paypal_address)
address = paypal_address[:updated_address]
recipient = paypal_address[:recipient]
def address_attributes(address, recipient)
country = ::Spree::Country.find_by(iso: address[:country_code])

{
attributes = {
address1: address[:address_line_1],
address2: address[:address_line_2],
state: find_state(address[:admin_area_1], country),
state_name: address[:admin_area_1],
city: address[:admin_area_2],
state: find_state(address[:admin_area_1] || address[:state], country),
state_name: address[:admin_area_1] || address[:state],
city: address[:admin_area_2] || address[:city],
country: country,
zipcode: address[:postal_code],
firstname: recipient[:name][:given_name],
lastname: recipient[:name][:surname]
}

if SolidusSupport.combined_first_and_last_name_in_address?
attributes[:name] = "#{recipient[:name][:given_name]} #{recipient[:name][:surname]}"
else
attributes[:firstname] = recipient[:name][:given_name]
attributes[:lastname] = recipient[:name][:surname]
end

attributes
end
end
end
2 changes: 1 addition & 1 deletion solidus_paypal_commerce_platform.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Gem::Specification.new do |spec|

spec.add_dependency 'deface', '~> 1.5'
spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 3']
spec.add_dependency 'solidus_support', [">= 0.5.1", "< 1"]
spec.add_dependency 'solidus_support', [">= 0.8.0", "< 1"]
spec.add_dependency 'solidus_webhooks', '~> 0.2'

spec.add_dependency 'paypal-checkout-sdk'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe SolidusPaypalCommercePlatform::PaypalAddress, type: :model do
let(:order) { create(:order) }
let(:original_address) { create(:address) }
let(:address) { create(:address) }
let(:address) { create(:address, name_attributes) }
let(:params) {
{
updated_address: {
Expand All @@ -16,8 +16,8 @@
},
recipient: {
name: {
given_name: address.firstname,
surname: address.lastname
given_name: "Alexander",
surname: "Hamilton"
}
}
}
Expand All @@ -37,8 +37,12 @@
expect(subject.address2).to eq address.address2
expect(subject.zipcode).to eq address.zipcode
expect(subject.country).to eq address.country
expect(subject.firstname).to eq address.firstname
expect(subject.lastname).to eq address.lastname
if SolidusSupport.combined_first_and_last_name_in_address?
expect(subject.name).to eq address.name
else
expect(subject.firstname).to eq address.firstname
expect(subject.lastname).to eq address.lastname
end
expect(subject.phone).to eq original_address.phone
end

Expand All @@ -52,4 +56,12 @@
end
end
end

def name_attributes
if SolidusSupport.combined_first_and_last_name_in_address?
{ name: "Alexander Hamilton" }
else
{ firstname: "Alexander", lastname: "Hamilton" }
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

get solidus_paypal_commerce_platform.verify_total_path, params: params

expect(response).to have_http_status(200)
expect(response).to have_http_status(:ok)
end
end

Expand All @@ -29,7 +29,7 @@

get solidus_paypal_commerce_platform.verify_total_path, params: params

expect(response).to have_http_status(400)
expect(response).to have_http_status(:bad_request)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

expect(payment_method.preferred_client_id).to eq("CLIENT-ID")
expect(payment_method.preferred_client_secret).to eq("CLIENT-SECRET")
expect(response).to have_http_status(201)
expect(response).to have_http_status(:created)
end
end
end

0 comments on commit 7a70553

Please sign in to comment.