From d3fdeedca79451a91afbcca0c9489d4bec9e645b Mon Sep 17 00:00:00 2001 From: Lovro Colic Date: Fri, 28 Jun 2024 14:28:11 +0200 Subject: [PATCH] add support for shippig address --- lib/lago/api/resources/customer.rb | 15 +++++++++++++++ spec/factories/customer.rb | 9 +++++++++ spec/fixtures/api/customer.json | 7 +++++++ spec/lago/api/resources/customer_spec.rb | 2 ++ 4 files changed, 33 insertions(+) diff --git a/lib/lago/api/resources/customer.rb b/lib/lago/api/resources/customer.rb index 0911ffa..15ae124 100644 --- a/lib/lago/api/resources/customer.rb +++ b/lib/lago/api/resources/customer.rb @@ -78,6 +78,10 @@ def whitelist_params(params) result_hash[:billing_configuration] = config unless config.empty? end + whitelist_shipping_address(params[:shipping_address]).tap do |address| + result_hash[:shipping_address] = address unless address.empty? + end + integration_customers = whitelist_integration_customers(params[:integration_customers]) result_hash[:integration_customers] = integration_customers unless integration_customers.empty? @@ -100,6 +104,17 @@ def whitelist_billing_configuration(billing_params) ) end + def whitelist_shipping_address(address) + (address || {}).slice( + :address_line1, + :address_line2, + :city, + :zipcode, + :state, + :country, + ) + end + def whitelist_integration_customers(integration_customers) processed_integration_customers = [] diff --git a/spec/factories/customer.rb b/spec/factories/customer.rb index 9a8ac53..a9ec8df 100644 --- a/spec/factories/customer.rb +++ b/spec/factories/customer.rb @@ -28,6 +28,15 @@ document_locale: 'fr', } end + shipping_address do + { + address_line1: '5230 Penfield Ave', + city: 'Woodland Hills', + zipcode: '91364', + state: 'CA', + country: 'US', + } + end integration_customers do [ { diff --git a/spec/fixtures/api/customer.json b/spec/fixtures/api/customer.json index 3303f01..c851ba4 100644 --- a/spec/fixtures/api/customer.json +++ b/spec/fixtures/api/customer.json @@ -30,6 +30,13 @@ "document_locale": "fr", "provider_payment_methods": ["card"] }, + "shipping_address": { + "address_line1": "5230 Penfield Ave", + "city": "Woodland Hills", + "zipcode": "91364", + "state": "CA", + "country": "US" + }, "integration_customers": [ { "lago_id": "123asd123lkj987lkj", diff --git a/spec/lago/api/resources/customer_spec.rb b/spec/lago/api/resources/customer_spec.rb index 630dd99..07c9e29 100644 --- a/spec/lago/api/resources/customer_spec.rb +++ b/spec/lago/api/resources/customer_spec.rb @@ -39,6 +39,8 @@ expect(customer.billing_configuration.invoice_grace_period).to eq(3) expect(customer.billing_configuration.provider_customer_id).to eq('cus_12345') expect(customer.billing_configuration.provider_payment_methods).to eq(['card']) + expect(customer.shipping_address.city).to eq('Woodland Hills') + expect(customer.shipping_address.country).to eq('US') expect(customer.integration_customers.first.external_customer_id).to eq('123456789') expect(customer.integration_customers.first.type).to eq('netsuite') expect(customer.metadata.first.key).to eq('key')