Skip to content

feat: bypass salesforce harness for Staging Integration - #247

Open
rthota-sonata-hue wants to merge 3 commits into
mainfrom
rthota/ENT-12113
Open

feat: bypass salesforce harness for Staging Integration#247
rthota-sonata-hue wants to merge 3 commits into
mainfrom
rthota/ENT-12113

Conversation

@rthota-sonata-hue

Copy link
Copy Markdown
Contributor

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.

@rthota-sonata-hue
rthota-sonata-hue requested review from a team as code owners July 22, 2026 14:39
Copilot AI review requested due to automatic review settings July 22, 2026 14:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_BYPASS as a hard settings guard (default False) in addition to a new Waffle flag.
  • Adds a customer_billing.bypass_salesforce_for_provisioning Waffle flag (+ toggle helper) to control bypass behavior at runtime.
  • Implements and tests a bypass path in the Stripe invoice.paid handler to directly run ProvisionNewCustomerWorkflow and update CheckoutIntent state 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

  1. moderate enterprise_access/apps/customer_billing/stripe_event_handlers.py:414 — bypass provisioning can raise non-UnitOfWorkException exceptions that currently escape the webhook handler (causing Stripe retries instead of recording a provisioning error).

HOTSPOTS:

  1. 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.

Comment on lines +414 to +436
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)
Comment on lines +546 to +548
# 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

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.51%. Comparing base (f313bfc) to head (a44c074).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI review requested due to automatic review settings July 23, 2026 06:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 empty trial_subscription_plan_request_dict / first_paid_subscription_plan_request_dict ({}, {}). The provisioning workflow step inputs require fields like title, salesforce_opportunity_line_item, start_date, expiration_date, and desired_num_licenses for the trial plan, so this bypass path will raise during workflow execution and never reach mark_as_fulfilled.
            None,
            None,
            {},
            {},
            checkout_intent.ssp_product.slug,

Comment on lines +546 to +549
# 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
Copilot AI review requested due to automatic review settings July 23, 2026 06:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment on lines +419 to +423
None,
None,
{},
{},
checkout_intent.ssp_product.slug,
Comment on lines +428 to +432
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants