Version 4.6.0

This commit is contained in:
Neo committed 2025-12-19 05:55:31 -08:00
1 parent f79dcf067a
commit 517a5e1f70
2036 files changed
+110041 -26162

No files matched your search

@@ -12,6 +12,8 @@
\define('REPORT_EXCEPTIONS', TRUE);
require_once '../../../../init.php';
\IPS\Output::i()->pageCaching = FALSE;
try
{
$invoice = \IPS\nexus\Invoice::load( \IPS\Request::i()->x_invoice_num );
@@ -12,6 +12,8 @@
\define('REPORT_EXCEPTIONS', TRUE);
require_once '../../../../init.php';
\IPS\Output::i()->pageCaching = FALSE;
$webhookNotification = NULL;
$transaction = NULL;
foreach ( \IPS\nexus\Gateway::roots() as $method )
@@ -13,6 +13,8 @@
require_once '../../../../init.php';
\IPS\Session\Front::i();
\IPS\Output::i()->pageCaching = FALSE;
/**
* PayPal Webhook Handler
*/
@@ -71,10 +71,11 @@ try
$transaction->billing_agreement = $billingAgreement;
$transaction->save();
/* Just save that we're waiting for the webhook */
/* Just save that we're waiting for the webhook, but also try again in a few minutes because PayPal is flakey */
$transaction->status = \IPS\nexus\Transaction::STATUS_GATEWAY_PENDING;
$transaction->save();
$transaction->sendNotification();
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 1 ), "`key`='gatewayPending'" );
\IPS\Output::i()->redirect( $transaction->url() );
}
@@ -101,11 +102,49 @@ try
$billingAgreement->save();
$transaction->billing_agreement = $billingAgreement;
$transaction->save();
/* Get the initial setup transaction if possible */
$haveInitialTransaction = FALSE;
$transactions = $transaction->method->api( "payments/billing-agreements/{$billingAgreement->gw_id}/transactions?start_date=" . date( 'Y-m-d', time() - 86400 ) . '&end_date=' . date( 'Y-m-d' ), NULL, 'get' );
foreach ( $transactions['agreement_transaction_list'] as $t )
{
if ( $t['status'] == 'Completed' )
{
$transaction->gw_id = $t['transaction_id'];
$transaction->save();
if ( $fraudResult and $fraudResult !== \IPS\nexus\Transaction::STATUS_PAID )
{
$transaction->executeFraudAction( $fraudResult, TRUE );
}
else
{
$transaction->member->log( 'transaction', array(
'type' => 'paid',
'status' => $transaction::STATUS_PAID,
'id' => $transaction->id,
'invoice_id' => $transaction->invoice->id,
'invoice_title' => $transaction->invoice->title,
) );
$memberJustCreated = $transaction->approve();
if ( $memberJustCreated )
{
\IPS\Session::i()->setMember( $memberJustCreated );
\IPS\Member\Device::loadOrCreate( $memberJustCreated, FALSE )->updateAfterAuthentication( NULL );
}
}
$transaction->sendNotification();
\IPS\Output::i()->redirect( $transaction->url() );
}
}
/* Just save that we're waiting for the webhook */
$transaction->status = \IPS\nexus\Transaction::STATUS_GATEWAY_PENDING;
$transaction->save();
$transaction->sendNotification();
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => 1 ), "`key`='gatewayPending'" );
\IPS\Output::i()->redirect( $transaction->url() );
}
@@ -13,6 +13,8 @@
require_once '../../../../init.php';
\IPS\Session\Front::i();
\IPS\Output::i()->pageCaching = FALSE;
/* Get the invoice */
try
{
@@ -13,6 +13,8 @@
require_once '../../../../init.php';
\IPS\Session\Front::i();
\IPS\Output::i()->pageCaching = FALSE;
/* Little IN_DEV helper to prevent firing this until we've triggered the webhooks */
if ( \IPS\IN_DEV and !isset( \IPS\Request::i()->indevconfirm ) )
{
@@ -13,6 +13,8 @@
require_once '../../../../init.php';
\IPS\Session\Front::i();
\IPS\Output::i()->pageCaching = FALSE;
/**
* Stripe Webhook Handler
*/
@@ -113,7 +115,7 @@ class stripeWebhookHandler
private function chargeSucceeded()
{
/* Check the status */
if ( $this->transaction->status !== \IPS\nexus\Transaction::STATUS_GATEWAY_PENDING )
if ( !\in_array( $this->transaction->status, [ \IPS\nexus\Transaction::STATUS_GATEWAY_PENDING, IPS\nexus\Transaction::STATUS_PENDING ] ) )
{
if ( $this->transaction->status === \IPS\nexus\Transaction::STATUS_PAID )
{
@@ -183,7 +185,7 @@ class stripeWebhookHandler
private function chargeSucceededNew()
{
/* Check the status */
if ( $this->transaction->status !== \IPS\nexus\Transaction::STATUS_PENDING )
if ( !\in_array( $this->transaction->status, [ \IPS\nexus\Transaction::STATUS_GATEWAY_PENDING, IPS\nexus\Transaction::STATUS_PENDING ] ) )
{
if ( $this->transaction->status === \IPS\nexus\Transaction::STATUS_PAID )
{
@@ -195,6 +197,12 @@ class stripeWebhookHandler
}
}
/* If the invoice this is for is already paid, this may be a duplicate charge, so don't capture */
if ( $this->transaction->invoice->status === \IPS\nexus\Invoice::STATUS_PAID )
{
throw new \Exception('INVOICE_ALREADY_PAID');
}
/* Validate the charge with Stripe */
try
{