Search code examples
mysqlnode.jsbraintree

Braintree integration in Node js database issue


Hi guys so my problem is i use Braintree in my web app node js / mysql and what i want is users to have ability to buy a full version of my product. So i want to implement 2 methods for payment one with reccurring bill and without. In Braintree this is separeted on Subscripton and Transaction. My aproach to detect users is it paid is i have a table with user_id, start_date, end_date and when user log in in system i check with func NOW() in mysql is NOW() BETWEEN start_date and end_date if is it so he is paid.But when i use Braintree and user is deside to be recurring bill i have info one time when he is make paid and i make a record for 1 month for example start_date 28.12.2017 end_date 28.01.2018. And here is the problem when Braintree charge him next month on 28.01.2018 i cant make a reckord in my db. If someone is facing the same problem i will enjoy to share it with me.


Solution

  • There are two ways to solve this issue. One of them is to use Braintree webhooks so each time your customer is charged Braintree will let you know so you can update the record in your database. More info on that https://developers.braintreepayments.com/reference/general/webhooks/subscription/node

    The other way would be to periodically (once a day) fetch this data from Braintree and update it in your database. More info https://developers.braintreepayments.com/reference/request/subscription/find/node