:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(braintree): sync transaction decline and risk details (#125025)
Tom Owers3b7cf4e57ffe
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/canonical_descriptions.pyindex 778c6eff7d91..8b73a3536480 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/canonical_descriptions.py@@ -21,12 +21,15 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"amount": "Monetary amount of the transaction, with value and currency code.","orderId": "Merchant-supplied order identifier associated with the transaction.","merchantAccountId": "Identifier of the merchant account the transaction was processed under.",- "paymentMethodSnapshot": "Snapshot of the payment method used at the time of the transaction. For cards, includes the brand code, last 4 digits and BIN.",+ "source": "Origin of the request that created the transaction (API, CONTROL_PANEL, PAYMENT_READER, RECURRING or UNKNOWN).",+ "paymentMethodSnapshot": "Snapshot of the payment method used at the time of the transaction. For cards, includes the brand code, last 4 digits, BIN, the account type (credit or debit) and the BIN data: issuing bank, country of issuance, and whether the card is debit, prepaid, commercial and so on.","customer": "Customer associated with the transaction, with its id and legacy id. Joins to the customers table.","paymentMethod": "Vaulted payment method used for the transaction. Its legacyId is the payment method token. Absent for single-use or deleted payment methods.","disbursementDetails": "Disbursement details, including the date funds were disbursed. Only present once the transaction is settled on an eligible merchant account.","installmentDetails": "Installment details, including the number of installments.",- "processorAuthorizationResponse": "Authorization response from the processor, including the AVS postal code, AVS street address and CVV response codes.",+ "processorAuthorizationResponse": "Authorization response from the processor, including the processor response code (legacyCode, e.g. 2001) and its message (e.g. Insufficient Funds), additional information, and the AVS postal code, AVS street address and CVV response codes.",+ "riskData": "Fraud check result for the transaction, including the risk decision (APPROVE, DECLINE, REVIEW or NOT_EVALUATED), the decision reasons, the risk score and the fraud service provider.",+ "statusHistory": "One entry per status change, with the status, timestamp, source and amount. A PROCESSOR_DECLINED entry adds the decline type (SOFT or HARD), the processor, network and merchant advice responses and the risk decision. A GATEWAY_REJECTED entry adds the gateway rejection reason (e.g. CVV, AVS, FRAUD, RISK_THRESHOLD, DUPLICATE).",},},"refunds": {diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/settings.pyindex 721dc28d0346..260d74cbad02 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/braintree/settings.py@@ -13,25 +13,94 @@ _CREATED_AT_INCREMENTAL_FIELDS: list[IncrementalField] = [},]+_BIN_DATA_FIELDS = """binData {+ issuingBank+ countryOfIssuance+ productId+ debit+ prepaid+ prepaidReloadable+ commercial+ consumer+ business+ corporate+ purchase+ payroll+ healthcare+ durbinRegulated+ }"""++_PROCESSOR_RESPONSE_FIELDS = "processorResponse { legacyCode message additionalInformation }"+# Node field selections per stream — conservative, well-documented fields only.-_TRANSACTION_FIELDS = """+# The decline type and the gateway rejection reason only exist on the matching status+# history event, so `statusHistory` selects them per event type.+_TRANSACTION_FIELDS = f"""idlegacyIdcreatedAtstatus- amount { value currencyCode }+ source+ amount {{ value currencyCode }}orderIdmerchantAccountId- customer { id legacyId }- paymentMethod { legacyId }- disbursementDetails { date }- installmentDetails { count }- processorAuthorizationResponse { avsPostalCodeResponse avsStreetAddressResponse cvvResponse }- paymentMethodSnapshot {+ customer {{ id legacyId }}+ paymentMethod {{ legacyId }}+ disbursementDetails {{ date }}+ installmentDetails {{ count }}+ processorAuthorizationResponse {{+ legacyCode+ message+ additionalInformation+ avsPostalCodeResponse+ avsStreetAddressResponse+ cvvResponse+ }}+ riskData {{ id decision decisionReasons score fraudServiceProvider deviceDataCaptured }}+ statusHistory {{__typename- ... on CreditCardTransactionDetails { creditCard { brandCode last4 bin } }- ... on CreditCardDetails { brandCode last4 bin }- }+ status+ timestamp+ source+ amount {{ value currencyCode }}+ ... on ProcessorDeclinedEvent {{+ declineType+ riskDecision+ {_PROCESSOR_RESPONSE_FIELDS}+ networkResponse {{ code message }}+ merchantAdviceCodeResponse {{ code message }}+ }}+ ... on GatewayRejectedEvent {{+ gatewayRejectionReason+ riskDecision+ {_PROCESSOR_RESPONSE_FIELDS}+ networkResponse {{ code message }}+ merchantAdviceCodeResponse {{ code message }}+ }}+ ... on FailedEvent {{+ riskDecision+ {_PROCESSOR_RESPONSE_FIELDS}+ networkResponse {{ code message }}+ }}+ }}+ paymentMethodSnapshot {{+ __typename+ ... on CreditCardTransactionDetails {{+ accountType+ creditCard {{+ brandCode+ last4+ bin+ {_BIN_DATA_FIELDS}+ }}+ }}+ ... on CreditCardDetails {{+ brandCode+ last4+ bin+ {_BIN_DATA_FIELDS}+ }}+ }}"""_REFUND_FIELDS = """