Version 4.7.0

This commit is contained in:
Neo committed 2025-12-19 16:00:35 -08:00
1 parent 517a5e1f70
commit 8ba7d43898
1933 files changed
+65613 -11332

No files matched your search

@@ -150,6 +150,14 @@ class paypalWebhookHandler
$invoice->billaddress = $transaction->billing_agreement->member->primaryBillingAddress();
foreach ( $purchases as $purchase )
{
if( !$purchase->renewals )
{
// Renewals have been cancelled for this purchase since PayPal tried to bill for it.
$amount = new \IPS\nexus\Money( $purchase->renewal_price, $transaction->amount->currency );
$invoice->addItem( new \IPS\nexus\extensions\nexus\Item\MiscellaneousCharge( sprintf( $purchase->member->language()->get('renew_payment_no_ba'), $purchase->name ), $amount ) );
continue;
}
$invoice->addItem( \IPS\nexus\Invoice\Item\Renewal::create( $purchase ) );
}
$invoice->save();
@@ -28,9 +28,7 @@ catch ( \OutOfRangeException $e )
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=nexus&module=checkout&controller=checkout&do=transaction&id=&t=" . \IPS\Request::i()->nexusTransactionId, 'front', 'nexus_checkout' ) );
}
/* Process */
try
{
$fraudCheck = function( $transaction, $refuseExecute=TRUE ) {
/* Check fraud rules */
$maxMind = NULL;
if ( \IPS\Settings::i()->maxmind_key and ( !\IPS\Settings::i()->maxmind_gateways or \IPS\Settings::i()->maxmind_gateways == '*' or \in_array( $transaction->method->id, explode( ',', \IPS\Settings::i()->maxmind_gateways ) ) ) )
@@ -40,13 +38,19 @@ try
$maxMind->setTransactionType( 'paypal' );
}
$fraudResult = $transaction->runFraudCheck( $maxMind );
if ( $fraudResult === \IPS\nexus\Transaction::STATUS_REFUSED )
if ( $refuseExecute AND $fraudResult === \IPS\nexus\Transaction::STATUS_REFUSED )
{
$transaction->executeFraudAction( $fraudResult, FALSE );
$transaction->sendNotification();
\IPS\Output::i()->redirect( $transaction->url() );
}
return $fraudResult;
};
/* Process */
try
{
/* Subscription */
if ( isset( \IPS\Request::i()->subscription ) )
{
@@ -70,7 +74,10 @@ try
}
$transaction->billing_agreement = $billingAgreement;
$transaction->save();
/* Check Fraud */
$fraudResult = $fraudCheck( $transaction, FALSE );
/* 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();
@@ -113,6 +120,8 @@ try
$transaction->gw_id = $t['transaction_id'];
$transaction->save();
/* Check Fraud Actions */
$fraudResult = $fraudCheck( $transaction );
if ( $fraudResult and $fraudResult !== \IPS\nexus\Transaction::STATUS_PAID )
{
$transaction->executeFraudAction( $fraudResult, TRUE );
@@ -163,6 +172,9 @@ try
$transaction->extra = $extra;
}
$transaction->save();
/* Fraud Check */
$fraudResult = $fraudCheck( $transaction, FALSE );
}
/* Capture */
@@ -74,7 +74,7 @@ class stripeWebhookHandler
}
/* Validate the source with Stripe */
$source = $this->transaction->method->api( 'sources/' . preg_replace( '/[^A-Z0-9_]/i', '', $this->data['data']['object']['id'] ) );
$source = $this->transaction->method->api( 'sources/' . preg_replace( '/[^A-Z0-9_]/i', '', $this->data['data']['object']['id'] ), null, 'get' );
if ( $source['client_secret'] != $this->data['data']['object']['client_secret'] )
{
throw new \Exception('BAD_SECRET');
@@ -130,7 +130,7 @@ class stripeWebhookHandler
/* Validate the charge with Stripe */
try
{
$charge = $this->transaction->method->api( 'charges/' . preg_replace( '/[^A-Z0-9_]/i', '', $this->data['data']['object']['id'] ) );
$charge = $this->transaction->method->api( 'charges/' . preg_replace( '/[^A-Z0-9_]/i', '', $this->data['data']['object']['id'] ), null, 'get' );
if ( !\in_array( $charge['status'], array( 'succeeded', 'paid' ) ) )
{
throw new \Exception;
@@ -206,7 +206,7 @@ class stripeWebhookHandler
/* Validate the charge with Stripe */
try
{
$charge = $this->transaction->method->api( 'charges/' . preg_replace( '/[^A-Z0-9_]/i', '', $this->data['data']['object']['id'] ) );
$charge = $this->transaction->method->api( 'charges/' . preg_replace( '/[^A-Z0-9_]/i', '', $this->data['data']['object']['id'] ), null, 'get' );
if ( !\in_array( $charge['status'], array( 'succeeded', 'paid' ) ) )
{
throw new \Exception;
@@ -281,7 +281,7 @@ class stripeWebhookHandler
/* Validate the charge with Stripe */
try
{
$charge = $this->transaction->method->api( 'charges/' . preg_replace( '/[^A-Z0-9_]/i', '', $this->data['data']['object']['id'] ) );
$charge = $this->transaction->method->api( 'charges/' . preg_replace( '/[^A-Z0-9_]/i', '', $this->data['data']['object']['id'] ), null, 'get' );
if ( $charge['status'] !== 'failed' )
{
throw new \Exception;
@@ -323,7 +323,7 @@ class stripeWebhookHandler
/* Validate the dispute with Stripe */
try
{
$dispute = $this->transaction->method->api( 'disputes/' . preg_replace( '/[^A-Z0-9_]/i', '', $this->data['data']['object']['id'] ) );
$dispute = $this->transaction->method->api( 'disputes/' . preg_replace( '/[^A-Z0-9_]/i', '', $this->data['data']['object']['id'] ), null, 'get' );
if ( !\in_array( $dispute['status'], array( 'needs_response', 'warning_needs_response' ) ) )
{
throw new \Exception;
@@ -331,7 +331,7 @@ class stripeWebhookHandler
if ( \substr( $this->transaction->gw_id, 0, 3 ) === 'pi_' )
{
$paymentIntent = $this->transaction->method->api( 'payment_intents/' . $this->transaction->gw_id );
$paymentIntent = $this->transaction->method->api( 'payment_intents/' . $this->transaction->gw_id, null, 'get' );
$ok = FALSE;
foreach ( $paymentIntent['charges']['data'] as $charge )
@@ -398,7 +398,7 @@ class stripeWebhookHandler
$dispute = $this->transaction->method->api( 'disputes/' . preg_replace( '/[^A-Z0-9_]/i', '', $this->data['data']['object']['id'] ) );
if ( \substr( $this->transaction->gw_id, 0, 3 ) === 'pi_' )
{
$paymentIntent = $this->transaction->method->api( 'payment_intents/' . $this->transaction->gw_id );
$paymentIntent = $this->transaction->method->api( 'payment_intents/' . $this->transaction->gw_id, null, 'get' );
$ok = FALSE;
foreach ( $paymentIntent['charges']['data'] as $charge )
@@ -476,7 +476,7 @@ class stripeWebhookHandler
{
try
{
$charge = $method->api( 'charges/' . preg_replace( '/[^A-Z0-9_]/i', '', $this->data['data']['object']['charge'] ) );
$charge = $method->api( 'charges/' . preg_replace( '/[^A-Z0-9_]/i', '', $this->data['data']['object']['charge'] ), null, 'get' );
if ( isset( $charge['payment_intent'] ) )
{
$paymentIntentId = $charge['payment_intent'];
@@ -618,6 +618,7 @@ class stripeWebhookHandler
$class = new stripeWebhookHandler( trim( @file_get_contents('php://input') ) );
try
{
sleep( 5 ); // Stripe can send web hooks very quickly, we need to delay to ensure we've processed the transaction first.
$response = $class->run( isset( $_SERVER['HTTP_STRIPE_SIGNATURE'] ) ? $_SERVER['HTTP_STRIPE_SIGNATURE'] : '' );
\IPS\Output::i()->sendOutput( $response, 200, 'text/plain' );
}