From 1e2d53f0076241db5e830c4b00bbd82135ada51d Mon Sep 17 00:00:00 2001 From: Craig Christenson Date: Thu, 3 Apr 2014 16:48:23 -0400 Subject: [PATCH] Sandbox Support for admin API --- lib/Twocheckout.php | 7 +++++-- lib/Twocheckout/Api/TwocheckoutApi.php | 2 +- test/ChargeTest.php | 6 +++--- test/CouponTest.php | 8 ++++---- test/OptionTest.php | 12 +++++------ test/ProductTest.php | 12 +++++------ test/SaleTest.php | 28 +++++++++++++------------- 7 files changed, 39 insertions(+), 36 deletions(-) mode change 100644 => 100755 lib/Twocheckout.php mode change 100644 => 100755 lib/Twocheckout/Api/TwocheckoutApi.php mode change 100644 => 100755 test/ChargeTest.php mode change 100644 => 100755 test/CouponTest.php mode change 100644 => 100755 test/OptionTest.php mode change 100644 => 100755 test/ProductTest.php mode change 100644 => 100755 test/SaleTest.php diff --git a/lib/Twocheckout.php b/lib/Twocheckout.php old mode 100644 new mode 100755 index 2817756..a2d5504 --- a/lib/Twocheckout.php +++ b/lib/Twocheckout.php @@ -11,12 +11,15 @@ abstract class Twocheckout public static $apiUrl; public static $environment; public static $error; - const VERSION = '0.2.0'; + const VERSION = '0.2.1'; - static function setCredentials($user, $pass, $environment="production") + static function setCredentials($user, $pass, $mode='', $environment="production") { self::$user = $user; self::$pass = $pass; + if ($mode == 'sandbox') { + self::$apiBaseUrl = 'https://sandbox.2checkout.com/api/'; + } self::$environment = $environment; } diff --git a/lib/Twocheckout/Api/TwocheckoutApi.php b/lib/Twocheckout/Api/TwocheckoutApi.php old mode 100644 new mode 100755 index 7ff2194..f92fbe9 --- a/lib/Twocheckout/Api/TwocheckoutApi.php +++ b/lib/Twocheckout/Api/TwocheckoutApi.php @@ -36,7 +36,7 @@ function do_call($urlSuffix, $data=array()) if ($resp === FALSE) { throw new Twocheckout_Error("cURL call failed", "403"); } else { - return $resp; + return utf8_encode($resp); } } diff --git a/test/ChargeTest.php b/test/ChargeTest.php old mode 100644 new mode 100755 index 38353f7..4c60c8c --- a/test/ChargeTest.php +++ b/test/ChargeTest.php @@ -131,12 +131,12 @@ public function testChargeLink() public function testChargeAuth() { - Twocheckout::setApiCredentials('1817037', '9999999'); + Twocheckout::setApiCredentials('901248204', 'BE632CB0-BB29-11E3-AFB6-D99C28100996', 'sandbox'); try { $charge = Twocheckout_Charge::auth(array( - "sellerId" => "1817037", + "sellerId" => "901248204", "merchantOrderId" => "123", - "token" => 'Y2U2OTdlZjMtOGQzMi00MDdkLWJjNGQtMGJhN2IyOTdlN2Ni', + "token" => 'MjFiYzIzYjAtYjE4YS00ZmI0LTg4YzYtNDIzMTBlMjc0MDlk', "currency" => 'USD', "total" => '10.00', "billingAddr" => array( diff --git a/test/CouponTest.php b/test/CouponTest.php old mode 100644 new mode 100755 index 1e2432f..503205e --- a/test/CouponTest.php +++ b/test/CouponTest.php @@ -6,7 +6,7 @@ class TestCoupon extends PHPUnit_Framework_TestCase { public function setUp() { - Twocheckout::setCredentials("APIuser1817037", "APIpass1817037"); + Twocheckout::setCredentials("testlibraryapi901248204", "testlibraryapi901248204PASS", "sandbox"); } public function testCouponListRetrieve() @@ -34,17 +34,17 @@ public function testCouponCreate() public function testCouponRetrieve() { $params = array( - 'coupon_code' => "7EBHJFP" + 'coupon_code' => "1396528010" ); $coupon = Twocheckout_Coupon::retrieve($params, 'array'); - $this->assertEquals("7EBHJFP", $coupon['coupon']['coupon_code']); + $this->assertEquals("1396528010", $coupon['coupon']['coupon_code']); } public function testCouponUpdate() { $params = array( 'date_expire' => "2020-01-01", - 'coupon_code' => "7EBHJFP" + 'coupon_code' => "1396528010" ); $response = Twocheckout_Coupon::update($params, 'array'); $this->assertEquals("Coupon updated successfully", $response['response_message']); diff --git a/test/OptionTest.php b/test/OptionTest.php old mode 100644 new mode 100755 index 1ef8372..466f2aa --- a/test/OptionTest.php +++ b/test/OptionTest.php @@ -6,16 +6,16 @@ class TestOption extends PHPUnit_Framework_TestCase { public function setUp() { - Twocheckout::setCredentials("APIuser1817037", "APIpass1817037"); + Twocheckout::setCredentials("testlibraryapi901248204", "testlibraryapi901248204PASS", "sandbox"); } public function testOptionListRetrieve() { $params = array( - 'pagesize' => 20 + 'pagesize' => 2 ); $options = Twocheckout_Option::retrieve($params, 'array'); - $this->assertEquals(20, sizeof($options['options'])); + $this->assertEquals(2, sizeof($options['options'])); } public function testOptionCreate() @@ -34,17 +34,17 @@ public function testOptionCreate() public function testOptionRetrieve() { $params = array( - 'option_id' => 4774404362 + 'option_id' => 9093717691995 ); $product = Twocheckout_Option::retrieve($params, 'array'); - $this->assertEquals("4774404362", $product['option'][0]['option_id']); + $this->assertEquals("9093717691995", $product['option'][0]['option_id']); } public function testOptionUpdate() { $params = array( 'option_name' => "test1", - 'option_id' => 4774404362 + 'option_id' => 9093717691995 ); $response = Twocheckout_Option::update($params, 'array'); $this->assertEquals("Option updated successfully", $response['response_message']); diff --git a/test/ProductTest.php b/test/ProductTest.php old mode 100644 new mode 100755 index 650bed9..94116d7 --- a/test/ProductTest.php +++ b/test/ProductTest.php @@ -6,16 +6,16 @@ class TestProduct extends PHPUnit_Framework_TestCase { public function setUp() { - Twocheckout::setCredentials("APIuser1817037", "APIpass1817037"); + Twocheckout::setCredentials("testlibraryapi901248204", "testlibraryapi901248204PASS", "sandbox"); } public function testProductListRetrieve() { $params = array( - 'pagesize' => 20 + 'pagesize' => 2 ); $products = Twocheckout_Product::retrieve($params, 'array'); - $this->assertEquals(20, sizeof($products['products'])); + $this->assertEquals(2, sizeof($products['products'])); } public function testProductCreate() @@ -33,17 +33,17 @@ public function testProductCreate() public function testProductRetrieve() { $params = array( - 'product_id' => 4774387610 + 'product_id' => 9093717691932 ); $product = Twocheckout_Product::retrieve($params, 'array'); - $this->assertEquals("4774387610", $product['product']['product_id']); + $this->assertEquals("9093717691932", $product['product']['product_id']); } public function testProductUpdate() { $params = array( 'name' => "test", - 'product_id' => 4774387610 + 'product_id' => 9093717691932 ); $response = Twocheckout_Product::update($params, 'array'); $this->assertEquals("Product successfully updated", $response['response_message']); diff --git a/test/SaleTest.php b/test/SaleTest.php old mode 100644 new mode 100755 index b665666..050cc22 --- a/test/SaleTest.php +++ b/test/SaleTest.php @@ -5,31 +5,31 @@ class TestSale extends PHPUnit_Framework_TestCase public function setUp() { - Twocheckout::setCredentials("APIuser1817037", "APIpass1817037"); + Twocheckout::setCredentials("testlibraryapi901248204", "testlibraryapi901248204PASS", "sandbox"); } public function testSaleRetrieve() { $params = array( - 'sale_id' => 4774380224 + 'sale_id' => 9093717691800 ); $sale = Twocheckout_Sale::retrieve($params, 'array'); - $this->assertEquals("4774380224", $sale['sale']['sale_id']); + $this->assertEquals("9093717691800", $sale['sale']['sale_id']); } public function testSaleRetrieveList() { $params = array( - 'pagesize' => 20 + 'pagesize' => 2 ); $sale = Twocheckout_Sale::retrieve($params, 'array'); - $this->assertEquals(20, sizeof($sale['sale_summary'])); + $this->assertEquals(2, sizeof($sale['sale_summary'])); } public function testSaleRefundSale() { $params = array( - 'sale_id' => 4774380224, + 'sale_id' => 9093717691800, 'category' => 1, 'comment' => 'Order never sent.' ); @@ -37,14 +37,14 @@ public function testSaleRefundSale() $sale = Twocheckout_Sale::refund($params, 'array'); $this->assertEquals("OK", sizeof($sale['response_code'])); } catch (Twocheckout_Error $e) { - $this->assertEquals("Invoice too old to refund.", $e->getMessage()); + $this->assertEquals("Invoice was already refunded.", $e->getMessage()); } } public function testSaleRefundLineitem() { $params = array( - 'lineitem_id' => 4834917634, + 'lineitem_id' => 9093717693210, 'category' => 1, 'comment' => 'Order never sent.' ); @@ -59,7 +59,7 @@ public function testSaleRefundLineitem() public function testSaleStopSale() { $params = array( - 'sale_id' => 4834917619 + 'sale_id' => 9093717691800 ); try { $response = Twocheckout_Sale::stop($params, 'array'); @@ -72,7 +72,7 @@ public function testSaleStopSale() public function testSaleStopLineitem() { $params = array( - 'lineitem_id' => 4834917634 + 'lineitem_id' => 9093717693210 ); try { $response = Twocheckout_Sale::stop($params, 'array'); @@ -85,7 +85,7 @@ public function testSaleStopLineitem() public function testSaleActive() { $params = array( - 'sale_id' => 4834917619 + 'sale_id' => 9093717691800 ); try { $response = Twocheckout_Sale::active($params, 'array'); @@ -98,7 +98,7 @@ public function testSaleActive() public function testSaleComment() { $params = array( - 'sale_id' => 4774380224, + 'sale_id' => 9093717691800, 'sale_comment' => "test" ); $result = Twocheckout_Sale::comment($params, 'array'); @@ -108,7 +108,7 @@ public function testSaleComment() public function testSaleShip() { $params = array( - 'sale_id' => 4774380224, + 'sale_id' => 9093717691800, 'tracking_number' => "test" ); try { @@ -122,7 +122,7 @@ public function testSaleShip() public function testSaleReauth() { $params = array( - 'sale_id' => 4774380224 + 'sale_id' => 9093717691800 ); try { $result = Twocheckout_Sale::reauth($params, 'array');