Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -12,7 +12,7 @@
|
||||
namespace IPS\nexus\Gateway;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -48,7 +48,7 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
|
||||
}
|
||||
|
||||
/* European processors require a full name and billing address */
|
||||
if ( in_array( $settings['processor'], array( 8, 9, 10, 11, 12, 13 ) ) )
|
||||
if ( \in_array( $settings['processor'], array( 8, 9, 10, 11, 12, 13 ) ) )
|
||||
{
|
||||
if ( !$customer->cm_first_name or !$customer->cm_last_name or !$billingAddress )
|
||||
{
|
||||
@@ -56,7 +56,7 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
|
||||
}
|
||||
}
|
||||
/* GPN Canada and WorldPay Streamline Processing Platform also require a billing address */
|
||||
if ( in_array( $settings['processor'], array( 4, 13 ) ) )
|
||||
if ( \in_array( $settings['processor'], array( 4, 13 ) ) )
|
||||
{
|
||||
if ( !$billingAddress )
|
||||
{
|
||||
@@ -66,31 +66,31 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
|
||||
|
||||
/* 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 ) ) )
|
||||
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 ) ) )
|
||||
if ( \in_array( $settings['processor'], array( 1, 2, 4 ) ) )
|
||||
{
|
||||
$currencies[] = 'CAD';
|
||||
}
|
||||
if ( in_array( $settings['processor'], array( 8, 9, 10, 11, 12, 13 ) ) )
|
||||
if ( \in_array( $settings['processor'], array( 8, 9, 10, 11, 12, 13 ) ) )
|
||||
{
|
||||
$currencies[] = 'GBP';
|
||||
}
|
||||
if ( in_array( $settings['processor'], array( 8, 9, 11, 13 ) ) )
|
||||
if ( \in_array( $settings['processor'], array( 8, 9, 11, 13 ) ) )
|
||||
{
|
||||
$currencies[] = 'EUR';
|
||||
}
|
||||
if ( in_array( $settings['processor'], array( 14, 15 ) ) )
|
||||
if ( \in_array( $settings['processor'], array( 14, 15 ) ) )
|
||||
{
|
||||
$currencies[] = 'AUD';
|
||||
}
|
||||
if ( in_array( $settings['processor'], array( 14 ) ) )
|
||||
if ( \in_array( $settings['processor'], array( 14 ) ) )
|
||||
{
|
||||
$currencies[] = 'NZD';
|
||||
}
|
||||
if ( !in_array( $amount->currency, $currencies ) )
|
||||
if ( !\in_array( $amount->currency, $currencies ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -98,13 +98,24 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
|
||||
/* Still here? We're good - pass to parent for general checks */
|
||||
return parent::checkValidity( $amount, $billingAddress, $customer, $recurrings );
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get Node Description
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function get__description()
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'gateway_deprecated', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack('gateway__' . $this->gateway ) ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Can store cards?
|
||||
*
|
||||
* @param bool $adminCreatableOnly If TRUE, will only return gateways where the admin (opposed to the user) can create a new option
|
||||
* @return bool
|
||||
*/
|
||||
public function canStoreCards()
|
||||
public function canStoreCards( $adminCreatableOnly = FALSE )
|
||||
{
|
||||
$settings = json_decode( $this->settings, TRUE );
|
||||
return ( $settings['method'] === 'AIM' and $settings['cim'] );
|
||||
@@ -113,9 +124,10 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
|
||||
/**
|
||||
* Admin can manually charge using this gateway?
|
||||
*
|
||||
* @param \IPS\nexus\Customer $customer The customer we're wanting to charge
|
||||
* @return bool
|
||||
*/
|
||||
public function canAdminCharge()
|
||||
public function canAdminCharge( \IPS\nexus\Customer $customer )
|
||||
{
|
||||
$settings = json_decode( $this->settings, TRUE );
|
||||
return ( $settings['method'] === 'AIM' );
|
||||
@@ -126,13 +138,14 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
|
||||
/**
|
||||
* Payment Screen Fields
|
||||
*
|
||||
* @param \IPS\nexus\Invoice $invoice Invoice
|
||||
* @param \IPS\nexus\Money $amount The amount to pay now
|
||||
* @param \IPS\nexus\Customer $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
|
||||
* @param \IPS\nexus\Invoice $invoice Invoice
|
||||
* @param \IPS\nexus\Money $amount The amount to pay now
|
||||
* @param \IPS\nexus\Customer $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
|
||||
* @param bool $type 'checkout' means the cusotmer is doing this on the normal checkout screen, 'admin' means the admin is doing this in the ACP, 'card' means the user is just adding a card
|
||||
* @return array
|
||||
*/
|
||||
public function paymentScreen( \IPS\nexus\Invoice $invoice, \IPS\nexus\Money $amount, \IPS\nexus\Customer $member = NULL, $recurrings = array() )
|
||||
public function paymentScreen( \IPS\nexus\Invoice $invoice, \IPS\nexus\Money $amount, \IPS\nexus\Customer $member = NULL, $recurrings = array(), $type = 'checkout' )
|
||||
{
|
||||
$return = array();
|
||||
$settings = json_decode( $this->settings, TRUE );
|
||||
@@ -142,14 +155,14 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
|
||||
{
|
||||
$types = array();
|
||||
|
||||
if ( in_array( $settings['processor'], array( 1, 2, 3, 4, 5, 6, 7 ) ) )
|
||||
if ( \in_array( $settings['processor'], array( 1, 2, 3, 4, 5, 6, 7 ) ) )
|
||||
{
|
||||
$types[] = \IPS\nexus\CreditCard::TYPE_AMERICAN_EXPRESS;
|
||||
$types[] = \IPS\nexus\CreditCard::TYPE_DINERS_CLUB;
|
||||
$types[] = \IPS\nexus\CreditCard::TYPE_DISCOVER;
|
||||
$types[] = \IPS\nexus\CreditCard::TYPE_JCB;
|
||||
}
|
||||
elseif ( in_array( $settings['processor'], array( 9, 13 ) ) )
|
||||
elseif ( \in_array( $settings['processor'], array( 9, 13 ) ) )
|
||||
{
|
||||
$types[] = \IPS\nexus\CreditCard::TYPE_JCB;
|
||||
}
|
||||
@@ -182,10 +195,11 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
|
||||
'x_method' => 'CC',
|
||||
'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_hash' => isset( $settings['signature_key'] ) ? hash_hmac( 'sha512', "{$settings['login']}^{$invoice->id}^{$timestamp}^{$amount->amount}^{$amount->currency}", hex2bin( $settings['signature_key'] ) ) : hash_hmac( 'md5', "{$settings['login']}^{$invoice->id}^{$timestamp}^{$amount->amount}^{$amount->currency}", $settings['tran_key'] ),
|
||||
'x_fp_sequence' => $invoice->id,
|
||||
'x_fp_timestamp' => $timestamp,
|
||||
'x_invoice_num' => $invoice->id,
|
||||
'x_description' => $invoice->title,
|
||||
'x_first_name' => $invoice->member->cm_first_name,
|
||||
'x_last_name' => $invoice->member->cm_last_name,
|
||||
'x_address' => $invoice->billaddress ? implode( ', ', $invoice->billaddress->addressLines ) : '',
|
||||
@@ -199,7 +213,7 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
|
||||
'x_cust_id' => $invoice->member->member_id,
|
||||
'x_customer_ip' => \IPS\Request::i()->ipAddress(),
|
||||
'x_relay_response' => 'TRUE',
|
||||
'x_relay_url' => \IPS\Settings::i()->base_url . 'applications/nexus/interface/gateways/authorize.php',
|
||||
'x_relay_url' => \IPS\Settings::i()->base_url . 'applications/nexus/interface/gateways/authorize.php?payment_method=' . $this->id,
|
||||
) )
|
||||
);
|
||||
|
||||
@@ -224,12 +238,13 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
|
||||
* @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
|
||||
* @param array $recurrings Details about recurring costs
|
||||
* @param string|NULL $source 'checkout' if the customer is doing this at a normal checkout, 'renewal' is an automatically generated renewal invoice, 'manual' is admin manually charging. NULL is unknown
|
||||
* @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, $recurrings = array() )
|
||||
public function auth( \IPS\nexus\Transaction $transaction, $values, \IPS\nexus\Fraud\MaxMind\Request $maxMind = NULL, $recurrings = array(), $source = NULL )
|
||||
{
|
||||
$card = is_array( $values ) ? $values[ $this->id . '_card' ] : $values;
|
||||
$card = \is_array( $values ) ? $values[ $this->id . '_card' ] : $values;
|
||||
|
||||
/* Stored Card */
|
||||
if ( $card instanceof \IPS\nexus\Gateway\AuthorizeNet\CreditCard )
|
||||
@@ -269,6 +284,8 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
|
||||
$response = $this->api( array(
|
||||
'x_type' => 'AUTH_ONLY',
|
||||
'x_method' => 'CC',
|
||||
'x_invoice_num' => $transaction->invoice->id,
|
||||
'x_description' => $transaction->invoice->title,
|
||||
'x_amount' => (string) $transaction->amount->amount,
|
||||
'x_currency_code' => $transaction->amount->currency,
|
||||
'x_card_num' => $card->number,
|
||||
@@ -286,6 +303,7 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
|
||||
'x_email_customer' => 'FALSE',
|
||||
'x_cust_id' => $transaction->member->member_id,
|
||||
'x_customer_ip' => \IPS\Request::i()->ipAddress(),
|
||||
'x_relay_response' => 'false'
|
||||
) );
|
||||
|
||||
/* Save? */
|
||||
@@ -353,6 +371,7 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
|
||||
$this->api( array(
|
||||
'x_type' => 'PRIOR_AUTH_CAPTURE',
|
||||
'x_trans_id' => $transaction->gw_id,
|
||||
'x_relay_response' => 'false'
|
||||
) );
|
||||
}
|
||||
|
||||
@@ -396,6 +415,8 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
|
||||
public function settings( &$form )
|
||||
{
|
||||
$settings = json_decode( $this->settings, TRUE );
|
||||
|
||||
$form->addMessage( \IPS\Member::loggedIn()->language()->addToStack( 'gateway_deprecated', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack('gateway__' . $this->gateway ) ) ) ), 'ipsMessage ipsMessage_warning' );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'authorizenet_login', $settings['login'], TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'authorizenet_tran_key', $settings['tran_key'], TRUE ) );
|
||||
@@ -406,11 +427,15 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
|
||||
),
|
||||
'toggles' => array(
|
||||
'AIM' => array( 'authorizenet_cim' ),
|
||||
'DPM' => array( 'authorizenet_hash' )
|
||||
'DPM' => array( 'authorizenet_signature_key', 'authorizenet_hash' )
|
||||
)
|
||||
) ) );
|
||||
$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\Text( 'authorizenet_signature_key', isset( $settings['signature_key'] ) ? $settings['signature_key'] : '', FALSE, array(), NULL, NULL, NULL, 'authorizenet_signature_key' ) );
|
||||
if ( isset( $settings['hash'] ) and !isset( $settings['signature_key'] ) )
|
||||
{
|
||||
$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', isset( $settings['processor'] ) ? $settings['processor'] : '0', FALSE, array( 'options' => array(
|
||||
0 => 'dont_know',
|
||||
'North American Payment Processors' => array(
|
||||
@@ -484,6 +509,10 @@ class _AuthorizeNet extends \IPS\nexus\Gateway
|
||||
*/
|
||||
protected function _handleResponse( $response )
|
||||
{
|
||||
$response = array_map( function( $v ) {
|
||||
return trim( $v, ';' );
|
||||
}, $response );
|
||||
|
||||
if ( $response[0] != 1 )
|
||||
{
|
||||
throw new \IPS\nexus\Gateway\AuthorizeNet\Exception( $response[2] );
|
||||
|
||||
Reference in new issue
Block a user