Jump to content

[ASK] How to use If-Else condition from Selected Dropdown List Payment Method ?


Mas-J

Recommended Posts

Condition:

I've create copy of banktransfer and rename it as localbank.

My goal: I want to show some dynamic Virtual Account number (combination of fixed bank code + custom field) when payment method localbank is selected and client preview invoice then choose it (viewinvoice.tpl)

I've try with several variable but there's no suitable value to match the selected payment method using if-else condition.

Could you tell me what the correct variable for selected payment method ?

Here's my custom script on viewinvoice.tpl

{if $paymentmethod == "localbank"}
     <td>: 123123{$clientsdetails["customfields2"]}</td>
{else}
     <td>: 77777{$clientsdetails["customfields2"]}</td>
{/if}

With that code, when localbank is selected the result always show the else result.

Although when I change the $paymentmenthod value to banktransfer, it still show the else result.

Link to comment
Share on other sites

1 hour ago, Mas-J said:

My goal: I want to show some dynamic Virtual Account number (combination of fixed bank code + custom field) when payment method localbank is selected and client preview invoice then choose it (viewinvoice.tpl)

instinctively, i'd be more inclined to do this in localbank.php than mess around with the viewinvoice template.

1 hour ago, Mas-J said:

Could you tell me what the correct variable for selected payment method ?

my suspicion is that if you've just blindly copied banktransfer.php and made no internal changes to the file, then WHMCS will see "localbank" as being called "banktransfer".

1 hour ago, Mas-J said:

With that code, when localbank is selected the result always show the else result.

which confirms the suspicion I think.

I am therefore assuming that you haven't renamed the two functions in localbank.php...

function banktransfer_config() {

function banktransfer_link($params) {

to...

function localbank_config() {

function localbank_link($params) {
1 hour ago, Mas-J said:

Although when I change the $paymentmenthod value to banktransfer, it still show the else result.

because "banktransfer" is not called "localbank" and so only the else will be triggered.

btw - that last function is the one that returns the text that you're trying to manipulate in the viewinvoice template...

function banktransfer_link($params) {
    $code = '<p>'
        . nl2br($params['instructions'])
        . '<br />'
        . Lang::trans('invoicerefnum')
        . ': '
        . $params['invoicenum']
        . '</p>';

    return $code;

}

you'll have access to the $clientsdetails array in there (via $params) (though whether that includes customfield values I can't remember - and i'll be damned if I start checking when I wasn't planning on being here today or tomorrow! 🎂)... but even if it doesn't, worst case scenario, you could get the client id from the invoice id value and query the cf value from the database.

however, if you're going to do it in the viewinvoice template, then hopefully the above function renaming changes will trigger your if statement to work as you intend.

Link to comment
Share on other sites

38 minutes ago, brian! said:

my suspicion is that if you've just blindly copied banktransfer.php and made no internal changes to the file, then WHMCS will see "localbank" as being called "banktransfer".

I've already change it actually when post this thread 🙂

I can confirm it because I can see the difference when select one of them, the description will change when select the payment method

image.thumb.png.b80553070d1508c222b282b80440ba3f.png

That's why I asked, maybe there's another clue ?

Maybe can you try on your dev environtment @brian! just for make sure ?

Link to comment
Share on other sites

11 minutes ago, Mas-J said:

I've already change it actually when post this thread 🙂

well done. thanks.png

16 minutes ago, Mas-J said:

That's why I asked, maybe there's another clue ?

i'll give you two presents and then i'm gone until Saturday... 🎁

  • if you're intent on doing this in the viewinvoice template, then it would be...
    {if $paymentmodule == "localbank"}
         <td>: 123123{$clientsdetails["customfields2"]}</td>
    {else}
         <td>: 77777{$clientsdetails["customfields2"]}</td>
    {/if}

    or...

    {if $paymentmethod == "Local Bank"}
         <td>: 123123{$clientsdetails["customfields2"]}</td>
    {else}
         <td>: 77777{$clientsdetails["customfields2"]}</td>
    {/if}

    either should work and you just need to decide whether to check for the gateway name (localbank) or its display name "Local Bank".

  • if you're going to do it in localbank.php, then it will work there too and remove the need for you to edit the viewinvoice template (and worry about updates removing those changes in the future)...

    function localbank_link($params) {
        $code = '<p>'
            . '123123 '
            . $params['clientdetails']['customfields2']
            . '</p>';
    
        return $code;
    
    }

    ezvUjxK.png

Link to comment
Share on other sites

32 minutes ago, brian! said:

if you're intent on doing this in the viewinvoice template, then it would be...


{if $paymentmodule == "localbank"}
     <td>: 123123{$clientsdetails["customfields2"]}</td>
{else}
     <td>: 77777{$clientsdetails["customfields2"]}</td>
{/if}

or...


{if $paymentmethod == "Local Bank"}
     <td>: 123123{$clientsdetails["customfields2"]}</td>
{else}
     <td>: 77777{$clientsdetails["customfields2"]}</td>
{/if}

either should work and you just need to decide whether to check for the gateway name (localbank) or its display name "Local Bank".

 

Thank you for your suggestion @brian! 🙂

I've try the two option and the value of banktransfer is show the correct value, I didn't know why the template can't recognize the $paymentmethod or $paymentmodule for custom/copy banktransfer in this case is localbank. It's weird.

Is it possible if I open ticket to WHMCS support ?

Link to comment
Share on other sites

2 minutes ago, Mas-J said:

I've try the two option and the value of banktransfer is show the correct value, I didn't know why the template can't recognize the $paymentmethod or $paymentmodule for custom/copy banktransfer in this case is localbank. It's weird.

tbh - I didn't try the code in viewinvoice, but all things being equal, it should work.

however, it is not the place to be doing this - if it were me, i'd be leaving the viewinvoice template alone and changing localbank.php as I suggested - that screenshot is from the modified localbank.php returning what you want... you shouldn't need any additional code in the template as I think you're overcomplicating the issue by doing that.

Link to comment
Share on other sites

Actually why I'm doing in template, because I've custom template so there's no worries if there's update on template six.

If there's an update on that template, I just need to compare the changes if needed.

Then, for locating the description of the payment method by default is on the top of view invoice page, where my finance team want located that information after the transaction table. That's why I need use new script to make it appear on new table that I created. For the payment method description on the top of page I just write "See the payment instrcution below".

Another reason, the PDF need to show the table of the payment method that my finance team want, so the invoice should as same as PDF hehehe...

Maybe I'll consider to move it to the bottom and replace my custom code if I stuck and WHMCS support didn't give any clue 🙂

Btw, thanks for the suggestion @brian!

Edited by Mas-J
additional infrmation
Link to comment
Share on other sites

52 minutes ago, Mas-J said:

Then, for locating the description of the payment method by default is on the top of view invoice page, where my finance team want located that information after the transaction table. That's why I need use new script to make it appear on new table that I created. For the payment method description on the top of page I just write "See the payment instrcution below".

is this only applying to paid invoices ?

i'm tempted to suggest that you could just add {$paymentmethod} anywhere in the template and that would echo the current gateway choice...

53 minutes ago, Mas-J said:

Maybe I'll consider to move it to the bottom and replace my custom code if I stuck and WHMCS support didn't give any clue

sadly, they often don't. 🙄

if it helps, the viewinvoice code works just fine in Six - so if it's not working for you, something else might be going wrong.

a visit to the activity logs can often tell you any specific issues with Smarty code.

Link to comment
Share on other sites

On 6/18/2020 at 10:22 PM, brian! said:

is this only applying to paid invoices ?

i'm tempted to suggest that you could just add {$paymentmethod} anywhere in the template and that would echo the current gateway choice...

Finnaly I solved this and didn't why it can be working right now LoL

<td>
	{if $paymentmodule == "localbank"}
		: 12312{$clientsdetails["customfields2"]}
	{elseif $paymentmodule == "banktransfer"}
		: 77777{$clientsdetails["customfields2"]}
	{/if}
</td>

Even I've change the script from @brian! it working too, thanks !

{if $paymentmodule == "localbank"}
     <td>: 123123{$clientsdetails["customfields2"]}</td>
{else}
     <td>: 77777{$clientsdetails["customfields2"]}</td>
{/if}

or...

{if $paymentmethod == "Local Bank"}
     <td>: 123123{$clientsdetails["customfields2"]}</td>
{else}
     <td>: 77777{$clientsdetails["customfields2"]}</td>
{/if}
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