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 ...@@ -13,10 +13,16 @@ module Subscriptions
def execute def execute
response = client.create_customer(create_customer_params) response = client.create_customer(create_customer_params)
return response unless response[:success] return response unless response[:success]
token = response.with_indifferent_access[:data][:customer][:authentication_token] # We can't use an email from GL.com because it may differ from the billing email.
client.create_subscription(create_subscription_params, current_user.email, token) # 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 end
private private
......
---
title: Use billing email for purchasing subscriptions
merge_request: 47105
author:
type: fixed
...@@ -28,6 +28,7 @@ RSpec.describe Subscriptions::CreateService do ...@@ -28,6 +28,7 @@ RSpec.describe Subscriptions::CreateService do
} }
end end
let_it_be(:customer_email) { 'first.last@gitlab.com' }
let_it_be(:client) { Gitlab::SubscriptionPortal::Client } 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 } 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 ...@@ -44,11 +45,11 @@ RSpec.describe Subscriptions::CreateService do
context 'when successfully creating a customer' do context 'when successfully creating a customer' do
before 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 end
it 'creates a subscription with the returned authentication token' do 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 subject.execute
end end
...@@ -75,7 +76,7 @@ RSpec.describe Subscriptions::CreateService do ...@@ -75,7 +76,7 @@ RSpec.describe Subscriptions::CreateService do
context 'passing the correct parameters to the client' do context 'passing the correct parameters to the client' do
before 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' }) allow(client).to receive(:create_subscription).and_return(success: true, data: { success: true, subscription_id: 'xxx' })
end end
...@@ -86,7 +87,7 @@ RSpec.describe Subscriptions::CreateService do ...@@ -86,7 +87,7 @@ RSpec.describe Subscriptions::CreateService do
end end
it 'passes the correct parameters for creating a subscription' do 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 subject.execute
end 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