Skip to content

Commit

Permalink
Merge pull request #537 from stripe/remi-add-invoice-methods
Browse files Browse the repository at this point in the history
Add new methods to the Invoice
  • Loading branch information
remi-stripe authored Nov 9, 2018
2 parents d9e9b35 + 80f7b0e commit 7119f72
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 8 deletions.
70 changes: 65 additions & 5 deletions lib/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
* @property string $billing
* @property string $billing_reason
* @property string $charge
* @property bool $closed
* @property string $currency
* @property string $customer
* @property int $date
* @property string $description
* @property Discount $discount
* @property int $due_date
* @property int $ending_balance
* @property bool $forgiven
* @property string $hosted_invoice_url
* @property string $invoice_pdf
* @property int $last_payment_attempt
* @property Collection $lines
* @property bool $livemode
* @property StripeObject $metadata
Expand All @@ -39,6 +38,7 @@
* @property string $receipt_number
* @property int $starting_balance
* @property string $statement_descriptor
* @property string $status
* @property string $subscription
* @property int $subscription_proration_date
* @property int $subtotal
Expand All @@ -56,9 +56,66 @@ class Invoice extends ApiResource

use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Delete;
use ApiOperations\Retrieve;
use ApiOperations\Update;

/**
* @param array|null $params
* @param array|string|null $opts
*
* @return Invoice The finalized invoice.
*/
public function finalizeInvoice($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/finalize';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}

/**
* @param array|null $params
* @param array|string|null $opts
*
* @return Invoice The uncollectible invoice.
*/
public function markUncollectible($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/mark_uncollectible';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}

/**
* @param array|null $params
* @param array|string|null $opts
*
* @return Invoice The paid invoice.
*/
public function pay($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/pay';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}

/**
* @param array|null $params
* @param array|string|null $opts
*
* @return Invoice The sent invoice.
*/
public function sendInvoice($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/send';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
}

/**
* @param array|null $params
* @param array|string|null $opts
Expand All @@ -75,11 +132,14 @@ public static function upcoming($params = null, $opts = null)
}

/**
* @return Invoice The paid invoice.
* @param array|null $params
* @param array|string|null $opts
*
* @return Invoice The voided invoice.
*/
public function pay($params = null, $opts = null)
public function voidInvoice($params = null, $opts = null)
{
$url = $this->instanceUrl() . '/pay';
$url = $this->instanceUrl() . '/void';
list($response, $opts) = $this->_request('post', $url, $params, $opts);
$this->refreshFrom($response, $opts);
return $this;
Expand Down
65 changes: 62 additions & 3 deletions tests/Stripe/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,53 @@ public function testIsUpdatable()
$this->assertInstanceOf("Stripe\\Invoice", $resource);
}

public function testIsDeletable()
{
$resource = Invoice::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'delete',
'/v1/invoices/' . self::TEST_RESOURCE_ID
);
$resource->delete();
$this->assertInstanceOf("Stripe\\Invoice", $resource);
}

public function testCanFinalizeInvoice()
{
$invoice = Invoice::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'post',
'/v1/invoices/' . $invoice->id . '/finalize'
);
$resource = $invoice->finalizeInvoice();
$this->assertInstanceOf("Stripe\\Invoice", $resource);
$this->assertSame($resource, $invoice);
}

public function testCanMarkUncollectible()
{
$invoice = Invoice::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'post',
'/v1/invoices/' . $invoice->id . '/mark_uncollectible'
);
$resource = $invoice->markUncollectible();
$this->assertInstanceOf("Stripe\\Invoice", $resource);
$this->assertSame($resource, $invoice);
}

public function testCanPay()
{
$invoice = Invoice::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'post',
'/v1/invoices/' . $invoice->id . '/pay'
);
$resource = $invoice->pay();
$this->assertInstanceOf("Stripe\\Invoice", $resource);
$this->assertSame($resource, $invoice);
}

public function testCanRetrieveUpcoming()
{
$this->expectsRequest(
Expand All @@ -73,14 +120,26 @@ public function testCanRetrieveUpcoming()
$this->assertInstanceOf("Stripe\\Invoice", $resource);
}

public function testIsPayable()
public function testCanSendInvoice()
{
$invoice = Invoice::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'post',
'/v1/invoices/' . $invoice->id . '/pay'
'/v1/invoices/' . $invoice->id . '/send'
);
$resource = $invoice->pay();
$resource = $invoice->sendInvoice();
$this->assertInstanceOf("Stripe\\Invoice", $resource);
$this->assertSame($resource, $invoice);
}

public function testCanVoidInvoice()
{
$invoice = Invoice::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'post',
'/v1/invoices/' . $invoice->id . '/void'
);
$resource = $invoice->voidInvoice();
$this->assertInstanceOf("Stripe\\Invoice", $resource);
$this->assertSame($resource, $invoice);
}
Expand Down

0 comments on commit 7119f72

Please sign in to comment.