Skip to content

Commit

Permalink
Removing all octopus demo code (#1194)
Browse files Browse the repository at this point in the history
  • Loading branch information
keshavc-stripe authored Aug 23, 2023
1 parent 6386e11 commit aa6c901
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 10,057 deletions.
22 changes: 0 additions & 22 deletions app/controllers/stripe_webhook_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# typed: true
class StripeWebhookController < ApplicationController
skip_forgery_protection
include StripeForce::Utilities::DemoUtil

WEBHOOK_SECRET = ENV.fetch("STRIPE_WEBHOOK_SECRET")
STRIPEFORCE_CI_ACCOUNT = "acct_1MHBTOC9fP1FVBtd"
Expand Down Expand Up @@ -53,11 +52,6 @@ def stripe_webhook
return
end

if stripe_account_id == STRIPEFORCE_DEMO_ACCOUNT && event_type == 'customer.subscription.created'
# TODO: Delete after demo
user = StripeForce::User[259]
end

set_error_context(user: user, stripe_resource: event)

if !user.enabled
Expand All @@ -84,22 +78,6 @@ def stripe_webhook
return
end

if event_type == 'customer.subscription.created'
if user.feature_enabled?(FeatureFlags::BIDIRECTIONAL_SYNC_DEMO)
StripeForce::Utilities::DemoUtil.user = user
subscription_start_date = event.data.object['current_period_start'] ? Time.at(event.data.object['current_period_start']) : now_time
# TODO: check to make sure that there isn't a SF order ID already in item metadata
create_demo_evergreen_order(user: user, additional_quote_fields: {
CPQ_QUOTE_SUBSCRIPTION_START_DATE => format_date_for_salesforce(subscription_start_date),
CPQ_QUOTE_SUBSCRIPTION_TERM => SF_ORDER_DEFAULT_EVERGREEN_SUBSCRIPTION_TERM,
}, additional_order_fields: {GENERIC_STRIPE_ID => event.data.object['id']})
render plain: "Successfully processed event to create demo evergreen Salesforce order #{event_id}"
return
end
render plain: "Skipped processing event #{event_id}"
return
end

if event_type != 'invoiceitem.created'
head :ok
return
Expand Down
28 changes: 0 additions & 28 deletions test/controllers/test_stripe_webhook_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,33 +103,5 @@ def send_webhook(payload, signature: nil)
assert_equal(503, response.status, response.body)
assert_match("user exists, but webhook rejected", response.body)
end

it 'creates evergreen order when webhook is fired' do
@user.enable_feature FeatureFlags::BIDIRECTIONAL_SYNC_DEMO
# Most recent order before webhook fired
previous_order = sf_get_recent("Order")

e = create_event('customer.subscription.created')
send_webhook(e)

# Most recent order after webhook fired
sf_evergreen_order = sf_get_recent(SF_ORDER)

# The most recent order before and after the webhook is fired should be different, indicating that we've created a new order
# by firing the webhook
assert_not_equal(previous_order.Id, sf_evergreen_order.Id)

order_items = sf_get_related(sf_evergreen_order, SF_ORDER_ITEM)

order_items.each do |order_item|
assert_equal(1, order_item[CPQ_QUOTE_SUBSCRIPTION_TERM])
assert_equal(CPQProductSubscriptionTypeOptions::EVERGREEN.serialize, order_item[CPQ_PRODUCT_SUBSCRIPTION_TYPE])
assert_equal('Fixed Price', order_item[CPQ_QUOTE_SUBSCRIPTION_PRICING])
end

# Ensure that a valid stripe ID is being set
stripe_id = @user.sf_client.query("Select #{GENERIC_STRIPE_ID} from #{SF_ORDER} where Id = '#{sf_evergreen_order.Id}'")
assert_not_empty(stripe_id)
end
end
end
57 changes: 0 additions & 57 deletions test/integration/amendments/test_evergreen_amendments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require_relative './_lib'

class Critic::EvergreenAmendmentTest < Critic::OrderAmendmentFunctionalTest
include StripeForce::Utilities::DemoUtil
before do
set_cassette_dir(__FILE__)
Timecop.freeze(VCR.current_cassette.originally_recorded_at || now_time)
Expand Down Expand Up @@ -327,60 +326,4 @@ class Critic::EvergreenAmendmentTest < Critic::OrderAmendmentFunctionalTest
assert_match("Adding Salesforce products with type 'Renewable' to orders of type 'Evergreen' is not supported.", exception.message)
end
end
describe 'demo tests' do
it 'amends the demo evergreen order, and uses the created user to create a new non evergreen order' do
# Due to the user switch, create demo evergreen order returns a user at the end instead of the order
StripeForce::Utilities::DemoUtil.user = @user
create_demo_evergreen_order(user: @user, additional_quote_fields: {
CPQ_QUOTE_SUBSCRIPTION_START_DATE => format_date_for_salesforce(now_time),
CPQ_QUOTE_SUBSCRIPTION_TERM => SF_ORDER_DEFAULT_EVERGREEN_SUBSCRIPTION_TERM,
})
sf_evergreen_order = sf_get_recent(SF_ORDER)

sf_contract = create_contract_from_order(sf_evergreen_order)
# api precondition: initial orders have a nil contract ID
sf_evergreen_order.refresh
assert_nil(sf_evergreen_order.ContractId)

# the contract should reference the initial order that was created
assert_equal(sf_evergreen_order[SF_ID], sf_contract[SF_CONTRACT_ORDER_ID])

amendment_quote = create_quote_data_from_contract_amendment(sf_contract)

# wipe out the product
amendment_quote["lineItems"].first["record"][CPQ_QUOTE_QUANTITY] = 0
amendment_quote["record"][CPQ_QUOTE_SUBSCRIPTION_START_DATE] = now_time_formatted_for_salesforce
amendment_quote["record"][CPQ_QUOTE_SUBSCRIPTION_TERM] = SF_ORDER_DEFAULT_EVERGREEN_SUBSCRIPTION_TERM

sf_order_amendment = create_order_from_quote_data(amendment_quote)
assert_equal(sf_order_amendment.Type, OrderTypeOptions::AMENDMENT.serialize)

StripeForce::Translate.perform_inline(@user, sf_order_amendment.Id)

sf_evergreen_order.refresh
stripe_id = sf_evergreen_order[prefixed_stripe_field(GENERIC_STRIPE_ID)]

canceled_subscription = Stripe::Subscription.retrieve(stripe_id, @user.stripe_credentials)

assert_equal("canceled", canceled_subscription.status)
assert_equal(sf_evergreen_order.Id, canceled_subscription.metadata['salesforce_order_id'])

create_salesforce_order(sf_account_id: sf_evergreen_order['AccountId'], additional_quote_fields: {
CPQ_QUOTE_SUBSCRIPTION_START_DATE => format_date_for_salesforce(now_time),
CPQ_QUOTE_SUBSCRIPTION_TERM => SF_ORDER_DEFAULT_EVERGREEN_SUBSCRIPTION_TERM,
})
new_order = sf_get_recent(SF_ORDER)
assert_not_equal(sf_evergreen_order.Id, new_order.Id)

new_order_items = sf_get_related(new_order, SF_ORDER_ITEM)

new_order_items.each do |order_item|
# ensure that the new order is valid, but is not evergreen
assert_equal(1, order_item[CPQ_QUOTE_SUBSCRIPTION_TERM])
assert_equal(CPQProductSubscriptionTypeOptions::RENEWABLE.serialize, order_item[CPQ_PRODUCT_SUBSCRIPTION_TYPE])
assert_equal('Fixed Price', order_item[CPQ_QUOTE_SUBSCRIPTION_PRICING])
end
StripeForce::Translate.perform_inline(@user, new_order.Id)
end
end
end
Loading

0 comments on commit aa6c901

Please sign in to comment.