Skip to content

Conversation

sean-rose
Copy link
Contributor

Description

Rather than looking for Stripe invoices with paypalTransactionId metadata fields, which doesn't work if the subscription was a trial or used a 100%-off coupon, and thus no PayPal transaction was initiated.

Related Tickets & Documents

  • DENG-9565: Fix some known issues in SubPlat consolidated reporting ETLs
  • DENG-9768: Base Stripe logical subscription's payment_provider on the Stripe subscription's collection_method

Reviewer, please follow this checklist

…n the Stripe subscription's `collection_method` (DENG-9768).
@dataops-ci-bot
Copy link

Integration report for "fix(SubPlat): Base Stripe logical subscription's payment_provider on the Stripe subscription's collection_method (DENG-9768)."

sql.diff

Click to expand!
diff -bur --no-dereference --new-file /tmp/workspace/main-generated-sql/sql/moz-fx-data-shared-prod/subscription_platform_derived/stripe_logical_subscriptions_history_v1/query.sql /tmp/workspace/generated-sql/sql/moz-fx-data-shared-prod/subscription_platform_derived/stripe_logical_subscriptions_history_v1/query.sql
--- /tmp/workspace/main-generated-sql/sql/moz-fx-data-shared-prod/subscription_platform_derived/stripe_logical_subscriptions_history_v1/query.sql	2025-09-29 21:16:31.000000000 +0000
+++ /tmp/workspace/generated-sql/sql/moz-fx-data-shared-prod/subscription_platform_derived/stripe_logical_subscriptions_history_v1/query.sql	2025-09-29 21:13:39.000000000 +0000
@@ -77,14 +77,6 @@
   GROUP BY
     plan_id
 ),
-paypal_subscriptions AS (
-  SELECT DISTINCT
-    subscription_id
-  FROM
-    `moz-fx-data-shared-prod.stripe_external.invoice_v1`
-  WHERE
-    JSON_VALUE(metadata, '$.paypalTransactionId') IS NOT NULL
-),
 subscriptions_history_charge_summaries AS (
   SELECT
     history.id AS subscriptions_history_id,
@@ -226,7 +218,11 @@
       FORMAT_TIMESTAMP('%FT%H:%M:%E6S', history.subscription_first_active_at)
     ) AS id,
     'Stripe' AS provider,
-    IF(paypal_subscriptions.subscription_id IS NOT NULL, 'PayPal', 'Stripe') AS payment_provider,
+    IF(
+      history.subscription.collection_method = 'send_invoice',
+      'PayPal',
+      'Stripe'
+    ) AS payment_provider,
     history.subscription.id AS provider_subscription_id,
     subscription_item.id AS provider_subscription_item_id,
     history.subscription.created AS provider_subscription_created_at,
@@ -247,7 +243,7 @@
             charge_summaries.latest_card_country
           )
       -- SubPlat copies the PayPal billing agreement country to the customer's address.
-      WHEN paypal_subscriptions.subscription_id IS NOT NULL
+      WHEN history.subscription.collection_method = 'send_invoice'
         THEN NULLIF(history.subscription.customer.address.country, '')
       ELSE charge_summaries.latest_card_country
     END AS country_code,
@@ -345,9 +341,6 @@
   plan_services
   ON subscription_item.plan.id = plan_services.plan_id
 LEFT JOIN
-  paypal_subscriptions
-  ON history.subscription.id = paypal_subscriptions.subscription_id
-LEFT JOIN
   subscriptions_history_charge_summaries AS charge_summaries
   ON history.id = charge_summaries.subscriptions_history_id
 LEFT JOIN

Link to full diff

@sean-rose sean-rose added this pull request to the merge queue Oct 2, 2025
Merged via the queue into main with commit ba38a11 Oct 2, 2025
22 checks passed
@sean-rose sean-rose deleted the DENG-9768-Stripe-payment_provider branch October 2, 2025 16:52
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