Skip to content

Commit

Permalink
Bindings for Terminal endpoints (#523)
Browse files Browse the repository at this point in the history
* Bindings for Terminal endpoints

* Linting fixes

* Bump StripeMock version

* connection_token property -> secret
  • Loading branch information
daz-stripe authored and brandur-stripe committed Sep 24, 2018
1 parent 6f226e4 commit 514eaf8
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ php:

env:
global:
- STRIPE_MOCK_VERSION=0.32.0
- STRIPE_MOCK_VERSION=0.33.0
matrix:
- AUTOLOAD=1
- AUTOLOAD=0
Expand Down
3 changes: 3 additions & 0 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
require(dirname(__FILE__) . '/lib/SourceTransaction.php');
require(dirname(__FILE__) . '/lib/Subscription.php');
require(dirname(__FILE__) . '/lib/SubscriptionItem.php');
require(dirname(__FILE__) . '/lib/Terminal/ConnectionToken.php');
require(dirname(__FILE__) . '/lib/Terminal/Location.php');
require(dirname(__FILE__) . '/lib/Terminal/Reader.php');
require(dirname(__FILE__) . '/lib/ThreeDSecure.php');
require(dirname(__FILE__) . '/lib/Token.php');
require(dirname(__FILE__) . '/lib/Topup.php');
Expand Down
17 changes: 17 additions & 0 deletions lib/Terminal/ConnectionToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Stripe\Terminal;

/**
* Class ConnectionToken
*
* @property string $secret
*
* @package Stripe\Terminal
*/
class ConnectionToken extends \Stripe\ApiResource
{
const OBJECT_NAME = "terminal.connection_token";

use \Stripe\ApiOperations\Create;
}
28 changes: 28 additions & 0 deletions lib/Terminal/Location.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Stripe\Terminal;

/**
* Class Location
*
* @property string $id
* @property string $object
* @property string $display_name
* @property string $address_city
* @property string $address_country
* @property string $address_line1
* @property string $address_line2
* @property string $address_state
* @property string $address_postal_code
*
* @package Stripe\Terminal
*/
class Location extends \Stripe\ApiResource
{
const OBJECT_NAME = "terminal.location";

use \Stripe\ApiOperations\All;
use \Stripe\ApiOperations\Create;
use \Stripe\ApiOperations\Retrieve;
use \Stripe\ApiOperations\Update;
}
25 changes: 25 additions & 0 deletions lib/Terminal/Reader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Stripe\Terminal;

/**
* Class Reader
*
* @property string $id
* @property string $object
* @property string $device_type
* @property string $serial_number
* @property string $label
* @property string $ip_address
*
* @package Stripe\Terminal
*/
class Reader extends \Stripe\ApiResource
{
const OBJECT_NAME = "terminal.reader";

use \Stripe\ApiOperations\All;
use \Stripe\ApiOperations\Create;
use \Stripe\ApiOperations\Retrieve;
use \Stripe\ApiOperations\Update;
}
3 changes: 3 additions & 0 deletions lib/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public static function convertToStripeObject($resp, $opts)
\Stripe\Subscription::OBJECT_NAME => 'Stripe\\Subscription',
\Stripe\SubscriptionItem::OBJECT_NAME => 'Stripe\\SubscriptionItem',
\Stripe\ThreeDSecure::OBJECT_NAME => 'Stripe\\ThreeDSecure',
\Stripe\Terminal\ConnectionToken::OBJECT_NAME => 'Stripe\\Terminal\\ConnectionToken',
\Stripe\Terminal\Location::OBJECT_NAME => 'Stripe\\Terminal\\Location',
\Stripe\Terminal\Reader::OBJECT_NAME => 'Stripe\\Terminal\\Reader',
\Stripe\Token::OBJECT_NAME => 'Stripe\\Token',
\Stripe\Topup::OBJECT_NAME => 'Stripe\\Topup',
\Stripe\Transfer::OBJECT_NAME => 'Stripe\\Transfer',
Expand Down
16 changes: 16 additions & 0 deletions tests/Stripe/Terminal/ConnectionTokenTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Stripe\Terminal;

class ConnectionTokenTest extends \Stripe\TestCase
{
public function testIsCreatable()
{
$this->expectsRequest(
'post',
'/v1/terminal/connection_tokens'
);
$resource = ConnectionToken::create();
$this->assertInstanceOf("Stripe\\Terminal\\ConnectionToken", $resource);
}
}
84 changes: 84 additions & 0 deletions tests/Stripe/Terminal/LocationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace Stripe\Terminal;

class LocationTest extends \Stripe\TestCase
{
const TEST_RESOURCE_ID = 'loc_123';

public function testIsListable()
{
$this->expectsRequest(
'get',
'/v1/terminal/locations'
);
$resources = Location::all();
$this->assertTrue(is_array($resources->data));
$this->assertInstanceOf("Stripe\\Terminal\\Location", $resources->data[0]);
}

public function testIsRetrievable()
{
$this->expectsRequest(
'get',
'/v1/terminal/locations/' . self::TEST_RESOURCE_ID
);
$resource = Location::retrieve(self::TEST_RESOURCE_ID);
$this->assertInstanceOf("Stripe\\Terminal\\Location", $resource);
}

public function testIsSaveable()
{
$resource = Location::retrieve(self::TEST_RESOURCE_ID);
$resource->display_name = "new-name";

$this->expectsRequest(
'post',
'/v1/terminal/locations/' . self::TEST_RESOURCE_ID
);
$resource->save();
$this->assertInstanceOf("Stripe\\Terminal\\Location", $resource);
}

public function testIsUpdatable()
{
$this->expectsRequest(
'post',
'/v1/terminal/locations/' . self::TEST_RESOURCE_ID,
["display_name" => "new-name"]
);
$resource = Location::update(self::TEST_RESOURCE_ID, [
"display_name" => "new-name",
]);
$this->assertInstanceOf("Stripe\\Terminal\\Location", $resource);
}

public function testIsCreatable()
{
$this->expectsRequest(
'post',
'/v1/terminal/locations',
[
"display_name" => "name",
"address" => [
"line1" => "line1",
"country" => "US",
"state" => "CA",
"postal_code" => "12345",
"city" => "San Francisco"
]
]
);
$resource = Location::create([
"display_name" => "name",
"address" => [
"line1" => "line1",
"country" => "US",
"state" => "CA",
"postal_code" => "12345",
"city" => "San Francisco"
]
]);
$this->assertInstanceOf("Stripe\\Terminal\\Location", $resource);
}
}
66 changes: 66 additions & 0 deletions tests/Stripe/Terminal/ReaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Stripe\Terminal;

class ReaderTest extends \Stripe\TestCase
{
const TEST_RESOURCE_ID = 'rdr_123';

public function testIsListable()
{
$this->expectsRequest(
'get',
'/v1/terminal/readers'
);
$resources = Reader::all();
$this->assertTrue(is_array($resources->data));
$this->assertInstanceOf("Stripe\\Terminal\\Reader", $resources->data[0]);
}

public function testIsRetrievable()
{
$this->expectsRequest(
'get',
'/v1/terminal/readers/' . self::TEST_RESOURCE_ID
);
$resource = Reader::retrieve(self::TEST_RESOURCE_ID);
$this->assertInstanceOf("Stripe\\Terminal\\Reader", $resource);
}

public function testIsSaveable()
{
$resource = Reader::retrieve(self::TEST_RESOURCE_ID);
$resource->label = "new-name";

$this->expectsRequest(
'post',
'/v1/terminal/readers/' . self::TEST_RESOURCE_ID
);
$resource->save();
$this->assertInstanceOf("Stripe\\Terminal\\Reader", $resource);
}

public function testIsUpdatable()
{
$this->expectsRequest(
'post',
'/v1/terminal/readers/' . self::TEST_RESOURCE_ID,
["label" => "new-name"]
);
$resource = Reader::update(self::TEST_RESOURCE_ID, [
"label" => "new-name",
]);
$this->assertInstanceOf("Stripe\\Terminal\\Reader", $resource);
}

public function testIsCreatable()
{
$this->expectsRequest(
'post',
'/v1/terminal/readers',
["registration_code" => "a-b-c"]
);
$resource = Reader::create(['registration_code' => 'a-b-c']);
$this->assertInstanceOf("Stripe\\Terminal\\Reader", $resource);
}
}
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

define("MOCK_MINIMUM_VERSION", "0.32.0");
define("MOCK_MINIMUM_VERSION", "0.33.0");
define("MOCK_PORT", getenv("STRIPE_MOCK_PORT") ?: 12111);

// Send a request to stripe-mock
Expand Down

0 comments on commit 514eaf8

Please sign in to comment.