Commit a1a409a5 authored by Vitaly Slobodin's avatar Vitaly Slobodin Committed by Robert Speicher

Use billing email to create subscriptions

We can't use an email from GL.com because
it may differ from the billing email.
Instead we must use the email
received from the CustomersDot as a billing email.

Closes https://gitlab.com/gitlab-org/customers-gitlab-com/-/issues/2168
parent 290f691c
......@@ -13,10 +13,16 @@ module Subscriptions
def execute
response = client.create_customer(create_customer_params)
return response unless response[:success]
token = response.with_indifferent_access[:data][:customer][:authentication_token]
client.create_subscription(create_subscription_params, current_user.email, token)
# We can't use an email from GL.com because it may differ from the billing email.
# Instead we use the email received from the CustomersDot as a billing email.
customer_data = response.with_indifferent_access[:data][:customer]
billing_email = customer_data[:email]
token = customer_data[:authentication_token]
client.create_subscription(create_subscription_params, billing_email, token)
end
private
......
---
title: Use billing email for purchasing subscriptions
merge_request: 47105
author:
type: fixed
......@@ -28,6 +28,7 @@ RSpec.describe Subscriptions::CreateService do
}
end
let_it_be(:customer_email) { 'first.last@gitlab.com' }
let_it_be(:client) { Gitlab::SubscriptionPortal::Client }
let_it_be(:create_service_params) { Gitlab::Json.parse(fixture_file('create_service_params.json', dir: 'ee')).deep_symbolize_keys }
......@@ -44,11 +45,11 @@ RSpec.describe Subscriptions::CreateService do
context 'when successfully creating a customer' do
before do
allow(client).to receive(:create_customer).and_return(success: true, data: { success: true, 'customer' => { 'authentication_token' => 'token' } })
allow(client).to receive(:create_customer).and_return(success: true, data: { success: true, 'customer' => { 'authentication_token' => 'token', 'email' => customer_email } })
end
it 'creates a subscription with the returned authentication token' do
expect(client).to receive(:create_subscription).with(anything, user.email, 'token')
expect(client).to receive(:create_subscription).with(anything, customer_email, 'token')
subject.execute
end
......@@ -75,7 +76,7 @@ RSpec.describe Subscriptions::CreateService do
context 'passing the correct parameters to the client' do
before do
allow(client).to receive(:create_customer).and_return(success: true, data: { success: true, customer: { authentication_token: 'token' } })
allow(client).to receive(:create_customer).and_return(success: true, data: { success: true, customer: { authentication_token: 'token', email: customer_email } })
allow(client).to receive(:create_subscription).and_return(success: true, data: { success: true, subscription_id: 'xxx' })
end
......@@ -86,7 +87,7 @@ RSpec.describe Subscriptions::CreateService do
end
it 'passes the correct parameters for creating a subscription' do
expect(client).to receive(:create_subscription).with(create_service_params[:subscription], 'first.last@gitlab.com', 'token')
expect(client).to receive(:create_subscription).with(create_service_params[:subscription], customer_email, 'token')
subject.execute
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment