From ab28802d5a2bacb75bf11329efa83da55fb42de7 Mon Sep 17 00:00:00 2001 From: Tanmay Deep Sharma Date: Thu, 6 Nov 2025 15:25:57 +0530 Subject: [PATCH 1/2] update gemfile stripe version to alpha --- Gemfile | 2 +- Gemfile.lock | 4 ++-- app/views/api/v1/models/_account.json.jbuilder | 8 ++++++-- .../enterprise/api/v1/accounts/concerns/billing_v2.rb | 2 +- .../enterprise/billing/create_stripe_customer_service.rb | 6 +----- .../services/enterprise/billing/v2/change_plan_service.rb | 2 +- .../enterprise/billing/v2/checkout_session_service.rb | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index 666ffea54..8413739f2 100644 --- a/Gemfile +++ b/Gemfile @@ -159,7 +159,7 @@ gem 'working_hours' gem 'pg_search' # Subscriptions, Billing -gem 'stripe', '17.2.0.pre.beta.1' +gem 'stripe', '17.2.0.pre.alpha.2' ## - helper gems --## ## to populate db with sample data diff --git a/Gemfile.lock b/Gemfile.lock index 4a62aeab7..9d0c6286b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -902,7 +902,7 @@ GEM squasher (0.7.2) stackprof (0.2.25) statsd-ruby (1.5.0) - stripe (17.2.0.pre.beta.1) + stripe (17.2.0.pre.alpha.2) telephone_number (1.4.20) test-prof (1.2.1) thor (1.4.0) @@ -1110,7 +1110,7 @@ DEPENDENCIES spring-watcher-listen squasher stackprof - stripe (= 17.2.0.pre.beta.1) + stripe (= 17.2.0.pre.alpha.2) telephone_number test-prof tidewave diff --git a/app/views/api/v1/models/_account.json.jbuilder b/app/views/api/v1/models/_account.json.jbuilder index 0cd9bf038..886777017 100644 --- a/app/views/api/v1/models/_account.json.jbuilder +++ b/app/views/api/v1/models/_account.json.jbuilder @@ -7,8 +7,12 @@ if resource.custom_attributes.present? json.subscription_status resource.custom_attributes['subscription_status'] json.subscription_ends_on resource.custom_attributes['subscription_ends_on'] json.stripe_subscription_id resource.custom_attributes['stripe_subscription_id'] if resource.custom_attributes['stripe_subscription_id'].present? - json.pending_stripe_pricing_plan_id resource.custom_attributes['pending_stripe_pricing_plan_id'] if resource.custom_attributes['pending_stripe_pricing_plan_id'].present? - json.pending_subscription_quantity resource.custom_attributes['pending_subscription_quantity'] if resource.custom_attributes['pending_subscription_quantity'].present? + if resource.custom_attributes['pending_stripe_pricing_plan_id'].present? + json.pending_stripe_pricing_plan_id resource.custom_attributes['pending_stripe_pricing_plan_id'] + end + if resource.custom_attributes['pending_subscription_quantity'].present? + json.pending_subscription_quantity resource.custom_attributes['pending_subscription_quantity'] + end json.stripe_pricing_plan_id resource.custom_attributes['stripe_pricing_plan_id'] if resource.custom_attributes['stripe_pricing_plan_id'].present? json.next_billing_date resource.custom_attributes['next_billing_date'] if resource.custom_attributes['next_billing_date'].present? json.industry resource.custom_attributes['industry'] if resource.custom_attributes['industry'].present? diff --git a/enterprise/app/controllers/enterprise/api/v1/accounts/concerns/billing_v2.rb b/enterprise/app/controllers/enterprise/api/v1/accounts/concerns/billing_v2.rb index 045699b62..79ec14834 100644 --- a/enterprise/app/controllers/enterprise/api/v1/accounts/concerns/billing_v2.rb +++ b/enterprise/app/controllers/enterprise/api/v1/accounts/concerns/billing_v2.rb @@ -67,7 +67,7 @@ module Enterprise::Api::V1::Accounts::Concerns::BillingV2 service = Enterprise::Billing::V2::ChangePlanService.new(account: @account) result = service.change_plan( new_pricing_plan_id: params[:pricing_plan_id], - quantity: params[:quantity].to_i + quantity: params[:quantity]&.to_i ) if result[:success] diff --git a/enterprise/app/services/enterprise/billing/create_stripe_customer_service.rb b/enterprise/app/services/enterprise/billing/create_stripe_customer_service.rb index 15be677d2..531516b3d 100644 --- a/enterprise/app/services/enterprise/billing/create_stripe_customer_service.rb +++ b/enterprise/app/services/enterprise/billing/create_stripe_customer_service.rb @@ -19,12 +19,8 @@ class Enterprise::Billing::CreateStripeCustomerService def prepare_customer_id customer_id = account.custom_attributes['stripe_customer_id'] - test_clock = Stripe::TestHelpers::TestClock.create({ - frozen_time: Time.now.to_i, - name: 'Test Clock for Account' - }) if customer_id.blank? - customer = Stripe::Customer.create({ name: account.name, email: billing_email, test_clock: test_clock.id }) + customer = Stripe::Customer.create({ name: account.name, email: billing_email }) customer_id = customer.id end customer_id diff --git a/enterprise/app/services/enterprise/billing/v2/change_plan_service.rb b/enterprise/app/services/enterprise/billing/v2/change_plan_service.rb index 44fcc0b45..30ba26055 100644 --- a/enterprise/app/services/enterprise/billing/v2/change_plan_service.rb +++ b/enterprise/app/services/enterprise/billing/v2/change_plan_service.rb @@ -20,7 +20,7 @@ class Enterprise::Billing::V2::ChangePlanService < Enterprise::Billing::V2::Base def validate_parameters(new_pricing_plan_id, quantity) return { success: false, message: 'Must specify either new_pricing_plan_id or quantity' } if new_pricing_plan_id.nil? && quantity.nil? - return { success: false, message: 'Invalid quantity' } if quantity && !quantity.positive? + return { success: false, message: 'Invalid quantity' } if !quantity.nil? && !quantity.positive? # Validate customer has a default payment method using common service payment_service = Enterprise::Billing::V2::InvoicePaymentService.new(account: account) diff --git a/enterprise/app/services/enterprise/billing/v2/checkout_session_service.rb b/enterprise/app/services/enterprise/billing/v2/checkout_session_service.rb index 502545f92..4e21bf0e5 100644 --- a/enterprise/app/services/enterprise/billing/v2/checkout_session_service.rb +++ b/enterprise/app/services/enterprise/billing/v2/checkout_session_service.rb @@ -12,7 +12,7 @@ class Enterprise::Billing::V2::CheckoutSessionService < Enterprise::Billing::V2: validate_params store_pending_subscription_quantity - session = create_checkout_session + session = create_checkout_session(checkout_session_params) { success: true, redirect_url: session.url } end From fb86b1354af89dfb122000c7c51f8a7be9fdd310 Mon Sep 17 00:00:00 2001 From: Tanmay Deep Sharma Date: Thu, 6 Nov 2025 15:31:06 +0530 Subject: [PATCH 2/2] make stripe billing version consistent --- .../enterprise/billing/create_stripe_customer_service.rb | 2 +- .../enterprise/billing/create_stripe_customer_service_spec.rb | 4 ++-- .../enterprise/billing/v2/usage_reporter_service_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/enterprise/app/services/enterprise/billing/create_stripe_customer_service.rb b/enterprise/app/services/enterprise/billing/create_stripe_customer_service.rb index 531516b3d..742bac00a 100644 --- a/enterprise/app/services/enterprise/billing/create_stripe_customer_service.rb +++ b/enterprise/app/services/enterprise/billing/create_stripe_customer_service.rb @@ -67,7 +67,7 @@ class Enterprise::Billing::CreateStripeCustomerService attributes = { stripe_customer_id: customer_id, - stripe_billing_version: 'v2' + stripe_billing_version: '2' } if hacker_plan_config&.value.present? diff --git a/spec/enterprise/services/enterprise/billing/create_stripe_customer_service_spec.rb b/spec/enterprise/services/enterprise/billing/create_stripe_customer_service_spec.rb index a2fac700f..731a77762 100644 --- a/spec/enterprise/services/enterprise/billing/create_stripe_customer_service_spec.rb +++ b/spec/enterprise/services/enterprise/billing/create_stripe_customer_service_spec.rb @@ -54,7 +54,7 @@ describe Enterprise::Billing::CreateStripeCustomerService do expect(Stripe::Customer).to have_received(:create).with({ name: account.name, email: admin1.email }) expect(account.reload.custom_attributes).to include( 'stripe_customer_id' => 'cus_random_number', - 'stripe_billing_version' => 'v2', + 'stripe_billing_version' => '2', 'stripe_pricing_plan_id' => 'bpp_hacker_123', 'plan_name' => 'Hacker', 'subscribed_quantity' => 2 @@ -79,7 +79,7 @@ describe Enterprise::Billing::CreateStripeCustomerService do expect(Stripe::Customer).not_to have_received(:create) expect(account.reload.custom_attributes).to include( 'stripe_customer_id' => 'cus_existing_v2', - 'stripe_billing_version' => 'v2', + 'stripe_billing_version' => '2', 'stripe_pricing_plan_id' => 'bpp_hacker_123', 'plan_name' => 'Hacker', 'subscribed_quantity' => 2 diff --git a/spec/enterprise/services/enterprise/billing/v2/usage_reporter_service_spec.rb b/spec/enterprise/services/enterprise/billing/v2/usage_reporter_service_spec.rb index 354463bb7..7bd2ce6e6 100644 --- a/spec/enterprise/services/enterprise/billing/v2/usage_reporter_service_spec.rb +++ b/spec/enterprise/services/enterprise/billing/v2/usage_reporter_service_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe Enterprise::Billing::V2::UsageReporterService do - let(:account) { create(:account, custom_attributes: { 'stripe_billing_version' => 2, 'stripe_customer_id' => 'cus_123' }) } + let(:account) { create(:account, custom_attributes: { 'stripe_billing_version' => '2', 'stripe_customer_id' => 'cus_123' }) } let(:service) { described_class.new(account: account) } describe '#report' do