Skip to content

Deduplicate deals and use consistent unique_app_id#3539

Open
cp-at-mit wants to merge 6 commits intomainfrom
11103-hubspot-deals-are-begin-duplicated-and-created-in-both-xpro-and-mitxonline-accounts
Open

Deduplicate deals and use consistent unique_app_id#3539
cp-at-mit wants to merge 6 commits intomainfrom
11103-hubspot-deals-are-begin-duplicated-and-created-in-both-xpro-and-mitxonline-accounts

Conversation

@cp-at-mit
Copy link
Copy Markdown
Contributor

Prevent duplicate cart-add deals by looking up existing deals by dealname and a new consistent unique_app_id before creating; update existing deals when found. Change OrderToDealSerializer.get_unique_app_id to generate a stable ID based on purchaser email and the purchasable object (fallback to order id for orders without lines) so cart-add and checkout flows use the same identifier. Update tests to assert the new unique_app_id generation logic.

What are the relevant tickets?

https://github.com/mitodl/hq/issues/11103

Description (What does it do?)

Hoping that this fixes an issue where multiple new deals were being created between the mitx online and xpro hubspot accounts, and sometimes duplicated on the same hubspot account, when a user adds a UAI course to their cart and completes the checkout process.

How can this be tested?

  1. Create a UAI course that will satisfy the logic in is_uai_course_run.
  2. Login through Keycloak.
  3. Add the UAI course from step 1 to your cart.
  4. Verify that the logs show a celery task kicked off to create the hubspot deal in the xpro account.
  5. Verify that the deal was created in the hubspot xpro account.
  6. Complete the purchase of the course.
  7. Verify that the logs show a celery task kicked off to update the hubspot deal in xpro account.
  8. Verify that the same deal that was created in step 5 was updated and now has a "close" date.
  9. Verify that no other hubspot deals were created.

Prevent duplicate cart-add deals by looking up existing deals by dealname and a new consistent unique_app_id before creating; update existing deals when found. Change OrderToDealSerializer.get_unique_app_id to generate a stable ID based on purchaser email and the purchasable object (fallback to order id for orders without lines) so cart-add and checkout flows use the same identifier. Update tests to assert the new unique_app_id generation logic.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

OpenAPI Changes

Show/hide ## Changes for v0.yaml:
## Changes for v0.yaml:
No changes detected

## Changes for v1.yaml:
No changes detected

## Changes for v2.yaml:
No changes detected

Unexpected changes? Ensure your branch is up-to-date with main (consider rebasing).

pre-commit-ci Bot and others added 3 commits May 1, 2026 16:10
…-both-xpro-and-mitxonline-accounts' of https://github.com/mitodl/mitxonline into 11103-hubspot-deals-are-begin-duplicated-and-created-in-both-xpro-and-mitxonline-accounts
@cp-at-mit cp-at-mit marked this pull request as ready for review May 1, 2026 16:38
Comment thread hubspot_sync/serializers.py Outdated
@cp-at-mit cp-at-mit requested a review from rhysyngsun May 1, 2026 18:09
@annagav annagav self-requested a review May 5, 2026 15:33
Copy link
Copy Markdown
Contributor

@annagav annagav left a comment

Choose a reason for hiding this comment

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

I think this is working. I was able to verify that the deal was created on "add_to_cart" and updated on checkout. However, I had to use coupon for checkout in order to close the order.

I saw some strange things which I think were happening because I could add multiple courses to cart, so I hope that is not an issue.

Another, thing is that we usually don't create an order on "add_to_cart" (at least that was the behavior I see locally), but when we sync this "event" with hubspot an order was created in order to sync, and when I further checkout out I verified that it didn't get duplicated.

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.

3 participants