From bcf56475f07f4a9bfd3eb0e9c0800f26cb093346 Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Tue, 26 Nov 2019 13:05:57 -0800 Subject: [PATCH] Add support for `CreditNote` preview. --- .travis.yml | 2 +- lib/CreditNote.php | 17 +++++++++++++++++ tests/Stripe/CreditNoteTest.php | 13 +++++++++++++ tests/bootstrap.php | 2 +- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3f848ebb8..7f5e9e4c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,7 +42,7 @@ matrix: env: global: - - STRIPE_MOCK_VERSION=0.72.0 + - STRIPE_MOCK_VERSION=0.76.0 cache: directories: - $HOME/.composer/cache/files diff --git a/lib/CreditNote.php b/lib/CreditNote.php index 93dc25a11..93d0a6dc7 100644 --- a/lib/CreditNote.php +++ b/lib/CreditNote.php @@ -58,6 +58,23 @@ class CreditNote extends ApiResource const TYPE_POST_PAYMENT = 'post_payment'; const TYPE_PRE_PAYMENT = 'pre_payment'; + /** + * @param array|null $params + * @param array|string|null $opts + * + * @throws \Stripe\Exception\ApiErrorException if the request fails + * + * @return CreditNote The previewed credit note. + */ + public static function preview($params = null, $opts = null) + { + $url = static::classUrl() . '/preview'; + list($response, $opts) = static::_staticRequest('get', $url, $params, $opts); + $obj = Util\Util::convertToStripeObject($response->json, $opts); + $obj->setLastResponse($response); + return $obj; + } + /** * @param array|null $params * @param array|string|null $opts diff --git a/tests/Stripe/CreditNoteTest.php b/tests/Stripe/CreditNoteTest.php index c05c811d9..2c57f46ee 100644 --- a/tests/Stripe/CreditNoteTest.php +++ b/tests/Stripe/CreditNoteTest.php @@ -65,6 +65,19 @@ public function testIsUpdatable() $this->assertInstanceOf(\Stripe\CreditNote::class, $resource); } + public function testCanPreview() + { + $this->expectsRequest( + 'get', + '/v1/credit_notes/preview' + ); + $resource = CreditNote::preview([ + 'amount' => 100, + 'invoice' => 'in_123', + ]); + $this->assertInstanceOf(\Stripe\CreditNote::class, $resource); + } + public function testCanVoidCreditNote() { $creditNote = CreditNote::retrieve(self::TEST_RESOURCE_ID); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 1cf3c9796..d1e26e430 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,7 +2,7 @@ require_once(__DIR__ . '/StripeMock.php'); -define("MOCK_MINIMUM_VERSION", "0.72.0"); +define("MOCK_MINIMUM_VERSION", "0.76.0"); if (\Stripe\StripeMock::start()) { register_shutdown_function('\Stripe\StripeMock::stop');