Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -125,10 +125,22 @@ class _billingAgreements extends \IPS\Task
|
||||
}
|
||||
$billingAgreement->save();
|
||||
}
|
||||
catch ( \IPS\Http\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();
|
||||
}
|
||||
|
||||
@@ -38,7 +38,8 @@ class _cartCleanup extends \IPS\Task
|
||||
{
|
||||
$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 )
|
||||
/* Fetch active session IDs */
|
||||
foreach ( \IPS\Db::i()->select( 'nexus_cart_uploads.id', 'nexus_cart_uploads', array( 'time<? AND ' . \IPS\Db::i()->in( 'session_id', \IPS\Session\Store::i()->getSessionids(), true ), ( time() - 86400 ) ) ) as $id )
|
||||
{
|
||||
\IPS\File::unclaimAttachments( 'nexus_Purchases', $id, NULL, 'cart' );
|
||||
$ids[] = $id;
|
||||
|
||||
@@ -36,7 +36,7 @@ class _gatewayPending extends \IPS\Task
|
||||
*/
|
||||
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
|
||||
$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;
|
||||
@@ -49,46 +49,50 @@ class _gatewayPending extends \IPS\Task
|
||||
/* Get it */
|
||||
$transaction = \IPS\nexus\Transaction::constructFromData( $transaction );
|
||||
|
||||
/* Try to capture it */
|
||||
try
|
||||
if ( $transaction->method instanceof \IPS\nexus\Gateway\Paypal )
|
||||
{
|
||||
$transaction->capture();
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
if ( $e->getMessage() === 'FAIL' or $e->getMessage() === 'RFND' or $transaction->date->getTimestamp() > ( time() - ( 86400 * 3 ) ) )
|
||||
/* Try to capture it */
|
||||
try
|
||||
{
|
||||
$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();
|
||||
}
|
||||
$transaction->capture();
|
||||
}
|
||||
continue;
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
/* 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -74,10 +74,36 @@ class _generateRenewalInvoices extends \IPS\Task
|
||||
$invoice->system = TRUE;
|
||||
$invoice->currency = $currency;
|
||||
$invoice->member = $member;
|
||||
$items = array();
|
||||
|
||||
foreach ( $purchases as $purchase )
|
||||
{
|
||||
$invoice->addItem( \IPS\nexus\Invoice\Item\Renewal::create( $purchase ) );
|
||||
/* Check the renewal is valid */
|
||||
if( $purchase->canBeRenewed() )
|
||||
{
|
||||
$items[] = $purchase;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Remove renewals for this purchase */
|
||||
$purchase->renewals = NULL;
|
||||
$purchase->member->log( 'purchase', array( 'type' => 'info', 'id' => $purchase->id, 'name' => $purchase->name, 'info' => 'remove_renewals' ) );
|
||||
$purchase->can_reactivate = TRUE;
|
||||
$purchase->save();
|
||||
}
|
||||
|
||||
/* Continue to next invoice if no items left */
|
||||
if( !count( $items ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Add items to invoice */
|
||||
foreach( $items as $item )
|
||||
{
|
||||
$invoice->addItem( \IPS\nexus\Invoice\Item\Renewal::create( $item ) );
|
||||
}
|
||||
|
||||
$invoice->save();
|
||||
|
||||
/* Nothing to pay? */
|
||||
@@ -193,7 +219,7 @@ class _generateRenewalInvoices extends \IPS\Task
|
||||
$invoice->status = $transaction->invoice->status;
|
||||
}
|
||||
// error with card, move on
|
||||
catch ( \LogicException $e ){}
|
||||
catch ( \Exception $e ){}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,16 @@ class _sendInvoiceWarnings extends \IPS\Task
|
||||
foreach ( new \IPS\Patterns\ActiveRecordIterator( $select, 'IPS\nexus\Purchase' ) as $purchase )
|
||||
{
|
||||
$agreementId = ( $purchase->billing_agreement AND !$purchase->billing_agreement->canceled ) ? $purchase->billing_agreement->id : 0;
|
||||
$groupedPurchases[ $purchase->member->member_id ][ $agreementId ][ $purchase->renewal_currency ][ $purchase->id ] = $purchase;
|
||||
|
||||
if ( $purchase->onExpireWarning() )
|
||||
{
|
||||
$purchase->invoice_warning_sent = 1;
|
||||
$purchase->save();
|
||||
}
|
||||
else
|
||||
{
|
||||
$groupedPurchases[ $purchase->member->member_id ][ $agreementId ][ $purchase->renewal_currency ][ $purchase->id ] = $purchase;
|
||||
}
|
||||
}
|
||||
|
||||
/* Loop */
|
||||
@@ -59,7 +68,7 @@ class _sendInvoiceWarnings extends \IPS\Task
|
||||
{
|
||||
$email = NULL;
|
||||
|
||||
/* Create a temporary invoice (we're not going to save this) so that we knkow what the charges will be */
|
||||
/* Create a temporary invoice (we're not going to save this) so that we know what the charges will be */
|
||||
$invoice = new \IPS\nexus\Invoice;
|
||||
foreach ( $purchases as $purchase )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user