feat: bypass salesforce harness for Staging Integration - #247
feat: bypass salesforce harness for Staging Integration#247rthota-sonata-hue wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a staging-oriented escape hatch to let the invoice.paid (trial-path) Stripe webhook directly trigger provisioning when Salesforce integration isn’t available, gated by both a hard Django setting and a Waffle flag.
Changes:
- Introduces
ALLOW_SALESFORCE_BYPASSas a hard settings guard (defaultFalse) in addition to a new Waffle flag. - Adds a
customer_billing.bypass_salesforce_for_provisioningWaffle flag (+ toggle helper) to control bypass behavior at runtime. - Implements and tests a bypass path in the Stripe
invoice.paidhandler to directly runProvisionNewCustomerWorkflowand updateCheckoutIntentstate on success/failure.
HEADLINE: The bypass flow needs broader exception handling so webhook processing doesn’t unexpectedly error/retry when non-UnitOfWorkException failures occur during bypass provisioning.
House-Rule Findings
| Rule | Severity | Location | Finding | Should have used |
|---|---|---|---|---|
| — | — | — | No confirmed house-rule issues found in the diff. | — |
Security & Tests
- moderate enterprise_access/apps/customer_billing/stripe_event_handlers.py:414 — bypass provisioning can raise non-
UnitOfWorkExceptionexceptions that currently escape the webhook handler (causing Stripe retries instead of recording a provisioning error).
HOTSPOTS:
- enterprise_access/apps/customer_billing/stripe_event_handlers.py:_bypass_salesforce_for_provisioning — new operationally sensitive control-flow in a webhook handler (workflow execution + state transitions).
MERGE_READINESS: CHANGES_REQUIRED
The bypass path should handle realistic exception cases to avoid unintended webhook failures/retries when the bypass is enabled.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| enterprise_access/settings/base.py | Adds a hard settings guard (ALLOW_SALESFORCE_BYPASS) for the staging bypass. |
| enterprise_access/apps/customer_billing/toggles.py | Introduces the Waffle flag wrapper for the Salesforce bypass toggle. |
| enterprise_access/apps/customer_billing/stripe_event_handlers.py | Adds the bypass provisioning path to the trial invoice.paid handler. |
| enterprise_access/apps/customer_billing/constants.py | Defines the new Waffle flag name constant. |
| enterprise_access/apps/customer_billing/tests/test_stripe_event_handlers.py | Adds tests covering bypass enabled/disabled and workflow failure behavior. |
| workflow_input_dict = ProvisionNewCustomerWorkflow.generate_input_dict( | ||
| customer_request_dict, | ||
| admin_email_list, | ||
| None, | ||
| None, | ||
| None, | ||
| {}, | ||
| {}, | ||
| checkout_intent.ssp_product.slug, | ||
| ) | ||
| workflow = ProvisionNewCustomerWorkflow.objects.create(input_data=workflow_input_dict) | ||
|
|
||
| try: | ||
| workflow.execute() | ||
| except UnitOfWorkException as exc: | ||
| logger.error( | ||
| 'Salesforce bypass provisioning workflow failed for checkout_intent uuid=%s: %s', | ||
| checkout_intent.uuid, exc, | ||
| ) | ||
| checkout_intent.mark_provisioning_error(str(exc), workflow=workflow) | ||
| return | ||
|
|
||
| checkout_intent.mark_as_fulfilled(workflow=workflow) |
| # Hard guard for the customer_billing.bypass_salesforce_for_provisioning waffle flag. | ||
| # Must be explicitly enabled (e.g. in stage) in addition to the waffle flag before the | ||
| # invoice.paid webhook handler will bypass Salesforce and directly trigger provisioning. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #247 +/- ##
==========================================
+ Coverage 87.46% 87.51% +0.04%
==========================================
Files 157 158 +1
Lines 13295 13325 +30
Branches 1296 1298 +2
==========================================
+ Hits 11629 11661 +32
+ Misses 1354 1352 -2
Partials 312 312 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
enterprise_access/apps/customer_billing/stripe_event_handlers.py:423
ProvisionNewCustomerWorkflow.generate_input_dict()is being called with emptytrial_subscription_plan_request_dict/first_paid_subscription_plan_request_dict({},{}). The provisioning workflow step inputs require fields liketitle,salesforce_opportunity_line_item,start_date,expiration_date, anddesired_num_licensesfor the trial plan, so this bypass path will raise during workflow execution and never reachmark_as_fulfilled.
None,
None,
{},
{},
checkout_intent.ssp_product.slug,
| # Hard guard for the customer_billing.bypass_salesforce_for_provisioning waffle flag. | ||
| # Must be explicitly enabled (e.g. in stage) in addition to the waffle flag before the | ||
| # invoice.paid webhook handler will bypass Salesforce and directly trigger provisioning. | ||
| ALLOW_SALESFORCE_BYPASS = False |
| None, | ||
| None, | ||
| {}, | ||
| {}, | ||
| checkout_intent.ssp_product.slug, |
| logger.exception( | ||
| 'Salesforce bypass provisioning failed for checkout_intent uuid=%s: %s', | ||
| checkout_intent.uuid, exc, | ||
| ) | ||
| checkout_intent.mark_provisioning_error(str(exc), workflow=workflow) |
Description:
To enable end-to-end testing of the provisioning and checkout flow in the staging environment while the Salesforce integration is in development, This flag act as a stand-in for Salesforce, allowing us to verify our system's behavior and payload processing.
Jira:
https://2u-internal.atlassian.net/browse/ENT-12113
Changes:
BYPASS_SALESFORCE_PROVISIONING_FLAG default will be false. If we need to by pass salesforce, we update this flag to true.