Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save edwinclement08/94baa8d7201a5a5db3edeb6f14b6a191 to your computer and use it in GitHub Desktop.
Save edwinclement08/94baa8d7201a5a5db3edeb6f14b6a191 to your computer and use it in GitHub Desktop.
group_id = 4404657
latest_order = 556451
latest_cancellation_order = 556452
subscription_number = 'A-S00052771'
# InvoicePosted, Order Processed
bcs_invoice_posted = '1219450'
bcs_order_processed = '1219447'
billing_communications = [bcs_invoice_posted, bcs_order_processed]
subs_ssn_info = 199457
cancellation_date = BillingCommunication.find(bcs_order_processed).contract_effective_date.to_date
opportunity_id = '0062y000002fUsfAAE'
future_order = false
existing_account_number = group_id.to_s
order_handler = OrderManagement::Base.new({ group_id: group_id })
optional_hash = { account_number: existing_account_number, contract_effective_date: cancellation_date,
send_txn_entry: false, do_not_expire_plans: true, run_billing: true }
order_cancel_subs = order_handler.cancel_subscription(subscription_number, optional_hash)
puts 'Order Cancel Subscription Response'
puts order_cancel_subs.to_json rescue order_cancel_subs
# update orders
group = Group.find(group_id)
expired_date = cancellation_date
o1 = Order.find(latest_order)
o1.active_line_items.each do |li|
all_gps = li.all_associated_group_plans(group)
all_gps.each { |gp| gp.update_attributes(block: true, block_date: expired_date) }
end
o1.deactivate_active_line_items
o1.update_attributes(status: 'failed')
# expire previous cancelled line items
cancellation_order = Order.find(latest_cancellation_order)
cancellation_order.deactivate_active_line_items
cancellation_order.update_attributes(status: 'failed')
billing_communications.each do |bc|
BillingCommunication.find(bc).update_attributes(status: 2)
end
SubscriptionSessionInfo.find(subs_ssn_info).update_attributes(status: 2)
ExecuteMethodWorker.perform_async('AdminController', 'push_order_cancellation_to_sfdc',
[group_id, latest_cancellation_order, opportunity_id, future_order])
################################################################################
########################################
# Zombie side script
########################################
transactions = [2960324, 2960323]
transactions.each do |txn|
Transaction.find(txn).update_attributes(status: 'Failed')
end
@maazrk
Copy link

maazrk commented Oct 7, 2020

Use the contact_effective_date of the order processed callout as cancellation date

@maazrk
Copy link

maazrk commented Oct 7, 2020

mark the cancelled order as failed 556452

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment