diff --git a/init.php b/init.php index 0ed7ab45d..a3c193aa6 100644 --- a/init.php +++ b/init.php @@ -73,6 +73,7 @@ require(dirname(__FILE__) . '/lib/Collection.php'); require(dirname(__FILE__) . '/lib/CountrySpec.php'); require(dirname(__FILE__) . '/lib/Coupon.php'); +require(dirname(__FILE__) . '/lib/CreditNote.php'); require(dirname(__FILE__) . '/lib/Customer.php'); require(dirname(__FILE__) . '/lib/Discount.php'); require(dirname(__FILE__) . '/lib/Dispute.php'); diff --git a/lib/CreditNote.php b/lib/CreditNote.php new file mode 100644 index 000000000..169ed0815 --- /dev/null +++ b/lib/CreditNote.php @@ -0,0 +1,73 @@ +instanceUrl() . '/void'; + list($response, $opts) = $this->_request('post', $url, $params, $opts); + $this->refreshFrom($response, $opts); + return $this; + } +} diff --git a/lib/Event.php b/lib/Event.php index 38eb24cf3..bb9b3bfbb 100644 --- a/lib/Event.php +++ b/lib/Event.php @@ -53,6 +53,9 @@ class Event extends ApiResource const COUPON_CREATED = 'coupon.created'; const COUPON_DELETED = 'coupon.deleted'; const COUPON_UPDATED = 'coupon.updated'; + const CREDIT_NOTE_CREATED = 'credit_note.created'; + const CREDIT_NOTE_UPDATED = 'credit_note.updated'; + const CREDIT_NOTE_VOIDED = 'credit_note.voided'; const CUSTOMER_CREATED = 'customer.created'; const CUSTOMER_DELETED = 'customer.deleted'; const CUSTOMER_UPDATED = 'customer.updated'; diff --git a/lib/Util/Util.php b/lib/Util/Util.php index 03b80ee30..7b167cd64 100644 --- a/lib/Util/Util.php +++ b/lib/Util/Util.php @@ -85,6 +85,7 @@ public static function convertToStripeObject($resp, $opts) \Stripe\Checkout\Session::OBJECT_NAME => 'Stripe\\Checkout\\Session', \Stripe\CountrySpec::OBJECT_NAME => 'Stripe\\CountrySpec', \Stripe\Coupon::OBJECT_NAME => 'Stripe\\Coupon', + \Stripe\CreditNote::OBJECT_NAME => 'Stripe\\CreditNote', \Stripe\Customer::OBJECT_NAME => 'Stripe\\Customer', \Stripe\Discount::OBJECT_NAME => 'Stripe\\Discount', \Stripe\Dispute::OBJECT_NAME => 'Stripe\\Dispute', diff --git a/tests/Stripe/CreditNoteTest.php b/tests/Stripe/CreditNoteTest.php new file mode 100644 index 000000000..c256bb91c --- /dev/null +++ b/tests/Stripe/CreditNoteTest.php @@ -0,0 +1,79 @@ +expectsRequest( + 'get', + '/v1/credit_notes' + ); + $resources = CreditNote::all(); + $this->assertTrue(is_array($resources->data)); + $this->assertInstanceOf("Stripe\\CreditNote", $resources->data[0]); + } + + public function testIsRetrievable() + { + $this->expectsRequest( + 'get', + '/v1/credit_notes/' . self::TEST_RESOURCE_ID + ); + $resource = CreditNote::retrieve(self::TEST_RESOURCE_ID); + $this->assertInstanceOf("Stripe\\CreditNote", $resource); + } + + public function testIsCreatable() + { + $this->expectsRequest( + 'post', + '/v1/credit_notes' + ); + $resource = CreditNote::create([ + "amount" => 100, + "invoice" => "in_132", + "reason" => "duplicate", + ]); + $this->assertInstanceOf("Stripe\\CreditNote", $resource); + } + + public function testIsSaveable() + { + $resource = CreditNote::retrieve(self::TEST_RESOURCE_ID); + $resource->metadata["key"] = "value"; + $this->expectsRequest( + 'post', + '/v1/credit_notes/' . $resource->id + ); + $resource->save(); + $this->assertInstanceOf("Stripe\\CreditNote", $resource); + } + + public function testIsUpdatable() + { + $this->expectsRequest( + 'post', + '/v1/credit_notes/' . self::TEST_RESOURCE_ID + ); + $resource = CreditNote::update(self::TEST_RESOURCE_ID, [ + "metadata" => ["key" => "value"], + ]); + $this->assertInstanceOf("Stripe\\CreditNote", $resource); + } + + public function testCanVoidCreditNote() + { + $creditNote = CreditNote::retrieve(self::TEST_RESOURCE_ID); + $this->expectsRequest( + 'post', + '/v1/credit_notes/' . $creditNote->id . '/void' + ); + $resource = $creditNote->voidCreditNote(); + $this->assertInstanceOf("Stripe\\CreditNote", $resource); + $this->assertSame($resource, $creditNote); + } +}