Skip to content

Commit

Permalink
Add namespaced service
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Mar 9, 2020
1 parent 2a7ae8e commit b8ba85f
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 0 deletions.
1 change: 1 addition & 0 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,5 @@
require __DIR__ . '/lib/Service/AbstractService.php';
require __DIR__ . '/lib/Service/CouponService.php';
require __DIR__ . '/lib/Service/FileService.php';
require __DIR__ . '/lib/Service/Issuing/CardService.php';
require __DIR__ . '/lib/Service/PaymentIntentService.php';
79 changes: 79 additions & 0 deletions lib/Service/Issuing/CardService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace Stripe\Service\Issuing;

class CardService extends \Stripe\Service\AbstractService
{
public function basePath()
{
return '/v1/issuing/cards';
}

/**
* List all cards.
*
* @param array $params
* @param array $opts
*
* @return \Stripe\Collection
*/
public function all($params = [], $opts = [])
{
return $this->allObjects($params, $opts);
}

/**
* Create a card.
*
* @param array $params
* @param array $opts
*
* @return \Stripe\Issuing\Card
*/
public function create($params = [], $opts = [])
{
return $this->createObject($params, $opts);
}

/**
* Retrieve a card details.
*
* @param string $id
* @param array $params
* @param array $opts
*
* @return \Stripe\Issuing\CardDetails
*/
public function details($id, $params = [], $opts = [])
{
return $this->request('get', $this->instancePath($id) . '/details', $params, $opts);
}

/**
* Retrieve a card.
*
* @param string $id
* @param array $params
* @param array $opts
*
* @return \Stripe\Issuing\Card
*/
public function retrieve($id, $params = [], $opts = [])
{
return $this->retrieveObject($id, $params, $opts);
}

/**
* Update a card.
*
* @param string $id
* @param array $params
* @param array $opts
*
* @return \Stripe\Issuing\Card
*/
public function update($id, $params = [], $opts = [])
{
return $this->updateObject($id, $params, $opts);
}
}
81 changes: 81 additions & 0 deletions tests/Stripe/Service/Issuing/CardServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Stripe\Service\Issuing;

/**
* @internal
*/
final class CardServiceTest extends \PHPUnit\Framework\TestCase
{
use \Stripe\TestHelper;

const TEST_RESOURCE_ID = 'ic_123';

private $client;
private $service;

/**
* @before
*/
protected function setUpService()
{
$this->client = new \Stripe\StripeClient('sk_test_123', null, MOCK_URL);
$this->service = new CardService($this->client);
}

public function testAll()
{
$this->expectsRequest(
'get',
'/v1/issuing/cards'
);
$resources = $this->service->all();
static::assertInternalType('array', $resources->data);
static::assertInstanceOf(\Stripe\Issuing\Card::class, $resources->data[0]);
}

public function testCreate()
{
$this->expectsRequest(
'post',
'/v1/issuing/cards'
);
$resource = $this->service->create([
'currency' => 'usd',
'type' => 'physical',
]);
static::assertInstanceOf(\Stripe\Issuing\Card::class, $resource);
}

public function testDetails()
{
$this->expectsRequest(
'get',
'/v1/issuing/cards/' . self::TEST_RESOURCE_ID . '/details'
);
$resource = $this->service->details(self::TEST_RESOURCE_ID);
static::assertInstanceOf(\Stripe\Issuing\CardDetails::class, $resource);
}

public function testRetrieve()
{
$this->expectsRequest(
'get',
'/v1/issuing/cards/' . self::TEST_RESOURCE_ID
);
$resource = $this->service->retrieve(self::TEST_RESOURCE_ID);
static::assertInstanceOf(\Stripe\Issuing\Card::class, $resource);
}

public function testUpdate()
{
$this->expectsRequest(
'post',
'/v1/issuing/cards/' . self::TEST_RESOURCE_ID
);
$resource = $this->service->update(self::TEST_RESOURCE_ID, [
'metadata' => ['key' => 'value'],
]);
static::assertInstanceOf(\Stripe\Issuing\Card::class, $resource);
}
}

0 comments on commit b8ba85f

Please sign in to comment.