diff --git a/app/services/payment_provider_customers/gocardless_service.rb b/app/services/payment_provider_customers/gocardless_service.rb index f83a5566b90..bc0a7b993b8 100644 --- a/app/services/payment_provider_customers/gocardless_service.rb +++ b/app/services/payment_provider_customers/gocardless_service.rb @@ -70,12 +70,14 @@ def client end def create_gocardless_customer - client.customers.create( - params: { - email: customer.email&.strip&.split(',')&.first, - company_name: customer.name - } - ) + customer_params = { + email: customer.email&.strip&.split(',')&.first, + company_name: customer.name.presence, + given_name: customer.firstname.presence, + family_name: customer.lastname.presence + }.compact + + client.customers.create(customer_params) rescue GoCardlessPro::Error => e deliver_error_webhook(e) diff --git a/spec/services/payment_provider_customers/gocardless_service_spec.rb b/spec/services/payment_provider_customers/gocardless_service_spec.rb index 9b1194e742f..0e76abb64a4 100644 --- a/spec/services/payment_provider_customers/gocardless_service_spec.rb +++ b/spec/services/payment_provider_customers/gocardless_service_spec.rb @@ -27,6 +27,20 @@ .and_return(GoCardlessPro::Resources::Customer.new('id' => '123')) end + context 'when all customer details are present' do + it 'creates a customer with company_name, given_name, and family_name' do + gocardless_service.create + expect(gocardless_customers_service).to have_received(:create).with( + hash_including( + email: customer.email, + company_name: customer.name, + given_name: customer.firstname, + family_name: customer.lastname + ) + ) + end + end + it 'creates the gocardless customer' do result = gocardless_service.create