Jump to content
Craft

Auto Accept Order

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

Share this post


Link to post
Share on other sites
14 minutes ago, aissa el youssfu said:

under which name should i save this 

same file .. take a backup from your current file then replace the code

Share this post


Link to post
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

Share this post


Link to post
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)

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
26 minutes ago, aissa el youssfu said:

still pending

b.JPG

That’s correct because the order should be paid first then it will accept the order

Now you need to solve the payment issue first

Share this post


Link to post
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

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