alexmorrisnz / moodle-paygw_stripe

https://moodle.org/plugins/paygw_stripe
10 stars 12 forks source link

Store payment intent ID in Moodle DB #4

Closed iforwms closed 2 years ago

iforwms commented 2 years ago

Is it possible to store the payment intent ID in the Moodle database? Perhaps in a paygw_stripe table, along side other useful data such as amount, status etc. This way payments could be queried Stripe-side at a later date, but also used for reporting.

I can only find Stripe customer ID's and Stripe product ID's being stored, and can only return all payment intents or intents limited by Stripe customer ID.

alexmorrisnz commented 2 years ago

All of this data is already stored stripe side, including the customer Moodle ID and course name. You should be able to build reports within Stripe already to query this information, what's the purpose of duplicating it within Moodle?

iforwms commented 2 years ago

From reading the Stripe API docs I was only able to fetch the transaction data using the Stripe transaction ID (which isn't stored in the Moodle database) - which I want to use to query the transaction status.

I'm aware the Moodle ID and course is stored on Stripe, but I couldn't find anywhere in the Stripe API docs saying how to query a transaction by Moodle ID and course name. I could only request all payment records for the Stripe customer ID (stored in the Moodle DB) and then loop through these transactions to filter by course name.

I'm not too au fait with the Stripe platform, are you saying it's possible to directly query by Moodle ID and course name?

alexmorrisnz commented 2 years ago

That should be possible with Sigma custom reports, however it is a paid service. A bit disappointing you can't fetch PaymentIntents by customer ID and product ID from the Stripe API.

I'll look into storing a table of PaymentIntents created by the plugin, may be a few weeks before I do though. PRs are welcome.

alexmorrisnz commented 2 years ago

Hi @iforwms, I've updated the Moodle plugins directory with the latest version which includes the changes requested here.

It's storing user ID, payment intent ID, customer ID, total amount paid, payment status, checkout status, and product ID. You should be able to fetch transaction data from Stripe using this data.

I'm also planning to add a report builder report source for this once Moodle 4.0 has been released.

Please note that with v1.11 I removed compatibility for Moodle 3.10 as it's security support will be ending soon.