Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -1,163 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief billingAgreements Task
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage Nexus
|
||||
* @since 17 Dec 2015
|
||||
*/
|
||||
|
||||
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 5 days before giving up, which is how long PayPal will try for if there's an issue. */
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
if ( $billingAgreement->next_cycle->getTimestamp() > ( time() - ( 86400 * 5 ) ) )
|
||||
{
|
||||
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 ( \IPS\Http\Url\Exception $e )
|
||||
{
|
||||
/* Just log the issue, but don't do anything here,.. this was probably a temporary issue so let the next call run this again */
|
||||
\IPS\Log::log( $e, 'ba_sync_fail' );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
\IPS\Log::log( $e, 'ba_sync_fail' );
|
||||
|
||||
$billingAgreement->next_cycle = NULL;
|
||||
$billingAgreement->save();
|
||||
}
|
||||
catch ( \Throwable $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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -53,7 +53,7 @@ class _capture extends \IPS\Task
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
if ( in_array( $transaction->status, array( $transaction::STATUS_PENDING, $transaction::STATUS_WAITING, $transaction::STATUS_GATEWAY_PENDING ) ) )
|
||||
if ( \in_array( $transaction->status, array( $transaction::STATUS_PENDING, $transaction::STATUS_WAITING, $transaction::STATUS_GATEWAY_PENDING ) ) )
|
||||
{
|
||||
$transaction->status = \IPS\nexus\Transaction::STATUS_REFUSED;
|
||||
$extra = $transaction->extra;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -38,7 +38,7 @@ class _expectedOutputMonitoring extends \IPS\Task
|
||||
{
|
||||
$rules = \IPS\nexus\Hosting\EOM::roots();
|
||||
|
||||
if ( !count( $rules ) )
|
||||
if ( !\count( $rules ) )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 0 ), array( '`key`=?', 'expectedOutputMonitoring' ) );
|
||||
return NULL;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief gatewayPending Task
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @subpackage nexus
|
||||
* @since 06 Jun 2016
|
||||
*/
|
||||
|
||||
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 exhaustion 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 );
|
||||
|
||||
if ( $transaction->method instanceof \IPS\nexus\Gateway\Paypal )
|
||||
{
|
||||
/* Try to capture it */
|
||||
try
|
||||
{
|
||||
$transaction->capture();
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
if ( $e->getMessage() === 'FAIL' or $e->getMessage() === 'RFND' or $transaction->date->getTimestamp() < ( time() - ( 86400 * 5 ) ) )
|
||||
{
|
||||
$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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -36,16 +36,19 @@ class _generateRenewalInvoices extends \IPS\Task
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/* What's out cutoff? */
|
||||
$renewalDate = \IPS\DateTime::create();
|
||||
if( \IPS\Settings::i()->cm_invoice_generate )
|
||||
{
|
||||
$renewalDate->add( new \DateInterval( 'P' . \IPS\Settings::i()->cm_invoice_generate . 'D' ) );
|
||||
}
|
||||
$renewalDate->add( new \DateInterval( 'PT' . \IPS\Settings::i()->cm_invoice_generate . 'H' ) );
|
||||
}
|
||||
|
||||
/* 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<? AND ps_billing_agreement IS NULL AND ( ps_grouped_renewals='' OR ps_grouped_renewals IS NULL )",
|
||||
"ps_cancelled=0 AND 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 );
|
||||
$log = \IPS\Db::_replaceBinds( $select->query, $select->binds ) . "\n" . \count( $select ) . " matches\n\n";
|
||||
|
||||
$groupedPurchases = array();
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( $select, 'IPS\nexus\Purchase' ) as $purchase )
|
||||
@@ -68,14 +71,17 @@ class _generateRenewalInvoices extends \IPS\Task
|
||||
{
|
||||
$member = \IPS\nexus\Customer::load( $memberId );
|
||||
foreach ( $currencies as $currency => $purchases )
|
||||
{
|
||||
{
|
||||
$log .= "Member {$memberId}, {$currency}: " . \count( $purchases ) . " purchase(s) to be renewed: " . implode( ', ', array_keys( $purchases ) ) . ". ";
|
||||
|
||||
/* Create Invoice */
|
||||
$invoice = new \IPS\nexus\Invoice;
|
||||
$invoice->system = TRUE;
|
||||
$invoice->currency = $currency;
|
||||
$invoice->member = $member;
|
||||
$invoice->billaddress = $member->primaryBillingAddress();
|
||||
$items = array();
|
||||
|
||||
|
||||
foreach ( $purchases as $purchase )
|
||||
{
|
||||
/* Check the renewal is valid */
|
||||
@@ -86,6 +92,7 @@ class _generateRenewalInvoices extends \IPS\Task
|
||||
}
|
||||
|
||||
/* Remove renewals for this purchase */
|
||||
$log .= "Purchase {$purchase->id} cannot be renewed. ";
|
||||
$purchase->renewals = NULL;
|
||||
$purchase->member->log( 'purchase', array( 'type' => 'info', 'id' => $purchase->id, 'name' => $purchase->name, 'info' => 'remove_renewals' ) );
|
||||
$purchase->can_reactivate = TRUE;
|
||||
@@ -93,7 +100,7 @@ class _generateRenewalInvoices extends \IPS\Task
|
||||
}
|
||||
|
||||
/* Continue to next invoice if no items left */
|
||||
if( !count( $items ) )
|
||||
if( !\count( $items ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -103,129 +110,146 @@ class _generateRenewalInvoices extends \IPS\Task
|
||||
{
|
||||
$invoice->addItem( \IPS\nexus\Invoice\Item\Renewal::create( $item ) );
|
||||
}
|
||||
|
||||
$invoice->save();
|
||||
|
||||
/* Nothing to pay? */
|
||||
if ( $invoice->amountToPay()->amount->isZero() )
|
||||
$log .= "Invoice {$invoice->id} generated... ";
|
||||
|
||||
/* Try to take payment automatically, but *only* if we have a billing address (i.e. the customer has a primary billing address set)
|
||||
otherwise we don't know how we're taxing this and the customer will need to manually come and pay it */
|
||||
if ( $invoice->billaddress )
|
||||
{
|
||||
$extra = $invoice->status_extra;
|
||||
$extra['type'] = 'zero';
|
||||
$invoice->status_extra = $extra;
|
||||
$invoice->markPaid();
|
||||
}
|
||||
|
||||
/* Charge what we can to account credit */
|
||||
if ( $invoice->status !== $invoice::STATUS_PAID )
|
||||
{
|
||||
$credits = $member->cm_credits;
|
||||
if ( isset( $credits[ $currency ] ) )
|
||||
/* Nothing to pay? */
|
||||
if ( $invoice->amountToPay()->amount->isZero() )
|
||||
{
|
||||
$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;
|
||||
}
|
||||
$log .= "Nothing to pay!";
|
||||
|
||||
$extra = $invoice->status_extra;
|
||||
$extra['type'] = 'zero';
|
||||
$invoice->status_extra = $extra;
|
||||
$invoice->markPaid();
|
||||
}
|
||||
}
|
||||
/* Charge to card */
|
||||
if ( $invoice->status !== $invoice::STATUS_PAID )
|
||||
{
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_customer_cards', array( 'card_member=?', $member->member_id ) ), 'IPS\nexus\Customer\CreditCard' ) as $card )
|
||||
|
||||
/* Charge what we can to account credit */
|
||||
if ( $invoice->status !== $invoice::STATUS_PAID )
|
||||
{
|
||||
try
|
||||
$credits = $member->cm_credits;
|
||||
if ( isset( $credits[ $currency ] ) )
|
||||
{
|
||||
$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;
|
||||
$transaction->method = $gateway;
|
||||
$transaction->amount = $amountToPay;
|
||||
$transaction->currency = $currency;
|
||||
$transaction->extra = array( 'automatic' => TRUE );
|
||||
|
||||
try
|
||||
$credit = $credits[$currency]->amount;
|
||||
if( $credit->isGreaterThanZero() )
|
||||
{
|
||||
$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,
|
||||
'id' => $transaction->id,
|
||||
'invoice_id' => $invoice->id,
|
||||
'invoice_title' => $invoice->title,
|
||||
'automatic' => TRUE,
|
||||
), FALSE );
|
||||
|
||||
$log .= "{$credit} account credit available... ";
|
||||
|
||||
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();
|
||||
|
||||
break;
|
||||
}
|
||||
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,
|
||||
$log .= "Transaction {$transaction->id} generated... ";
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
$invoice->status = $transaction->invoice->status;
|
||||
}
|
||||
// error with card, move on
|
||||
catch ( \Exception $e ){}
|
||||
}
|
||||
/* Charge to card */
|
||||
if ( $invoice->status !== $invoice::STATUS_PAID )
|
||||
{
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'nexus_customer_cards', array( 'card_member=?', $member->member_id ) ), 'IPS\nexus\Customer\CreditCard' ) as $card )
|
||||
{
|
||||
$log .= "Attempting card {$card->id}... ";
|
||||
|
||||
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;
|
||||
$transaction->method = $gateway;
|
||||
$transaction->amount = $amountToPay;
|
||||
$transaction->currency = $currency;
|
||||
$transaction->extra = array( 'automatic' => TRUE );
|
||||
|
||||
try
|
||||
{
|
||||
$transaction->auth = $gateway->auth( $transaction, array(
|
||||
( $gateway->id . '_card' ) => $card
|
||||
), NULL, array(), 'renewal' );
|
||||
$transaction->capture();
|
||||
|
||||
$transaction->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 );
|
||||
|
||||
$transaction->approve();
|
||||
|
||||
$log .= "Transaction {$transaction->id} approved! ";
|
||||
|
||||
break;
|
||||
}
|
||||
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();
|
||||
|
||||
$log .= "Transaction {$transaction->id} failed. ";
|
||||
|
||||
$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;
|
||||
}
|
||||
// error with card, move on
|
||||
catch ( \Exception $e ){}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Update the purchase */
|
||||
if ( $invoice->status !== $invoice::STATUS_PAID )
|
||||
{
|
||||
{
|
||||
foreach ( $purchases as $purchase )
|
||||
{
|
||||
$purchase->invoice_pending = $invoice;
|
||||
@@ -235,8 +259,11 @@ class _generateRenewalInvoices extends \IPS\Task
|
||||
|
||||
/* Send notification */
|
||||
$invoice->sendNotification();
|
||||
$log .= "Final status: {$invoice->status}\n";
|
||||
}
|
||||
}
|
||||
|
||||
return $log;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -96,11 +96,11 @@ class _monitor extends \IPS\Task
|
||||
$server->monitor_fails++;
|
||||
$server->save();
|
||||
|
||||
if ( $server->monitor_fails == ( intval( \IPS\Settings::i()->monitoring_allowed_fails ) + 1 ) )
|
||||
if ( $server->monitor_fails == ( \intval( \IPS\Settings::i()->monitoring_allowed_fails ) + 1 ) )
|
||||
{
|
||||
$server->monitoringOffline();
|
||||
}
|
||||
elseif ( $server->monitor_fails == intval( \IPS\Settings::i()->monitoring_panic ) and !$server->monitor_acknowledged )
|
||||
elseif ( $server->monitor_fails == \intval( \IPS\Settings::i()->monitoring_panic ) and !$server->monitor_acknowledged )
|
||||
{
|
||||
$server->monitoringPanic();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -38,8 +38,8 @@ class _sendInvoiceWarnings extends \IPS\Task
|
||||
{
|
||||
if ( \IPS\Settings::i()->cm_invoice_warning )
|
||||
{
|
||||
$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();
|
||||
$normalCutoff = \IPS\DateTime::create()->add( new \DateInterval( 'PT' . \IPS\Settings::i()->cm_invoice_generate . 'H' ) )->add( new \DateInterval( 'PT' . \IPS\Settings::i()->cm_invoice_warning . 'H' ) )->getTimestamp();
|
||||
$billingAgreementCutoff = \IPS\DateTime::create()->add( new \DateInterval( 'PT' . \IPS\Settings::i()->cm_invoice_warning . 'H' ) )->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();
|
||||
@@ -76,7 +76,7 @@ class _sendInvoiceWarnings extends \IPS\Task
|
||||
}
|
||||
$invoice->setDefaultTitle();
|
||||
|
||||
/* If there is a billing agreement - send an email abiout that */
|
||||
/* If there is a billing agreement - send an email about that */
|
||||
$billingAgreement = NULL;
|
||||
if ( $billingAgreementId )
|
||||
{
|
||||
@@ -95,7 +95,8 @@ class _sendInvoiceWarnings extends \IPS\Task
|
||||
}
|
||||
if ( $billingAgreement )
|
||||
{
|
||||
$email = \IPS\Email::buildFromTemplate( 'nexus', 'invoiceWarning', array( array(), NULL, $billingAgreement, $invoice, $invoice->summary() ), \IPS\Email::TYPE_TRANSACTIONAL );
|
||||
$paymentDate = \IPS\DateTime::create()->add( new \DateInterval( 'PT' . \IPS\Settings::i()->cm_invoice_warning . 'H' ) )->localeDate( $member );
|
||||
$email = \IPS\Email::buildFromTemplate( 'nexus', 'invoiceWarning', array( array(), NULL, $billingAgreement, $invoice, $invoice->summary( $member->language() ), $paymentDate ), \IPS\Email::TYPE_TRANSACTIONAL );
|
||||
}
|
||||
/* Otherwise check account credit and cards */
|
||||
else
|
||||
@@ -113,9 +114,10 @@ class _sendInvoiceWarnings extends \IPS\Task
|
||||
$credits = $member->cm_credits;
|
||||
$credit = isset( $credits[ $currency ] ) ? $credits[ $currency ]->amount : ( new \IPS\Math\Number( '0' ) );
|
||||
|
||||
if ( count( $cards ) or $credit->isGreaterThanZero() )
|
||||
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 );
|
||||
$paymentDate = \IPS\DateTime::create()->add( new \DateInterval( 'PT' . \IPS\Settings::i()->cm_invoice_warning . 'H' ) )->localeDate( $member );
|
||||
$email = \IPS\Email::buildFromTemplate( 'nexus', 'invoiceWarning', array( $cards, isset( $credits[ $currency ] ) ? $credits[ $currency ] : ( new \IPS\nexus\Money( 0, $currency ) ), NULL, $invoice, $invoice->summary( $member->language() ), $paymentDate ), \IPS\Email::TYPE_TRANSACTIONAL );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +133,7 @@ class _sendInvoiceWarnings extends \IPS\Task
|
||||
},
|
||||
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() )
|
||||
( ( \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() )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -56,7 +56,7 @@ class _supportAssignedReminder extends \IPS\Task
|
||||
|
||||
foreach ( $sendTo as $staffId => $requests )
|
||||
{
|
||||
if ( in_array( $staffId, $staffIds ) )
|
||||
if ( \in_array( $staffId, $staffIds ) )
|
||||
{
|
||||
$email = \IPS\Email::buildFromTemplate( 'nexus', 'staffAssignedReminder', array( $requests ), \IPS\Email::TYPE_TRANSACTIONAL )->send( \IPS\Member::load( $staffId ) );
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\tasks;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
|
||||
Reference in new issue
Block a user