Jump to content
Craft

Auto Accept Order

Recommended Posts

Hi
I would like to auto accept any order on payment, so I did the following:
General Settings >> Ordering >> Auto Provision
Products/Services >> Module Settings >> Auto setup as soon as first payment is received
I added this hook (jetserver_AutoAcceptOrders.php) and I set everything to true (Check the screenshot)

When I Pay using (promo code with amount ZERO) or (amount $$ but paid from my account balance), I see the hosting is setup successfully, the order is accepted and status is Active.
But when I pay using Paypal, I see the hosting is setup successfully and order status is Pending. (Order Accepted is not mentioned at the Activity log).

jetserverauto.png

payment from credit.png

Payment from paypal.png

Pending Order.png

Share this post


Link to post
Share on other sites

which PHP version are you using? i'm not entirely sure that this is PHP7 compatible.

Share this post


Link to post
Share on other sites
Posted (edited)
1 hour ago, brian! said:

which PHP version are you using? i'm not entirely sure that this is PHP7 compatible.

@brian! Yea I'm using php 7.0

But I couldn't change to php 5.6 as WHMCS won't work :)

So what we should do now? :)

How can we make this file (jetserver_AutoAcceptOrders.php) compatible with php 7.0? Is there an alternative solution?

Edited by Craft

Share this post


Link to post
Share on other sites
10 hours ago, VanguardOne said:

Hello,

I was searching for a similar solution. I found this thread - https://whmcs.community/topic/274669-auto-accept-orders/ - I wonder if the hook called out here from a few years ago, still works? Can a mod confirm for us?

Thank you!

I did all the steps exactly as your mentioned old thread but it's not working.

Maybe the php file is not compatible any more with php 7.0

Share this post


Link to post
Share on other sites
16 hours ago, Craft said:

But I couldn't change to php 5.6 as WHMCS won't work 🙂

really? for simplicity sake, I tend to keep my 7.7.1 dev in 5.6 - seems to work without issue, though maybe you have addons that require PHP7.

16 hours ago, Craft said:

So what we should do now? 🙂

well from your screenshots, you can tell that it fundamentally works with credit balances, or I assume, 0.00 discounted invoices..... i'd be tempted to try it with bank transfer/mail-in payment to see if this is purely a PayPal issue, or if it doesn't like gateways in general.

16 hours ago, Craft said:

How can we make this file (jetserver_AutoAcceptOrders.php) compatible with php 7.0?

in that thread from @VanguardOne others have stated that it works with PHP7, so i'm inclined to think it's more an issue with PayPal or its configuration at your end - but without testing this locally myself, I can't know for sure.

17 hours ago, Craft said:

Is there an alternative solution?

if you want a commercial solution, Order Assistant from BusyRack is available from the Marketplace - it's $20 per year, or $80 to buy it.

12 hours ago, VanguardOne said:

Can a mod confirm for us?

I doubt that any moderator here (who will all be staff I assume) would comment on that unless they have used it themselves - they probably wouldn't comment on the status of a live third-party project, let alone an archived one.

2 hours ago, Craft said:

I did all the steps exactly as your mentioned old thread but it's not working.

but your screenshots show that it partially is, just not in your case for that PayPal order... so possibly something different with the variable values in the hook using PHP7 rather than 5.6 ?

2 hours ago, Craft said:

Maybe the php file is not compatible any more with php 7.0

I would suggest that you do one of two things (or both)...

  1. post the issue on their GitHub site as that's where anyone familiar with this will see it and may already have a solution.
  2. perhaps it just needs to use OrderPaid or InvoicePaid instead of the current hook point - there's a post with updated code here, but I haven't tried it.

Share this post


Link to post
Share on other sites
Posted (edited)
5 hours ago, brian! said:

I would suggest that you do one of two things (or both)...

  1. post the issue on their GitHub site as that's where anyone familiar with this will see it and may already have a solution.
  2. perhaps it just needs to use OrderPaid or InvoicePaid instead of the current hook point - there's a post with updated code here, but I haven't tried it.

@brian! I solved it.

The old github php file is really not compatible with the new version of WHMCS 7.7

So I used the modified code at the link you sent me and now it's working fine, thank you :)

https://github.com/Jetserver/WHMCS-Auto-Accept-Orders/issues/1#issuecomment-412626577

 

Edited by Craft

Share this post


Link to post
Share on other sites
7 hours ago, Craft said:

@brian! I solved it.

The old github php file is really not compatible with the new version of WHMCS 7.7

So I used the modified code at the link you sent me and now it's working fine, thank you :)

https://github.com/Jetserver/WHMCS-Auto-Accept-Orders/issues/1#issuecomment-412626577

 

Awesome, Craft. Do you mind sharing the code you created via Github that's working for you in whmcs 7.7 with the modifications you made? 

Share this post


Link to post
Share on other sites
15 hours ago, VanguardOne said:

Awesome, Craft. Do you mind sharing the code you created via Github that's working for you in whmcs 7.7 with the modifications you made? 

@VanguardOne Yea sure, the new code is here: https://github.com/Jetserver/WHMCS-Auto-Accept-Orders/issues/1#issuecomment-412626577

I tested it and it's working fine for WHMCS 7.7

here you are the code again

function AutoAcceptOrders_settings()
{
return array(
'apiuser'	=> '', // one of the admins username
'autosetup' => true, // determines whether product provisioning is performed
'sendregistrar' => false, // determines whether domain automation is performed
'sendemail' => true, // sets if welcome emails for products and registration confirmation emails for domains should be sent
'ispaid'	=> true, // set to true if you want to accept only paid orders
);
}

function AutoAcceptOrders_accept($vars)
{
$settings = AutoAcceptOrders_settings();

$ispaid = true;

if($vars['InvoiceID'])
{
    $result = localAPI('GetInvoice', array(
        'invoiceid'	=> $vars['invoiceId'],
    ), $settings['apiuser']);

    $ispaid = ($result['result'] == 'success' && $result['balance'] <= 0) ? true : false;

}
logActivity("Order isPaid: ".$ispaid,0);

if(( $settings['ispaid'] && $ispaid))
{
    $result = localAPI('AcceptOrder', array(
        'orderid' => $vars['orderId'],
        'autosetup'	=> $settings['autosetup'],
        'sendemail' => $settings['sendemail'],
    ), $settings['apiuser']);
    logActivity("Order Accept", 0);
    if(is_array($result)){
        foreach($result as $index=>$value){
            logActivity("$index:$value",0);
        }
    }

}
}
add_hook('OrderPaid', 1, 'AutoAcceptOrders_accept');

 

Share this post


Link to post
Share on other sites
On 7/11/2019 at 11:12 PM, Craft said:

@VanguardOne Yea sure, the new code is here: https://github.com/Jetserver/WHMCS-Auto-Accept-Orders/issues/1#issuecomment-412626577

I tested it and it's working fine for WHMCS 7.7

here you are the code again


function AutoAcceptOrders_settings()
{
return array(
'apiuser'	=> '', // one of the admins username
'autosetup' => true, // determines whether product provisioning is performed
'sendregistrar' => false, // determines whether domain automation is performed
'sendemail' => true, // sets if welcome emails for products and registration confirmation emails for domains should be sent
'ispaid'	=> true, // set to true if you want to accept only paid orders
);
}

function AutoAcceptOrders_accept($vars)
{
$settings = AutoAcceptOrders_settings();

$ispaid = true;

if($vars['InvoiceID'])
{
    $result = localAPI('GetInvoice', array(
        'invoiceid'	=> $vars['invoiceId'],
    ), $settings['apiuser']);

    $ispaid = ($result['result'] == 'success' && $result['balance'] <= 0) ? true : false;

}
logActivity("Order isPaid: ".$ispaid,0);

if(( $settings['ispaid'] && $ispaid))
{
    $result = localAPI('AcceptOrder', array(
        'orderid' => $vars['orderId'],
        'autosetup'	=> $settings['autosetup'],
        'sendemail' => $settings['sendemail'],
    ), $settings['apiuser']);
    logActivity("Order Accept", 0);
    if(is_array($result)){
        foreach($result as $index=>$value){
            logActivity("$index:$value",0);
        }
    }

}
}
add_hook('OrderPaid', 1, 'AutoAcceptOrders_accept');

 

Hello

Do you mind how you did to get this working?

Did you set the 'apiuser' to anything, or did you leave it as is?

Cause I can't get this code to work with 7.7.1

Share this post


Link to post
Share on other sites
13 hours ago, V1King said:

Hello

Do you mind how you did to get this working?

Did you set the 'apiuser' to anything, or did you leave it as is?

Cause I can't get this code to work with 7.7.1

Yea, you should add a username of an admin account (Check the attached screenshot)

And set all to "true" as mentioned below:

function AutoAcceptOrders_settings()
{
return array(
'apiuser'	=> 'admin', // one of the admins username
'autosetup' => true, // determines whether product provisioning is performed
'sendregistrar' => true, // determines whether domain automation is performed
'sendemail' => true, // sets if welcome emails for products and registration confirmation emails for domains should be sent
'ispaid'	=> true, // set to true if you want to accept only paid orders
);
}

Do you know where you should add this file? here: (includes/hooks)

Also you should do the following options:

General Settings >> Ordering >> Only Auto Provision for Existing (Uncheck it)
Products/Services >> Module Settings >> Auto setup as soon as first payment is received (Select it)

Good Luck ^^

username admin.png

Share this post


Link to post
Share on other sites
12 hours ago, Craft said:

Yea, you should add a username of an admin account (Check the attached screenshot)

And set all to "true" as mentioned below:


function AutoAcceptOrders_settings()
{
return array(
'apiuser'	=> 'admin', // one of the admins username
'autosetup' => true, // determines whether product provisioning is performed
'sendregistrar' => true, // determines whether domain automation is performed
'sendemail' => true, // sets if welcome emails for products and registration confirmation emails for domains should be sent
'ispaid'	=> true, // set to true if you want to accept only paid orders
);
}

Do you know where you should add this file? here: (includes/hooks)

Also you should do the following options:

General Settings >> Ordering >> Only Auto Provision for Existing (Uncheck it)
Products/Services >> Module Settings >> Auto setup as soon as first payment is received (Select it)

Good Luck ^^

username admin.png

Thanks a lot for taking your time to help.

Though I have done exactly as described it seems still not working for me. I am trying with a test account and with credits loaded on that account, I think that should not make any difference, should it?

Share this post


Link to post
Share on other sites
13 hours ago, V1King said:

Thanks a lot for taking your time to help.

Though I have done exactly as described it seems still not working for me. I am trying with a test account and with credits loaded on that account, I think that should not make any difference, should it?

It should work whatever you are paying with (credit loaded on the account) or (Paypal) or (ZERO amount with promo code).

After you make the order via client area, do you see it still pending at your admin area?

Try to share a screenshot for the activity log after you make the order, maybe something else is doing this issue. From (Utilities >> Logs >> Activity Log)

 

Share this post


Link to post
Share on other sites
On 8/1/2019 at 8:08 AM, Craft said:

It should work whatever you are paying with (credit loaded on the account) or (Paypal) or (ZERO amount with promo code).

After you make the order via client area, do you see it still pending at your admin area?

Try to share a screenshot for the activity log after you make the order, maybe something else is doing this issue. From (Utilities >> Logs >> Activity Log)

 

Yes, it is still pending in admin area.

I have also checked that the hook loads, which is does.

This is exactly how the hook looks at my side.

function AutoAcceptOrders_settings()
{
return array(
'apiuser'	=> 'whmscroot', // one of the admins username
'autosetup' => true, // determines whether product provisioning is performed
'sendregistrar' => true, // determines whether domain automation is performed
'sendemail' => true, // sets if welcome emails for products and registration confirmation emails for domains should be sent
'ispaid'	=> true, // set to true if you want to accept only paid orders
);
}


function AutoAcceptOrders_accept($vars)
{
$settings = AutoAcceptOrders_settings();

$ispaid = true;

if($vars['InvoiceID'])
{
    $result = localAPI('GetInvoice', array(
        'invoiceid'	=> $vars['invoiceId'],
    ), $settings['apiuser']);

    $ispaid = ($result['result'] == 'success' && $result['balance'] <= 0) ? true : false;

}
logActivity("Order isPaid: ".$ispaid,0);

if(( $settings['ispaid'] && $ispaid))
{
    $result = localAPI('AcceptOrder', array(
        'orderid' => $vars['orderId'],
        'autosetup'	=> $settings['autosetup'],
        'sendemail' => $settings['sendemail'],
    ), $settings['apiuser']);
    logActivity("Order Accept", 0);
    if(is_array($result)){
        foreach($result as $index=>$value){
            logActivity("$index:$value",0);
        }
    }

}
}
add_hook('OrderPaid', 1, 'AutoAcceptOrders_accept');

 

activitylog.png

order.png

Share this post


Link to post
Share on other sites
On 8/4/2019 at 4:10 PM, V1King said:

Yes, it is still pending in admin area.

I have also checked that the hook loads, which is does.

This is exactly how the hook looks at my side.


function AutoAcceptOrders_settings()
{
return array(
'apiuser'	=> 'whmscroot', // one of the admins username
'autosetup' => true, // determines whether product provisioning is performed
'sendregistrar' => true, // determines whether domain automation is performed
'sendemail' => true, // sets if welcome emails for products and registration confirmation emails for domains should be sent
'ispaid'	=> true, // set to true if you want to accept only paid orders
);
}


function AutoAcceptOrders_accept($vars)
{
$settings = AutoAcceptOrders_settings();

$ispaid = true;

if($vars['InvoiceID'])
{
    $result = localAPI('GetInvoice', array(
        'invoiceid'	=> $vars['invoiceId'],
    ), $settings['apiuser']);

    $ispaid = ($result['result'] == 'success' && $result['balance'] <= 0) ? true : false;

}
logActivity("Order isPaid: ".$ispaid,0);

if(( $settings['ispaid'] && $ispaid))
{
    $result = localAPI('AcceptOrder', array(
        'orderid' => $vars['orderId'],
        'autosetup'	=> $settings['autosetup'],
        'sendemail' => $settings['sendemail'],
    ), $settings['apiuser']);
    logActivity("Order Accept", 0);
    if(is_array($result)){
        foreach($result as $index=>$value){
            logActivity("$index:$value",0);
        }
    }

}
}
add_hook('OrderPaid', 1, 'AutoAcceptOrders_accept');

 

activitylog.png

order.png

I’m sorry but it’s something strange.

”Order Accepted” module doesn’t appear at the activity log!

@brian! any suggestion? 🙂

Share this post


Link to post
Share on other sites
7 hours ago, Craft said:

any suggestion? 🙂

there's an obvious one, but I don't know if it's clever obfuscation on V1King's part or just a typo. 🙂

'apiuser'	=> 'whmscroot', // one of the admins username

did you mean to use 'whmcsroot' rather than 'whmscroot' ? always remember: "We Have Many Compulsory Settings".  😛

an invalid apiuser value would prevent the hook from running the code within it - as I think would that admin not having "API Access" enabled in their administrator roles settings.

if I run this as a hook to save time (shouldn't matter if it's a hook or an addon - either should work) - so I pasted the above code in a .php file within the hooks folder; changed the apiuser value to my admin username; made an order as a client; enter that the invoice has been paid in the admin area (by mailin payment) - that automatically triggers the OrderPaid hook and it marked the order as accepted and logged it in the Activity log.

FJluM4W.png

Share this post


Link to post
Share on other sites
6 minutes ago, brian! said:

there's an obvious one, but I don't know if it's clever obfuscation on V1King's part or just a typo. 🙂


'apiuser'	=> 'whmscroot', // one of the admins username

did you mean to use 'whmcsroot' rather than 'whmscroot' ? always remember: "We Have Many Compulsory Settings".  😛

an invalid apiuser value would prevent the hook from running the code within it - as I think would that admin not having "API Access" enabled in their administrator roles settings.

if I run this as a hook to save time (shouldn't matter if it's a hook or an addon - either should work) - so I pasted the above code in a .php file within the hooks folder; changed the apiuser value to my admin username; made an order as a client; enter that the invoice has been paid in the admin area (by mailin payment) - that automatically triggers the OrderPaid hook and it marked the order as accepted and logged it in the Activity log.

FJluM4W.png

Regarding the admin user, yes, it is actually they way I choose to spell the root user, should have mentioned that, sorry for confusing you. =D

Then there have to be something else in my setup that is not right, just can't figure out what...

Share this post


Link to post
Share on other sites
9 hours ago, Craft said:

I’m sorry but it’s something strange.

”Order Accepted” module doesn’t appear at the activity log!

@brian! any suggestion? 🙂

Is there a module called "Order Accepted"?  When I look I have nothing called that, maybe I am missing something?

Share this post


Link to post
Share on other sites
23 hours ago, V1King said:

Is there a module called "Order Accepted"?

no it's a core function of WHMCS that when an order is accepted, it logs it in the activity log... so from that screenshot, "Order Accept" is this hook/addon logging that WHMCS has been told to accept the order, and "OrderAccepted" is WHMCS logging that the order has been accepted.

if you filter the activity log for "Order Accepted", do you not see multiple occurrences of it (assuming of course that you have previous orders that have been accepted) ?

Share this post


Link to post
Share on other sites
53 minutes ago, brian! said:

no it's a core function of WHMCS that when an order is accepted, it logs it in the activity log... so from that screenshot, "Order Accept" is this hook/addon logging that WHMCS has been told to accept the order, and "OrderAccepted" is WHMCS logging that the order has been accepted.

if you filter the activity log for "Order Accepted", do you not see multiple occurrences of it (assuming of course that you have previous orders that have been accepted) ?

Ah ok, I understand.

Still though, what other reasons can there be that make this not working?  Is there any other way I can check errors etc?

Share this post


Link to post
Share on other sites
3 hours ago, V1King said:

Still though, what other reasons can there be that make this not working?  Is there any other way I can check errors etc?

you could alter the coding to log more details to the activity log...

which WHMCS and PHP versions are you using ?

Share this post


Link to post
Share on other sites
19 hours ago, brian! said:

you could alter the coding to log more details to the activity log...

which WHMCS and PHP versions are you using ?

I am using the latest WHMCS and PHP 7.2

Share this post


Link to post
Share on other sites
30 minutes ago, V1King said:

I am using the latest WHMCS and PHP 7.2

oh that's what I used in the above test - v7.7.1 and PHP7.2 🙂

would be interesting to know if it's failing because of the API... perhaps post in the GitHub link I gave previously, as they'll be more familiar with this addon and might have ran across the issue before.

Share this post


Link to post
Share on other sites
11 hours ago, brian! said:

oh that's what I used in the above test - v7.7.1 and PHP7.2 🙂

would be interesting to know if it's failing because of the API... perhaps post in the GitHub link I gave previously, as they'll be more familiar with this addon and might have ran across the issue before.

Yeah, very strange it works for some and other not.

GitHub doesn't seem to much activity about this now. Think I will just leave it like this now, anyway, thanks for helping out and giving me more insight.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

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