'WHMCS payment gateway: recurring but not credit card
I'm working on a custom WHMCS payment gateway module for the Mollie payment gateway. So far I integrated one-off payments with no issue, but I'm having some trouble implementing recurring payments.
The flow for either a subscription or authorization to charge the customer on-demand differs slightly.
The flow for creating a subscription is:
- Create a customer profile in Mollie
- Create a mandate by performing an authorization payment - used to link a payment method to a customer (must be a payment of at least €0.01, requires user input)
- Add a subscription to a mandate, telling Mollie to charge the associated card x amount every x days/weeks/months
The flow for authorizing the merchant to charge on-demand is:
- Create a customer profile in Mollie
- Create a mandate by performing an authorization payment - used to link a payment method to a customer (must be a payment of at least €0.01, requires user input)
- Merchant sends a payment request to Mollie for every new invoice
The problem that I have is that Mollie supports multiple payment methods per customer. While WHMCS has built their gateway module system around single-method gateways such as Stripe.
What I want to do is replace the credit card management page with a custom page (preferably generated in the module, without modifying any templates) that allows customers to manage their Mollie details. This would include seeing active mandates and adding new ones (again, a mandate is basically an authorization for me to use a specific payment method for subscriptions or on-demand charging).
I could not find any way of doing this in the WHMCS documentation. Is this at all possible, or should I accept that the only way for customers to see the pages generated by my module is for them to go through an invoice first.
Solution 1:[1]
You are going to need to create two modules that work together, a payment gateway module and an addon module. The addon module will allow you to create client side pages where customers can enter agreements / adjust agreements and then use the _link function to display a form where clients can pick which agreement to use when paying the invoice.
Solution 2:[2]
Seems perhaps useful to mention for consideration that WHMCS does already support recurring payments with a mature and native UI and integrates it with good invoicing practice. The customer is sent an invoice ahead of the payment, then on the due date, the card is charged and the customer is sent a receipt. Customers can see an audit trail of these invoices in the system.
While the business and charging needs of applications vary immensely due to a variety of driving reasons, I would think that for most people implementing recurring payments using WHMCS's recurring payment is a simple and effective solution. Remember, WHMCS lives for these - as just one example, it works brilliantly well with recurring paymentsfor hosting and domain renewal; the domain is simply not renewed and reminders are sent until paid; and any hosting will expire if not paid and eventually be optionally deleted from the server. It's always going to be harder to craft these sorts of automations with subscription-based payment system - even if a webhook is triggered on successful subscription renewal. (It can be done, it's just harder and less reliable than native - what if the IPN/webhook doesn't arrive reliably, or other issues break things). I'm just advocating that any new readers consider doing this within WHMCS's very capable and time-tested recurring transaction framework for this - I think it's worth at least considering, and hasn't been mentioned above, unless I missed it. I'm also mentioning this because for those who are newer to WHMCS this may not occur as a good idea immediately. WHMCS is all about making recurring transactions easy, letting customers see an invoice trail, etc.
I realise that it is now 2022 and that this discussion was originally held in late 2016, but wanted to add this to the great ideas above for new readers.
Apologies if this is annoying; again, fully realize that legacy decisions and business factors can make it essential to stay with external recurring payments!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | n8whnp |
Solution 2 |