Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -9,52 +9,66 @@
|
||||
* @since 20 Jul 2017
|
||||
*/
|
||||
|
||||
\define('REPORT_EXCEPTIONS', TRUE);
|
||||
require_once '../../../../init.php';
|
||||
\IPS\Session\Front::i();
|
||||
use IPS\Log;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Device;
|
||||
use IPS\nexus\Gateway;
|
||||
use IPS\nexus\Gateway\Stripe;
|
||||
use IPS\nexus\Invoice;
|
||||
use IPS\nexus\Money;
|
||||
use IPS\nexus\Transaction;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Session\Front;
|
||||
use IPS\Settings;
|
||||
|
||||
\IPS\Output::setCacheTime( false );
|
||||
define('REPORT_EXCEPTIONS', TRUE);
|
||||
require_once '../../../../init.php';
|
||||
Front::i();
|
||||
|
||||
Output::i()->pageCaching = FALSE;
|
||||
|
||||
/* Get the invoice */
|
||||
try
|
||||
{
|
||||
$invoice = \IPS\nexus\Invoice::load( \IPS\Request::i()->invoice );
|
||||
$invoice = Invoice::load( Request::i()->invoice );
|
||||
|
||||
if ( !$invoice->canView() )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch (OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( json_encode( array( 'success' => 0 ) ), 500, 'application/json' );
|
||||
Output::i()->sendOutput( json_encode( array( 'success' => 0 ) ), 500, 'application/json' );
|
||||
}
|
||||
|
||||
/* Get the gateway */
|
||||
try
|
||||
{
|
||||
$gateway = \IPS\nexus\Gateway::load( \IPS\Request::i()->gateway );
|
||||
if ( !( $gateway instanceof \IPS\nexus\Gateway\Stripe ) )
|
||||
$gateway = Gateway::load( Request::i()->gateway );
|
||||
if ( !( $gateway instanceof Stripe ) )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch (OutOfRangeException )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( json_encode( array( 'success' => 0 ) ), 500, 'application/json' );
|
||||
Output::i()->sendOutput( json_encode( array( 'success' => 0 ) ), 500, 'application/json' );
|
||||
}
|
||||
|
||||
/* Create a transaction */
|
||||
$transaction = new \IPS\nexus\Transaction;
|
||||
$transaction->member = \IPS\Member::loggedIn();
|
||||
$transaction = new Transaction;
|
||||
$transaction->member = Member::loggedIn();
|
||||
$transaction->invoice = $invoice;
|
||||
$transaction->amount = new \IPS\nexus\Money( \IPS\Request::i()->amount, mb_strtoupper( \IPS\Request::i()->currency ) );
|
||||
$transaction->ip = \IPS\Request::i()->ipAddress();
|
||||
$transaction->amount = new Money( Request::i()->amount, mb_strtoupper( Request::i()->currency ) );
|
||||
$transaction->ip = Request::i()->ipAddress();
|
||||
$transaction->method = $gateway;
|
||||
|
||||
/* Create a MaxMind request */
|
||||
$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 ( Settings::i()->maxmind_key and ( !Settings::i()->maxmind_gateways or Settings::i()->maxmind_gateways == '*' or in_array( $transaction->method->id, explode( ',', Settings::i()->maxmind_gateways ) ) ) )
|
||||
{
|
||||
$maxMind = new \IPS\nexus\Fraud\MaxMind\Request;
|
||||
$maxMind->setTransaction( $transaction );
|
||||
@@ -64,25 +78,25 @@ if ( \IPS\Settings::i()->maxmind_key and ( !\IPS\Settings::i()->maxmind_gateways
|
||||
try
|
||||
{
|
||||
/* Authorize */
|
||||
$transaction->auth = $gateway->auth( $transaction, array( "{$gateway->id}_card" => \IPS\Request::i()->token ), $maxMind );
|
||||
$transaction->auth = $gateway->auth( $transaction, array( "{$gateway->id}_card" => Request::i()->token ), $maxMind );
|
||||
|
||||
/* Check Fraud Rules and capture */
|
||||
$memberJustCreated = $transaction->checkFraudRulesAndCapture( $maxMind );
|
||||
if ( $memberJustCreated )
|
||||
{
|
||||
\IPS\Session::i()->setMember( $memberJustCreated );
|
||||
\IPS\Member\Device::loadOrCreate( $memberJustCreated, FALSE )->updateAfterAuthentication( NULL );
|
||||
Session::i()->setMember( $memberJustCreated );
|
||||
Device::loadOrCreate( $memberJustCreated, FALSE )->updateAfterAuthentication( NULL );
|
||||
}
|
||||
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch (Exception $e )
|
||||
{
|
||||
\IPS\Log::log( $e, 'applepay' );
|
||||
\IPS\Output::i()->sendOutput( json_encode( array( 'success' => 0 ) ), 500, 'application/json' );
|
||||
Log::log( $e, 'applepay' );
|
||||
Output::i()->sendOutput( json_encode( array( 'success' => 0 ) ), 500, 'application/json' );
|
||||
}
|
||||
|
||||
/* Send email receipt */
|
||||
$transaction->sendNotification();
|
||||
|
||||
/* Return */
|
||||
\IPS\Output::i()->sendOutput( json_encode( array( 'success' => 1, 'url' => (string) $transaction->url() ) ), 200, 'application/json' );
|
||||
Output::i()->sendOutput( json_encode( array( 'success' => 1, 'url' => (string) $transaction->url() ) ), 200, 'application/json' );
|
||||
Reference in new issue
Block a user