Jump to content

Allowable payment gateway per invoice


evotz

Recommended Posts

I'm not seeing where this is possible, but maybe I'm missing something.

 

Is there a way to create or edit an invoice so that it can be paid with the user's choice of payment gateway, but the administrator limits the specific gateways?

 

For example, say I have PayPal, Authorize.Net, and Skrill as available payment gateways in my WHMCS. But I create an invoice for a client and I want them to be able to pay with either PayPal or Authorize.Net (but not Skrill). Is that possible?

 

I want to be able to select multiple payment gateways (but not all payment gateways) per invoice.

 

Possible?

Link to comment
Share on other sites

I think your first suggestion could be done, not in the admin area but possibly by some template modification - e.g if client id = 1, then don't show PayPal... though this would apply to all of that client's invoices... though it comes unstuck in your second part when you say you want to do it per invoice.

 

one possible way around this, and this will depend on your products, is that you can define payment method options by product group... so say your options are paypal, authorize and skrill, but in a certain product group, only paypal and authorize are options - if someone orders a product from that product group, they will only be allowed to pay using paypal or authorize...

 

now what happens if you manually setup an invoice for that product and send it to the client, I don't know - logically, it should work the same way, but i've never tried it... it might be worth you sending a test invoice to yourself to see what occurs when you try to pay it.

Link to comment
Share on other sites

I'm actually not that concerned with orders. I can use custom order forms for this and order time.

 

I'm really more interested in specific invoices. For example when a client orders an addon, such as a dedicated IP, or backup service. Forcing them to pay with PayPal (Micro PayPal) for a $3 amount is more cost effective than going through the credit card processing fee.

 

The only thing I can come up with is to make different Payment gateways with these grouped, one for each possible permutation. Then hide those superfluous gateways from the order forms and add a bit in the invoicing template to show specific gateways if one of these superfluous gateways is defined for an invoice.

 

With 3 payment gateways that works out to 7 permutations, so you would have to create 4 superfluous gateways. But this grows quite considerably when more than 3. With 4 payments gateways that's a total of 15 permutations, so 11 superfluous gateways would need to be created.

Link to comment
Share on other sites

dealing with the low order value issue, you could tweak viewinvoice.tpl to only show Micro Paypal as a payment option if the order value is say less than $5.

 

you'd have to do some manipulation on $total to remove any currency prefix or suffix, but once you have it has a number, you can base an {if} statement around its value and code it to only show Micro Paypal as the only option.

Link to comment
Share on other sites

Well, really all of that was just an example. I'd really like for the WHMCS administrator to be able to define allowable payment gateways per invoice, instead of a defined limit employed directly in the invoice template.

 

Having trouble getting all of this worked out. The simplest solution would seem to be to have another table where defined gateways are listed per invoice id. And if that is present build {$gatewaydropdown} accordingly against that list instead of building it with all gateways.

 

Right now, I'm not sure where {$gatewaydropdown} is being defined or set.

Link to comment
Share on other sites

Right now, I'm not sure where {$gatewaydropdown} is being defined or set.

it's defined in one of the encrypted files - so that'll be why you can't find it! :)

 

have you considered using the "Notes" box to pass the available payment gateways to viewinvoice? you'd probably then have to remove the $notes output from viewinvoice and the pdf...

 

i'm thinking that in the notes field you add "paypal, authorize" and then in viewinvoice.tpl, you create your payment options based on those values...

 

by default, {$gatewaydropdown} will list all the available gateways, but you can remove a gateway from that list using some Smarty code...

 

{$gatewaydropdown|replace:'<option value="paypal">PayPal</option>':''}

would remove Paypal from the dropdown... multiple replaces can be used too...

 

{$gatewaydropdown|replace:'<option value="paypal">PayPal</option>':''|replace:'<option value="banktransfer">Bank Transfer</option>':''}

this would remove paypal and bank transfer from the gateway options..

 

so if we use this in the form...

 

<form method="post" action="{$smarty.server.PHP_SELF}?id={$invoiceid}">{if $notes|strstr:"authorize"}{$gatewaydropdown|replace:'<option value="paypal">PayPal</option>':''}{else}{$gatewaydropdown}{/if}</form>

let's assume you have authorize and paypal as your payment options, but only want the client to pay using authorize on this invoice - the above code would remove paypal - leaving authorize as the only option.

 

if you want to manipulate {$gatewaydropdown}, then I think in this situation it's easier to remove rather than add, so removing unwanted gateways may be easier than just adding the ones you want... though you would run into your permutation issue as you would need to use a few OR and {else} to cover the combinations.

 

I think a far better solution for your situation, would be to abandon using $gatewaydropdown and reproduce the dropdown from scratch - this will allow you to build it as you want it...

 

<form method="post" action="{$smarty.server.PHP_SELF}?id={$invoiceid}">
<input type="hidden" name="token" value="{$token}" />
<select name="gateway" size="1" onchange="submit()">
{if $notes|stristr:"banktransfer"}<option value="banktransfer"{if $notes|strtolower|stristr:"banktransfer" eq $paymentmodule} selected="selected"{/if}>Bank Transfer</option>{/if}
{if $notes|stristr:"mailin"}<option value="mailin"{if $notes|strtolower|stristr:"mailin" eq $paymentmodule} selected="selected"{/if}>Mail In Payment</option>{/if}
{if $notes|stristr:"paypal"}<option value="paypal"{if $notes|strtolower|stristr:"paypal" eq $paymentmodule} selected="selected"{/if}>Paypal</option>{/if}
{if !$notes|stristr:"banktransfer" and !$notes|stristr:"mailin" and !$notes|stristr:"paypal"}<option value="banktransfer" {if $paymentmodule eq "banktransfer"}selected="selected"{/if}>Bank Transfer</option><option value="mailin" {if $paymentmodule eq "mailin"}selected="selected"{/if}>Mail In Payment</option><option value="paypal" {if $paymentmodule eq "paypal"}selected="selected"{/if}>PayPal</option>{/if}
</select></form>

this will check the $notes variable - if it contains payment gateway(s), it will enable only those gateway(s) listed - i've made this case-insensitive to make validation more friendly... it shouldn't matter whether you use "paypal" or "PayPal" in the notes box, both should match.

 

$paymentmodule is always lowercase, so we make the $notes comparison string lowercase using strtolower and then compare the two - if they are equal, then we mark that option as selected.

 

if $notes doesn't contain any relevant payment gateway terms, then it shows all gateways.

 

hope this helps. :)

Edited by brian!
Link to comment
Share on other sites

Sorry, I got to working on this and forgot to check back. I think I found a way to do this. I had not thought of using the notes, like you suggested.

 

Basically you create a new table in the MySQL database:

 

CREATE TABLE `tblnewinvoicegateways` (
 `invoiceid` int(10) DEFAULT NULL,
 `gateway` text
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

 

 

Then in the file:

 

templates/portal/viewinvoice.tpl

 

Near the top of the file:

 

templates/portal/viewinvoice.tpl:

{php}
$results = full_query("select `tblnewinvoicegateways`.`gateway` as `gateway`, `tblpaymentgateways`.`value` as `readable` from `tblnewinvoicegateways` left join `tblpaymentgateways` on `tblnewinvoicegateways`.`gateway`=`tblpaymentgateways`.`gateway` where `invoiceid`=" . $this->_tpl_vars['invoiceid'] . " and `tblpaymentgateways`.`setting`=\"name\"");
if (mysql_num_rows($results)) {
       $this->_tpl_vars['iscustompaymentform'] = true;
       $this->_tpl_vars['custompaymentform'] = '<input type="hidden" name="token" value="' . $this->_tpl_vars['token'] .'" /><select name="gateway" size="1" onchange="submit()">';
       while($info = mysql_fetch_array($results)) {
               $this->_tpl_vars['custompaymentform'] .= '<option value="' . $info['gateway'] . '"';
               if ($info['gateway'] == $this->_tpl_vars['paymentmodule']) {
                       $this->_tpl_vars['custompaymentform'] .= ' selected';
               }
               $this->_tpl_vars['custompaymentform'] .= '>' . $info['readable'] . '</option>';
       }
       $this->_tpl_vars['custompaymentform'] .= '</select>';
}
{/php}

 

And replace:

 

templates/portal/viewinvoice.tpl:

{if $status eq "Unpaid"}
<font class="unpaid">{$LANG.invoicesunpaid}</font><br />
{if $allowchangegateway}
<form method="post" action="{$smarty.server.PHP_SELF}?id={$invoiceid}">{$gatewaydropdown}</form>
{else}
{$paymentmethod}<br />
{/if}
{$paymentbutton}

 

With:

 

{if $status eq "Unpaid"}
<font class="unpaid">{$LANG.invoicesunpaid}</font><br />
{if $allowchangegateway}
<form method="post" action="{$smarty.server.PHP_SELF}?id={$invoiceid}">
{if $iscustompaymentform}
{$custompaymentform}
{else}
{$gatewaydropdown}
{/if}
</form>
{else}
{$paymentmethod}<br />
{/if}
{$paymentbutton}

 

Then you just have to write a script to populate the tblnewinvoicegateways table with the desired gateways for that invoice:

 

| invoiceid | gateway     |
+-----------+-------------+
|        24 | paypal      |
|        24 | authorize   |
|        25 | paypal      |
|        25 | authorize   |
|        25 | moneybookers|
+-----------+-------------+

 

May not be the most eloquent way to do it, but it seems to be working for me.

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.

×
×
  • 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