dualcube / moodle-enrol_stripepayment

Moodle Stripe Payment Collector
16 stars 27 forks source link

In Stripe a new customer id is created for every purchase and not linked to the customer id in moodle #115

Closed jimcrammond closed 1 year ago

jimcrammond commented 1 year ago

It would be desirable if the same customer id is used in stripe when applying coupons and making purchases. Currently every checkout session generates a new customer id which is not saved in the enrol_stripepayment database table. Only when coupons are applied are they applied against the customer id saved in the enrol_stripepayment table if it exists.

The fix for this is quite easy. This can be done by searching the enrol_stripepayment table for customer_id at the start of stripe_js_method and if found passing the that into the checkout session; (if not found, the checkout session will create the customer id). Then in stripe_success_url, the customer_id returned by the checkout session should be used (instead of searching the enrol table for it) when applying the coupon and inserting a new record into the enrol_stripepayment table.

This way, all purchases and coupons are applied to the same customer in Stripe making it easier to track.

The attached patch illustrates this. stripepayment-customer.patch