diff --git a/src/EventBuilder.php b/src/EventBuilder.php index 564cf9f..7ed9946 100644 --- a/src/EventBuilder.php +++ b/src/EventBuilder.php @@ -37,7 +37,6 @@ final class EventBuilder 'customer.discount.created' => Event\CustomerDiscountCreatedEvent::class, 'customer.discount.deleted' => Event\CustomerDiscountDeletedEvent::class, 'customer.discount.updated' => Event\CustomerDiscountUpdatedEvent::class, - 'customer.source.created' => Event\CustomerSourceCreatedEvent::class, 'customer.source.deleted' => Event\CustomerSourceDeletedEvent::class, 'customer.source.expiring' => Event\CustomerSourceExpiringEvent::class, 'customer.source.updated' => Event\CustomerSourceUpdatedEvent::class, @@ -96,6 +95,14 @@ public function createEventFromArray(array $data): Event\Event return \call_user_func($this->events[$data['type']].'::createFromArray', $data); } + if ('customer.source.created' === $data['type']) { + if ('card' === $data['data']['object']['object']) { + return Event\CustomerCardCreatedEvent::createFromArray($data); + } + + return Event\CustomerSourceCreatedEvent::createFromArray($data); + } + throw new InvalidArgumentException("Unable to process event: Event \"{$data['type']}\" is not supported yet."); } } diff --git a/src/Model/Event/ContainsCard.php b/src/Model/Event/ContainsCard.php new file mode 100644 index 0000000..ba20400 --- /dev/null +++ b/src/Model/Event/ContainsCard.php @@ -0,0 +1,17 @@ +card; + } +} diff --git a/src/Model/Event/CustomerCardCreatedEvent.php b/src/Model/Event/CustomerCardCreatedEvent.php new file mode 100644 index 0000000..ad38c48 --- /dev/null +++ b/src/Model/Event/CustomerCardCreatedEvent.php @@ -0,0 +1,15 @@ +assertSame('invoice.payment_action_required', $event->getType()); } + public function testCustomerCardCreatedEvent() + { + $data = json_decode(file_get_contents(__DIR__.'/fixtures/events/customer.card.created.json'), true); + $this->assertSame(\JSON_ERROR_NONE, json_last_error()); + + $this->assertSame('customer.source.created', $data['type']); + + $event = (new EventBuilder())->createEventFromArray($data); + $this->assertSame('customer.source.created', $event->getType()); + } + /** * @dataProvider unsupportedEvents */ diff --git a/tests/fixtures/events/customer.card.created.json b/tests/fixtures/events/customer.card.created.json new file mode 100644 index 0000000..95a46d2 --- /dev/null +++ b/tests/fixtures/events/customer.card.created.json @@ -0,0 +1,41 @@ +{ + "id": "evt_1FWhZZIpafQncvOMFWe2QlHA", + "object": "event", + "api_version": "2019-09-09", + "created": 1571828413, + "data": { + "object": { + "id": "card_1FWhZZIpafQncvOMOIqSU62P", + "object": "card", + "address_city": null, + "address_country": null, + "address_line1": null, + "address_line1_check": null, + "address_line2": null, + "address_state": null, + "address_zip": null, + "address_zip_check": null, + "brand": "Visa", + "country": "US", + "customer": "cus_G2n9nb3ufiT1iy", + "cvc_check": null, + "dynamic_last4": null, + "exp_month": 10, + "exp_year": 2020, + "fingerprint": "yhdusyvLVRkh3oYc", + "funding": "credit", + "last4": "4242", + "metadata": { + }, + "name": null, + "tokenization_method": null + } + }, + "livemode": false, + "pending_webhooks": 1, + "request": { + "id": "req_8P1yFTkKtYdH92", + "idempotency_key": null + }, + "type": "customer.source.created" +} diff --git a/tests/fixtures/events/customer.source.created.json b/tests/fixtures/events/customer.source.created.json index ad0db8e..7b2a919 100644 --- a/tests/fixtures/events/customer.source.created.json +++ b/tests/fixtures/events/customer.source.created.json @@ -1,12 +1,12 @@ { "created": 1326853478, "livemode": false, - "id": "customer.source.created_00000000000000", + "id": "evt_00000000000000", "type": "customer.source.created", "object": "event", "request": null, "pending_webhooks": 1, - "api_version": "2018-11-08", + "api_version": "2019-09-09", "data": { "object": { "id": "src_00000000000000", @@ -19,8 +19,8 @@ "swift_code": "TSTEZ122" }, "amount": null, - "client_secret": "src_client_secret_ETT9dPgHcXfUbKe0VE5YIUDj", - "created": 1549381912, + "client_secret": "src_client_secret_G2n6cnHECHjxABPeS45kLo7q", + "created": 1571828189, "currency": "eur", "flow": "receiver", "livemode": false,