Skip to content

Commit

Permalink
Add support for /v1/topups endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkakar-stripe committed Feb 16, 2018
1 parent 702a3ee commit 7c07bfc
Show file tree
Hide file tree
Showing 6 changed files with 106 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.5.0
- STRIPE_MOCK_VERSION=0.8.0
matrix:
- AUTOLOAD=1
- AUTOLOAD=0
Expand Down
1 change: 1 addition & 0 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
require(dirname(__FILE__) . '/lib/SubscriptionItem.php');
require(dirname(__FILE__) . '/lib/ThreeDSecure.php');
require(dirname(__FILE__) . '/lib/Token.php');
require(dirname(__FILE__) . '/lib/Topup.php');
require(dirname(__FILE__) . '/lib/Transfer.php');
require(dirname(__FILE__) . '/lib/TransferReversal.php');

Expand Down
32 changes: 32 additions & 0 deletions lib/Topup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Stripe;

/**
* Class Topup
*
* @property string $id
* @property string $object
* @property int $amount
* @property string $balance_transaction
* @property int $created
* @property string $currency
* @property string $description
* @property int $expected_availability_date
* @property string $failure_code
* @property string $failure_message
* @property bool $livemode
* @property StripeObject $metadata
* @property mixed $source
* @property string $statement_descriptor
* @property string $status
*
* @package Stripe
*/
class Topup extends ApiResource
{
use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Retrieve;
use ApiOperations\Update;
}
1 change: 1 addition & 0 deletions lib/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public static function convertToStripeObject($resp, $opts)
'subscription_item' => 'Stripe\\SubscriptionItem',
'three_d_secure' => 'Stripe\\ThreeDSecure',
'token' => 'Stripe\\Token',
'topup' => 'Stripe\\Topup',
'transfer' => 'Stripe\\Transfer',
'transfer_reversal' => 'Stripe\\TransferReversal',
];
Expand Down
3 changes: 2 additions & 1 deletion tests/Stripe/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public function testIsCreatable()
'/v1/products'
);
$resource = Product::create([
'name' => 'name'
'name' => 'name',
'type' => 'good'
]);
$this->assertInstanceOf("Stripe\\Product", $resource);
}
Expand Down
69 changes: 69 additions & 0 deletions tests/Stripe/TopupTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Stripe;

class TopupTest extends TestCase
{
const TEST_RESOURCE_ID = 'tu_123';

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

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

public function testIsCreatable()
{
$this->expectsRequest(
'post',
'/v1/topups'
);
$resource = Topup::create([
"amount" => 100,
"currency" => "usd",
"source" => "tok_123",
"description" => "description",
"statement_descriptor" => "statement descriptor"
]);
$this->assertInstanceOf("Stripe\\Topup", $resource);
}

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

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

0 comments on commit 7c07bfc

Please sign in to comment.