Commit c2286672 authored by Mark Chao's avatar Mark Chao

Merge branch 'dz/345674-send-full-params-on-first-addons-purchase' into 'master'

Add full params on first addons purchase

See merge request gitlab-org/gitlab!74519
parents a6701b67 5203239d
......@@ -71,10 +71,7 @@ module Subscriptions
end
def create_subscription(customer_data)
# When purchasing an add on, we don't want to send create_subscription_params
# in order to avoid amending the main product. Note that this will go away
# when fully transitioning the flow to GraphQL
create_params = add_on? ? create_addon_params : create_subscription_params
create_params = send_create_addon_params? ? create_addon_params : create_subscription_params
billing_email, token = customer_data.values_at(:email, :authentication_token)
client.create_subscription(create_params, billing_email, token)
......@@ -112,6 +109,14 @@ module Subscriptions
Gitlab::Utils.to_boolean(subscription_params[:is_addon], default: false)
end
def send_create_addon_params?
# We don't want to send create_subscription_params when purchasing addon
# in order to avoid amending the main product. The only exception to it
# is when we don't have an active subscription for a group purchasing addon.
# Note that this will go away when fully transitioning the flow to GraphQL
add_on? && subscription_params[:active_subscription].present?
end
def country_code(country)
World.alpha3_from_alpha2(country)
end
......
[
{
{
"subscription_params": {
"customer": {
"provider": "gitlab",
"uid": 111,
......@@ -35,7 +35,7 @@
"source": "some_source"
}
},
{
"addon_with_active_sub": {
"customer": {
"provider": "gitlab",
"uid": 111,
......@@ -67,5 +67,41 @@
"preview": "false",
"source": "some_source"
}
},
"addon_without_active_sub": {
"customer": {
"provider": "gitlab",
"uid": 111,
"credentials": {
"token": "foo_token"
},
"customer": {
"country": "NLD",
"address_1": "Address line 1",
"address_2": "Address line 2",
"city": "City",
"state": "State",
"zip_code": "Zip code",
"company": "My organization"
},
"info": {
"first_name": "First name",
"last_name": "Last name",
"email": "first.last@gitlab.com"
}
},
"subscription": {
"plan_id": "Add-on Plan ID",
"payment_method_id": "Payment method ID",
"products": {
"main": {
"quantity": 111
}
},
"gl_namespace_id": 222,
"gl_namespace_name": "Group name",
"preview": "false",
"source": "some_source"
}
}
]
}
\ No newline at end of file
......@@ -32,7 +32,7 @@ RSpec.describe Subscriptions::CreateService do
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'))[0].deep_symbolize_keys }
let_it_be(:create_service_params) { Gitlab::Json.parse(fixture_file('create_service_params.json', dir: 'ee'))["subscription_params"].deep_symbolize_keys }
describe '#execute' do
before do
......@@ -127,7 +127,6 @@ RSpec.describe Subscriptions::CreateService do
let_it_be(:subscription_params) do
{
is_addon: true,
active_subscription: 'A-000000',
plan_id: 'Add-on Plan ID',
payment_method_id: 'Payment method ID',
quantity: 111,
......@@ -135,12 +134,28 @@ RSpec.describe Subscriptions::CreateService do
}
end
it 'passes the correct parameters for creating a subscription' do
create_service_addon_params = Gitlab::Json.parse(fixture_file('create_service_params.json', dir: 'ee'))[1].deep_symbolize_keys
context 'without active subscription' do
it 'passes the correct parameters for creating a subscription' do
create_service_addon_params = Gitlab::Json.parse(fixture_file('create_service_params.json', dir: 'ee'))["addon_without_active_sub"].deep_symbolize_keys
expect(client).to receive(:create_subscription).with(create_service_addon_params[:subscription], customer_email, 'token')
expect(client).to receive(:create_subscription).with(create_service_addon_params[:subscription], customer_email, 'token')
execute
execute
end
end
context 'with active subscription' do
before do
subscription_params[:active_subscription] = 'A-000000'
end
it 'passes the correct parameters for creating a subscription' do
create_service_addon_params = Gitlab::Json.parse(fixture_file('create_service_params.json', dir: 'ee'))["addon_with_active_sub"].deep_symbolize_keys
expect(client).to receive(:create_subscription).with(create_service_addon_params[:subscription], customer_email, 'token')
execute
end
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