Skip to content

Commit

Permalink
Add support for Radar List and ListItem resources
Browse files Browse the repository at this point in the history
  • Loading branch information
remi-stripe committed Nov 12, 2018
1 parent 77eb5bb commit bd5e99b
Show file tree
Hide file tree
Showing 8 changed files with 196 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.35.0
- STRIPE_MOCK_VERSION=0.37.0
matrix:
- AUTOLOAD=1
- AUTOLOAD=0
Expand Down
2 changes: 2 additions & 0 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
require(dirname(__FILE__) . '/lib/Person.php');
require(dirname(__FILE__) . '/lib/Plan.php');
require(dirname(__FILE__) . '/lib/Product.php');
require(dirname(__FILE__) . '/lib/Radar/ValueList.php');
require(dirname(__FILE__) . '/lib/Radar/ValueListItem.php');
require(dirname(__FILE__) . '/lib/Recipient.php');
require(dirname(__FILE__) . '/lib/RecipientTransfer.php');
require(dirname(__FILE__) . '/lib/Refund.php');
Expand Down
32 changes: 32 additions & 0 deletions lib/Radar/ValueList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Stripe\Radar;

/**
* Class ValueList
*
* @property string $id
* @property string $object
* @property string $alias
* @property int $created
* @property string $created_by
* @property string $item_type
* @property Collection $list_items
* @property bool $livemode
* @property StripeObject $metadata
* @property mixed $name
* @property int $updated
* @property string $updated_by
*
* @package Stripe\Radar
*/
class ValueList extends \Stripe\ApiResource
{
const OBJECT_NAME = "radar.value_list";

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

namespace Stripe\Radar;

/**
* Class ValueListItem
*
* @property string $id
* @property string $object
* @property int $created
* @property string $created_by
* @property string $list
* @property bool $livemode
* @property string $value
*
* @package Stripe\Radar
*/
class ValueListItem extends \Stripe\ApiResource
{
const OBJECT_NAME = "radar.value_list_item";

use \Stripe\ApiOperations\All;
use \Stripe\ApiOperations\Create;
use \Stripe\ApiOperations\Delete;
use \Stripe\ApiOperations\Retrieve;
}
2 changes: 2 additions & 0 deletions lib/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public static function convertToStripeObject($resp, $opts)
\Stripe\Person::OBJECT_NAME => 'Stripe\\Person',
\Stripe\Plan::OBJECT_NAME => 'Stripe\\Plan',
\Stripe\Product::OBJECT_NAME => 'Stripe\\Product',
\Stripe\Radar\ValueList::OBJECT_NAME => 'Stripe\\Radar\\ValueList',
\Stripe\Radar\ValueListItem::OBJECT_NAME => 'Stripe\\Radar\\ValueListItem',
\Stripe\Recipient::OBJECT_NAME => 'Stripe\\Recipient',
\Stripe\RecipientTransfer::OBJECT_NAME => 'Stripe\\RecipientTransfer',
\Stripe\Refund::OBJECT_NAME => 'Stripe\\Refund',
Expand Down
55 changes: 55 additions & 0 deletions tests/Stripe/Radar/ValueListItemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Stripe\Radar;

class ValueListItemTest extends \Stripe\TestCase
{
const TEST_RESOURCE_ID = 'rsli_123';

public function testIsListable()
{
$this->expectsRequest(
'get',
'/v1/radar/value_list_items'
);
$resources = ValueListItem::all([
"value_list" => "rsl_123",
]);
$this->assertTrue(is_array($resources->data));
$this->assertInstanceOf("Stripe\\Radar\\ValueListItem", $resources->data[0]);
}

public function testIsRetrievable()
{
$this->expectsRequest(
'get',
'/v1/radar/value_list_items/' . self::TEST_RESOURCE_ID
);
$resource = ValueListItem::retrieve(self::TEST_RESOURCE_ID);
$this->assertInstanceOf("Stripe\\Radar\\ValueListItem", $resource);
}

public function testIsCreatable()
{
$this->expectsRequest(
'post',
'/v1/radar/value_list_items'
);
$resource = ValueListItem::create([
"value_list" => "rsl_123",
"value" => "value",
]);
$this->assertInstanceOf("Stripe\\Radar\\ValueListItem", $resource);
}

public function testIsDeletable()
{
$resource = ValueListItem::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'delete',
'/v1/radar/value_list_items/' . self::TEST_RESOURCE_ID
);
$resource->delete();
$this->assertInstanceOf("Stripe\\Radar\\ValueListItem", $resource);
}
}
77 changes: 77 additions & 0 deletions tests/Stripe/Radar/ValueListTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace Stripe\Radar;

class ValueListTest extends \Stripe\TestCase
{
const TEST_RESOURCE_ID = 'rsl_123';

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

public function testIsRetrievable()
{
$this->expectsRequest(
'get',
'/v1/radar/value_lists/' . self::TEST_RESOURCE_ID
);
$resource = ValueList::retrieve(self::TEST_RESOURCE_ID);
$this->assertInstanceOf("Stripe\\Radar\\ValueList", $resource);
}

public function testIsCreatable()
{
$this->expectsRequest(
'post',
'/v1/radar/value_lists'
);
$resource = ValueList::create([
"alias" => "alias",
"name" => "name",
]);
$this->assertInstanceOf("Stripe\\Radar\\ValueList", $resource);
}

public function testIsSaveable()
{
$resource = ValueList::retrieve(self::TEST_RESOURCE_ID);
$resource->metadata["key"] = "value";
$this->expectsRequest(
'post',
'/v1/radar/value_lists/' . self::TEST_RESOURCE_ID
);
$resource->save();
$this->assertInstanceOf("Stripe\\Radar\\ValueList", $resource);
}

public function testIsUpdatable()
{
$this->expectsRequest(
'post',
'/v1/radar/value_lists/' . self::TEST_RESOURCE_ID
);
$resource = ValueList::update(self::TEST_RESOURCE_ID, [
"metadata" => ["key" => "value"],
]);
$this->assertInstanceOf("Stripe\\Radar\\ValueList", $resource);
}

public function testIsDeletable()
{
$resource = ValueList::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'delete',
'/v1/radar/value_lists/' . self::TEST_RESOURCE_ID
);
$resource->delete();
$this->assertInstanceOf("Stripe\\Radar\\ValueList", $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.35.0");
define("MOCK_MINIMUM_VERSION", "0.37.0");
define("MOCK_PORT", getenv("STRIPE_MOCK_PORT") ?: 12111);

// Send a request to stripe-mock
Expand Down

0 comments on commit bd5e99b

Please sign in to comment.