Jump to content
  • 0

Payment method per-product?


TNMChris

Question

Anyone know if this is possible? I'm thinking I could introduce a dropdown menu to users and to admins under the product where they can select a credit card to use for automatic payments instead of the default.

Unfortunately, I don't see a hook anywhere in the docs that I could use to swap out which card ID to use before processing with the gateway.

I'm wanting to get this to work for Stripe but I imagine it would be a similar process for other gateways.

--

There's a bunch of people asking for this and there appears to be one addon that comes close but the addon is actually payment gateways per product and not the payment methods (cards). I'd be happy to build this addon but I'm not familiar enough with WHMCS to see where I could hook in to override the card being used for automatic payments.

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

You should be able to use the InvoiceCreation hook, but you'd need to set the ID of the credit card in the database. It doesn't seem like you can set that using an API, unfortunately.

You could create a new page where clients had a dropdown of all of their different cards next to each product. When the client chooses as specific card for a specific product, save that value to the database (tblinvoices). When WHMCS is making a charge attempt, it should use the ID in the database.

During InvoiceCreation, you lookup the invoiceid in tblinvoiceitems. If that invoice has a relid that is equal to the product ID, you should update the row in tblinvoices to use the card ID the client selected.

There's one issue with this though; what happens if an invoice covers multiple products where the client has set a different card id for each one? You could kinda work around this by setting "Seperate invoices" to true if the client updates their preferred card for a product.

Addition: You could also work around the mentioned issue by generating a new invoice: https://developers.whmcs.com/api-reference/createinvoice/
If a
n invoice that covers multiple products with different associated card IDS is generated, you'd split the invoice before sending the email to the customer.  It might be possible to do it like that, but it is also a bit more tricky.

Edited by DennisHermannsen
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated