Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

@@ -2,9 +2,9 @@
/**
* @brief Authorize.Net Gateway
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 17 Mar 2014
* @version SVN_VERSION_NUMBER
@@ -32,56 +32,72 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
/**
* Check the gateway can process this...
*
* @param $amount \IPS\nexus\Money The amount
* @param $billingAddress \IPS\GeoLocation The billing address
* @param $amount \IPS\nexus\Money The amount
* @param $billingAddress \IPS\GeoLocation|NULL The billing address, which may be NULL if one if not provided
* @param $customer \IPS\nexus\Customer The customer (Default NULL value is for backwards compatibility - it should always be provided.)
* @param array $recurrings Details about recurring costs
* @return bool
*/
public function checkValidity( \IPS\nexus\Money $amount, \IPS\GeoLocation $billingAddress )
public function checkValidity( \IPS\nexus\Money $amount, \IPS\GeoLocation $billingAddress = NULL, \IPS\nexus\Customer $customer = NULL, $recurrings = array() )
{
$settings = json_decode( $this->settings, TRUE );
/* If we don't know the processor, we can only go off the default checks */
if ( !$settings['processor'] )
{
return parent::checkValidity( $amount, $billingAddress );
return parent::checkValidity( $amount, $billingAddress, $customer, $recurrings );
}
$currencies = array();
/* European processors require a full name and billing address */
if ( in_array( $settings['processor'], array( 8, 9, 10, 11, 12, 13 ) ) )
{
if ( !$customer->cm_first_name or !$customer->cm_last_name or !$billingAddress )
{
return FALSE;
}
}
/* GPN Canada and WorldPay Streamline Processing Platform also require a billing address */
if ( in_array( $settings['processor'], array( 4, 13 ) ) )
{
if ( !$billingAddress )
{
return FALSE;
}
}
/* For everything else, check the currencies they can handle... */
$currencies = array();
if ( in_array( $settings['processor'], array( 1, 2, 4, 5, 6, 7, 8, 13, 14 ) ) )
{
$currencies[] = 'USD';
}
if ( in_array( $settings['processor'], array( 1, 2, 4 ) ) )
{
$currencies[] = 'CAD';
}
if ( in_array( $settings['processor'], array( 8, 9, 10, 11, 12, 13 ) ) )
{
$currencies[] = 'GBP';
}
if ( in_array( $settings['processor'], array( 8, 9, 11, 13 ) ) )
{
$currencies[] = 'EUR';
}
if ( in_array( $settings['processor'], array( 14, 15 ) ) )
{
$currencies[] = 'AUD';
}
if ( in_array( $settings['processor'], array( 14 ) ) )
{
$currencies[] = 'NZD';
}
if ( !in_array( $amount->currency, $currencies ) )
{
return FALSE;
}
return parent::checkValidity( $amount, $billingAddress );
/* Still here? We're good - pass to parent for general checks */
return parent::checkValidity( $amount, $billingAddress, $customer, $recurrings );
}
/**
@@ -113,9 +129,11 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
*
* @param \IPS\nexus\Invoice $invoice Invoice
* @param \IPS\nexus\Money $amount The amount to pay now
* @param \IPS\Member $member The member the payment screen is for (if in the ACP charging to a member's card) or NULL for currently logged in member
* @param array $recurrings Details about recurring costs
* @return array
*/
public function paymentScreen( \IPS\nexus\Invoice $invoice, \IPS\nexus\Money $amount )
public function paymentScreen( \IPS\nexus\Invoice $invoice, \IPS\nexus\Money $amount, \IPS\Member $member = NULL, $recurrings = array() )
{
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'global_gateways.js', 'nexus', 'global' ) );
@@ -146,7 +164,7 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
{
$types = array( \IPS\nexus\CreditCard::TYPE_AMERICAN_EXPRESS, \IPS\nexus\CreditCard::TYPE_DINERS_CLUB, \IPS\nexus\CreditCard::TYPE_DISCOVER, \IPS\nexus\CreditCard::TYPE_JCB, \IPS\nexus\CreditCard::TYPE_MASTERCARD, \IPS\nexus\CreditCard::TYPE_VISA );
}
$options = array( 'types' => $types );
$options = array( 'types' => $types, 'member' => $member );
/* If we're using DPM, we include all that data in here */
if ( $settings['method'] == 'DPM' )
@@ -165,7 +183,7 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
'x_version' => '3.1',
'x_type' => 'AUTH_ONLY',
'x_method' => 'CC',
'x_amount' => $amount->amount,
'x_amount' => (string) $amount->amount,
'x_currency_code' => $amount->currency,
'x_fp_hash' => hash_hmac( 'md5', "{$settings['login']}^{$invoice->id}^{$timestamp}^{$amount->amount}^{$amount->currency}", $settings['tran_key'] ),
'x_fp_sequence' => $invoice->id,
@@ -208,10 +226,11 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
* @param \IPS\nexus\Transaction $transaction Transaction
* @param array|\IPS\nexus\Customer\CreditCard $values Values from form OR a stored card object if this gateway supports them
* @param \IPS\nexus\Fraud\MaxMind\Request|NULL $maxMind *If* MaxMind is enabled, the request object will be passed here so gateway can additional data before request is made
* @return \IPS\DateTime|NULL Auth is valid until or NULL to indicate auth is good forever
* @throws \LogicException Message will be displayed to user
* @param array $recurrings Details about recurring costs
* @return \IPS\DateTime|NULL Auth is valid until or NULL to indicate auth is good forever
* @throws \LogicException Message will be displayed to user
*/
public function auth( \IPS\nexus\Transaction $transaction, $values, \IPS\nexus\Fraud\MaxMind\Request $maxMind = NULL )
public function auth( \IPS\nexus\Transaction $transaction, $values, \IPS\nexus\Fraud\MaxMind\Request $maxMind = NULL, $recurrings = array() )
{
$card = is_array( $values ) ? $values[ $this->id . '_card' ] : $values;
@@ -226,15 +245,18 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
/* Authorize */
$profiles = $card->member->cm_profiles;
$xml = $card->create( 'createCustomerProfileTransactionRequest' );
$xml = $card->createAuthenticationXml( 'createCustomerProfileTransactionRequest' );
$xml->addChild( 'transaction', array(
'profileTransAuthOnly' => array(
'amount' => $transaction->amount->amount,
'amount' => (string) $transaction->amount->amount,
'customerProfileId' => $profiles[ $card->method->id ],
'customerPaymentProfileId' => $card->data,
),
) );
$response = $this->_handleResponse( explode( ',', $card->api( $xml )->directResponse ) );
/* Change $card to the actual \IPS\nexus\CreditCard object so we get the last 4 digits correctly */
$card = $card->card;
}
/* New Card */
@@ -250,18 +272,18 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
$response = $this->api( array(
'x_type' => 'AUTH_ONLY',
'x_method' => 'CC',
'x_amount' => $transaction->amount->amount,
'x_amount' => (string) $transaction->amount->amount,
'x_currency_code' => $transaction->amount->currency,
'x_card_num' => $card->number,
'x_exp_date' => str_pad( $card->expMonth, 2, '0', STR_PAD_LEFT ) . '-' . $card->expYear,
'x_card_code' => $card->ccv,
'x_first_name' => $transaction->member->cm_first_name,
'x_last_name' => $transaction->member->cm_last_name,
'x_address' => implode( ', ', $transaction->invoice->billaddress->addressLines ),
'x_city' => $transaction->invoice->billaddress->city,
'x_state' => $transaction->invoice->billaddress->region,
'x_zip' => $transaction->invoice->billaddress->postalCode,
'x_country' => $transaction->invoice->billaddress->country,
'x_address' => $transaction->invoice->billaddress ? implode( ', ', $transaction->invoice->billaddress->addressLines ) : '',
'x_city' => $transaction->invoice->billaddress ? $transaction->invoice->billaddress->city : '',
'x_state' => $transaction->invoice->billaddress ? $transaction->invoice->billaddress->region : '',
'x_zip' => $transaction->invoice->billaddress ? $transaction->invoice->billaddress->postalCode : '',
'x_country' => $transaction->invoice->billaddress ? $transaction->invoice->billaddress->country : '',
'x_phone' => $transaction->member->cm_phone,
'x_email' => $transaction->member->email,
'x_email_customer' => 'FALSE',
@@ -339,15 +361,24 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
* @throws \Exception
*/
public function refund( \IPS\nexus\Transaction $transaction, $amount = NULL )
{
$extra = json_decode( $transaction->extra, TRUE );
$this->api( array(
'x_type' => 'CREDIT',
'x_trans_id' => $transaction->gw_id,
'x_amount' => $amount ?: $transaction->amount->amount,
'x_card_num' => $extra['lastFour']
) );
{
try
{
$this->api( array(
'x_type' => 'CREDIT',
'x_trans_id' => $transaction->gw_id,
'x_amount' => (string) ( $amount ?: $transaction->amount->amount ),
'x_card_num' => $transaction->extra['lastFour']
) );
}
catch( \IPS\nexus\Gateway\AuthorizeNet\Exception $e )
{
/* If the transaction is unsettled (error code 54 from the API), then we need to void it instead */
if ( $e->getCode() == 54 )
{
$this->void( $transaction );
}
}
}
/* !ACP Configuration */
@@ -376,7 +407,7 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
) ) );
$form->add( new \IPS\Helpers\Form\YesNo( 'authorizenet_cim', $settings['cim'], FALSE, array(), NULL, NULL, NULL, 'authorizenet_cim' ) );
$form->add( new \IPS\Helpers\Form\Text( 'authorizenet_hash', $settings['hash'], FALSE, array(), NULL, NULL, NULL, 'authorizenet_hash' ) );
$form->add( new \IPS\Helpers\Form\Select( 'authorizenet_processor', $settings['processor'], FALSE, array( 'options' => array(
$form->add( new \IPS\Helpers\Form\Select( 'authorizenet_processor', isset( $settings['processor'] ) ? $settings['processor'] : '0', FALSE, array( 'options' => array(
0 => 'dont_know',
'North American Payment Processors' => array(
1 => 'Chase Paymentech Tampa Processing Platform',
@@ -2,9 +2,9 @@
/**
* @brief Authorize.Net CIM Stored Card
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 17 Mar 2014
* @version SVN_VERSION_NUMBER
@@ -44,17 +44,50 @@ class _CreditCard extends \IPS\nexus\Customer\CreditCard
throw new \UnexpectedValueException;
}
$xml = $this->create('getCustomerPaymentProfileRequest');
$xml = $this->createAuthenticationXml('getCustomerPaymentProfileRequest');
$xml->addChild( 'customerProfileId', $profiles[ $this->method->id ] );
$xml->addChild( 'customerPaymentProfileId', $this->data );
$response = $this->api( $xml );
$this->_card = new \IPS\nexus\CreditCard;
$this->_card->lastFour = mb_substr( $response->paymentProfile->payment->creditCard->cardNumber, -4 );
$this->_card->lastFour = mb_substr( $response->paymentProfile->payment->creditCard->cardNumber, -4 );
if ( isset( $response->paymentProfile->payment->creditCard->cardType ) )
{
switch ( $response->paymentProfile->payment->creditCard->cardType )
{
case 'Visa':
$this->_card->type = \IPS\nexus\CreditCard::TYPE_VISA;
break;
case 'AmericanExpress':
$this->_card->type = \IPS\nexus\CreditCard::TYPE_AMERICAN_EXPRESS;
break;
case 'MasterCard':
$this->_card->type = \IPS\nexus\CreditCard::TYPE_MASTERCARD;
break;
case 'Discover':
$this->_card->type = \IPS\nexus\CreditCard::TYPE_DISCOVER;
break;
case 'JCB':
$this->_card->type = \IPS\nexus\CreditCard::TYPE_JCB;
break;
case 'DinersClub':
$this->_card->type = \IPS\nexus\CreditCard::TYPE_DINERS_CLUB;
break;
default:
$this->_card->type = NULL;
break;
}
}
else
{
$this->_card->type = NULL;
}
$this->_card->expYear = NULL;
$this->_card->expMonth = NULL;
}
return $this->_card;
}
/**
* Set card
*
@@ -67,7 +100,7 @@ class _CreditCard extends \IPS\nexus\Customer\CreditCard
$profiles = $this->member->cm_profiles;
if ( !isset( $profiles[ $this->method->id ] ) )
{
$xml = $this->create( 'createCustomerProfileRequest' );
$xml = $this->createAuthenticationXml( 'createCustomerProfileRequest' );
$xml->addChild( 'profile', array(
'merchantCustomerId' => $this->member->member_id
) );
@@ -83,7 +116,7 @@ class _CreditCard extends \IPS\nexus\Customer\CreditCard
}
/* Add the card */
$xml = $this->create( 'createCustomerPaymentProfileRequest' );
$xml = $this->createAuthenticationXml( 'createCustomerPaymentProfileRequest' );
$xml->addChild( 'customerProfileId', $profiles[ $this->method->id ] );
$xml->addChild( 'paymentProfile', array(
'payment' => array(
@@ -116,7 +149,7 @@ class _CreditCard extends \IPS\nexus\Customer\CreditCard
$profiles = $this->member->cm_profiles;
if ( isset( $profiles[ $this->method->id ] ) )
{
$xml = $this->create( 'deleteCustomerPaymentProfileRequest' );
$xml = $this->createAuthenticationXml( 'deleteCustomerPaymentProfileRequest' );
$xml->addChild( 'customerProfileId', $profiles[ $this->method->id ] );
$xml->addChild( 'customerPaymentProfileId', $this->data );
$response = $this->api( $xml );
@@ -146,7 +179,7 @@ class _CreditCard extends \IPS\nexus\Customer\CreditCard
* @param string $method The API method we will be calling
* @return \IPS\Xml\SimpleXML
*/
public function create( $method )
public function createAuthenticationXml( $method )
{
$settings = json_decode( $this->method->settings, TRUE );
$xml = \IPS\Xml\SimpleXML::create( $method, 'AnetApi/xml/v1/schema/AnetApiSchema.xsd' );
@@ -2,9 +2,9 @@
/**
* @brief Authorize.Net Exception
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 17 Mar 2014
* @version SVN_VERSION_NUMBER
+89 -14
View File
@@ -2,9 +2,9 @@
/**
* @brief Gateway Node
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 10 Feb 2014
* @version SVN_VERSION_NUMBER
@@ -227,6 +227,24 @@ class _Gateway extends \IPS\Node\Model
return $return;
}
/**
* Get gateways that support billing agreements
*
* @return array
*/
public static function billingAgreementGateways()
{
$return = array();
foreach ( static::roots() as $gateway )
{
if ( $gateway->billingAgreements() )
{
$return[ $gateway->id ] = $gateway;
}
}
return $return;
}
/**
* [ActiveRecord] Save Changed Columns
*
@@ -245,7 +263,14 @@ class _Gateway extends \IPS\Node\Model
*/
public function delete()
{
/* Delete cards and billing agreements */
\IPS\Db::i()->delete( 'nexus_customer_cards', array( 'card_method=?', $this->id ) );
\IPS\Db::i()->delete( 'nexus_billing_agreements', array( 'ba_method=?', $this->id ) );
/* Delete */
parent::delete();
/* Recount how many gateways support cards */
static::recountCardStorageGateways();
}
@@ -256,9 +281,11 @@ class _Gateway extends \IPS\Node\Model
*/
protected static function recountCardStorageGateways()
{
$count = count( static::cardStorageGateways() );
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => $count ), array( 'conf_key=?', 'card_storage_gateways' ) );
\IPS\Settings::i()->card_storage_gateways = $count;
foreach ( array( 'card_storage_gateways' => count( static::cardStorageGateways() ), 'billing_agreement_gateways' => count( static::billingAgreementGateways() ) ) as $k => $v )
{
\IPS\Db::i()->update( 'core_sys_conf_settings', array( 'conf_value' => $v ), array( 'conf_key=?', $k ) );
\IPS\Settings::i()->$k = $v;
}
unset( \IPS\Data\Store::i()->settings );
}
@@ -270,15 +297,24 @@ class _Gateway extends \IPS\Node\Model
/**
* Check the gateway can process this...
*
* @param $amount \IPS\nexus\Money The amount
* @param $billingAddress \IPS\GeoLocation The billing address
* @param $amount \IPS\nexus\Money The amount
* @param $billingAddress \IPS\GeoLocation|NULL The billing address, which may be NULL if one if not provided
* @param $customer \IPS\nexus\Customer The customer (Default NULL value is for backwards compatibility - it should always be provided.)
* @param array $recurrings Details about recurring costs
* @return bool
*/
public function checkValidity( \IPS\nexus\Money $amount, \IPS\GeoLocation $billingAddress )
public function checkValidity( \IPS\nexus\Money $amount, \IPS\GeoLocation $billingAddress = NULL, \IPS\nexus\Customer $customer = NULL, $recurrings = array() )
{
if ( $this->countries and $this->countries !== '*' )
{
return in_array( $billingAddress->country, explode( ',', $this->countries ) );
if ( $billingAddress )
{
return in_array( $billingAddress->country, explode( ',', $this->countries ) );
}
else
{
return FALSE;
}
}
return TRUE;
@@ -304,6 +340,16 @@ class _Gateway extends \IPS\Node\Model
return FALSE;
}
/**
* Supports billing agreements?
*
* @return bool
*/
public function billingAgreements()
{
return FALSE;
}
/* !Payment Gateway */
/**
@@ -311,9 +357,11 @@ class _Gateway extends \IPS\Node\Model
*
* @param \IPS\nexus\Invoice $invoice Invoice
* @param \IPS\nexus\Money $amount The amount to pay now
* @param \IPS\Member $member The member the payment screen is for (if in the ACP charging to a member's card) or NULL for currently logged in member
* @param array $recurrings Details about recurring costs
* @return array
*/
public function paymentScreen( \IPS\nexus\Invoice $invoice, \IPS\nexus\Money $amount )
public function paymentScreen( \IPS\nexus\Invoice $invoice, \IPS\nexus\Money $amount, \IPS\Member $member = NULL, $recurrings = array() )
{
return array();
}
@@ -322,12 +370,13 @@ class _Gateway extends \IPS\Node\Model
* Authorize
*
* @param \IPS\nexus\Transaction $transaction Transaction
* @param array|\IPS\nexus\Customer\StoredCard $values Values from form OR a stored card object if this gateway supports them
* @param array|\IPS\nexus\Customer\CreditCard $values Values from form OR a stored card object if this gateway supports them
* @param \IPS\nexus\Fraud\MaxMind\Request|NULL $maxMind *If* MaxMind is enabled, the request object will be passed here so gateway can additional data before request is made
* @return \IPS\DateTime|NULL Auth is valid until or NULL to indicate auth is good forever
* @throws \LogicException Message will be displayed to user
* @param array $recurrings Details about recurring costs
* @return \IPS\DateTime|NULL Auth is valid until or NULL to indicate auth is good forever
* @throws \LogicException Message will be displayed to user
*/
public function auth( \IPS\nexus\Transaction $transaction, $values, \IPS\nexus\Fraud\MaxMind\Request $maxMind = NULL )
public function auth( \IPS\nexus\Transaction $transaction, $values, \IPS\nexus\Fraud\MaxMind\Request $maxMind = NULL, $recurrings = array() )
{
return NULL;
}
@@ -368,4 +417,30 @@ class _Gateway extends \IPS\Node\Model
{
throw new \Exception;
}
/**
* Extra data to show on the ACP transaction page
*
* @param \IPS\nexus\Transaction $transaction Transaction
* @return string
*/
public function extraData( \IPS\nexus\Transaction $transaction )
{
return '';
}
/**
* Get output for API
*
* @return array
* @apiresponse int id ID number
* @apiresponse string name Name
*/
public function apiOutput()
{
return array(
'id' => $this->id,
'name' => $this->_title
);
}
}
@@ -2,9 +2,9 @@
/**
* @brief Manual Gateway
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 18 Mar 2014
* @version SVN_VERSION_NUMBER
@@ -32,16 +32,21 @@ class _Manual extends \IPS\nexus\Gateway
* @param \IPS\nexus\Transaction $transaction Transaction
* @param array|\IPS\nexus\Customer\CreditCard $values Values from form OR a stored card object if this gateway supports them
* @param \IPS\nexus\Fraud\MaxMind\Request|NULL $maxMind *If* MaxMind is enabled, the request object will be passed here so gateway can additional data before request is made
* @return \IPS\DateTime|NULL Auth is valid until or NULL to indicate auth is good forever
* @throws \LogicException Message will be displayed to user
* @param array $recurrings Details about recurring costs
* @return \IPS\DateTime|NULL Auth is valid until or NULL to indicate auth is good forever
* @throws \LogicException Message will be displayed to user
*/
public function auth( \IPS\nexus\Transaction $transaction, $values, \IPS\nexus\Fraud\MaxMind\Request $maxMind = NULL )
public function auth( \IPS\nexus\Transaction $transaction, $values, \IPS\nexus\Fraud\MaxMind\Request $maxMind = NULL, $recurrings = array() )
{
$transaction->status = \IPS\nexus\Transaction::STATUS_WAITING;
$extra = $transaction->extra;
$extra['history'][] = array( 's' => \IPS\nexus\Transaction::STATUS_WAITING );
$transaction->extra = $extra;
$transaction->save();
/* Send Notification */
$transaction->sendNotification();
\IPS\Output::i()->redirect( $transaction->url() );
}
@@ -2,9 +2,9 @@
/**
* @brief Manual Pay Out Gateway
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 7 Apr 2014
* @version SVN_VERSION_NUMBER
@@ -0,0 +1,176 @@
<?php
/**
* @brief PayPal Billing Agreement
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Community Suite
* @subpackage Nexus
* @since 16 Dec 2015
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\Gateway\PayPal;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* PayPal Billing Agreement
*/
class _BillingAgreement extends \IPS\nexus\Customer\BillingAgreement
{
/**
* Get status
*
* @return string See STATUS_* constants
* @throws \IPS\nexus\Gateway\PayPal\Exception
*/
public function status()
{
$data = $this->_getData();
switch ( $data['state'] )
{
case 'Active':
case 'Pending':
case 'Reactivate':
return static::STATUS_ACTIVE;
break;
case 'Suspend':
case 'Suspended':
return static::STATUS_SUSPENDED;
break;
case 'Expired':
case 'Cancel':
case 'Cancelled':
return static::STATUS_CANCELED;
break;
}
}
/**
* Get term
*
* @return \IPS\nexus\Purchase\RenewalTerm
* @throws \IPS\nexus\Gateway\PayPal\Exception
*/
public function term()
{
$data = $this->_getData();
$amount = $data['plan']['payment_definitions'][0]['amount']['value'];
if ( isset( $data['plan']['payment_definitions'][0]['charge_models'][0] ) )
{
$amount += $data['plan']['payment_definitions'][0]['charge_models'][0]['amount']['value'];
}
return new \IPS\nexus\Purchase\RenewalTerm( new \IPS\nexus\Money( $amount, $data['plan']['payment_definitions'][0]['amount']['currency'] ), new \DateInterval( 'P' . $data['plan']['payment_definitions'][0]['frequency_interval'] . mb_substr( $data['plan']['payment_definitions'][0]['frequency'], 0, 1 ) ) );
}
/**
* Get next payment date
*
* @return \IPS\DateTime
* @throws \IPS\nexus\Gateway\PayPal\Exception
*/
public function nextPaymentDate()
{
$data = $this->_getData();
return new \IPS\DateTime( $data['agreement_details']['next_billing_date'] );
}
/**
* Get latest unclaimed transaction (only gets transactions within the last 31 days which do not yet have a matching transaction)
*
* @return \IPS\nexus\Transaction
* @throws \IPS\nexus\Gateway\PayPal\Exception
* @throws \OutOfRangeException
*/
public function latestUnclaimedTransaction()
{
$url = "payments/billing-agreements/{$this->gw_id}/transactions?start_date=" . date( 'Y-m-d', time() - ( 86400 * 31 ) ) . '&end_date=' . date( 'Y-m-d' );
$transactions = $this->method->api( $url, NULL, 'get' );
foreach ( array_reverse( $transactions['agreement_transaction_list'] ) as $t )
{
if ( $t['status'] == 'Completed' )
{
try
{
$existingTransaction = \IPS\Db::i()->select( 't_id', 'nexus_transactions', array( 't_method=? AND t_gw_id=?', $this->method->id, $t['transaction_id'] ) )->first();
}
catch ( \UnderflowException $e )
{
$transaction = new \IPS\nexus\Transaction;
$transaction->member = $this->member;
$transaction->method = $this->method;
$transaction->amount = new \IPS\nexus\Money( $t['amount']['value'], $t['amount']['currency'] );
$transaction->date = new \IPS\DateTime( $t['time_stamp'] );
$transaction->extra = array( 'automatic' => TRUE );
$transaction->gw_id = $t['transaction_id'];
$transaction->billing_agreement = $this;
return $transaction;
}
}
}
throw new \OutOfRangeException( "{$this->id} ({$this->gw_id})\n{$url}\n\n" . print_r( $transactions, TRUE ) );
}
/**
* Suspend
*
* @return void
* @throws \DomainException
*/
public function doSuspend()
{
$this->method->api( "payments/billing-agreements/{$this->gw_id}/suspend", array( 'note' => 'Suspend' ) );
}
/**
* Reactivate
*
* @return void
* @throws \DomainException
*/
public function doReactivate()
{
$this->method->api( "payments/billing-agreements/{$this->gw_id}/re-activate", array( 'note' => 'Reactivate' ) );
}
/**
* Cancel
*
* @return void
* @throws \DomainException
*/
public function doCancel()
{
$this->method->api( "payments/billing-agreements/{$this->gw_id}/cancel", array( 'note' => 'Cancel' ) );
}
/**
* @brief Cached data
*/
protected $_payPalData = NULL;
/**
* Get data
*
* @return array
* @throws \IPS\nexus\Gateway\PayPal\Exception
*/
protected function _getData()
{
if ( $this->_payPalData === NULL )
{
$this->_payPalData = $this->method->api( "payments/billing-agreements/{$this->gw_id}", NULL, 'get' );
}
return $this->_payPalData;
}
}
@@ -2,9 +2,9 @@
/**
* @brief PayPal Stored Card
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 10 Feb 2014
* @version SVN_VERSION_NUMBER
@@ -2,9 +2,9 @@
/**
* @brief PayPal Exception
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 10 Mar 2014
* @version SVN_VERSION_NUMBER
@@ -43,7 +43,7 @@ class _Exception extends \DomainException
*/
public function __construct( \IPS\Http\Response $response, $refund=FALSE )
{
\IPS\Log::i( \LOG_DEBUG )->write( (string) $response );
\IPS\Log::debug( (string) $response, 'paypal' );
$details = $response->decodeJson();
$this->name = $details['name'];
@@ -80,9 +80,14 @@ class _Exception extends \DomainException
break;
case 'ADDRESS_INVALID':
case 'VALIDATION_ERROR':
$message = \IPS\Member::loggedIn()->language()->get( 'address_invalid' );
break;
case 'INSTRUMENT_DECLINED':
$message = \IPS\Member::loggedIn()->language()->get( 'payment_refused' );
break;
default:
if ( $refund )
{
File diff suppressed because it is too large. Load diff
@@ -2,9 +2,9 @@
/**
* @brief PayPal Pay Out Gateway
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 7 Apr 2014
* @version SVN_VERSION_NUMBER
@@ -1,391 +0,0 @@
<?php
/**
* @brief SagePay Gateway
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @subpackage Nexus
* @since 17 Mar 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\nexus\Gateway;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* SagePay Gateway
*/
class _SagePay extends \IPS\nexus\Gateway
{
/* !Features (Each gateway will override) */
const SUPPORTS_REFUNDS = TRUE;
const SUPPORTS_PARTIAL_REFUNDS = TRUE;
/**
* Can store cards?
*
* @return bool
*/
public function canStoreCards()
{
return FALSE;
}
/**
* Admin can manually charge using this gateway?
*
* @return bool
*/
public function canAdminCharge()
{
$settings = json_decode( $this->settings, TRUE );
return ( $settings['method'] === 'direct' );
}
/* !Payment Gateway */
/**
* Payment Screen Fields
*
* @param \IPS\nexus\Invoice $invoice Invoice
* @param \IPS\nexus\Money $amount The amount to pay now
* @return array
*/
public function paymentScreen( \IPS\nexus\Invoice $invoice, \IPS\nexus\Money $amount )
{
$return = array();
$settings = json_decode( $this->settings, TRUE );
if ( $settings['method'] === 'direct' )
{
$options = array();
$options['types'] = array( \IPS\nexus\CreditCard::TYPE_VISA, \IPS\nexus\CreditCard::TYPE_MASTERCARD, \IPS\nexus\CreditCard::TYPE_AMERICAN_EXPRESS, \IPS\nexus\CreditCard::TYPE_DINERS_CLUB, \IPS\nexus\CreditCard::TYPE_DISCOVER, \IPS\nexus\CreditCard::TYPE_JCB );
$return['card'] = new \IPS\nexus\Form\CreditCard( $this->id . '_card', NULL, FALSE, $options );
}
return $return;
}
/**
* Authorize
*
* @param \IPS\nexus\Transaction $transaction Transaction
* @param array|\IPS\nexus\Customer\CreditCard $values Values from form OR a stored card object if this gateway supports them
* @param \IPS\nexus\Fraud\MaxMind\Request|NULL $maxMind *If* MaxMind is enabled, the request object will be passed here so gateway can additional data before request is made
* @return \IPS\DateTime|NULL Auth is valid until or NULL to indicate auth is good forever
* @throws \LogicException Message will be displayed to user
*/
public function auth( \IPS\nexus\Transaction $transaction, $values, \IPS\nexus\Fraud\MaxMind\Request $maxMind = NULL )
{
/* Init */
$transaction->save();
$settings = json_decode( $this->settings, TRUE );
/* Build basic data */
$shipAddress = $transaction->invoice->shipaddress ?: $transaction->invoice->billaddress;
$data = array(
'TxType' => 'PAYMENT',
'VendorTxCode' => $transaction->id,
'Amount' => $transaction->amount->amount,
'Currency' => $transaction->amount->currency,
'Description' => mb_substr( $transaction->invoice->title, 0, 100 ),
'BillingSurname' => $transaction->member->cm_last_name,
'BillingFirstnames' => $transaction->member->cm_first_name,
'BillingAddress1' => $transaction->invoice->billaddress->addressLines[0],
'BillingAddress2' => isset( $transaction->invoice->billaddress->addressLines[1] ) ? $transaction->invoice->billaddress->addressLines[0] : NULL,
'BillingCity' => $transaction->invoice->billaddress->city,
'BillingPostCode' => $transaction->invoice->billaddress->postalCode,
'BillingCountry' => $transaction->invoice->billaddress->country,
'BillingState' => ( $transaction->invoice->billaddress->country === 'US' ) ? $transaction->invoice->billaddress->region : NULL,
'BillingPhone' => $transaction->member->cm_phone,
'DeliverySurname' => $transaction->member->cm_last_name,
'DeliveryFirstnames'=> $transaction->member->cm_first_name,
'DeliveryAddress1' => $shipAddress->addressLines[0],
'DeliveryAddress2' => isset( $shipAddress->addressLines[1] ) ? $shipAddress->addressLines[0] : NULL,
'DeliveryCity' => $shipAddress->city,
'DeliveryPostCode' => $shipAddress->postalCode,
'DeliveryCountry' => $shipAddress->country,
'DeliveryState' => ( $shipAddress->country === 'US' ) ? $shipAddress->region : NULL,
'DeliveryPhone' => $transaction->member->cm_phone,
'CustomerEMail' => $transaction->member->email,
);
/* Add method-specific data */
if ( $settings['method'] === 'direct' )
{
$data['ClientIPAddress'] = \IPS\Request::i()->ipAddress();
$card = $values[ $this->id . '_card' ];
$data['CardHolder'] = $transaction->member->cm_first_name . ' ' . $transaction->member->cm_last_name;
$data['CardNumber'] = $card->number;
$data['ExpiryDate'] = $card->expMonth . mb_substr( $card->expYear, 2 );
$data['CV2'] = $card->ccv;
$data['CardType'] = static::cardType( $card );
}
else
{
$data['NotificationURL'] = \IPS\Settings::i()->base_url . 'applications/nexus/interface/gateways/sagepay.php';
}
/* Add Basket XML */
if ( $transaction->amount->amount == $transaction->invoice->total->amount )
{
$summary = $transaction->invoice->summary();
$basketXml = \IPS\Xml\SimpleXml::create( 'basket' );
$discounts = array();
foreach ( $summary['items'] as $item )
{
if ( $item->price->amount < 0 )
{
$discounts[] = array(
'fixed' => abs( $item->price->amount * $item->quantity )
);
}
else
{
$basketXml->addChild( 'item', array(
'description' => $item->name,
'quantity' => $item->quantity,
'unitNetAmount' => $item->price->amount,
'unitTaxAmount' => $item->price->amount * $item->taxRate(),
'unitGrossAmount' => $item->price->amount + ( $item->price->amount * $item->taxRate() ),
'totalGrossAmount' => $item->grossLinePrice()->amount,
) );
}
}
$shippingNet = 0;
$shippingTax = 0;
foreach ( $summary['shipping'] as $shipping )
{
$shippingNet += $shipping->price->amount;
$shippingTax += ( $shipping->price->amount * $shipping->taxRate() );
}
if ( $shippingNet )
{
$basketXml->addChild( 'deliveryNetAmount', $shippingNet );
$basketXml->addChild( 'deliveryTaxAmount', $shippingTax );
$basketXml->addChild( 'deliveryGrossAmount', $shippingNet + $shippingTax );
}
if ( count( $discounts ) )
{
$basketXml->addChild( 'discounts', $discounts );
}
$data['BasketXML'] = trim( str_replace( '<?xml version="1.0" encoding="UTF-8"?>', '', $basketXml->asXml() ) );
}
/* Send */
try
{
if ( $settings['method'] === 'direct' )
{
$response = $this->api( 'vspdirect-register.vsp', $data );
if ( isset( $data['CreateToken'] ) and isset( $response['Token'] ) and $response['Token'] )
{
echo 'xx<pre>';
print_r( $response );
exit;
}
echo 'zz<pre>';
print_r( $response );
exit;
}
else
{
$response = $this->api( 'vspserver-register.vsp', $data );
}
}
catch ( \DomainException $e )
{
echo '<pre>';
print_r( $e );
exit;
throw new \DomainException( $transaction->member->language()->addToStack('gateway_err') );
}
/* Save details */
$transaction->gw_id = $response['VPSTxId'];
$extra = $transaction->extra;
$extra['sagepaySecurityKey'] = $response['SecurityKey'];
$transaction->extra = $extra;
$transaction->save();
/* Continue */
if ( $settings['method'] === 'direct' )
{
return NULL;
}
else
{
\IPS\Output::i()->redirect( $response['NextURL'] . '=' . $response['VPSTxId'] );
}
}
/**
* Refund
*
* @param \IPS\nexus\Transaction $transaction Transaction to be refunded
* @param float|NULL $amount Amount to refund (NULL for full amount - always in same currency as transaction)
* @return mixed Gateway reference ID for refund, if applicable
* @throws \Exception
*/
public function refund( \IPS\nexus\Transaction $transaction, $amount = NULL )
{
$refundId = $transaction->id . 'R' . rand( 1, 999 );
$extra = $transaction->extra;
$response = $this->api( 'refund.vsp', array(
'TxType' => 'REFUND',
'VendorTxCode' => $refundId,
'Amount' => $amount ?: $transaction->amount->amount,
'Currency' => $transaction->currency,
'Description' => $transaction->invoice->title,
'RelatedVPSTxId' => $transaction->gw_id,
'RelatedVendorTxCode' => $transaction->id,
'RelatedSecurityKey' => $extra['sagepaySecurityKey'],
'RelatedTxAuthNo' => $extra['sagepayAuth'],
) );
return $response['VPSTxId'];
}
/* !ACP Configuration */
/**
* Settings
*
* @param \IPS\Helpers\Form $form The form
* @return void
*/
public function settings( &$form )
{
$settings = json_decode( $this->settings, TRUE );
$form->add( new \IPS\Helpers\Form\Text( 'sagepay_vendor', $settings ? $settings['vendor'] : '', TRUE ) );
\IPS\Member::loggedIn()->language()->words['sagepay_vendor_desc'] = sprintf( \IPS\Member::loggedIn()->language()->get( 'sagepay_vendor_desc' ), gethostbyname( gethostname() ) );
$form->add( new \IPS\Helpers\Form\Radio( 'sagepay_method', $settings ? $settings['method'] : 'server', TRUE, array( 'options' => array( 'server' => 'sagepay_method_server', 'direct' => 'sagepay_method_direct' ) ) ) );
}
/**
* Test Settings
*
* @param array $settings Settings
* @return array
* @throws \InvalidArgumentException
*/
public function testSettings( $settings )
{
return $settings;
}
/* !Utility Methods */
/**
* Get card type
*
* @param \IPS\nexus\CreditCard $card The card
* @return string
*/
public static function cardType( \IPS\nexus\CreditCard $card )
{
switch ( $card->type )
{
case \IPS\nexus\CreditCard::TYPE_VISA:
if ( preg_match( '/^(400626|40854749|40940002|41228586|41373337|41378788|418760|41917679|419772|420672|42159294|422793|423769|431072|444001|44400508|44620011|44621354|44625772|44627483|446286|446294|450875|45397|454313|45443235|454742|45672545|46583079|46590150|47511059|47571059|47622069|47634089|48440910|484427|49096079|49218182)/', $card->number ) )
{
return 'DELTA';
}
elseif ( preg_match( '/^(400(115|121|83[7-9])|401773|4026|405670|410654|41292[1-3]|4140(49|99)|415045|416(039|451|896)|417(7|935)|4197(4[0-1]|7[3-6])|420796|429158|431262|4329(19|37)|433445|435225|44(0(626|753)|615[578]|8360)|4508|453904|479(056|731)|4844(0[6-9]|1[013489]|2[0-68-9]|[3-5][0-9])|491(3|7([3-5][0-9])|859)|4935|494114)
/', $card->number ) )
{
return 'UKE';
}
else
{
return 'VISA';
}
break;
case \IPS\nexus\CreditCard::TYPE_MASTERCARD:
if ( preg_match( '/^(?:5[0678]\d\d|6304|6390|67\d\d)\d{8,15}$/', $card->number ) )
{
return 'MAESTRO';
}
elseif ( in_array( mb_substr( $card->number, 0, 6 ), array( '516730', '516979', '517000', '517049', '535110', '535309', '535420', '535819', '537210', '537609', '557347', '557496', '557498', '557547' ) ) )
{
return 'MCDEBIT';
}
else
{
return 'MC';
}
break;
case \IPS\nexus\CreditCard::TYPE_AMERICAN_EXPRESS:
return 'AMEX';
break;
case \IPS\nexus\CreditCard::TYPE_DINERS_CLUB:
case \IPS\nexus\CreditCard::TYPE_DISCOVER:
return 'DC';
break;
case \IPS\nexus\CreditCard::TYPE_JCB:
return 'JCB';
break;
}
throw new \UnexpectedValueException;
}
/**
* Send API Request
*
* @param string $uri The API to request (e.g. "payments/payment")
* @param array $data The data to send
* @return array
* @throws \IPS\Http|Exception
*/
public function api( $uri, $data=NULL )
{
$settings = json_decode( $this->settings, TRUE );
$data = array_merge( array(
'VPSProtocol' => '3.00',
'Vendor' => $settings['vendor'],
), $data );
$_response = \IPS\Http\Url::external( \IPS\NEXUS_TEST_GATEWAYS ? 'https://test.sagepay.com/gateway/service/' . $uri : 'https://live.sagepay.com/gateway/service/' . $uri )->request()->post( $data );
$response = array();
foreach ( explode( "\n", $_response ) as $line )
{
$line = trim( $line );
if ( $line )
{
$ex = explode( '=', $line );
$response[ $ex[0] ] = $ex[1];
}
}
if ( !isset( $response['Status'] ) or $response['Status'] !== 'OK' )
{
throw new \DomainException( $response['StatusDetail'] );
}
return $response;
}
}
Whitespace-only changes.
@@ -2,9 +2,9 @@
/**
* @brief PayPal Stored Card
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 10 Feb 2014
* @version SVN_VERSION_NUMBER
@@ -94,7 +94,7 @@ class _CreditCard extends \IPS\nexus\Customer\CreditCard
}
$response = $this->method->api( "customers/{$profiles[ $this->method->id ]}/cards", array(
'card' => $card->token
'card' => isset( $card->token ) ? $card->token : NULL
) );
$this->data = $response['id'];
@@ -2,9 +2,9 @@
/**
* @brief Stripe Exception
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 10 Mar 2014
* @version SVN_VERSION_NUMBER
@@ -42,6 +42,10 @@ class _Exception extends \DomainException
{
parent::__construct( $response['message'] );
}
elseif ( $response['type'] == 'invalid_request_error' )
{
parent::__construct( \IPS\Member::loggedIn()->language()->get( 'card_number_invalid' ) );
}
else
{
parent::__construct( \IPS\Member::loggedIn()->language()->get( 'gateway_err' ) );
@@ -2,9 +2,9 @@
/**
* @brief Stripe Pay Out Gateway
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 7 Apr 2014
* @version SVN_VERSION_NUMBER
@@ -31,19 +31,7 @@ class _Payout extends \IPS\nexus\Payout
*/
public static function settings()
{
$settings = json_decode( \IPS\Settings::i()->nexus_payout, TRUE );
if ( !isset( $settings['Stripe'] ) or !count( $settings['Stripe'] ) )
{
try
{
$method = \IPS\Db::i()->select( '*', 'nexus_paymethods', array( 'm_gateway=? AND m_active=1', 'Stripe' ) )->first();
$_settings = json_decode( $method['m_settings'], TRUE );
$settings['Stripe']['secret_key'] = $_settings['secret_key'];
}
catch ( \UnderflowException $e ) { }
}
return array( new \IPS\Helpers\Form\Text( 'stripe_secret_key', ( isset( $settings['Stripe'] ) and isset( $settings['Stripe']['secret_key'] ) ) ? $settings['Stripe']['secret_key'] : NULL ) );
return array();
}
/**
@@ -53,64 +41,7 @@ class _Payout extends \IPS\nexus\Payout
*/
public static function form()
{
$return = array();
/* Get any details we've used before */
$previous = \IPS\Db::i()->select( 'po_data', 'nexus_payouts', array( 'po_member=? AND po_gateway=?', \IPS\Member::loggedIn()->member_id, 'Stripe' ) );
if ( count( $previous ) )
{
$options = array();
foreach ( $previous as $id )
{
$recipient = static::api( "recipients/{$id}", NULL, 'get' );
$options[ $id ] = "{$recipient['active_account']['bank_name']} - XXXX{$recipient['active_account']['last4']}";
}
$options[0] = 'other';
$return[] = new \IPS\Helpers\Form\Radio( 'stripe_recipient', NULL, NULL, array( 'options' => $options, 'toggles' => array( 0 => array( 'stripe_country', 'stripe_routing_number', 'stripe_account_number', 'stripe_account_type' ) ) ) );
}
/* Required Validation */
$requiredValidation = function( $val )
{
if ( !$val and \IPS\Request::i()->withdraw_method === 'Stripe' and isset( \IPS\Request::i()->stripe_recipient ) and !\IPS\Request::i()->stripe_recipient )
{
throw new \DomainException('form_required');
}
};
/* Build form for new */
return array_merge( $return, array(
'country' => new \IPS\Helpers\Form\Select( 'stripe_country', 'US', NULL, array( 'options' => array_map( function( $val )
{
return 'country-' . $val;
}, array_combine( \IPS\GeoLocation::$countries, \IPS\GeoLocation::$countries ) ) ), NULL, NULL, NULL, 'stripe_country' ),
'routing_number' => new \IPS\Helpers\Form\Text( 'stripe_routing_number', NULL, NULL, array(), $requiredValidation, NULL, NULL, 'stripe_routing_number' ),
'account_number' => new \IPS\Helpers\Form\Text( 'stripe_account_number', NULL, NULL, array(), $requiredValidation, NULL, NULL, 'stripe_account_number' ),
'account_type' => new \IPS\Helpers\Form\Radio( 'stripe_account_type', 'individual', NULL, array(
'options' => array(
'individual' => 'stripe_account_type_individual',
'corporation' => 'stripe_account_type_corporation'
),
'toggles' => array(
'individual' => array( 'stripe_individual_name' ),
'corporation' => array( 'stripe_corporation_name' )
)
), NULL, NULL, NULL, 'stripe_account_type' ),
'individual_name' => new \IPS\Helpers\Form\Text( 'stripe_individual_name', \IPS\nexus\Customer::loggedIn()->cm_name, NULL, array(), function( $val )
{
if ( !$val and \IPS\Request::i()->withdraw_method === 'Stripe' and isset( \IPS\Request::i()->stripe_recipient ) and !\IPS\Request::i()->stripe_recipient and \IPS\Request::i()->stripe_account_type === 'individual' )
{
throw new \DomainException('form_required');
}
}, NULL, NULL, 'stripe_individual_name' ),
'corporation_name' => new \IPS\Helpers\Form\Text( 'stripe_corporation_name', NULL, NULL, array(), function( $val )
{
if ( !$val and \IPS\Request::i()->withdraw_method === 'Stripe' and isset( \IPS\Request::i()->stripe_recipient ) and !\IPS\Request::i()->stripe_recipient and \IPS\Request::i()->stripe_account_type === 'corporation' )
{
throw new \DomainException('form_required');
}
}, NULL, NULL, 'stripe_corporation_name' ),
) );
return array();
}
/**
@@ -122,25 +53,7 @@ class _Payout extends \IPS\nexus\Payout
*/
public function getData( array $values )
{
if ( isset( $values['stripe_recipient'] ) and $values['stripe_recipient'] )
{
return $values['stripe_recipient'];
}
$recipient = static::api( 'recipients', array(
'name' => $values['stripe_account_type'] === 'individual' ? $values['stripe_individual_name'] : $values['stripe_corporation_name'],
'type' => $values['stripe_account_type'],
'bank_account' => array(
'country' => $values['stripe_country'],
'routing_number' => $values['stripe_routing_number'],
'account_number' => $values['stripe_account_number']
),
'metadata' => array(
'id' => \IPS\Member::loggedIn()->member_id
),
) );
return $recipient['id'];
return NULL;
}
/**
@@ -151,54 +64,6 @@ class _Payout extends \IPS\nexus\Payout
*/
public function process()
{
$response = static::api( 'transfers', array(
'amount' => $this->amount->amount,
'currency' => $this->amount->currency,
'recipient' => $this->data
) );
$this->status = static::STATUS_COMPLETE;
$this->completed = new \IPS\DateTime;
$this->gw_id = $response['id'];
$this->save();
}
/**
* Get recipient
*
* @return array
*/
public function recipient()
{
return static::api( "recipients/{$this->data}", NULL, 'get' );
}
/**
* Send API Request
*
* @param string $uri The API to request (e.g. "charges")
* @param array $data The data to send
* @param string $method Method (get/post)
* @return array
* @throws \IPS\Http|Exception
* @throws \IPS\nexus\Gateway\PayPal\Exception
*/
protected static function api( $uri, $data=NULL, $method='post' )
{
$settings = json_decode( \IPS\Settings::i()->nexus_payout, TRUE );
$response = \IPS\Http\Url::external( 'https://api.stripe.com/v1/' . $uri )
->request()
->setHeaders( array( 'Stripe-Version' => '2014-01-31' ) )
->login( $settings['Stripe']['secret_key'], '' )
->$method( $data )
->decodeJson();
if ( isset( $response['error'] ) )
{
throw new \DomainException( $response['error']['message'] );
}
return $response;
throw new \DomainException('stripe_payout_deprecated');
}
}
@@ -2,9 +2,9 @@
/**
* @brief Stripe Gateway
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 13 Mar 2014
* @version SVN_VERSION_NUMBER
@@ -32,17 +32,23 @@ class _Stripe extends \IPS\nexus\Gateway
/**
* Check the gateway can process this...
*
* @param $amount \IPS\nexus\Money The amount
* @param $billingAddress \IPS\GeoLocation The billing address
* @return bool
* @param $amount \IPS\nexus\Money The amount
* @param $billingAddress \IPS\GeoLocation|NULL The billing address, which may be NULL if one if not provided
* @param $customer \IPS\nexus\Customer The customer (Default NULL value is for backwards compatibility - it should always be provided.)
* @param array $recurrings Details about recurring costs
* @see <a href="https://support.stripe.com/questions/which-currencies-does-stripe-support/">Which currencies does Stripe support?</a>
* @return bool
*/
public function checkValidity( \IPS\nexus\Money $amount, \IPS\GeoLocation $billingAddress )
public function checkValidity( \IPS\nexus\Money $amount, \IPS\GeoLocation $billingAddress = NULL, \IPS\nexus\Customer $customer = NULL, $recurrings = array() )
{
if ( static::_amountAsCents( $amount ) < 50 )
{
return FALSE;
}
/* See https://support.stripe.com/questions/which-currencies-does-stripe-support#currencygroup1 */
$group1 = array( 'AED', 'ALL', 'ANG', 'ARS', 'AUD', 'AWG', 'BBD', 'BDT', 'BIF', 'BMD', 'BND', 'BOB', 'BRL', 'BSD', 'BWP', 'BZD', 'CAD', 'CHF', 'CLP', 'CNY', 'COP', 'CRC', 'CVE', 'CZK', 'DJF', 'DKK', 'DOP', 'DZD', 'EEK', 'EGP', 'ETB', 'EUR', 'FJD', 'FKP', 'GBP', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL', 'HRK', 'HTG', 'HUF', 'IDR', 'ILS', 'INR', 'ISK', 'JMD', 'JPY', 'KES', 'KHR', 'KMF', 'KRW', 'KYD', 'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LTL', 'LVL', 'MAD', 'MDL', 'MNT', 'MOP', 'MRO', 'MUR', 'MVR', 'MWK', 'MXN', 'MYR', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', 'RUB', 'SAR', 'SBD', 'SCR', 'SEK', 'SGD', 'SHP', 'SLL', 'SOS', 'STD', 'SVC', 'SZL', 'THB', 'TOP', 'TTD', 'TWD', 'TZS', 'UAH', 'UGX', 'USD', 'UYI', 'UZS', 'VEF', 'VND', 'VUV', 'WST', 'XAF', 'XOF', 'XPF', 'YER', 'ZAR' );
$group2 = array( 'AFN', 'AMD', 'AOA', 'AZN', 'BAM', 'BGN', 'CDF', 'GEL', 'LSL', 'MKD', 'RON', 'RWF', 'TJS', 'XCD', 'KGS', 'MGA', 'MZN', 'RSD', 'SRD', 'TRY', 'ZMW' );
$settings = json_decode( $this->settings, TRUE );
switch ( $settings['country'] )
@@ -53,23 +59,23 @@ class _Stripe extends \IPS\nexus\Gateway
return FALSE;
}
break;
case 'AU':
if( $amount->currency != 'AUD' )
if ( !in_array( $amount->currency, $group1 ) )
{
return FALSE;
}
break;
default:
if ( !in_array( $amount->currency, array( 'AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN', 'BAM', 'BBD', 'BDT', 'BGN', 'BIF', 'BMD', 'BND', 'BOB', 'BRL', 'BSD', 'BWP', 'BZD', 'CAD', 'CDF', 'CHF', 'CLP', 'CNY', 'COP', 'CRC', 'CVE', 'CZK', 'DJF', 'DKK', 'DOP', 'DZD', 'EEK', 'EGP', 'ETB', 'EUR', 'FJD', 'FKP', 'GBP', 'GEL', 'GIP', 'GMD', 'GNF', 'GTQ', 'GYD', 'HKD', 'HNL', 'HRK', 'HTG', 'HUF', 'IDR', 'ILS', 'INR', 'ISK', 'JMD', 'JPY', 'KES', 'KGS', 'KHR', 'KMF', 'KRW', 'KYD', 'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LTL', 'LVL', 'MAD', 'MDL', 'MGA', 'MKD', 'MNT', 'MOP', 'MRO', 'MUR', 'MVR', 'MWK', 'MXN', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO', 'NOK', 'NPR', 'NZD', 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR', 'RON', 'RSD', 'RUB', 'RWF', 'SAR', 'SBD', 'SCR', 'SEK', 'SGD', 'SHP', 'SLL', 'SOS', 'SRD', 'STD', 'SVC', 'SZL', 'THB', 'TJS', 'TOP', 'TRY', 'TTD', 'TWD', 'TZS', 'UAH', 'UGX', 'USD', 'UYI', 'UZS', 'VEF', 'VND', 'VUV', 'WST', 'XAF', 'XCD', 'XOF', 'XPF', 'YER', 'ZAR', 'ZMW' ) ) )
if ( !in_array( $amount->currency, array_merge( $group1, $group2 ) ) )
{
return FALSE;
}
break;
}
return parent::checkValidity( $amount, $billingAddress );
return parent::checkValidity( $amount, $billingAddress, $customer, $recurrings );
}
/**
@@ -100,16 +106,18 @@ class _Stripe extends \IPS\nexus\Gateway
*
* @param \IPS\nexus\Invoice $invoice Invoice
* @param \IPS\nexus\Money $amount The amount to pay now
* @param \IPS\Member $member The member the payment screen is for (if in the ACP charging to a member's card) or NULL for currently logged in member
* @param array $recurrings Details about recurring costs
* @return array
*/
public function paymentScreen( \IPS\nexus\Invoice $invoice, \IPS\nexus\Money $amount )
public function paymentScreen( \IPS\nexus\Invoice $invoice, \IPS\nexus\Money $amount, \IPS\Member $member = NULL, $recurrings = array() )
{
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'global_gateways.js', 'nexus', 'global' ) );
$settings = json_decode( $this->settings, TRUE );
$supportedCards = array( \IPS\nexus\CreditCard::TYPE_VISA, \IPS\nexus\CreditCard::TYPE_MASTERCARD );
if ( !in_array( $invoice->currency, array( 'AFN', 'AOA', 'ARS', 'AUD', 'BOB', 'BRL', 'CAD', 'CLP', 'COP', 'CRC', 'CVE', 'CZK', 'DJF', 'EEK', 'FKP', 'GNF', 'GTQ', 'HNL', 'INR', 'LAK', 'MUR', 'MXN', 'NIO', 'PAB', 'PEN', 'PYG', 'SHP', 'SRD', 'SVC', 'UYI', 'VEF', 'XOF', 'XPF' ) ) )
if ( !in_array( $invoice->currency, array( 'AFN', 'AOA', 'ARS', 'BOB', 'BRL', 'CAD', 'CLP', 'COP', 'CRC', 'CVE', 'CZK', 'DJF', 'EEK', 'FKP', 'GNF', 'GTQ', 'HNL', 'INR', 'LAK', 'MUR', 'MXN', 'NIO', 'PAB', 'PEN', 'PYG', 'SHP', 'SRD', 'SVC', 'UYI', 'VEF', 'XOF', 'XPF' ) ) )
{
$supportedCards[] = \IPS\nexus\CreditCard::TYPE_AMERICAN_EXPRESS;
}
@@ -131,7 +139,7 @@ class _Stripe extends \IPS\nexus\Gateway
'jsRequired' => TRUE,
'names' => FALSE,
'save' => ( $settings['cards'] and \IPS\Member::loggedIn()->member_id ) ? $this : NULL,
'member' => $invoice->member,
'member' => $member,
) ) );
}
@@ -141,10 +149,11 @@ class _Stripe extends \IPS\nexus\Gateway
* @param \IPS\nexus\Transaction $transaction Transaction
* @param array|\IPS\nexus\Customer\CreditCard $values Values from form OR a stored card object if this gateway supports them
* @param \IPS\nexus\Fraud\MaxMind\Request|NULL $maxMind *If* MaxMind is enabled, the request object will be passed here so gateway can additional data before request is made
* @return \IPS\DateTime|NULL Auth is valid until or NULL to indicate auth is good forever
* @throws \LogicException Message will be displayed to user
* @param array $recurrings Details about recurring costs
* @return \IPS\DateTime|NULL Auth is valid until or NULL to indicate auth is good forever
* @throws \LogicException Message will be displayed to user
*/
public function auth( \IPS\nexus\Transaction $transaction, $values, \IPS\nexus\Fraud\MaxMind\Request $maxMind = NULL )
public function auth( \IPS\nexus\Transaction $transaction, $values, \IPS\nexus\Fraud\MaxMind\Request $maxMind = NULL, $recurrings = array() )
{
/* Set MaxMind type */
if ( $maxMind )
@@ -302,8 +311,9 @@ class _Stripe extends \IPS\nexus\Gateway
$settings = $settings ?: json_decode( $this->settings, TRUE );
$response = \IPS\Http\Url::external( 'https://api.stripe.com/v1/' . $uri )
->request()
->request( \IPS\LONG_REQUEST_TIMEOUT )
->setHeaders( array( 'Stripe-Version' => '2014-01-31' ) )
->forceTls()
->login( $settings['secret_key'], '' )
->$method( $data )
->decodeJson();
@@ -326,11 +336,11 @@ class _Stripe extends \IPS\nexus\Gateway
{
if ( in_array( $amount->currency, array( 'BIF', 'CLP', 'DJF', 'GNF', 'JPY', 'KMF', 'KRW', 'MGA', 'PYG', 'RWF', 'VUV', 'XAF', 'XOF', 'XPF' ) ) )
{
return intval( $amount->amount );
return intval( (string) $amount->amount );
}
else
{
return intval( $amount->amount * 100 );
return intval( (string) $amount->amount->multiply( new \IPS\Math\Number( '100' ) ) );
}
}
}
@@ -2,9 +2,9 @@
/**
* @brief Test Gateway
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 10 Feb 2014
* @version SVN_VERSION_NUMBER
@@ -26,8 +26,8 @@ class _Test extends \IPS\nexus\Gateway
{
/* !Features */
const SUPPORTS_REFUNDS = FALSE;
const SUPPORTS_PARTIAL_REFUNDS = FALSE;
const SUPPORTS_REFUNDS = TRUE;
const SUPPORTS_PARTIAL_REFUNDS = TRUE;
/* !Payment Gateway */
@@ -36,9 +36,11 @@ class _Test extends \IPS\nexus\Gateway
*
* @param \IPS\nexus\Invoice $invoice Invoice
* @param \IPS\nexus\Money $amount The amount to pay now
* @param \IPS\Member $member The member the payment screen is for (if in the ACP charging to a member's card) or NULL for currently logged in member
* @param array $recurrings Details about recurring costs
* @return array
*/
public function paymentScreen( \IPS\nexus\Invoice $invoice, \IPS\nexus\Money $amount )
public function paymentScreen( \IPS\nexus\Invoice $invoice, \IPS\nexus\Money $amount, \IPS\Member $member = NULL, $recurrings = array() )
{
return array();
}
@@ -55,6 +57,19 @@ class _Test extends \IPS\nexus\Gateway
}
/**
* Refund
*
* @param \IPS\nexus\Transaction $transaction Transaction to be refunded
* @param float|NULL $amount Amount to refund (NULL for full amount - always in same currency as transaction)
* @return mixed Gateway reference ID for refund, if applicable
* @throws \Exception
*/
public function refund( \IPS\nexus\Transaction $transaction, $amount = NULL )
{
}
/* !ACP Configuration */
/**
@@ -2,9 +2,9 @@
/**
* @brief 2Checkout Gateway
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @subpackage Nexus
* @since 17 Mar 2014
* @version SVN_VERSION_NUMBER
@@ -28,6 +28,27 @@ class _TwoCheckout extends \IPS\nexus\Gateway
const SUPPORTS_REFUNDS = TRUE;
const SUPPORTS_PARTIAL_REFUNDS = TRUE;
/**
* Check the gateway can process this...
*
* @param $amount \IPS\nexus\Money The amount
* @param $billingAddress \IPS\GeoLocation|NULL The billing address, which may be NULL if one if not provided
* @param $customer \IPS\nexus\Customer The customer (Default NULL value is for backwards compatibility - it should always be provided.)
* @param array $recurrings Details about recurring costs
* @return bool
*/
public function checkValidity( \IPS\nexus\Money $amount, \IPS\GeoLocation $billingAddress = NULL, \IPS\nexus\Customer $customer = NULL, $recurrings = array() )
{
/* We require both a full name and a billing address */
if ( !$customer->cm_first_name or !$customer->cm_last_name or !$billingAddress )
{
return FALSE;
}
/* Still here? We're good - pass to parent for general checks */
return parent::checkValidity( $amount, $billingAddress, $customer, $recurrings );
}
/* !Payment Gateway */
@@ -37,10 +58,11 @@ class _TwoCheckout extends \IPS\nexus\Gateway
* @param \IPS\nexus\Transaction $transaction Transaction
* @param array|\IPS\nexus\Customer\CreditCard $values Values from form OR a stored card object if this gateway supports them
* @param \IPS\nexus\Fraud\MaxMind\Request|NULL $maxMind *If* MaxMind is enabled, the request object will be passed here so gateway can additional data before request is made
* @return \IPS\DateTime|NULL Auth is valid until or NULL to indicate auth is good forever
* @throws \LogicException Message will be displayed to user
* @param array $recurrings Details about recurring costs
* @return \IPS\DateTime|NULL Auth is valid until or NULL to indicate auth is good forever
* @throws \LogicException Message will be displayed to user
*/
public function auth( \IPS\nexus\Transaction $transaction, $values, \IPS\nexus\Fraud\MaxMind\Request $maxMind = NULL )
public function auth( \IPS\nexus\Transaction $transaction, $values, \IPS\nexus\Fraud\MaxMind\Request $maxMind = NULL, $recurrings = array() )
{
$settings = json_decode( $this->settings, TRUE );
$transaction->save();
@@ -80,18 +102,18 @@ class _TwoCheckout extends \IPS\nexus\Gateway
}
/* Items */
if ( $transaction->amount->amount == $transaction->invoice->total->amount )
if ( $transaction->amount->amount->compare( $transaction->invoice->total->amount ) === 0 )
{
$summary = $transaction->invoice->summary();
$k = 0;
foreach ( $summary['items'] as $item )
{
$data["li_{$k}_type"] = $item->price->amount >= 0 ? 'product' : 'coupon';
$data["li_{$k}_type"] = $item->price->amount->isGreaterThanZero() ? 'product' : 'coupon';
$data["li_{$k}_name"] = $item->name;
$data["li_{$k}_quantity"] = $item->quantity;
$data["li_{$k}_price"] = abs( $item->price->amount );
$data["li_{$k}_tangible"] = $item->physical ?'Y' : 'N';
$data["li_{$k}_price"] = (string) ( $item->price->amount->isPositive() ? $item->price->amount : $item->price->amount->multiply( new \IPS\Math\Number( '-1' ) ) );
$data["li_{$k}_tangible"] = $item->physical ? 'Y' : 'N';
$d = 0;
foreach ( $item->details as $label => $value )
@@ -109,7 +131,7 @@ class _TwoCheckout extends \IPS\nexus\Gateway
$data["li_{$k}_type"] = 'shipping';
$data["li_{$k}_name"] = $shipping->name;
$data["li_{$k}_quantity"] = 1;
$data["li_{$k}_price"] = $shipping->price->amount;
$data["li_{$k}_price"] = (string) $shipping->price->amount;
$data["li_{$k}_tangible"] = 'Y';
$k++;
@@ -117,20 +139,13 @@ class _TwoCheckout extends \IPS\nexus\Gateway
foreach ( $summary['tax'] as $tax )
{
\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $tax['name'] );
$data["li_{$k}_type"] = 'tax';
$data["li_{$k}_name"] = $tax['name'];
$data["li_{$k}_quantity"] = 1;
$data["li_{$k}_price"] = $tax['amount']->amount;
$data["li_{$k}_price"] = (string) $tax['amount']->amount;
$data["li_{$k}_tangible"] = 'N';
$d = 0;
foreach ( $item['details'] as $label => $value )
{
$data["li_{$k}_option_{$d}_name"] = $label;
$data["li_{$k}_option_{$d}_value"] = $value;
$d++;
}
$k++;
}
}
@@ -139,7 +154,7 @@ class _TwoCheckout extends \IPS\nexus\Gateway
$data["li_0_type"] = 'product';
$data["li_0_name"] = $transaction->member->language()->addToStack( 'partial_payment_desc', FALSE, array( 'sprintf' => array( $transaction->invoice->id ) ) );
$data["li_0_quantity"] = 1;
$data["li_0_price"] = $transaction->amount->amount;
$data["li_0_price"] = (string) $transaction->amount->amount;
$data["li_0_tangible"] = 'N';
}
@@ -175,7 +190,7 @@ class _TwoCheckout extends \IPS\nexus\Gateway
}
$settings = json_decode( $this->settings, TRUE );
$response = \IPS\Http\Url::external( 'https://www.2checkout.com/api/sales/refund_invoice' )->request()->login( $settings['api_username'], $settings['api_password'] )->post( $data )->decodeJson();
$response = \IPS\Http\Url::external( 'https://www.2checkout.com/api/sales/refund_invoice' )->request()->forceTls()->login( $settings['api_username'], $settings['api_password'] )->post( $data )->decodeJson();
if ( $response['response_code'] != 'OK' )
{
@@ -207,15 +222,29 @@ class _TwoCheckout extends \IPS\nexus\Gateway
* @throws \InvalidArgumentException
*/
public function testSettings( $settings )
{
$response = \IPS\Http\Url::external( 'https://www.2checkout.com/api/acct/detail_company_info' )->request()->setHeaders( array( 'Accept' => 'application/json' ) )->login( $settings['api_username'], $settings['api_password'] )->get()->decodeJson();
if ( isset( $response['errors'] ) )
{
try
{
throw new \LogicException( $response['errors'][0]['message'] );
$response = \IPS\Http\Url::external( 'https://www.2checkout.com/api/acct/detail_company_info' )->request()->forceTls()->setHeaders( array( 'Accept' => 'application/json' ) )->login( $settings['api_username'], $settings['api_password'] )->get()->decodeJson();
if ( isset( $response['errors'] ) )
{
throw new \InvalidArgumentException( $response['errors'][0]['message'] );
}
if ( $response['response_code'] != 'OK' )
{
throw new \InvalidArgumentException( $response['response_message'] );
}
}
if ( $response['response_code'] != 'OK' )
catch ( \IPS\Http\Request\Exception $e )
{
throw new \LogicException( $response['response_message'] );
if ( \OPENSSL_VERSION_NUMBER < 268439647 )
{
throw new \InvalidArgumentException( \IPS\Member::loggedIn()->language()->addToStack( 'twocheckout_openssl_req' ) );
}
else
{
throw $e;
}
}
$settings['sid'] = $response['vendor_company_info']['vendor_id'];