frappe / payments

A payments app for frappe
MIT License
69 stars 186 forks source link

Gocardless payment request issue (broken after update) #89

Open vcavel opened 2 weeks ago

vcavel commented 2 weeks ago

Information about bug

There is an issue when creating a gocardless payment request after the custumer subscribed to the service.

What should happen :

- Gocardless payment request is created for this customer for the 1st time
- A gocardless subscription email is sent to the customer because no mandate exists
- Customer subscribes to gocardless, a mandate is created, payment is made
- Gocardless payment request is created for this customer for the 2nd time
- Payment is made automatically because a mandate exists, no subscription email is send

What happens :

- Gocardless payment request is created for this customer for the 1st time
- A gocardless subscription email is sent to the customer because no mandate exists
- Customer subscribes to gocardless, a mandate is created, payment is made
- Gocardless payment request is created for this customer for the 2nd time
- Payment is not made, a subscription email is sent again to the customer even though the mandate already exists

This bug only happens on new customers who subscribed after an ERPNext v15.xxx update (i don't know which one), there are no issues for the customers who's mandates are older than the update who broke this integration.

Module

integrations

Version

Ecommerce Integrations: v1.20.1 (main) ERPNext: v15.27.1 (version-15) Frappe Framework: v15.29.1 (version-15)

Installation method

manual install

Relevant log output / Stack trace / Full Error Message.

No response

vcavel commented 1 week ago

Thanks @Nihantra-Patel, how can I help you to find a solution for this ?

vcavel commented 5 days ago

After further investigation, here is what I found :

The difference between a customer created before the update and a customer created after the update is is in the check_mandate_validity() function.

Line 66 of file payments/payment_gateways/doctype/gocardless_settings/gocardless_settings.py, the frappe.db.exists() exits without errors when checking if the mandate exists when it one of the new mandates.

It keeps going and finds the mandate when it's an older one ...

I still have not found the difference between the mandates though ...

vcavel commented 5 days ago

I checked directly in the database and the "customer" field is NULL for the new mandates. There must be something wrong when creating the mandate.

vcavel commented 5 days ago

FYI, I updated the records in my database manually and the payment requests are working perfectly. There is definitely an issue when creating the mandates.