Version 4.1.19
This commit is contained in:
1 parent
28bd025b35
commit
2bd5025018
2674 files changed
+233518
-77766
No files matched your search
@@ -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'];
|
||||
|
||||
Reference in new issue
Block a user