Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

@@ -9,7 +9,7 @@
* @since 07 Mar 2014
*/
define('REPORT_EXCEPTIONS', TRUE);
\define('REPORT_EXCEPTIONS', TRUE);
require_once '../../../../init.php';
\IPS\Session\Front::i();
@@ -33,7 +33,7 @@ try
{
/* 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 ) ) ) )
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 ) ) ) )
{
$maxMind = new \IPS\nexus\Fraud\MaxMind\Request;
$maxMind->setTransaction( $transaction );
@@ -47,8 +47,39 @@ try
\IPS\Output::i()->redirect( $transaction->url() );
}
/* Billing Agreement */
if ( isset( \IPS\Request::i()->billingAgreement ) )
/* Subscription */
if ( isset( \IPS\Request::i()->subscription ) )
{
/* Get details */
$response = $transaction->method->api( "billing/subscriptions/" . \IPS\Request::i()->subscription_id, NULL, 'get' );
/* Create Billing Agreement */
try
{
$billingAgreement = \IPS\nexus\Gateway\PayPal\BillingAgreement::constructFromData( \IPS\Db::i()->select( '*', 'nexus_billing_agreements', array( 'ba_gw_id=? AND ba_method=?', $response['id'], $transaction->method->id ) )->first() );
}
catch ( \UnderflowException $e )
{
$billingAgreement = new \IPS\nexus\Gateway\PayPal\BillingAgreement;
$billingAgreement->gw_id = $response['id'];
$billingAgreement->method = $transaction->method;
$billingAgreement->member = $transaction->member;
$billingAgreement->started = \IPS\DateTime::create();
$billingAgreement->next_cycle = ( new \IPS\DateTime( $response['billing_info']['next_billing_time'] ) );
$billingAgreement->save();
}
$transaction->billing_agreement = $billingAgreement;
$transaction->save();
/* Just save that we're waiting for the webhook */
$transaction->status = \IPS\nexus\Transaction::STATUS_GATEWAY_PENDING;
$transaction->save();
$transaction->sendNotification();
\IPS\Output::i()->redirect( $transaction->url() );
}
/* Billing Agreement (DEPRECATED) */
elseif ( isset( \IPS\Request::i()->billingAgreement ) )
{
/* Execute */
$response = $transaction->method->api( "payments/billing-agreements/" . \IPS\Request::i()->token . "/agreement-execute" );
@@ -70,49 +101,11 @@ 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/{$agreementId}/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() );
}
}
/* If it hasn't been processed yet (PayPal is a bit flakey), we need to try again in a few minutes */
/* 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() );
}