Skip to content

Commit

Permalink
Additional logging on amendments (#725)
Browse files Browse the repository at this point in the history
* Remove sorbet runtime var

it's not working

* Additional logging statements
  • Loading branch information
mbianco-stripe authored Sep 1, 2022
1 parent 2998ee9 commit f162a22
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
3 changes: 0 additions & 3 deletions .envrc-example
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/bin/bash

# use `direnv` to automatically load this (and any other!) vars into your shell automatically
export NO_SORBET_RUNTIME=true

# helpful if you are running into weird state issues
export DISABLE_SPRING=false

Expand Down
6 changes: 1 addition & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ git_source(:github) {|repo| "https://github.com/#{repo}.git" }
ruby '2.7.6'

gem 'sorbet', '~> 0.5.10346', group: :development
if ENV.fetch('NO_SORBET_RUNTIME', 'false') != 'true'
gem 'sorbet-runtime', '~> 0.5.10346', require: true
else
puts "Skipping sorbet-runtime"
end
gem 'sorbet-runtime', '~> 0.5.10346', require: true
gem 'sorbet-rails', '~> 0.7.34'

# https://github.com/ruby/irb/issues/43
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe-force/translate/mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def extract_salesforce_object_field(sf_object, key_path)
end

if target_object.nil?
log.info 'field value is nil',
log.debug 'field value is nil',
field_component: field_name,
field_path: key_path,
root_object: sf_object.sobject_type,
Expand Down
16 changes: 14 additions & 2 deletions lib/stripe-force/translate/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ def update_subscription_phases_from_order_amendments(contract_structure)
log.info 'processing amendment', sf_amendment_id: sf_order_amendment.Id, index: index

invoice_items_in_order, aggregate_phase_items = build_phase_items_from_order_amendment(aggregate_phase_items, sf_order_amendment)

# TODO right here, we should filter which lines are terminations and calculate the customer credit

is_order_terminated = aggregate_phase_items.all?(&:fully_terminated?)

if is_order_terminated && contract_structure.amendments.size - 1 != index
Expand Down Expand Up @@ -344,10 +347,16 @@ def update_subscription_phases_from_order_amendments(contract_structure)
)
end

# for debugging
aggregate_phase_items.each do |phase_item|
log.info 'including item on order', order_line_id: phase_item.order_line_id
end

new_phase = Stripe::StripeObject.construct_from({
add_invoice_items: invoice_items_in_order.map(&:stripe_params) + invoice_items_for_prorations,

# this is important, otherwise multiple phase changes in a single job run will use the same aggregate phase items
# `deep_dup` this is important, otherwise multiple phase changes in a
# single job run will use the same aggregate phase items
items: aggregate_phase_items.deep_dup.map(&:stripe_params),

# TODO should be moved to global defaults
Expand Down Expand Up @@ -418,10 +427,11 @@ def merge_subscription_line_items(original_aggregate_phase_items, new_phase_item
termination_lines, additive_lines = new_phase_items.partition(&:termination?)

additive_lines.each do |new_subscription_item|
log.info 'adding new line item'
log.info 'adding new line item', order_line_id: new_subscription_item.order_line_id
aggregate_phase_items << new_subscription_item
end

# NOTE this terminates the lines, but does NOT remove them
aggregate_phase_items = terminate_subscription_line_items(aggregate_phase_items, termination_lines)
aggregate_phase_items
end
Expand All @@ -436,6 +446,8 @@ def terminate_subscription_line_items(original_aggregate_phase_items, terminatio
aggregate_phase_items = original_aggregate_phase_items.dup
revision_map = T.let({}, T::Hash[String, T::Array[ContractItemStructure]])

# line items that are "new" (i.e. not revising anything) are "origin" lines which future
# revisions should be mapped to
aggregate_phase_items.select(&:new_order_line?).each do |origin_order_line|
if revision_map[origin_order_line.order_line_id].present?
raise Integrations::Errors::ImpossibleState.new("should never be more than a single revised order ID match")
Expand Down
11 changes: 9 additions & 2 deletions lib/stripe-force/translate/order/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module OrderHelpers

sig { params(subscription_schedule: Stripe::SubscriptionSchedule).returns(T::Array[T.any(Stripe::SubscriptionSchedulePhaseSubscriptionItem, Stripe::SubscriptionSchedulePhaseInvoiceItem)]) }
def self.extract_all_items_from_subscription_schedule(subscription_schedule)
subscription_schedule.phases.map(&:items).flatten + subscription_schedule.phases.map(&:add_invoice_items).flatten
subscription_schedule.phases.map(&:items).flatten +
subscription_schedule.phases.map(&:add_invoice_items).flatten
end

# after lines have been adjusted with termination line, they should be removed
Expand Down Expand Up @@ -66,6 +67,8 @@ def self.transform_payment_terms_to_days_until_due(raw_days_until_due)
).returns(Stripe::Price)
end
def self.duplicate_stripe_price(user, original_stripe_price, &block)
log.info 'duplicating price', stripe_price_id: original_stripe_price.id

stripe_price_params = original_stripe_price.to_hash
stripe_price_params.delete(:id)

Expand Down Expand Up @@ -109,7 +112,11 @@ def self.duplicate_stripe_price(user, original_stripe_price, &block)
yield(stripe_price)
end

Stripe::Price.create(stripe_price.to_hash, user.stripe_credentials)
new_stripe_price = Stripe::Price.create(stripe_price.to_hash, user.stripe_credentials)
log.info 'duplicated price',
original_stripe_price: original_stripe_price.id,
new_stripe_price: new_stripe_price.id
new_stripe_price
end

# since the input and output is "fake" stripe subhash, typing here doesn't work
Expand Down

0 comments on commit f162a22

Please sign in to comment.