Skip to content

Commit

Permalink
Non-anniversary amendments: read prorations from connector settings (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nadaismail-stripe authored Oct 6, 2023
1 parent ae6e427 commit 65e980d
Show file tree
Hide file tree
Showing 6 changed files with 14,338 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/stripe-force/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class OrderStatusOptions < T::Enum
CONNECTOR_SETTING_PACKAGE_VERSION = 'package_version'
CONNECTOR_SETTING_POLLING_ENABLED = 'polling_enabled'
CONNECTOR_SETTING_SYNC_START_DATE = 'sync_start_date'
CONNECTOR_SETTING_CPQ_PRORATE_PRECISION = 'cpq_prorate_precision'

TERMINATION_METADATA_PREFIX = 'sbc_termination.'

Expand Down
3 changes: 2 additions & 1 deletion lib/stripe-force/db/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class User < Sequel::Model
sync_start_date: nil,
sync_record_retention: 10_000,
default_currency: 'USD',
CONNECTOR_SETTING_CPQ_PRORATE_PRECISION: 'month',
CONNECTOR_SETTING_POLLING_ENABLED => false,
CONNECTOR_SETTING_SYNC_START_DATE => nil,
CONNECTOR_SETTING_CPQ_TERM_UNIT => 'month',
Expand Down Expand Up @@ -382,7 +383,7 @@ def hidden_sync_pref_fields
hidden_sync_pref_fields = []

if !feature_enabled?(FeatureFlags::NON_ANNIVERSARY_AMENDMENTS)
hidden_sync_pref_fields << "cpq_prorate_precision"
hidden_sync_pref_fields << CONNECTOR_SETTING_CPQ_PRORATE_PRECISION
end

hidden_sync_pref_fields
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe-force/translate/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ def update_subscription_phases_from_order_amendments(contract_structure)
if days > 0
# if feature DAY_PRORATIONS is enabled, set the number of days to prorate
# else, a partial month equals a whole month so add one to the subscription term
if @user.feature_enabled?(FeatureFlags::DAY_PRORATIONS)
if @user.feature_enabled?(FeatureFlags::DAY_PRORATIONS) || @user.connector_settings[CONNECTOR_SETTING_CPQ_PRORATE_PRECISION] == 'month+day'
log.info 'prorating line items by days', days_prorating: days
days_prorating = days
else
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe-force/translate/price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def calculate_price_multiplier(mapper, sf_order, sf_order_item, billing_frequenc
# if there is a partial month due to a non-anniversary amendment
# we calculate the price multiplier differently depending on the CPQ Subscription Prorate Precision setting
if days > 0
if @user.feature_enabled?(FeatureFlags::DAY_PRORATIONS)
if @user.feature_enabled?(FeatureFlags::DAY_PRORATIONS) || @user.connector_settings[CONNECTOR_SETTING_CPQ_PRORATE_PRECISION] == 'month+day'
# calculate the price multiplier for when CPQ Subscription Prorate Precision = 'Month + Day'
log.info 'using \'monthly + daily\' price multiplier calculations', sf_order_id: sf_order.Id, sf_order_item_id: sf_order_item.Id, days: days
calculated_price_multiplier = StripeForce::Utilities::SalesforceUtil.calculate_month_plus_day_price_multiplier(whole_months: quote_subscription_term, partial_month_days: days, product_subscription_term: effective_subscription_term)
Expand Down
10 changes: 7 additions & 3 deletions test/integration/amendments/test_proration_amendments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1530,8 +1530,12 @@ class Critic::ProratedAmendmentTranslation < Critic::OrderAmendmentFunctionalTes

describe 'non-anniversary amendments with day porations' do
it 'translates non-anniversary amendment order billed monthly with day proration enabled' do
# Note feature DAY_PRORATIONS should only be enabled if CPQ Subscription Prorate Precision is set to 'Month + Day'
@user.enable_feature FeatureFlags::DAY_PRORATIONS, update: true
# Note either feature DAY_PRORATIONS should only be enabled or connector settings needs to be set to 'month_day"
# for connector to use PQ Subscription Prorate Precision is set to 'Month + Day'
@user.disable_feature FeatureFlags::DAY_PRORATIONS, update: true
@user.connector_settings[CONNECTOR_SETTING_CPQ_PRORATE_PRECISION] = 'month+day'
@user.save

@user.enable_feature FeatureFlags::NON_ANNIVERSARY_AMENDMENTS, update: true
@user.enable_feature FeatureFlags::TEST_CLOCKS, update: true

Expand All @@ -1557,7 +1561,7 @@ class Critic::ProratedAmendmentTranslation < Critic::OrderAmendmentFunctionalTes

sf_order = create_subscription_order(
sf_product_id: sf_product_id,
contact_email: "non_anniversary_day_proration",
contact_email: "non_anniversary_day_proration_2",
additional_fields: {
CPQ_QUOTE_SUBSCRIPTION_START_DATE => format_date_for_salesforce(initial_order_start_date),
CPQ_QUOTE_SUBSCRIPTION_TERM => contract_term,
Expand Down
Loading

0 comments on commit 65e980d

Please sign in to comment.