Version 4.1.19
This commit is contained in:
1 parent
28bd025b35
commit
2bd5025018
2674 files changed
+233518
-77766
No files matched your search
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief billingAgreements Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Nexus
|
||||
* @since 17 Dec 2015
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* billingAgreements Task
|
||||
*/
|
||||
class _billingAgreements extends \IPS\Task
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* If ran successfully, should return anything worth logging. Only log something
|
||||
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
|
||||
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
|
||||
* Tasks should execute within the time of a normal HTTP request.
|
||||
*
|
||||
* @return mixed Message to log or NULL
|
||||
* @throws \IPS\Task\Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_billing_agreements', array( 'ba_next_cycle<?', time() ), 'ba_next_cycle ASC', 50 ), 'IPS\nexus\Customer\BillingAgreement' ) as $billingAgreement )
|
||||
{
|
||||
try
|
||||
{
|
||||
/* Get the status? */
|
||||
if ( $billingAgreement->status() != $billingAgreement::STATUS_ACTIVE )
|
||||
{
|
||||
if ( $billingAgreement->status() == $billingAgreement::STATUS_CANCELED )
|
||||
{
|
||||
$billingAgreement->canceled = TRUE;
|
||||
}
|
||||
throw new \DomainException("{$billingAgreement->id} - {$billingAgreement->status()}");
|
||||
}
|
||||
|
||||
/* Get the term */
|
||||
$term = $billingAgreement->term();
|
||||
|
||||
/* Fetch the latest unclaimed transaction */
|
||||
try
|
||||
{
|
||||
$transaction = $billingAgreement->latestUnclaimedTransaction();
|
||||
}
|
||||
/* If there isn't one yet, it might just be that PayPal hasn't taken it yet. Let it try for up to 3 days before giving up. */
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
if ( $billingAgreement->next_cycle->getTimestamp() > ( time() - ( 86400 * 3 ) ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get purchases */
|
||||
$purchases = new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_purchases', array( 'ps_billing_agreement=?', $billingAgreement->id ) ), 'IPS\nexus\Purchase' );
|
||||
|
||||
/* Generate an invoice */
|
||||
$invoice = new \IPS\nexus\Invoice;
|
||||
$invoice->system = TRUE;
|
||||
$invoice->currency = $transaction->amount->currency;
|
||||
$invoice->member = $billingAgreement->member;
|
||||
foreach ( $purchases as $purchase )
|
||||
{
|
||||
$invoice->addItem( \IPS\nexus\Invoice\Item\Renewal::create( $purchase ) );
|
||||
}
|
||||
$invoice->save();
|
||||
|
||||
/* Assign the transaction to it */
|
||||
$transaction->invoice = $invoice;
|
||||
$transaction->save();
|
||||
$transaction->approve();
|
||||
$invoice->status = $transaction->invoice->status;
|
||||
|
||||
/* Log */
|
||||
$invoice->member->log( 'transaction', array(
|
||||
'type' => 'paid',
|
||||
'status' => \IPS\nexus\Transaction::STATUS_PAID,
|
||||
'id' => $transaction->id,
|
||||
'invoice_id' => $invoice->id,
|
||||
'invoice_title' => $invoice->title,
|
||||
'automatic' => TRUE,
|
||||
), FALSE );
|
||||
|
||||
/* Update the purchase */
|
||||
if ( $invoice->status !== $invoice::STATUS_PAID )
|
||||
{
|
||||
foreach ( $purchases as $purchase )
|
||||
{
|
||||
$purchase->invoice_pending = $invoice;
|
||||
$purchase->save();
|
||||
}
|
||||
}
|
||||
|
||||
/* Send notification */
|
||||
$invoice->sendNotification();
|
||||
|
||||
/* Update billing agreement */
|
||||
if ( $invoice->status === $invoice::STATUS_PAID )
|
||||
{
|
||||
$billingAgreement->next_cycle = $billingAgreement->nextPaymentDate();
|
||||
}
|
||||
else
|
||||
{
|
||||
$billingAgreement->next_cycle = NULL;
|
||||
}
|
||||
$billingAgreement->save();
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
\IPS\Log::log( $e, 'ba_sync_fail' );
|
||||
|
||||
$billingAgreement->next_cycle = NULL;
|
||||
$billingAgreement->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup
|
||||
*
|
||||
* If your task takes longer than 15 minutes to run, this method
|
||||
* will be called before execute(). Use it to clean up anything which
|
||||
* may not have been done
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cleanup()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@
|
||||
/**
|
||||
* @brief Task to capture payments approaching their authorization deadlines
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage nexus
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Nexus
|
||||
* @since 12 Mar 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -39,14 +39,30 @@ class _capture extends \IPS\Task
|
||||
{
|
||||
$taskFrequency = new \DateInterval( $this->frequency );
|
||||
$time = \IPS\DateTime::create()->add( $taskFrequency )->add( $taskFrequency );
|
||||
|
||||
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_transactions', array( 't_auth<?', $time->getTimestamp() ) ), 'IPS\nexus\Transaction' ) as $transaction )
|
||||
{
|
||||
try
|
||||
if ( $transaction->method )
|
||||
{
|
||||
$transaction->capture();
|
||||
try
|
||||
{
|
||||
$transaction->capture();
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
}
|
||||
catch ( \Exception $e ) {}
|
||||
else
|
||||
{
|
||||
/* the gateway doesn't exist anymore, so reset the auth time */
|
||||
$transaction->auth = NULL;
|
||||
$extra = $transaction->extra;
|
||||
$extra['history'][] = array( 's' => \IPS\nexus\Transaction::STATUS_REFUSED, 'on' => time(), 'noteRaw' => 'invalid_gateway' );
|
||||
$transaction->extra = $extra;
|
||||
$transaction->status = \IPS\nexus\Transaction::STATUS_REFUSED;
|
||||
$transaction->save();
|
||||
|
||||
throw new \IPS\Task\Exception( $this, \IPS\Member::loggedIn()->language()->addToStack( 'invalid_gateway', FALSE, array( 'sprintf' => array( $transaction->id ) ) ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief cartCleanup Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @subpackage nexus
|
||||
* @since 17 Feb 2016
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* cartCleanup Task
|
||||
*/
|
||||
class _cartCleanup extends \IPS\Task
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* If ran successfully, should return anything worth logging. Only log something
|
||||
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
|
||||
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
|
||||
* Tasks should execute within the time of a normal HTTP request.
|
||||
*
|
||||
* @return mixed Message to log or NULL
|
||||
* @throws \IPS\Task\Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$ids = array();
|
||||
|
||||
foreach ( \IPS\Db::i()->select( 'nexus_cart_uploads.id', 'nexus_cart_uploads', array( 'time<? AND core_sessions.id IS NULL', ( time() - 86400 ) ) )->join( 'core_sessions', 'core_sessions.id=nexus_cart_uploads.session_id' ) as $id )
|
||||
{
|
||||
\IPS\File::unclaimAttachments( 'nexus_Purchases', $id, NULL, 'cart' );
|
||||
$ids[] = $id;
|
||||
}
|
||||
|
||||
\IPS\Db::i()->delete( 'nexus_cart_uploads', \IPS\Db::i()->in( 'id', $ids ) );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup
|
||||
*
|
||||
* If your task takes longer than 15 minutes to run, this method
|
||||
* will be called before execute(). Use it to clean up anything which
|
||||
* may not have been done
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cleanup()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@
|
||||
/**
|
||||
* @brief expectedOutputMonitoring Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage nexus
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Nexus
|
||||
* @since 12 Sep 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -41,7 +41,7 @@ class _expectedOutputMonitoring extends \IPS\Task
|
||||
|
||||
if ( !count( $rules ) )
|
||||
{
|
||||
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => 0 ), array( '`key`=?', 'expectedOutputMonitoring' ) );
|
||||
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 0 ), array( '`key`=?', 'expectedOutputMonitoring' ) );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class _expectedOutputMonitoring extends \IPS\Task
|
||||
|
||||
if ( !$match )
|
||||
{
|
||||
$email = \IPS\Email::buildFromTemplate( 'nexus', 'monitoring_eom', array( $rule ) );
|
||||
$email = \IPS\Email::buildFromTemplate( 'nexus', 'monitoring_eom', array( $rule ), \IPS\Email::TYPE_LIST );
|
||||
$email->send( json_decode( $rule->notify, TRUE ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
/**
|
||||
* @brief Expire Invoices Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage nexus
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Nexus
|
||||
* @since 01 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -42,6 +42,11 @@ class _expireInvoices extends \IPS\Task
|
||||
{
|
||||
$expireDate->sub( new \DateInterval( 'P' . \IPS\Settings::i()->cm_invoice_expireafter . 'D' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
// they don't expire so return only NULL
|
||||
return NULL;
|
||||
}
|
||||
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_invoices', array( 'i_status=? AND i_date<?', \IPS\nexus\Invoice::STATUS_PENDING, $expireDate->getTimestamp() ), 'i_date ASC', 100 ), 'IPS\nexus\Invoice' ) as $invoice )
|
||||
{
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
/**
|
||||
* @brief Expire Purchases Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage nexus
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Nexus
|
||||
* @since 01 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief gatewayPending Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @subpackage nexus
|
||||
* @since 06 Jun 2016
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\nexus\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* gatewayPending Task
|
||||
*/
|
||||
class _gatewayPending extends \IPS\Task
|
||||
{
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* If ran successfully, should return anything worth logging. Only log something
|
||||
* worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
|
||||
* If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
|
||||
* Tasks should execute within the time of a normal HTTP request.
|
||||
*
|
||||
* @return mixed Message to log or NULL
|
||||
* @throws \IPS\Task\Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$transactions = \IPS\Db::i()->select( '*', 'nexus_transactions', array( 't_status=?', \IPS\nexus\Transaction::STATUS_GATEWAY_PENDING ), 't_id ASC', 20 ); // We deliberately don't run until exauhstion here because we want to wait and try again later if it fails
|
||||
if ( !count( $transactions ) )
|
||||
{
|
||||
$this->enabled = FALSE;
|
||||
$this->save();
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ( $transactions as $transaction )
|
||||
{
|
||||
/* Get it */
|
||||
$transaction = \IPS\nexus\Transaction::constructFromData( $transaction );
|
||||
|
||||
/* Try to capture it */
|
||||
try
|
||||
{
|
||||
$transaction->capture();
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
if ( $e->getMessage() === 'FAIL' or $e->getMessage() === 'RFND' or $transaction->date->getTimestamp() > ( time() - ( 86400 * 3 ) ) )
|
||||
{
|
||||
$status = $e->getMessage() === 'RFND' ? \IPS\nexus\Transaction::STATUS_REFUNDED : \IPS\nexus\Transaction::STATUS_REFUSED;
|
||||
|
||||
$transaction->status = $status;
|
||||
$transaction->save();
|
||||
$transaction->member->log( 'transaction', array(
|
||||
'type' => 'status',
|
||||
'status' => $status,
|
||||
'id' => $transaction->id
|
||||
), FALSE );
|
||||
|
||||
if ( $status === \IPS\nexus\Transaction::STATUS_REFUNDED )
|
||||
{
|
||||
$transaction->sendNotification();
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If it succeeded, take any fraud action */
|
||||
$fraudResult = $transaction->fraud_blocked ? $transaction->fraud_blocked->action : NULL;
|
||||
if ( $fraudResult )
|
||||
{
|
||||
$transaction->executeFraudAction( $fraudResult, TRUE );
|
||||
}
|
||||
if ( !$fraudResult or $fraudResult === \IPS\nexus\Transaction::STATUS_PAID )
|
||||
{
|
||||
$transaction->approve();
|
||||
}
|
||||
|
||||
/* Let the customer know */
|
||||
$transaction->sendNotification();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup
|
||||
*
|
||||
* If your task takes longer than 15 minutes to run, this method
|
||||
* will be called before execute(). Use it to clean up anything which
|
||||
* may not have been done
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function cleanup()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,10 @@
|
||||
/**
|
||||
* @brief Generate Renewal Invoices Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage nexus
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Nexus
|
||||
* @since 01 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -44,14 +44,24 @@ class _generateRenewalInvoices extends \IPS\Task
|
||||
}
|
||||
/* Get purchases grouped by member and currency */
|
||||
$select = \IPS\Db::i()->select( '*', 'nexus_purchases', array(
|
||||
'ps_renewals>0 AND ps_invoice_pending=0 AND ps_active=1 AND ps_expire>0 AND ps_expire<?',
|
||||
"ps_renewals>0 AND ps_invoice_pending=0 AND ps_active=1 AND ps_expire>0 AND ps_expire<? AND ps_billing_agreement IS NULL AND ( ps_grouped_renewals='' OR ps_grouped_renewals IS NULL )",
|
||||
$renewalDate->getTimestamp()
|
||||
), 'ps_member', 50 );
|
||||
|
||||
$groupedPurchases = array();
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( $select, 'IPS\nexus\Purchase' ) as $purchase )
|
||||
{
|
||||
$groupedPurchases[ $purchase->member->member_id ][ $purchase->renewal_currency ][ $purchase->id ] = $purchase;
|
||||
/* If the member does not exist, we should not lock the task */
|
||||
try
|
||||
{
|
||||
$groupedPurchases[ $purchase->member->member_id ][ $purchase->renewal_currency ][ $purchase->id ] = $purchase;
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
{
|
||||
/* Set the purchase inactive so we don't try again. */
|
||||
$purchase->active = 0;
|
||||
$purchase->save();
|
||||
}
|
||||
}
|
||||
|
||||
/* Loop */
|
||||
@@ -72,7 +82,7 @@ class _generateRenewalInvoices extends \IPS\Task
|
||||
$invoice->save();
|
||||
|
||||
/* Nothing to pay? */
|
||||
if ( $invoice->amountToPay()->amount === (float) 0 )
|
||||
if ( $invoice->amountToPay()->amount->isZero() )
|
||||
{
|
||||
$extra = $invoice->status_extra;
|
||||
$extra['type'] = 'zero';
|
||||
@@ -84,45 +94,57 @@ class _generateRenewalInvoices extends \IPS\Task
|
||||
if ( $invoice->status !== $invoice::STATUS_PAID )
|
||||
{
|
||||
$credits = $member->cm_credits;
|
||||
$credit = $credits[$currency]->amount;
|
||||
if( $credit > 0 )
|
||||
if ( isset( $credits[ $currency ] ) )
|
||||
{
|
||||
$take = $credit > $invoice->total->amount ? $invoice->total->amount : $credit;
|
||||
|
||||
$transaction = new \IPS\nexus\Transaction;
|
||||
$transaction->member = $member;
|
||||
$transaction->invoice = $invoice;
|
||||
$transaction->amount = new \IPS\nexus\Money( $take, $currency );
|
||||
$transaction->extra = array('automatic' => TRUE);
|
||||
$transaction->save();
|
||||
$transaction->approve();
|
||||
|
||||
$member->log( 'transaction', array(
|
||||
'type' => 'paid',
|
||||
'status' => \IPS\nexus\Transaction::STATUS_PAID,
|
||||
'id' => $transaction->id,
|
||||
'invoice_id' => $invoice->id,
|
||||
'invoice_title' => $invoice->title,
|
||||
'automatic' => TRUE,
|
||||
), FALSE );
|
||||
|
||||
$credits[$currency]->amount -= $take;
|
||||
$member->cm_credits = $credits;
|
||||
$member->save();
|
||||
|
||||
$invoice->status = $transaction->invoice->status;
|
||||
$credit = $credits[$currency]->amount;
|
||||
if( $credit->isGreaterThanZero() )
|
||||
{
|
||||
if ( $credit->compare( $invoice->total->amount ) === 1 )
|
||||
{
|
||||
$take = $invoice->total->amount;
|
||||
}
|
||||
else
|
||||
{
|
||||
$take = $credit;
|
||||
}
|
||||
|
||||
$transaction = new \IPS\nexus\Transaction;
|
||||
$transaction->member = $member;
|
||||
$transaction->invoice = $invoice;
|
||||
$transaction->amount = new \IPS\nexus\Money( $take, $currency );
|
||||
$transaction->extra = array('automatic' => TRUE);
|
||||
$transaction->save();
|
||||
$transaction->approve();
|
||||
|
||||
$member->log( 'transaction', array(
|
||||
'type' => 'paid',
|
||||
'status' => \IPS\nexus\Transaction::STATUS_PAID,
|
||||
'id' => $transaction->id,
|
||||
'invoice_id' => $invoice->id,
|
||||
'invoice_title' => $invoice->title,
|
||||
'automatic' => TRUE,
|
||||
), FALSE );
|
||||
|
||||
$credits[$currency]->amount = $credits[$currency]->amount->subtract( $take );
|
||||
$member->cm_credits = $credits;
|
||||
$member->save();
|
||||
|
||||
$invoice->status = $transaction->invoice->status;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Charge to card */
|
||||
if ( $invoice->status !== $invoice::STATUS_PAID )
|
||||
{
|
||||
try
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_customer_cards', array( 'card_member=?', $member->member_id ) ), 'IPS\nexus\Customer\CreditCard' ) as $card )
|
||||
{
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_customer_cards', array( 'card_member=?', $member->member_id ) ), 'IPS\nexus\Customer\CreditCard' ) as $card )
|
||||
try
|
||||
{
|
||||
$cardDetails = $card->card; // We're just checking this doesn't throw an exception
|
||||
|
||||
$amountToPay = $invoice->amountToPay();
|
||||
$gateway = $card->method;
|
||||
|
||||
|
||||
$transaction = new \IPS\nexus\Transaction;
|
||||
$transaction->member = $member;
|
||||
$transaction->invoice = $invoice;
|
||||
@@ -130,14 +152,14 @@ class _generateRenewalInvoices extends \IPS\Task
|
||||
$transaction->amount = $amountToPay;
|
||||
$transaction->currency = $currency;
|
||||
$transaction->extra = array( 'automatic' => TRUE );
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
$transaction->auth = $gateway->auth( $transaction, array(
|
||||
( $gateway->id . '_card' ) => $card
|
||||
) );
|
||||
$transaction->capture();
|
||||
|
||||
|
||||
$transaction->member->log( 'transaction', array(
|
||||
'type' => 'paid',
|
||||
'status' => \IPS\nexus\Transaction::STATUS_PAID,
|
||||
@@ -146,17 +168,34 @@ class _generateRenewalInvoices extends \IPS\Task
|
||||
'invoice_title' => $invoice->title,
|
||||
'automatic' => TRUE,
|
||||
), FALSE );
|
||||
|
||||
|
||||
$transaction->approve();
|
||||
|
||||
break;
|
||||
}
|
||||
catch ( \Exception $e ){}
|
||||
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
$transaction->status = \IPS\nexus\Transaction::STATUS_REFUSED;
|
||||
$extra = $transaction->extra;
|
||||
$extra['history'][] = array( 's' => \IPS\nexus\Transaction::STATUS_REFUSED, 'noteRaw' => $e->getMessage() );
|
||||
$transaction->extra = $extra;
|
||||
$transaction->save();
|
||||
|
||||
$transaction->member->log( 'transaction', array(
|
||||
'type' => 'paid',
|
||||
'status' => \IPS\nexus\Transaction::STATUS_REFUSED,
|
||||
'id' => $transaction->id,
|
||||
'invoice_id' => $invoice->id,
|
||||
'invoice_title' => $invoice->title,
|
||||
'automatic' => TRUE,
|
||||
), FALSE );
|
||||
}
|
||||
|
||||
$invoice->status = $transaction->invoice->status;
|
||||
}
|
||||
// credit card doesn't exist anymore , move on
|
||||
catch ( \OutOfRangeException $e ){}
|
||||
}
|
||||
// credit card doesn't exist anymore , move on
|
||||
catch ( \OutOfRangeException $e ){}
|
||||
|
||||
}
|
||||
|
||||
/* Update the purchase */
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
/**
|
||||
* @brief Server Monitoring Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage nexus
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Nexus
|
||||
* @since 07 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -101,7 +101,7 @@ class _monitor extends \IPS\Task
|
||||
{
|
||||
$server->monitoringOffline();
|
||||
}
|
||||
elseif ( $server->monitor_fails == intval( \IPS\Settings::i()->monitoring_allowed_fails ) and !$server->monitor_acknowledged )
|
||||
elseif ( $server->monitor_fails == intval( \IPS\Settings::i()->monitoring_panic ) and !$server->monitor_acknowledged )
|
||||
{
|
||||
$server->monitoringPanic();
|
||||
}
|
||||
@@ -110,7 +110,7 @@ class _monitor extends \IPS\Task
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => 0 ), array( '`key`=?', 'monitor' ) );
|
||||
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 0 ), array( '`key`=?', 'monitor' ) );
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
/**
|
||||
* @brief Send Invoice Warnings Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage nexus
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Nexus
|
||||
* @since 01 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -39,47 +39,95 @@ class _sendInvoiceWarnings extends \IPS\Task
|
||||
{
|
||||
if ( \IPS\Settings::i()->cm_invoice_warning )
|
||||
{
|
||||
$cutoff = \IPS\DateTime::create()->add( new \DateInterval( 'P' . \IPS\Settings::i()->cm_invoice_generate . 'D' ) )->add( new \DateInterval( 'P' . \IPS\Settings::i()->cm_invoice_warning . 'D' ) )->getTimestamp();
|
||||
$select = \IPS\Db::i()->select( '*', 'nexus_purchases', array( 'ps_renewals>0 AND ps_invoice_pending=0 AND ps_invoice_warning_sent=0 AND ps_active=1 AND ps_expire>0 AND ps_expire<?', $cutoff ), 'ps_member', 50 );
|
||||
$normalCutoff = \IPS\DateTime::create()->add( new \DateInterval( 'P' . \IPS\Settings::i()->cm_invoice_generate . 'D' ) )->add( new \DateInterval( 'P' . \IPS\Settings::i()->cm_invoice_warning . 'D' ) )->getTimestamp();
|
||||
$billingAgreementCutoff = \IPS\DateTime::create()->add( new \DateInterval( 'P' . \IPS\Settings::i()->cm_invoice_warning . 'D' ) )->getTimestamp();
|
||||
$select = \IPS\Db::i()->select( '*', 'nexus_purchases', array( 'ps_renewals>0 AND ps_invoice_pending=0 AND ps_invoice_warning_sent=0 AND ps_active=1 AND ps_expire>0 AND ( ( ps_billing_agreement IS NULL AND ps_expire<? ) OR ( ps_billing_agreement IS NOT NULL AND ps_expire<? ) )', $normalCutoff, $billingAgreementCutoff ), 'ps_member', 50 );
|
||||
|
||||
$groupedPurchases = array();
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( $select, 'IPS\nexus\Purchase' ) as $purchase )
|
||||
{
|
||||
$groupedPurchases[ $purchase->member->member_id ][ $purchase->id ] = $purchase;
|
||||
$groupedPurchases[ $purchase->member->member_id ][ $purchase->billing_agreement AND !$purchase->billing_agreement->canceled ? $purchase->billing_agreement->id : 0 ][ $purchase->renewal_currency ][ $purchase->id ] = $purchase;
|
||||
}
|
||||
|
||||
/* Loop */
|
||||
foreach ( $groupedPurchases as $memberId => $purchases )
|
||||
foreach ( $groupedPurchases as $memberId => $_groupedPurchases )
|
||||
{
|
||||
$member = \IPS\nexus\Customer::load( $memberId );
|
||||
$cards = \IPS\Db::i()->select( '*', 'nexus_customer_cards', array( 'card_member=?', $member->member_id ) );
|
||||
|
||||
try
|
||||
foreach ( $_groupedPurchases as $billingAgreementId => $__groupedPurchases )
|
||||
{
|
||||
$card = \IPS\nexus\Customer\CreditCard::constructFromData( $cards->first() );
|
||||
|
||||
$invoice = new \IPS\nexus\Invoice; // We're not actually going to save this, it's just to know what the charges will be
|
||||
foreach ( $purchases as $purchase )
|
||||
foreach ( $__groupedPurchases as $currency => $purchases )
|
||||
{
|
||||
$invoice->addItem( \IPS\nexus\Invoice\Item\Renewal::create( $purchase ) );
|
||||
}
|
||||
|
||||
\IPS\Email::buildFromTemplate( 'nexus', 'invoiceWarning', array( $card, $invoice, $invoice->summary() ) )
|
||||
->send(
|
||||
$member,
|
||||
array_map(
|
||||
function( $contact )
|
||||
{
|
||||
return $contact->alt_id->email;
|
||||
},
|
||||
iterator_to_array( $member->alternativeContacts( array( 'billing=1' ) ) )
|
||||
),
|
||||
( ( in_array( 'invoice_warn', explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ) ) AND \IPS\Settings::i()->nexus_notify_copy_email ) ? explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) : array() )
|
||||
);
|
||||
}
|
||||
catch ( \UnderflowException $e ) {}
|
||||
$email = NULL;
|
||||
|
||||
/* Create a temporary invoice (we're not going to save this) so that we knkow what the charges will be */
|
||||
$invoice = new \IPS\nexus\Invoice;
|
||||
foreach ( $purchases as $purchase )
|
||||
{
|
||||
$invoice->addItem( \IPS\nexus\Invoice\Item\Renewal::create( $purchase ) );
|
||||
}
|
||||
$invoice->setDefaultTitle();
|
||||
|
||||
/* If there is a billing agreement - send an email abiout that */
|
||||
$billingAgreement = NULL;
|
||||
if ( $billingAgreementId )
|
||||
{
|
||||
try
|
||||
{
|
||||
$billingAgreement = \IPS\nexus\Customer\BillingAgreement::load( $billingAgreementId );
|
||||
|
||||
\IPS\Db::i()->update( 'nexus_purchases', array( 'ps_invoice_warning_sent' => 1 ), \IPS\Db::i()->in( 'ps_id', array_keys( $purchases ) ) );
|
||||
if ( $billingAgreement->status() == $billingAgreement::STATUS_CANCELED )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e ) { }
|
||||
}
|
||||
if ( $billingAgreement )
|
||||
{
|
||||
$email = \IPS\Email::buildFromTemplate( 'nexus', 'invoiceWarning', array( array(), NULL, $billingAgreement, $invoice, $invoice->summary() ), \IPS\Email::TYPE_TRANSACTIONAL );
|
||||
}
|
||||
/* Otherwise check account credit and cards */
|
||||
else
|
||||
{
|
||||
$cards = array();
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_customer_cards', array( 'card_member=?', $member->member_id ) ), 'IPS\nexus\Customer\CreditCard' ) as $card )
|
||||
{
|
||||
try
|
||||
{
|
||||
$cardDetails = $card->card; // We're just checking this doesn't throw an exception
|
||||
$cards[] = $card;
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
}
|
||||
$credits = $member->cm_credits;
|
||||
$credit = isset( $credits[ $currency ] ) ? $credits[ $currency ]->amount : ( new \IPS\Math\Number( '0' ) );
|
||||
|
||||
if ( count( $cards ) or $credit->isGreaterThanZero() )
|
||||
{
|
||||
$email = \IPS\Email::buildFromTemplate( 'nexus', 'invoiceWarning', array( $cards, isset( $credits[ $currency ] ) ? $credits[ $currency ] : ( new \IPS\nexus\Money( 0, $currency ) ), NULL, $invoice, $invoice->summary() ), \IPS\Email::TYPE_TRANSACTIONAL );
|
||||
}
|
||||
}
|
||||
|
||||
/* Send the email */
|
||||
if ( $email )
|
||||
{
|
||||
$email->send(
|
||||
$member,
|
||||
array_map(
|
||||
function( $contact )
|
||||
{
|
||||
return $contact->alt_id->email;
|
||||
},
|
||||
iterator_to_array( $member->alternativeContacts( array( 'billing=1' ) ) )
|
||||
),
|
||||
( ( in_array( 'invoice_warn', explode( ',', \IPS\Settings::i()->nexus_notify_copy_types ) ) AND \IPS\Settings::i()->nexus_notify_copy_email ) ? explode( ',', \IPS\Settings::i()->nexus_notify_copy_email ) : array() )
|
||||
);
|
||||
}
|
||||
|
||||
/* Update Purchases */
|
||||
\IPS\Db::i()->update( 'nexus_purchases', array( 'ps_invoice_warning_sent' => 1 ), \IPS\Db::i()->in( 'ps_id', array_keys( $purchases ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
/**
|
||||
* @brief supportAssignedReminder Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage nexus
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Nexus
|
||||
* @since 25 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -37,6 +37,12 @@ class _supportAssignedReminder extends \IPS\Task
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/* Don't send reminders if the application is disabled */
|
||||
if( !\IPS\Application::appIsEnabled('nexus') )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$openStatuses = iterator_to_array( \IPS\Db::i()->select( 'status_id', 'nexus_support_statuses', 'status_open=1' ) );
|
||||
$staffIds = array_keys( \IPS\nexus\Support\Request::staff() );
|
||||
|
||||
@@ -53,7 +59,7 @@ class _supportAssignedReminder extends \IPS\Task
|
||||
{
|
||||
if ( in_array( $staffId, $staffIds ) )
|
||||
{
|
||||
$email = \IPS\Email::buildFromTemplate( 'nexus', 'staffAssignedReminder', array( $requests ) )->send( \IPS\Member::load( $staffId ) );
|
||||
$email = \IPS\Email::buildFromTemplate( 'nexus', 'staffAssignedReminder', array( $requests ), \IPS\Email::TYPE_TRANSACTIONAL )->send( \IPS\Member::load( $staffId ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
/**
|
||||
* @brief supportAutoresolve Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage nexus
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Nexus
|
||||
* @since 25 Apr 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -37,7 +37,7 @@ class _supportAutoresolve extends \IPS\Task
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
if ( \IPS\Settings::i()->nexus_autoresolve_days )
|
||||
if ( \IPS\Settings::i()->nexus_autoresolve_days AND \IPS\Settings::i()->nexus_autoresolve_status != '' )
|
||||
{
|
||||
/* Build where */
|
||||
$where = array();
|
||||
@@ -52,22 +52,28 @@ class _supportAutoresolve extends \IPS\Task
|
||||
$resolvedStatus = \IPS\nexus\Support\Status::load( \IPS\Settings::i()->nexus_autoresolve_status );
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_support_requests', $resolveWhere ), 'IPS\nexus\Support\Request' ) as $request )
|
||||
{
|
||||
$oldStatus = $request->status;
|
||||
$request->status = $resolvedStatus;
|
||||
$request->save();
|
||||
$request->log( 'autoresolve', $oldStatus, $resolvedStatus, FALSE );
|
||||
}
|
||||
|
||||
/* Warnings */
|
||||
$warningWhere = array_merge( $where, array(
|
||||
array( 'r_last_reply<?', \IPS\DateTime::create()->sub( new \DateInterval( 'PT' . \IPS\Settings::i()->nexus_autoresolve_notify . 'H' ) )->getTimestamp() ),
|
||||
array( 'r_ar_notify=0' )
|
||||
) );
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_support_requests', $warningWhere ), 'IPS\nexus\Support\Request' ) as $request )
|
||||
{
|
||||
$email = \IPS\Email::buildFromTemplate( 'nexus', 'autoresolveWarning', array( $request, \IPS\DateTime::ts( $request->last_reply )->add( new \DateInterval( 'P' . \IPS\Settings::i()->nexus_autoresolve_days . 'D' ) )->relative() ) );
|
||||
$email->send( $request->email ?: $request->author() );
|
||||
|
||||
$request->ar_notify = TRUE;
|
||||
$request->save();
|
||||
if ( \IPS\Settings::i()->nexus_autoresolve_notify )
|
||||
{
|
||||
$warningWhere = array_merge( $where, array(
|
||||
array( 'r_last_reply<?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . \IPS\Settings::i()->nexus_autoresolve_days . 'D' ) )->add( new \DateInterval( 'PT' . \IPS\Settings::i()->nexus_autoresolve_notify . 'H' ) )->getTimestamp() ),
|
||||
array( 'r_ar_notify=0' )
|
||||
) );
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_support_requests', $warningWhere ), 'IPS\nexus\Support\Request' ) as $request )
|
||||
{
|
||||
$email = \IPS\Email::buildFromTemplate( 'nexus', 'autoresolveWarning', array( $request, \IPS\DateTime::ts( $request->last_reply )->add( new \DateInterval( 'P' . \IPS\Settings::i()->nexus_autoresolve_days . 'D' ) )->relative() ), \IPS\Email::TYPE_TRANSACTIONAL );
|
||||
$email->send( $request->email ?: $request->author() );
|
||||
|
||||
$request->ar_notify = TRUE;
|
||||
$request->save();
|
||||
$request->log( 'autoresolve_warning', NULL, NULL, FALSE );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
/**
|
||||
* @brief Terimate Expired Hosting Accounts Task
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @subpackage nexus
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Nexus
|
||||
* @since 11 Aug 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user