Version 4.1.2

This commit is contained in:
Neo committed 2025-12-19 05:32:19 -08:00
1 parent 3ba79295ee
commit 28bd025b35
1131 files changed
+63658 -20579

No files matched your search

+82 -5
View File
@@ -37,12 +37,68 @@ class _Application extends \IPS\Application
{
try
{
$saveSubscription = FALSE;
/* Get the subscription */
$subscription = \IPS\Db::i()->select( '*', 'nexus_subscriptions', array( 's_gateway_key=? AND s_id=?', 'paypal', \IPS\Request::i()->subscr_id ) )->first();
$items = \unserialize( $subscription['s_items'] );
if ( !is_array( $items ) or empty( $items ) )
try
{
exit;
$subscription = \IPS\Db::i()->select( '*', 'nexus_subscriptions', array( 's_gateway_key=? AND s_id=?', 'paypal', \IPS\Request::i()->subscr_id ) )->first();
$items = \unserialize( $subscription['s_items'] );
if ( !is_array( $items ) or empty( $items ) )
{
/* Don't exit here, throw an underflow exception so we can see if this is a legacy subscription */
throw new \UnderflowException( 'NO_ITEMS' );
}
}
catch( \UnderflowException $e )
{
/* Was this from the old IP.Subscriptions? */
if ( isset( \IPS\Request::i()->old ) or mb_strstr( \IPS\Request::i()->custom, '-' ) !== FALSE )
{
if ( mb_strstr( \IPS\Request::i()->custom, '-' ) !== FALSE )
{
$exploded = explode( '-', \IPS\Request::i()->custom );
$memberId = intval( $exploded[0] );
$purchaseId = intval( $exploded[1] );
$item = \IPS\Db::i()->select( '*', 'nexus_purchases', array( "ps_id=?", $purchaseId ), 'ps_id' )->first();
}
else
{
$memberId = intval( \IPS\Request::i()->custom );
$item = \IPS\Db::i()->select( '*', 'nexus_purchases', array( "ps_member=? AND ps_name=?", $memberId, $itemName ), 'ps_start DESC' )->first();
}
/* If the purchase isn't valid or was cancelled just exit */
if ( !$item['ps_id'] or $item['ps_cancelled'] )
{
exit;
}
/* We need $items below, not $item */
$items = array( $item['ps_id'] );
/* Grab the first paypal method we can find */
$method = \IPS\Db::i()->select( 'm_id', 'nexus_paymethods', array( 'm_gateway=?', 'PayPal' ) )->first();
/* We are here because the subscription record doesn't exist. The 3.x code just silently and automatically added one, so do the same now.
Note that we will need the transaction ID to save the subscription, but we can set the array parameters that will be referenced below. */
$subscription = array(
's_gateway_key' => 'paypal',
's_id' => \IPS\Request::i()->subscr_id,
's_start_trans' => 0, // We will set this later after saving the transaction
's_method' => $method,
's_member' => $memberId,
);
$saveSubscription = TRUE;
}
else
{
/* Just let the exception bubble up and get caught */
throw $e;
}
}
/* If the gateway still exists, fetch it */
@@ -53,7 +109,7 @@ class _Application extends \IPS\Application
}
catch ( \OutOfRangeException $e ) { }
/* Check this waas actually a PayPal IPN message */
/* Check this was actually a PayPal IPN message */
try
{
$response = \IPS\Http\Url::external( 'https://www.' . ( \IPS\NEXUS_TEST_GATEWAYS ? 'sandbox.' : '' ) . 'paypal.com/cgi-bin/webscr/' )->request()->setHeaders( array( 'Accept' => 'application/x-www-form-urlencoded' ) )->post( array_merge( array( 'cmd' => '_notify-validate' ), $_POST ) );
@@ -114,6 +170,14 @@ class _Application extends \IPS\Application
$transaction->amount = new \IPS\nexus\Money( $_POST['mc_gross'], $_POST['mc_currency'] );
$transaction->gw_id = $_POST['txn_id'];
$transaction->approve();
/* If this was a legacy subscription payment, we'll need to save the subscription now that we have a trans ID */
if( $saveSubscription === TRUE )
{
$subscription['s_start_trans'] = $transaction->id;
\IPS\Db::i()->insert( 'nexus_subscriptions', $subscription );
}
}
catch ( \UnderflowException $e ) { }
}
@@ -181,4 +245,17 @@ class _Application extends \IPS\Application
{
return 'shopping-cart';
}
/**
* Can view page even when user is a guest when guests cannot access the site
*
* @param \IPS\Application\Module $module The module
* @param string $controller The controller
* @param string|NULL $do To "do" parameter
* @return bool
*/
public function allowGuestAccess( \IPS\Application\Module $module, $controller, $do )
{
return $module->key == 'store';
}
}