Skip to content

Commit b25f7a3

Browse files
JustShahfthobe
authored andcommitted
Enable address API to support email, vat_id, and reverse_charge_status
Update the API components to include email, vat_id, and reverse_charge_status in the address attributes. Modified `Spree::ApiConfiguration` and `Spree::PermittedAttributes` to handle the new fields. These changes improve data completeness and tax handling by storing additional information in the address.
1 parent 98c9256 commit b25f7a3

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

api/lib/spree/api_configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class ApiConfiguration < Preferences::Configuration
8585
preference :address_attributes, :array, default: [
8686
:id, :name, :address1, :address2, :city, :zipcode, :phone, :company,
8787
:alternative_phone, :country_id, :country_iso, :state_id, :state_name,
88-
:state_text
88+
:state_text, :email, :vat_id, :reverse_charge_status
8989
]
9090

9191
preference :country_attributes, :array, default: [:id, :iso_name, :iso, :iso3, :name, :numcode]

api/spec/requests/spree/api/address_books_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,31 @@ module Spree::Api
9090
end
9191
end
9292

93+
context "when updating a default address with email, VAT-ID and reverse charge status" do
94+
let(:user) { create(:user, spree_api_key: 'galleon') }
95+
let(:changes) {
96+
{ name: "Hermione Granger", email: "[email protected]", vat_id: "AB1234567",
97+
reverse_charge_status: "enabled", id: user.ship_address.id}
98+
}
99+
before do
100+
# Create "Harry Potter" default shipping address
101+
user.save_in_address_book(harry_address_attributes, true)
102+
end
103+
104+
it "changes the address and marks the changed address as default" do
105+
expect {
106+
put "/api/users/#{user.id}/address_book",
107+
params: { address_book: harry_address_attributes.merge(changes) },
108+
headers: { Authorization: 'Bearer galleon' }
109+
}.to change { user.reload.ship_address.name }.from("Harry Potter").to("Hermione Granger")
110+
111+
expect(json_response.first["reverse_charge_status"]).to eq("enabled")
112+
expect(json_response.first["email"]).to eq("[email protected]")
113+
expect(json_response.first["vat_id"]).to eq("AB1234567")
114+
expect(response.status).to eq(200)
115+
end
116+
end
117+
93118
context 'when creating an address' do
94119
it 'marks the update_target' do
95120
user = create(:user, spree_api_key: 'galleon')

api/spec/requests/spree/api/checkouts_spec.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ module Spree::Api
7777
phone: '3014445002',
7878
zipcode: '20814',
7979
state_id: @state.id,
80-
country_id: @country.id
80+
country_id: @country.id,
81+
82+
vat_id: 'ab1235',
83+
reverse_charge_status: 'disabled'
8184
}
8285
end
8386

@@ -95,7 +98,14 @@ module Spree::Api
9598
} }
9699
expect(json_response['state']).to eq('delivery')
97100
expect(json_response['bill_address']['name']).to eq('John Doe')
101+
expect(json_response['bill_address']['email']).to eq('[email protected]')
102+
expect(json_response['bill_address']['vat_id']).to eq('ab1235')
103+
expect(json_response['bill_address']['reverse_charge_status']).to eq('disabled')
98104
expect(json_response['ship_address']['name']).to eq('John Doe')
105+
expect(json_response['ship_address']['email']).to eq('[email protected]')
106+
expect(json_response['ship_address']['vat_id']).to eq('ab1235')
107+
expect(json_response['ship_address']['reverse_charge_status']).to eq('disabled')
108+
99109
expect(response.status).to eq(200)
100110
end
101111

core/lib/spree/permitted_attributes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module PermittedAttributes
4242
@@address_attributes = [
4343
:id, :name, :address1, :address2, :city, :country_id, :state_id,
4444
:zipcode, :phone, :state_name, :country_iso, :alternative_phone, :company,
45+
:email, :vat_id, :reverse_charge_status,
4546
country: [:iso, :name, :iso3, :iso_name],
4647
state: [:name, :abbr]
4748
]

0 commit comments

Comments
 (0)