Permalink
Browse files

Merge branch 'develop'

  • Loading branch information...
2 parents eaa53c3 + 3ba8786 commit e8b39e7ce9d9e9bb0c55076025fb1f8535a4bd3b @akDeveloper committed Oct 3, 2013
@@ -34,31 +34,23 @@
* @author Andreas Kollaros
* @license MIT {@link http://opensource.org/licenses/mit-license.php}
*/
-class Moneris extends Gateway
+class Moneris extends Gateway
{
- const US_TEST_URL = 'https://esplusqa.moneris.com/gateway_us/servlet/MpgRequest';
- const US_LIVE_URL = 'https://esplus.moneris.com/gateway_us/servlet/MpgRequest';
-
- const CA_TEST_URL = 'https://esqa.moneris.com/gateway2/servlet/MpgRequest';
- const CA_LIVE_URL = 'https://www3.moneris.com/gateway2/servlet/MpgRequest';
-
- #Urls
- private $TEST_URL;
- private $LIVE_URL;
- private $API_VERSION;
+ const TEST_URL = 'https://esqa.moneris.com/gateway2/servlet/MpgRequest';
+ const LIVE_URL = 'https://www3.moneris.com/gateway2/servlet/MpgRequest';
#Actions
- private $authorize;
- private $cavv_authorize;
- private $purchase;
- private $cavv_purchase;
- private $capture;
- private $void;
- private $credit;
+ protected $authorize;
+ protected $cavv_authorize;
+ protected $purchase;
+ protected $cavv_purchase;
+ protected $capture;
+ protected $void;
+ protected $credit;
# The countries the gateway supports merchants from as 2 digit ISO country codes
- public static $supported_countries = array('US','CA');
+ public static $supported_countries = array('CA');
# The card types supported by the payment gateway
public static $supported_cardtypes = array( 'visa', 'master','american_express', 'discover');
@@ -69,7 +61,7 @@ class Moneris extends Gateway
# The display name of the gateway
public static $display_name = 'Moneris Payment Gateway (eSelect Plus)';
- public static $default_currency;
+ public static $default_currency = 'CAD';
private $options;
private $post;
@@ -83,55 +75,33 @@ class Moneris extends Gateway
'NO' => 'discover'
);
- const US_API_VERSION = 'US PHP Api v.1.1.2';
- const CA_API_VERSION = 'MpgApi Version 2.03(php)';
+ const API_VERSION = 'MpgApi Version 2.03(php)';
const FRAUD_REVIEW = 1;
/**
- * $options array includes login parameters of merchant, optional currency
+ * $options array includes login parameters of merchant, optional currency
* and region (US or CA).
*
- * @param array $options
+ * @param array $options
*/
public function __construct(array $options = array())
{
- Options::required('store_id, api_token, region', $options);
+ Options::required('store_id, api_token', $options);
$this->options = new Options($options);
if (isset( $options['currency'])) {
self::$default_currency = $options['currency'];
}
- if ($options['region'] == 'US') {
- $this->TEST_URL = self::US_TEST_URL;
- $this->LIVE_URL = self::US_LIVE_URL;
- $this->API_VERSION = self::US_API_VERSION;
-
- $this->authorize = 'us_preauth';
- $this->cavv_authorize = 'us_cavv_preauth';
- $this->purchase = 'us_purchase';
- $this->cavv_purchase = 'us_cavv_purchase';
- $this->capture = 'us_completion';
- $this->void = 'us_purchasecorrection';
- $this->credit = 'us_refund';
-
- static::$default_currency = 'USD';
- } elseif($options['region'] == 'CA') {
- $this->TEST_URL = self::CA_TEST_URL;
- $this->LIVE_URL = self::CA_LIVE_URL;
- $this->API_VERSION = self::CA_API_VERSION;
-
- $this->authorize = 'preauth';
- $this->cavv_authorize = 'cavv_preauth';
- $this->purchase = 'purchase';
- $this->cavv_purchase = 'cavv_purchase';
- $this->capture = 'completion';
- $this->void = 'purchasecorrection';
- $this->credit = 'refund';
-
- static::$default_currency = 'CAD';
- }
+ $this->authorize = 'preauth';
+ $this->cavv_authorize = 'cavv_preauth';
+ $this->purchase = 'purchase';
+ $this->cavv_purchase = 'cavv_purchase';
+ $this->capture = 'completion';
+ $this->void = 'purchasecorrection';
+ $this->credit = 'refund';
+
}
/**
@@ -199,7 +169,7 @@ public function purchase($money, CreditCard $creditcard, $options=array())
public function capture($money, $authorization, $options = array())
{
Options::required('order_id', $options);
-
+
$this->add_invoice($options);
$this->post .= "<comp_amount>{$this->amount($money)}</comp_amount>";
$this->post .= "<txn_number>$authorization</txn_number>";
@@ -217,10 +187,10 @@ public function capture($money, $authorization, $options = array())
public function void($authorization, $options = array())
{
Options::required('order_id', $options);
-
+
$this->add_invoice($options);
$this->post .= "<txn_number>$authorization</txn_number>";
-
+
return $this->commit($this->void, null);
}
@@ -349,7 +319,7 @@ private function add_invoice($options)
private function add_creditcard(CreditCard $creditcard)
{
- $exp_date = $this->cc_format($creditcard->year, 'two_digits')
+ $exp_date = $this->cc_format($creditcard->year, 'two_digits')
. $this->cc_format($creditcard->month, 'two_digits');
$this->post .= "<pan>{$creditcard->number}</pan><expdate>{$exp_date}</expdate><cvd_info><cvd_indicator>1</cvd_indicator><cvd_value>{$creditcard->verification_value}</cvd_value></cvd_info>";
@@ -377,16 +347,16 @@ private function parse($body)
$response['message'] = (string) $xml->receipt->Message;
$response['trans_amount'] = (string) $xml->receipt->TransAmount;
$cardtype = (string) $xml->receipt->CardType;
- $response['card_type'] = isset($this->credit_card_types[$cardtype])
- ? $this->credit_card_types[$cardtype]
+ $response['card_type'] = isset($this->credit_card_types[$cardtype])
+ ? $this->credit_card_types[$cardtype]
: null;
$response['transaction_id'] = (string) $xml->receipt->TransID;
$response['timed_out'] = (string) $xml->receipt->TimedOut;
$response['bank_totals'] = (string) $xml->receipt->BankTotals;
$response['ticket'] = (string) $xml->receipt->Ticket;
$response['avs_result_code']= (string) $xml->receipt->AvsResultCode;
$response['cvd_result_code']= (string) $xml->receipt->CvdResultCode;
-
+
if ($response['avs_result_code'] == 'null') {
$response['avs_result_code'] = null;
}
@@ -404,13 +374,13 @@ private function parse($body)
*/
private function commit($action, $money, $parameters=array())
{
- $url = $this->isTest() ? $this->TEST_URL : $this->LIVE_URL;
+ $url = $this->isTest() ? static::TEST_URL : static::LIVE_URL;
$data = $this->ssl_post(
- $url,
+ $url,
$this->post_data($action, $parameters),
array(
- 'user_agent' => $this->API_VERSION,
+ 'user_agent' => static::API_VERSION,
'timeout'=> 60
)
);
@@ -491,12 +461,12 @@ private function avs_result_from($response)
* @param string $action
* @param array $parameters
*/
- private function post_data($action, $parameters = array())
+ private function post_data($action, $parameters = array())
{
$xml = '<?xml version="1.0"?><request>';
$xml .= "<store_id>{$this->options['store_id']}</store_id><api_token>{$this->options['api_token']}</api_token>";
$xml .= "<$action>$this->post<crypt_type>{$this->crypt_type}</crypt_type></$action></request>";
-
+
return $xml;
}
@@ -0,0 +1,30 @@
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+namespace AktiveMerchant\Billing\Gateways;
+
+class MonerisUs extends Moneris
+{
+ const TEST_URL = 'https://esplusqa.moneris.com/gateway_us/servlet/MpgRequest';
+ const LIVE_URL = 'https://esplus.moneris.com/gateway_us/servlet/MpgRequest';
+
+ const API_VERSION = 'US PHP Api v.1.1.2';
+
+ public static $supported_countries = array('US');
+
+ public static $default_currency = 'USD';
+
+ public function __construct(array $options = array())
+ {
+ parent::__construct($options);
+
+ $this->authorize = 'us_preauth';
+ $this->cavv_authorize = 'us_cavv_preauth';
+ $this->purchase = 'us_purchase';
+ $this->cavv_purchase = 'us_cavv_purchase';
+ $this->capture = 'us_completion';
+ $this->void = 'us_purchasecorrection';
+ $this->credit = 'us_refund';
+ }
+}
@@ -32,8 +32,7 @@ public function setUp()
Base::mode('test');
$login_info = $this->getFixtures()->offsetGet('moneris');
-
- $login_info['region'] = 'CA';
+
$this->gateway = new Moneris($login_info);
$this->amount = 10;
@@ -74,24 +73,24 @@ public function setUp()
public function testSuccessfulAuthorize()
{
$this->mock_request($this->successful_authorize_response());
-
+
$response = $this->gateway->authorize(
$this->amount,
$this->creditcard,
$this->options
);
-
+
$this->assert_success($response);
$this->assertTrue($response->test());
-
+
$request_body = $this->request->getBody();
$this->assertEquals(
$this->successful_authorize_request($this->options['order_id']),
$request_body
);
-
+
$params = $response->params();
-
+
$this->assertEquals('10.00', $params->trans_amount);
}
@@ -108,26 +107,26 @@ private function successful_authorize_response()
public function testSuccessfulCapture()
{
$this->mock_request($this->successful_capture_response());
-
+
$response = $this->gateway->capture(
$this->amount,
'358973-0_8',
array(
'order_id' => '8915641235'
)
);
-
+
$this->assert_success($response);
$this->assertTrue($response->test());
-
+
$request_body = $this->request->getBody();
$this->assertEquals(
$this->successful_capture_request(),
$request_body
);
-
+
$params = $response->params();
-
+
$this->assertEquals('10.00', $params->trans_amount);
}
@@ -144,27 +143,27 @@ private function successful_capture_response()
public function testSuccessfulPurchase()
{
$this->mock_request($this->successful_purchase_response($this->options['order_id']));
-
+
$response = $this->gateway->purchase(
$this->amount,
$this->creditcard,
$this->options
);
-
+
$this->assert_success($response);
$this->assertTrue($response->test());
-
+
$request_body = $this->request->getBody();
$this->assertEquals(
$this->successful_purchase_request($this->options['order_id']),
$request_body
);
-
+
$params = $response->params();
-
+
$this->assertEquals('10.00', $params->trans_amount);
}
-
+
private function successful_purchase_request($order_id)
{
return '<?xml version="1.0"?><request><store_id>store1</store_id><api_token>yesguy</api_token><purchase><order_id>'.$order_id.'</order_id><pan>4242424242424242</pan><expdate>1501</expdate><cvd_info><cvd_indicator>1</cvd_indicator><cvd_value>000</cvd_value></cvd_info><billing><first_name>John</first_name><last_name>Dows</last_name><address>1 Main St</address><city>San Jose</city><province>CA</province><country>United States</country><postal_code>95131</postal_code></billing><shipping><first_name>John</first_name><last_name>Dows</last_name><address>1 Main St</address><city>San Jose</city><province>CA</province><country>United States</country><postal_code>95131</postal_code></shipping><avs_info><avs_street_number>1</avs_street_number><avs_street_name>Main St</avs_street_name><avs_zipcode>95131</avs_zipcode></avs_info><amount>10.00</amount><crypt_type>7</crypt_type></purchase></request>';
@@ -178,26 +177,26 @@ private function successful_purchase_response($order_id)
public function testSuccessfulCredit()
{
$this->mock_request($this->successful_credit_response());
-
+
$response = $this->gateway->credit(
$this->amount,
'360246-0_8',
array(
'order_id' => '1419381921'
)
);
-
+
$this->assert_success($response);
$this->assertTrue($response->test());
-
+
$request_body = $this->request->getBody();
$this->assertEquals(
$this->successful_credit_request(),
$request_body
);
-
+
$params = $response->params();
-
+
$this->assertEquals('10.00', $params->trans_amount);
}
@@ -214,23 +213,23 @@ private function successful_credit_response()
public function testSuccessfulVoid()
{
$this->mock_request($this->successful_void_response());
-
+
$response = $this->gateway->void(
'359029-1_8',
array(
'order_id' => '8915641235'
)
);
-
+
$this->assert_success($response);
$this->assertTrue($response->test());
-
+
$request_body = $this->request->getBody();
$this->assertEquals(
$this->successful_void_request(),
$request_body
);
-
+
$params = $response->params();
}
Oops, something went wrong.

0 comments on commit e8b39e7

Please sign in to comment.