Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for CreditNote preview. #811

Merged
merged 1 commit into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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