Skip to content

Commit

Permalink
Sandbox Support for admin API
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Christenson committed Apr 3, 2014
1 parent 7fcb956 commit 1e2d53f
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 36 deletions.
7 changes: 5 additions & 2 deletions lib/Twocheckout.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Twocheckout/Api/TwocheckoutApi.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/ChargeTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions test/CouponTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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']);
Expand Down
12 changes: 6 additions & 6 deletions test/OptionTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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']);
Expand Down
12 changes: 6 additions & 6 deletions test/ProductTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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']);
Expand Down
28 changes: 14 additions & 14 deletions test/SaleTest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,46 @@ 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.'
);
try {
$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.'
);
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -108,7 +108,7 @@ public function testSaleComment()
public function testSaleShip()
{
$params = array(
'sale_id' => 4774380224,
'sale_id' => 9093717691800,
'tracking_number' => "test"
);
try {
Expand All @@ -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');
Expand Down

0 comments on commit 1e2d53f

Please sign in to comment.