Skip to content

Commit

Permalink
PLATINT-1501: Add field defaults for proration and end behavior (#1136)
Browse files Browse the repository at this point in the history
* Add enum for proration behavior

* Added end behavior enum and called constants in code
  • Loading branch information
jocelyntseng-stripe authored Jun 23, 2023
1 parent a168a6e commit 476f4d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
15 changes: 15 additions & 0 deletions lib/stripe-force/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,21 @@ class MetadataKeys < T::Enum
end
end

class StripeProrationBehavior < T::Enum
enums do
CREATE_PRORATIONS = new('create_prorations')
NONE = new('none')
ALWAYS_INVOICE = new('always_invoice')
end
end

class StripeEndBehavior < T::Enum
enums do
RELEASE = new('release')
CANCEL = new('cancel')
end
end

# time related constants
SECONDS_IN_DAY = 86400
DAYS_IN_YEAR = 365
Expand Down
12 changes: 6 additions & 6 deletions lib/stripe-force/translate/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def migrate_pre_integration_order(contract_structure)
metadata: Metadata.stripe_metadata_for_sf_object(@user, sf_order).merge({StripeForce::Translate::Metadata.metadata_key(@user, MetadataKeys::PRE_INTEGRATION_ORDER) => true}),
items: subscription_items.map(&:stripe_params),
add_invoice_items: invoice_items.map(&:stripe_params),
proration_behavior: 'none',
proration_behavior: StripeProrationBehavior::NONE.serialize,
})

mapper.assign_values_from_hash(subscription, subscription_params)
Expand Down Expand Up @@ -188,7 +188,7 @@ def migrate_pre_integration_order(contract_structure)
# Metadata doesn't come over with the sub -> sub schedule migration
subscription_schedule.metadata = subscription.metadata
# End behavior is not a subscription field, so we have to set it on the schedule
subscription_schedule.end_behavior = 'cancel'
subscription_schedule.end_behavior = StripeEndBehavior::CANCEL.serialize
subscription_schedule.save

update_sf_stripe_id(sf_order, subscription_schedule)
Expand Down Expand Up @@ -346,7 +346,7 @@ def create_stripe_transaction_from_sf_order(sf_order)

subscription_schedule = Stripe::SubscriptionSchedule.construct_from({
# TODO this should be specified in the defaults hash... we should create a defaults hash https://jira.corp.stripe.com/browse/PLATINT-1501
end_behavior: 'cancel',
end_behavior: StripeEndBehavior::CANCEL.serialize,
metadata: Metadata.stripe_metadata_for_sf_object(@user, sf_order),
})

Expand Down Expand Up @@ -477,7 +477,7 @@ def generate_phases_for_initial_order(sf_order:, invoice_items:, subscription_it
# this field indicates that we should not bill the customer for this period
skip_initial_phase_proration = initial_order_starts_now_or_future || sf_order[SKIP_PAST_INITIAL_INVOICES] == true
if skip_initial_phase_proration
initial_phase[:proration_behavior] = 'none'
initial_phase[:proration_behavior] = StripeProrationBehavior::NONE.serialize
end

if is_initial_order_backend_prorated
Expand Down Expand Up @@ -509,7 +509,7 @@ def generate_phases_for_initial_order(sf_order:, invoice_items:, subscription_it
prorated_phase = {
# TODO https://jira.corp.stripe.com/browse/PLATINT-1501
# we do not want to bill the user for a entire billing cycle, so we turn off prorations
proration_behavior: 'none',
proration_behavior: StripeProrationBehavior::NONE.serialize,

# in the prorated phase, the item list will be exactly the same as the initial phase
items: subscription_items.map(&:stripe_params),
Expand Down Expand Up @@ -948,7 +948,7 @@ def update_subscription_phases_from_order_amendments(contract_structure)
end

# `none` is really important to ensure that the user is not billed by stripe for any prorated amounts
subscription_schedule.proration_behavior = 'none'
subscription_schedule.proration_behavior = StripeProrationBehavior::NONE.serialize
subscription_schedule.phases = final_subscription_phases

# note: to support stacked amendments, we want to update the local sub_schedule and sub_phases
Expand Down

0 comments on commit 476f4d0

Please sign in to comment.