diff --git a/press/press/doctype/stripe_webhook_log/stripe_webhook_log.json b/press/press/doctype/stripe_webhook_log/stripe_webhook_log.json index 745ba7cc50..bf601e5d83 100644 --- a/press/press/doctype/stripe_webhook_log/stripe_webhook_log.json +++ b/press/press/doctype/stripe_webhook_log/stripe_webhook_log.json @@ -13,6 +13,7 @@ "customer_id", "invoice_id", "stripe_payment_method", + "stripe_payment_intent_id", "section_break_ecbt", "payload" ], @@ -39,7 +40,8 @@ "fieldname": "invoice", "fieldtype": "Link", "label": "Invoice", - "options": "Invoice" + "options": "Invoice", + "search_index": 1 }, { "fieldname": "invoice_id", @@ -50,7 +52,8 @@ "fieldname": "team", "fieldtype": "Link", "label": "Team", - "options": "Team" + "options": "Team", + "search_index": 1 }, { "fieldname": "column_break_hywj", @@ -67,10 +70,15 @@ { "fieldname": "section_break_ecbt", "fieldtype": "Section Break" + }, + { + "fieldname": "stripe_payment_intent_id", + "fieldtype": "Data", + "label": "Stripe Payment Intent ID" } ], "links": [], - "modified": "2024-06-12 14:53:14.051698", + "modified": "2024-11-29 10:44:55.011202", "modified_by": "Administrator", "module": "Press", "name": "Stripe Webhook Log", diff --git a/press/press/doctype/stripe_webhook_log/stripe_webhook_log.py b/press/press/doctype/stripe_webhook_log/stripe_webhook_log.py index 39ae096bbe..0378effa48 100644 --- a/press/press/doctype/stripe_webhook_log/stripe_webhook_log.py +++ b/press/press/doctype/stripe_webhook_log/stripe_webhook_log.py @@ -30,6 +30,7 @@ class StripeWebhookLog(Document): invoice: DF.Link | None invoice_id: DF.Data | None payload: DF.Code | None + stripe_payment_intent_id: DF.Data | None stripe_payment_method: DF.Link | None team: DF.Link | None # end: auto-generated types @@ -40,6 +41,7 @@ def before_insert(self): self.event_type = payload.get("type") customer_id = get_customer_id(payload) invoice_id = get_invoice_id(payload) + self.stripe_payment_intent_id = get_intent_id(payload) if customer_id: self.customer_id = customer_id self.team = frappe.db.get_value("Team", {"stripe_customer_id": customer_id}, "name") @@ -61,7 +63,11 @@ def before_insert(self): "name", ) - if self.event_type == "invoice.payment_failed" and self.invoice and payload.get("data", {}).get("object", {}).get("next_payment_attempt"): + if ( + self.event_type == "invoice.payment_failed" + and self.invoice + and payload.get("data", {}).get("object", {}).get("next_payment_attempt") + ): next_payment_attempt_date = datetime.fromtimestamp( payload.get("data", {}).get("object", {}).get("next_payment_attempt") ).strftime("%Y-%m-%d") @@ -95,6 +101,17 @@ def stripe_webhook_handler(): raise +def get_intent_id(form_dict): + try: + form_dict_str = frappe.as_json(form_dict) + intent_id = re.search(r"pi_\w+", form_dict_str) + if intent_id: + return intent_id.group(0) + return None + except Exception: + frappe.log_error(title="Failed to capture intent id from stripe webhook log") + + def get_customer_id(form_dict): try: form_dict_str = frappe.as_json(form_dict)