Permalink
Browse files

Merge branch 'develop'

  • Loading branch information...
2 parents b1a2579 + 03865b4 commit f3a4bc294a030b823b07356ca0e50c67f7460fd9 @akDeveloper committed Jul 16, 2013
View
@@ -3,3 +3,4 @@
vendor
bin/*
composer.lock
+unit_tests/fixtures.ini
View
@@ -12,6 +12,8 @@ The aim is to develop a PHP application to includes payment gateways under commo
* [Eway](http://www.eway.com.au/)
* [Fat Zebra](https://www.fatzebra.com.au)
* [Hsbc Secure e-Payment](http://www.hsbc.co.uk/1/2/business/cards-payments/secure-epayments)
+* [Moneris](http://www.moneris.com)
+* [Moneris US](http://www.monerisusa.com)
* [PayPal Payflow Pro](https://www.paypal.com/cgi-bin/webscr?cmd=_payflow-pro-overview-outside)
* [PayPal Payflow Pro Uk](https://www.paypal.com/uk/cgi-bin/webscr?cmd=_wp-pro-overview-outside)
* [Paypal Express Checkout](https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECGettingStarted)
@@ -4,6 +4,8 @@
namespace AktiveMerchant\Billing;
+use AktiveMerchant\Common\Inflect;
+
/**
*
* @package Aktive-Merchant
@@ -69,19 +71,11 @@ public static function is_test()
*/
public static function gateway($name=null, $options = array())
{
- $gateway = "\\AktiveMerchant\\Billing\\Gateways\\" . self::camelize($name);
+ $gateway = "\\AktiveMerchant\\Billing\\Gateways\\" . Inflect::camelize($name);
if (class_exists($gateway))
return new $gateway($options);
throw new Exception("Unable to load class: {$gateway}.");
}
-
- private static function camelize($string)
- {
- return str_replace(' ', '', ucwords(str_replace('_', ' ', $string)));
- }
-
-
-
}
@@ -13,6 +13,7 @@
use AktiveMerchant\Http\AdapterInterface;
use AktiveMerchant\Http\Adapter\cUrl;
use AktiveMerchant\Common\Options;
+use AktiveMerchant\Common\Inflect;
/**
* Gateway abstract class
@@ -123,7 +124,8 @@ public function homepage_url()
public function factory_name()
{
$class = str_replace('ActiveMerchant\\Billing\\Gateways\\', '', get_class($this));
- return $this->underscore($class);
+
+ return Inflect::underscore($class);
}
public function display_name()
@@ -396,11 +398,4 @@ protected function currency_lookup($code)
return false;
}
-
- private function underscore($string)
- {
- return strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $string));
- }
-
-
}
@@ -171,20 +171,36 @@ public function store(CreditCard $creditcard, $options=array())
* Creates a recurring billing subscription for a customer.
*
* Available options for period are: "Daily", "Weekly", "Fortnightly", "Monthly", "Quarterly", "Bi-Annually", "Annually"
+ *
* start_date can be a DateTime object a timestamp or a string the can be
* parsed via strtime function.
+ *
+ * customer_id can be a string with id returned when you created a customer (XXX-C-XXXXXXXX).
+ * if customer_id ommited then a new customer will be cteated.
+ *
+ * @param string $plan The plan id returned when you created a plan (XXX-PL-XXXXXXXX).
+ * @param CreditCard $creditcard
+ * @param array $options
+ *
+ * @access public
+ * @return void
*/
public function recurring($plan, CreditCard $creditcard, $options=array())
{
$this->post = array();
Options::required('first_name, last_name, email, customer_id, start_date, period', $options);
- //$response = $this->createCustomer($creditcard, $options);
-
$options = new Options($options);
+
+ if (null === $options->customer_id) {
+ $response = $this->createCustomer($creditcard, $options);
+ $customer_id = $response->params()->id;
+ } else {
+ $customer_id = $options->customer_id;
+ }
- $this->post['customer'] = '071-C-VN0XU40J'; //$response->params()->customer;
+ $this->post['customer'] = $customer_id;
$start_date = $options->start_date instanceof \DateTime ? $options->start_date : new \DateTime(strtotime($options->start_date));
$this->post['start_date'] = $start_date->format('Y-m-d');
$this->post['plan'] = $plan;
@@ -193,8 +209,6 @@ public function recurring($plan, CreditCard $creditcard, $options=array())
$this->post['reference'] = $options->customer_id;
return $this->commit('subscriptions');
-
-
}
public function cancelRecurring($subscription_id)
@@ -204,7 +218,6 @@ public function cancelRecurring($subscription_id)
$this->post['is_active'] = false;
return $this->commit("subscriptions/{$subscription_id}", RequestInterface::METHOD_PUT);
-
}
@@ -368,6 +381,7 @@ private function add_address($options)
$this->post['address'] = $address->getMappedFields();
}
+
/**
* Customer data like e-mail, ip, web browser used for transaction etc
*
@@ -388,7 +402,6 @@ private function add_customer_data($options)
}
}
-
/**
* Adds invoice info if exists.
*
@@ -54,7 +54,7 @@ public function address()
return array(
'name' => $this->params['SHIPTONAME'],
'address1' => $this->params['SHIPTOSTREET'],
- 'address2' => isset($this->params['SHIPTOSTREET2']) ? $this->params['SHIPTOSTREET2'] : null,
+ 'address2' => $this->params['SHIPTOSTREET2'],
'city' => $this->params['SHIPTOCITY'],
'state' => $this->params['SHIPTOSTATE'],
'zip' => $this->params['SHIPTOZIP'],
@@ -0,0 +1,18 @@
+<?php
+
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+namespace ActiveMerchant\Common;
+
+class Inflect()
+{
+ public static function camelize($string)
+ {
+ return str_replace(' ', '', ucwords(str_replace('_', ' ', $string)));
+ }
+
+ public function underscore($string)
+ {
+ return strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $string));
+ }
+}
@@ -355,7 +355,7 @@ public function testSuccessfulCreateCustomer()
$this->mock_request($this->successful_create_customer_response($options['customer_id']));
- $response = $this->gateway->createCustomer($this->creditcard,$options);
+ $response = $this->gateway->createCustomer($this->creditcard, $options);
$this->assert_success($response);
$this->assertTrue($response->test());
@@ -365,6 +365,8 @@ public function testSuccessfulCreateCustomer()
$this->successful_create_customer_request($options['customer_id']),
$request_body
);
+
+ $this->assertEquals('071-C-WG7M3QQ3', $response->params()->id);
}
private function successful_create_customer_response($user_id)
@@ -489,7 +491,7 @@ public function testSuccessSubscription()
$options = array(
'first_name' => 'Johny',
'last_name' => 'Doeing',
- 'customer_id' => "USER_" . $this->gateway->generateUniqueId(),
+ 'customer_id' => "071-C-VN0XU40J",
'email' => 'jonh.doing@example.com',
'start_date' => new \DateTime('tomorrow'),
'period' => 'Monthly',
@@ -521,7 +523,7 @@ public function testSuccessSubscription()
$this->assertTrue($response->test());
$this->assertTrue($response->params()->is_active);
- $this->assertEquals("Scheduled",$response->params()->last_status);
+ $this->assertEquals("Scheduled", $response->params()->last_status);
}
@@ -95,6 +95,79 @@ private function successful_setup_authorize_response()
return "TOKEN=EC%2d8LV868742E9298213&TIMESTAMP=2012%2d10%2d04T00%3a33%3a08Z&CORRELATIONID=b11ac5e2a3057&ACK=Success&VERSION=63%2e0&BUILD=3881757";
}
+ public function testGetDetailsForToken()
+ {
+
+ $this->mock_request($this->successful_get_details_for_token_response());
+
+ $token = 'EC-81B81448TC460182J';
+ $payer_id = '3L2BZTVKN8N7G';
+
+ $response = $this->gateway->get_details_for($token, $payer_id);
+
+ $request_body = $this->request->getBody();
+ $this->assertEquals(
+ $this->successful_get_details_for_token_request(),
+ $request_body
+ );
+
+ $this->assert_success($response);
+
+ $address = array(
+ 'name' => 'Andreas Kollaros',
+ 'address1' => '1234 Penny Lane',
+ 'address2' => '2nd Floor',
+ 'city' => 'Durham',
+ 'state' => 'NC',
+ 'zip' => '27701',
+ 'country_code' => 'US',
+ 'country' => 'United States',
+ 'address_status' => 'Confirmed',
+ );
+ $this->assertEquals($address, $response->address());
+ }
+
+ private function successful_get_details_for_token_request()
+ {
+ return "METHOD=GetExpressCheckoutDetails&TOKEN=EC-81B81448TC460182J&USER=x&PWD=y&VERSION=94.0&SIGNATURE=z&PAYMENTREQUEST_0_CURRENCYCODE=EUR";
+ }
+
+ private function successful_get_details_for_token_response()
+ {
+ return "TOKEN=EC%2d81B81448TC460182J&CHECKOUTSTATUS=PaymentActionNotInitiated&TIMESTAMP=2013%2d07%2d10T20%3a39%3a32Z&CORRELATIONID=ffb0d99d6c73e&ACK=Success&VERSION=94%2e0&BUILD=6825724&EMAIL=andreas%2ekollaros%2epersonal%40gmail%2ecom&PAYERID=3L2BZTVKN8N7G&PAYERSTATUS=verified&FIRSTNAME=Andreas&LASTNAME=Kollaros&COUNTRYCODE=GB&SHIPTONAME=Andreas%20Kollaros&SHIPTOSTREET=1234%20Penny%20Lane&SHIPTOSTREET2=2nd%20Floor&SHIPTOCITY=Durham&SHIPTOSTATE=NC&SHIPTOZIP=27701&SHIPTOCOUNTRYCODE=US&SHIPTOCOUNTRYNAME=United%20States&ADDRESSSTATUS=Confirmed&CURRENCYCODE=EUR&AMT=10%2e00&SHIPPINGAMT=0%2e00&HANDLINGAMT=0%2e00&TAXAMT=0%2e00&INSURANCEAMT=0%2e00&SHIPDISCAMT=0%2e00&PAYMENTREQUEST_0_CURRENCYCODE=EUR&PAYMENTREQUEST_0_AMT=10%2e00&PAYMENTREQUEST_0_SHIPPINGAMT=0%2e00&PAYMENTREQUEST_0_HANDLINGAMT=0%2e00&PAYMENTREQUEST_0_TAXAMT=0%2e00&PAYMENTREQUEST_0_INSURANCEAMT=0%2e00&PAYMENTREQUEST_0_SHIPDISCAMT=0%2e00&PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED=false&PAYMENTREQUEST_0_SHIPTONAME=Andreas%20Kollaros&PAYMENTREQUEST_0_SHIPTOSTREET=1234%20Penny%20Lane&PAYMENTREQUEST_0_SHIPTOSTREET2=2nd%20Floor&PAYMENTREQUEST_0_SHIPTOCITY=Durham&PAYMENTREQUEST_0_SHIPTOSTATE=NC&PAYMENTREQUEST_0_SHIPTOZIP=27701&PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=US&PAYMENTREQUEST_0_SHIPTOCOUNTRYNAME=United%20States&PAYMENTREQUEST_0_ADDRESSSTATUS=Confirmed&PAYMENTREQUESTINFO_0_ERRORCODE=0";
+ }
+
+ public function testAuthorize()
+ {
+
+ $this->mock_request($this->successful_authorize_response());
+
+ $amount = 10;
+ $token = 'EC-81B81448TC460182J';
+ $payer_id = '3L2BZTVKN8N7G';
+ $options = array('token' => $token, 'payer_id' => $payer_id);
+
+ $response = $this->gateway->authorize($amount, $options);
+
+ $request_body = $this->request->getBody();
+ $this->assertEquals(
+ $this->successful_authorize_request(),
+ $request_body
+ );
+
+ $this->assert_success($response);
+ }
+
+ private function successful_authorize_request()
+ {
+ return "METHOD=DoExpressCheckoutPayment&PAYMENTREQUEST_0_AMT=10.00&TOKEN=EC-81B81448TC460182J&PAYERID=3L2BZTVKN8N7G&USER=x&PWD=y&VERSION=94.0&SIGNATURE=z&PAYMENTREQUEST_0_CURRENCYCODE=EUR";
+ }
+
+ private function successful_authorize_response()
+ {
+ return "TOKEN=EC%2d81B81448TC460182J&SUCCESSPAGEREDIRECTREQUESTED=false&TIMESTAMP=2013%2d07%2d10T20%3a39%3a36Z&CORRELATIONID=39d0dd30dc347&ACK=Success&VERSION=94%2e0&BUILD=6825724&INSURANCEOPTIONSELECTED=false&SHIPPINGOPTIONISDEFAULT=false&PAYMENTINFO_0_TRANSACTIONID=7D898616SW447534J&PAYMENTINFO_0_TRANSACTIONTYPE=expresscheckout&PAYMENTINFO_0_PAYMENTTYPE=instant&PAYMENTINFO_0_ORDERTIME=2013%2d07%2d10T20%3a39%3a35Z&PAYMENTINFO_0_AMT=10%2e00&PAYMENTINFO_0_FEEAMT=0%2e69&PAYMENTINFO_0_TAXAMT=0%2e00&PAYMENTINFO_0_CURRENCYCODE=EUR&PAYMENTINFO_0_PAYMENTSTATUS=Completed&PAYMENTINFO_0_PENDINGREASON=None&PAYMENTINFO_0_REASONCODE=None&PAYMENTINFO_0_PROTECTIONELIGIBILITY=Eligible&PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE=ItemNotReceivedEligible%2cUnauthorizedPaymentEligible&PAYMENTINFO_0_SECUREMERCHANTACCOUNTID=XXXXXXXXXXXXX&PAYMENTINFO_0_ERRORCODE=0&PAYMENTINFO_0_ACK=Success";
+ }
+
public function testSetExpressPurchase()
{
$options = array(
@@ -199,7 +272,7 @@ private function successful_credit_request()
private function successful_credit_response()
{
- return "REFUNDTRANSACTIONID=98R99007WE150102S&FEEREFUNDAMT=1%2e33&GROSSREFUNDAMT=46%2e00&NETREFUNDAMT=44%2e67&CURRENCYCODE=USD&TOTALREFUNDEDAMOUNT=46%2e00&TIMESTAMP=2012%2d12%2d30T00%3a13%3a21Z&CORRELATIONID=b906e26f283d&ACK=Success&VERSION=94%2e0&BUILD=4181146&REFUNDSTATUS=Instant&PENDINGREASON=None";
+ return "REFUNDTRANSACTIONID=98R99007WE150102S&FEEREFUNDAMT=1%2e33&GROSSREFUNDAMT=46%2e00&NETREFUNDAMT=44%2e67&CURRENCYCODE=EUR&TOTALREFUNDEDAMOUNT=46%2e00&TIMESTAMP=2012%2d12%2d30T00%3a13%3a21Z&CORRELATIONID=b906e26f283d&ACK=Success&VERSION=94%2e0&BUILD=4181146&REFUNDSTATUS=Instant&PENDINGREASON=None";
}
@@ -53,3 +53,6 @@ url = 'http://127.0.0.1'
[fat_zebra]
username = 'TEST'
token = 'TEST'
+[vme]
+apikey = 'x'
+secret = 'y'

0 comments on commit f3a4bc2

Please sign in to comment.