Jump to content

Auto Accept Order


Craft

Recommended Posts

38 minutes ago, aissa el youssfu said:

thanks for your response 

this isthe code 

<?php
  /*
  *
  * Auto Accept Orders
  * Created By Idan Ben-Ezra
  *
  * Copyrights @ Jetserver Web Hosting
  * www.jetserver.net
  *
  * Hook version 1.0.1
  *
  **/
  if (!defined("WHMCS"))
  die("This file cannot be accessed directly");
   
  /*********************
  Auto Accept Orders Settings
  *********************/
  function jetserverAutoAcceptOrders_settings()
  {
  return array(
  'apiuser' =>myadminusername '', // 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
  'paymentmethod' => array(), // set the payment method you want to accept automaticly (leave empty to use all payment methods) * example array('paypal','amazonsimplepay')
  );
  }
  /********************/
   
  function jetserverAutoAcceptOrders_accept($vars)
  {
  $settings = jetserverAutoAcceptOrders_settings();
   
  $ispaid = true;
   
  if($vars['InvoiceID'])
  {
  $result = localAPI('getinvoice', array(
  'invoiceid' => $vars['InvoiceID'],
  ), $settings['apiuser']);
   
  $ispaid = ($result['result'] == 'success' && $result['balance'] <= 0) ? true : false;
  }
   
  if((!sizeof($settings['paymentmethod']) || sizeof($settings['paymentmethod']) && in_array($vars['PaymentMethod'], $settings['paymentmethod'])) && (!$settings['ispaid'] || $settings['ispaid'] && $ispaid))
  {
  $result = localAPI('acceptorder', array(
  'orderid' => $vars['OrderID'],
  'autosetup' => $settings['autosetup'],
  'sendregistrar' => $settings['sendregistrar'],
  'sendemail' => $settings['sendemail'],
  ), $settings['apiuser']);
  }
  }
   
  add_hook('AfterShoppingCartCheckout', 0, 'jetserverAutoAcceptOrders_accept');

Yea this is the old hook which working on the old versions on WHMCS

But you need to replace this code with the updated one to be compatible with the new version of WHMCS

But take care, it's working only for hosting orders not for domain registration/transfer orders

Here is the update code:

<?php
/*
*
* Auto Accept Orders
* Created By Idan Ben-Ezra
*
* Copyrights @ Jetserver Web Hosting
* www.jetserver.net
*
* Hook version 1.0.1
*
**/
if (!defined("WHMCS"))
	die("This file cannot be accessed directly");

/*********************
 Auto Accept Orders Settings
*********************/
function AutoAcceptOrders_settings()
{
return array(
    'apiuser'	=> 'admin', // 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');

?>

Reference: https://github.com/Jetserver/WHMCS-Auto-Accept-Orders/issues/1

Edited by Craft
Link to comment
Share on other sites

34 minutes ago, aissa el youssfu said:

oh yeah thank you so much I think it works but he problem is when a client pays i go to my paypal the payment is recieved but at the client dashboard there still an invoice 

Share a screenshot to understand you better and try to solve the issue

Link to comment
Share on other sites

15 minutes ago, aissa el youssfu said:

this is the dashboard of one my client, he paid the invoice and the payment is recieved. but as you can see the incoice is still appearing. 

Capture.JPG

in.JPG

Yea because (isPaid) function doesn't run successfully.

Can you share a screenshot from the Activity log (Utilities >> Log >> Activity Log)

Link to comment
Share on other sites

24 minutes ago, aissa el youssfu said:

please what causes also those errors with green marks

kk.JPG

This issue is not related to the hook by the way.

Your order is now "Active" or still pending? I'm asking about the Order Status not the Order Item!

You can check it from the main page of "Orders" tab >> List All Orders

Link to comment
Share on other sites

1 hour ago, aissa el youssfu said:

please what causes also those errors with green marks

kk.JPG

Make sure that you are using a valid emails here:

Setup >> General Settings >> General tab >> (Email Address) field

Setup >> General Settings >> Mail tab >> (System Emails From Email) field

Link to comment
Share on other sites

  • 10 months later...
  • 1 month later...
On 10/1/2020 at 10:19 AM, brian! said:

Kian posted a hook that auto accepts orders when the invoice is paid - I see no reason why it wouldn't work on v8, though I haven't tested it.

https://github.com/Katamaze/WHMCS-Free-Action-Hooks/blob/master/hooks/AcceptOrderOnInvociePaid.php

How could this be configured to only Accept Orders that are under $21.00 USD?

Link to comment
Share on other sites

On 15/11/2020 at 04:27, Synister said:

How could this be configured to only Accept Orders that are under $21.00 USD?

well this is Kian's baby, but there is a line in the hook...

$invoiceAmount = false; // Auto-accept order only if invoice amount is >= $invoiceAmount. Set false to auto-accept everything (Important: currency conversion not supported)

if you only have one currency, USD, then you could change that false to 21 and you should be good to go.

if you have multiple currencies in WHMCS, then you might need to find the currency of the invoice and alter the hook coding accordingly.

Link to comment
Share on other sites

  • 2 years later...

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