Jump to content

What is the best way to add funds to an existing product/service?


mustardman

Recommended Posts

I have a situation where I am creating a prepay product that needs to be refilled with credit periodically. It doesn't neatly fit into any of the WHMCS features because it doesn't use recurring invoices.

 

Add funds is not a great solution because add funds only works on accounts, not on products. The only way I can do this the WHMCS way would be to require the customer to first add funds to their account, then use the internal API to give them the ability to transfer the add funds credit to the product by pressing a button in product details area. It could work but kind of kludgey and would not present an intuitive user experience with natural flow. I am looking for a way to do it with just one button press.

 

The other way I could do this would be to create a separate refill product that is simply creating the order, invoice, and receiving payment. That's not a great solution because it adds a separate product to client area each time they order another refill. It doesn't make sense to have a bunch of products show up in client area which are simply refill orders. So then I would have to automatically delete the products somehow after the invoice is paid. All in all not a very good solution imo.

 

I also looked at billable items. That's not a good fit because it does not have the option to generate an invoice immediately. If it had the ability to generate an invoice immediately like add funds does then it would be more viable.

 

Is there another way that would work better? I am ok with more coding if it makes the user experience better.

Edited by mustardman
Link to comment
Share on other sites

Hi,

 

Can you provide more details? What's the point of this system? What are you trying to achieve? I can only suppose that you are selling some kind of products (e.g. virtual machines or cloud instances) that you bill periodically based on the amount of "prepaid" credit assigned to the products in question.

Link to comment
Share on other sites

Hi,

 

Can you provide more details? What's the point of this system? What are you trying to achieve? I can only suppose that you are selling some kind of products (e.g. virtual machines or cloud instances) that you bill periodically based on the amount of "prepaid" credit assigned to the products in question.

 

Just think of it like add funds except for a specific product/service that exists in the client account. So add funds behaviour applies such as no periodic invoices generated. Everything initiated by the customer. Nothing changes on the system so nothing is created or suspended or upgraded. Just like add funds.

 

For arguments sake you can pretend it's a remote cloud instance that WHMCS does not control. WHMCS just collects the money and tells the remote product/service how much credit is available for that product/service. There is no product control. There is no automation. There is no cron activity. Just like add funds.

Edited by mustardman
Link to comment
Share on other sites

This is perfectly doable with custom hooks. I used a similar kind of system for a service of mine and there are many different options.

 

First of all you could avoid to use your product and connect your cloud instance directly to tblclients.credit column. Even if there's a particular reason for using a product (maybe you need to activate/suspend/terminate) this option is still valid. Anyway in case you really want to keep everything separated from WHMCS you can try approach described below.

 

Create a new clientarea page from which clients can allocate funds for their cloud instance. There will be a simple input text where clients specify the amount that they want to pay. Now let's say that a client decides to allocate 50 euro. As soon as he confirms, with an action hook and an API function, we create a proforma of 50 euro with a description like "Cloud instance add funds" that he can normally pay using any of your payment methods. Now the tricky part. The type of the proforma that we have just created is not "AddFunds" (I am talking about tblinvoiceitems.type). In this way when he sends you the payment you don't mess up Summary > Credit Log.

 

That said in the end we have a real invoice of 50 euro and a real transaction with an equivalent amount. Now, still using an action hook, simply run an UPDATE query to update the credit balance allocated to the cloud. Keep in mind that if you really do not want to leave any trace of this payment in WHMCS, with less than 3 queries we can also delete the resulting invoice and the transaction all automatically and in real-time.

 

From the point of view of your client the process is super simple. They visit "Allocate funds" page specifying the amount that they want to pay, we redirect them to the resulting proforma so that they can proceed with payment and, as soon as they pay for example with PayPal, they are automatically redirected to "Allocate funds" page with a beautiful green box with a message like «Thank you for your payment! You have now 75.54 euro allocated to your cloud» with no invoices and transactions. Of course if you want to keep them it's not a problem. Another good thing is that they can also pay this invoice using their balance available on WHMCS.

 

On paper you can achieve the same exact result without even creating a new page. Just change clientareaaddfunds.tpl adding a dropdown (select) with the following option "Add funds in my account" and "Allocate funds to my cloud". If they choose the first option we let them normally upload funds in their account otherwise we allocate the money for your cloud.

 

Ok so in conclusion you can make it with a custom page (optional), InvoicePaid (or InvoicePaidPreEmail depending on your configuration) and CreateInvoice API.

Edited by Kian
Link to comment
Share on other sites

I think I followed most of that. I haven't thought through the hooks yet. WHMCS support suggested I create an invoice using the create invoice api.

 

I have that working so now I have an invoice being generated from product details area in tblinvoiceitems that is associated with a tblhosting id. I believe I will need a hook to transfer the credit to the tblhosting id product/service when the invoice is paid. That should get me most of the way there.

 

Some of what you suggested sounds similar. I need to transfer the credit value to the remote cloud system so that it can run on it's own even if WHMCS billing is unavailable. The remote system does it's own incremental deductions from the transferred credit as the customer uses the service. So it can run completely on it's own once it has credit. I am not familiar with those tables you mentioned so I will look into that to see what possibilities that presents.

 

I am using the sample provisioning module. It has all that custom template plumbing built in. That is what I am using in the product details area. That is where the funds need to be added from. So far I have an invoice being generated with the invoice generation API. Just need to figure out the rest of it.

https://github.com/WHMCS/sample-provisioning-module

Edited by mustardman
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
Reply to this topic...

×   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