diff --git a/.travis.yml b/.travis.yml index e8be80ce5..806d56a22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ php: env: global: - - STRIPE_MOCK_VERSION=0.57.0 + - STRIPE_MOCK_VERSION=0.58.0 matrix: - AUTOLOAD=1 - AUTOLOAD=0 diff --git a/init.php b/init.php index d476e32d2..e3cb473bd 100644 --- a/init.php +++ b/init.php @@ -76,6 +76,7 @@ require(dirname(__FILE__) . '/lib/Coupon.php'); require(dirname(__FILE__) . '/lib/CreditNote.php'); require(dirname(__FILE__) . '/lib/Customer.php'); +require(dirname(__FILE__) . '/lib/CustomerBalanceTransaction.php'); require(dirname(__FILE__) . '/lib/Discount.php'); require(dirname(__FILE__) . '/lib/Dispute.php'); require(dirname(__FILE__) . '/lib/EphemeralKey.php'); diff --git a/lib/CreditNote.php b/lib/CreditNote.php index 169ed0815..66351ffb8 100644 --- a/lib/CreditNote.php +++ b/lib/CreditNote.php @@ -8,6 +8,7 @@ * @property string $id * @property string $object * @property int $amount + * @property string $customer_balance_transaction * @property int $created * @property string $currency * @property string $customer diff --git a/lib/Customer.php b/lib/Customer.php index acb5c3131..6e78f981e 100644 --- a/lib/Customer.php +++ b/lib/Customer.php @@ -7,8 +7,8 @@ * * @property string $id * @property string $object - * @property int $account_balance * @property mixed $address + * @property int $balance * @property string $created * @property string $currency * @property string $default_source @@ -62,6 +62,7 @@ public static function getSavedNestedResources() return $savedNestedResources; } + const PATH_BALANCE_TRANSACTIONS = '/balance_transactions'; const PATH_SOURCES = '/sources'; const PATH_TAX_IDS = '/tax_ids'; @@ -265,4 +266,55 @@ public static function allTaxIds($id, $params = null, $opts = null) { return self::_allNestedResources($id, static::PATH_TAX_IDS, $params, $opts); } + + /** + * @param string|null $id The ID of the customer on which to create the balance transaction. + * @param array|null $params + * @param array|string|null $opts + * + * @return ApiResource + */ + public static function createBalanceTransaction($id, $params = null, $opts = null) + { + return self::_createNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $params, $opts); + } + + /** + * @param string|null $id The ID of the customer to which the balance transaction belongs. + * @param string|null $balanceTransactionId The ID of the balance transaction to retrieve. + * @param array|null $params + * @param array|string|null $opts + * + * @return ApiResource + */ + public static function retrieveBalanceTransaction($id, $balanceTransactionId, $params = null, $opts = null) + { + return self::_retrieveNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $balanceTransactionId, $params, $opts); + } + + /** + * @param string|null $id The ID of the customer on which to update the balance transaction. + * @param string|null $balanceTransactionId The ID of the balance transaction to update. + * @param array|null $params + * @param array|string|null $opts + * + * + * @return ApiResource + */ + public static function updateBalanceTransaction($id, $balanceTransactionId, $params = null, $opts = null) + { + return self::_updateNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $balanceTransactionId, $params, $opts); + } + + /** + * @param string|null $id The ID of the customer on which to retrieve the customer balance transactions. + * @param array|null $params + * @param array|string|null $opts + * + * @return Collection The list of customer balance transactions. + */ + public static function allBalanceTransactions($id, $params = null, $opts = null) + { + return self::_allNestedResources($id, static::PATH_BALANCE_TRANSACTIONS, $params, $opts); + } } diff --git a/lib/CustomerBalanceTransaction.php b/lib/CustomerBalanceTransaction.php new file mode 100644 index 000000000..e128a33dc --- /dev/null +++ b/lib/CustomerBalanceTransaction.php @@ -0,0 +1,88 @@ + 'Stripe\\Coupon', \Stripe\CreditNote::OBJECT_NAME => 'Stripe\\CreditNote', \Stripe\Customer::OBJECT_NAME => 'Stripe\\Customer', + \Stripe\CustomerBalanceTransaction::OBJECT_NAME => 'Stripe\\CustomerBalanceTransaction', \Stripe\Discount::OBJECT_NAME => 'Stripe\\Discount', \Stripe\Dispute::OBJECT_NAME => 'Stripe\\Dispute', \Stripe\EphemeralKey::OBJECT_NAME => 'Stripe\\EphemeralKey', diff --git a/tests/Stripe/CustomerBalanceTransactionTest.php b/tests/Stripe/CustomerBalanceTransactionTest.php new file mode 100644 index 000000000..817a46899 --- /dev/null +++ b/tests/Stripe/CustomerBalanceTransactionTest.php @@ -0,0 +1,18 @@ +assertSame( + "/v1/customers/" . self::TEST_CUSTOMER_ID . "/balance_transactions/" . self::TEST_RESOURCE_ID, + $resource->instanceUrl() + ); + } +} diff --git a/tests/Stripe/CustomerTest.php b/tests/Stripe/CustomerTest.php index 1defcbfa4..3b1eeadbe 100644 --- a/tests/Stripe/CustomerTest.php +++ b/tests/Stripe/CustomerTest.php @@ -7,6 +7,7 @@ class CustomerTest extends TestCase const TEST_RESOURCE_ID = 'cus_123'; const TEST_SOURCE_ID = 'ba_123'; const TEST_TAX_ID_ID = 'txi_123'; + const TEST_CUSTOMER_BALANCE_TRANSACTION_ID = 'cbtxn_123'; public function testIsListable() { @@ -304,4 +305,44 @@ public function testCanListTaxIds() $resources = Customer::allTaxIds(self::TEST_RESOURCE_ID); $this->assertTrue(is_array($resources->data)); } + + public function testCanCreateBalanceTransaction() + { + $this->expectsRequest( + 'post', + '/v1/customers/' . self::TEST_RESOURCE_ID . '/balance_transactions' + ); + $resource = Customer::createBalanceTransaction(self::TEST_RESOURCE_ID, [ + "amount" => 1234, + "currency" => "usd", + ]); + } + + public function testCanRetrieveBalanceTransaction() + { + $this->expectsRequest( + 'get', + '/v1/customers/' . self::TEST_RESOURCE_ID . '/balance_transactions/' . self::TEST_CUSTOMER_BALANCE_TRANSACTION_ID + ); + $resource = Customer::retrieveBalanceTransaction(self::TEST_RESOURCE_ID, self::TEST_CUSTOMER_BALANCE_TRANSACTION_ID); + } + + public function testCanUpdateBalanceTransaction() + { + $this->expectsRequest( + 'post', + '/v1/customers/' . self::TEST_RESOURCE_ID . '/balance_transactions/' . self::TEST_CUSTOMER_BALANCE_TRANSACTION_ID + ); + $resource = Customer::updateBalanceTransaction(self::TEST_RESOURCE_ID, self::TEST_CUSTOMER_BALANCE_TRANSACTION_ID, ["description" => "new"]); + } + + public function testCanListCustomerBalanceTransactions() + { + $this->expectsRequest( + 'get', + '/v1/customers/' . self::TEST_RESOURCE_ID . '/balance_transactions' + ); + $resources = Customer::allBalanceTransactions(self::TEST_RESOURCE_ID); + $this->assertTrue(is_array($resources->data)); + } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index a7efedc7f..4f1c1ad10 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,7 +2,7 @@ require_once(__DIR__ . '/StripeMock.php'); -define("MOCK_MINIMUM_VERSION", "0.57.0"); +define("MOCK_MINIMUM_VERSION", "0.58.0"); if (\Stripe\StripeMock::start()) { register_shutdown_function('\Stripe\StripeMock::stop');