diff --git a/lib/Invoice.php b/lib/Invoice.php index 14aa9ca7e..6352ae7b4 100644 --- a/lib/Invoice.php +++ b/lib/Invoice.php @@ -17,7 +17,6 @@ * @property string $billing * @property string $billing_reason * @property string $charge - * @property bool $closed * @property string $currency * @property string $customer * @property int $date @@ -25,9 +24,9 @@ * @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 @@ -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 @@ -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 @@ -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; diff --git a/tests/Stripe/InvoiceTest.php b/tests/Stripe/InvoiceTest.php index f1ae93786..578b551a1 100644 --- a/tests/Stripe/InvoiceTest.php +++ b/tests/Stripe/InvoiceTest.php @@ -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( @@ -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); }