Skip to content

Commit

Permalink
Merge pull request #811 from stripe/remi-creditnote-preview
Browse files Browse the repository at this point in the history
Add support for `CreditNote` preview.
  • Loading branch information
remi-stripe authored Nov 26, 2019
2 parents 140feae + bcf5647 commit 10a291e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions lib/CreditNote.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions tests/Stripe/CreditNoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 10a291e

Please sign in to comment.