From db53153427c0933cfaaaf76f782b47869079fe93 Mon Sep 17 00:00:00 2001 From: Vladyslav Shut Date: Tue, 25 Jun 2019 11:05:50 +0300 Subject: [PATCH 1/2] Fix creation subscription with not accepted mandate --- src/Resource/Factory/SubscriptionFactory.php | 2 +- .../Factory/SubscriptionFactoryTest.php | 5 +- .../subscription_mandate_is_not_accepted.json | 53 +++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 tests/files/UnitTests/Client/Factory/SubscriptionFactoryTest/subscription_mandate_is_not_accepted.json diff --git a/src/Resource/Factory/SubscriptionFactory.php b/src/Resource/Factory/SubscriptionFactory.php index f94923b..6b0b4a8 100644 --- a/src/Resource/Factory/SubscriptionFactory.php +++ b/src/Resource/Factory/SubscriptionFactory.php @@ -56,7 +56,7 @@ private function getMandate(array $data): Mandate return new Mandate( $data['mandate_code'], $this->extractBoolean('mandate_accepted', $data), - new DateTimeImmutable($data['mandate_accepted_date']) + $this->extractDateTimeImmutableOrNull('mandate_accepted_date', $data) ); } diff --git a/tests/Unit/Client/Factory/SubscriptionFactoryTest.php b/tests/Unit/Client/Factory/SubscriptionFactoryTest.php index 2f1bfdd..a76b266 100644 --- a/tests/Unit/Client/Factory/SubscriptionFactoryTest.php +++ b/tests/Unit/Client/Factory/SubscriptionFactoryTest.php @@ -46,7 +46,7 @@ public function fromData(array $data): void self::assertEquals($data['data']['id'], $subscriptionPlan->getId()); self::assertSame($data['data']['attributes']['mandate_code'], $subscriptionPlan->getMandate()->getCode()); self::assertSame($data['data']['attributes']['mandate_accepted'], $subscriptionPlan->getMandate()->isAccepted()); - self::assertSame($data['data']['attributes']['mandate_accepted_date'], $subscriptionPlan->getMandate()->getAcceptedDate()->format(DateTime::ATOM)); + self::assertDateTimeOrNull($data['data']['attributes']['mandate_accepted_date'], $subscriptionPlan->getMandate()->getAcceptedDate()); self::assertSame($data['data']['attributes']['start_date'], $subscriptionPlan->getStartDate()->format(DateTime::ATOM)); self::assertSame($data['data']['attributes']['status'], $subscriptionPlan->getStatus()->getValue()); self::assertSame($data['data']['attributes']['confirmation_page'], $subscriptionPlan->getConfirmationPage()); @@ -75,7 +75,8 @@ private static function assertTransactions($data, TransactionInterface ...$trans public function getTransactionData(): array { return [ - 'subscription' => [$this->getDataFromFile('subscription.json')], + [$this->getDataFromFile('subscription.json')], + [$this->getDataFromFile('subscription_mandate_is_not_accepted.json')], ]; } } diff --git a/tests/files/UnitTests/Client/Factory/SubscriptionFactoryTest/subscription_mandate_is_not_accepted.json b/tests/files/UnitTests/Client/Factory/SubscriptionFactoryTest/subscription_mandate_is_not_accepted.json new file mode 100644 index 0000000..89c4f83 --- /dev/null +++ b/tests/files/UnitTests/Client/Factory/SubscriptionFactoryTest/subscription_mandate_is_not_accepted.json @@ -0,0 +1,53 @@ +{ + "links": { + "self": "https://api.ecurring.com/subscriptions/1" + }, + "data": { + "type": "subscription", + "id": "1", + "links": { + "self": "https://api.ecurring.com/subscriptions/1" + }, + "attributes": { + "mandate_code": "ECUR-1", + "mandate_accepted": false, + "mandate_accepted_date": null, + "start_date": "2017-11-21T22:11:57+01:00", + "status": "active", + "cancel_date": null, + "resume_date": null, + "confirmation_page": "https://app.ecurring.com/mandate/accept/1/ECUR-1", + "confirmation_sent": false, + "subscription_webhook_url": null, + "transaction_webhook_url": null, + "success_redirect_url": null, + "created_at": "2017-02-01T11:21:09+01:00", + "updated_at": "2017-02-11T00:00:00+01:00" + }, + "relationships": { + "subscription-plan": { + "data": { + "type": "subscription-plan", + "id": "1" + } + }, + "customer": { + "data": { + "type": "customer", + "id": "1" + } + }, + "transactions": { + "links": { + "related": "https://api.ecurring.com/subscriptions/1/transactions" + }, + "data": [ + { + "type": "transaction", + "id": "02f3c67b-1e1a-4692-8826-14f17f9b2c61" + } + ] + } + } + } +} From 119a08018459d8ca2379456e834d3e76671c1b2b Mon Sep 17 00:00:00 2001 From: Vladyslav Shut Date: Tue, 2 Jul 2019 08:16:15 +0300 Subject: [PATCH 2/2] Fix transactions --- phpunit.xml | 3 +++ src/Http/Endpoint/MapperInterface.php | 2 +- .../Factory/Transaction/EventFactory.php | 1 + src/eCurringClient.php | 7 +++++- tests/Features/GetTransactionTest.php | 22 +++++++++++++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 tests/Features/GetTransactionTest.php diff --git a/phpunit.xml b/phpunit.xml index cbecaeb..4a3bf4b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -19,6 +19,9 @@ + + ./tests/Features + ./tests/Unit diff --git a/src/Http/Endpoint/MapperInterface.php b/src/Http/Endpoint/MapperInterface.php index ed17e4c..2b41e52 100644 --- a/src/Http/Endpoint/MapperInterface.php +++ b/src/Http/Endpoint/MapperInterface.php @@ -23,7 +23,7 @@ interface MapperInterface public const GET_SUBSCRIPTION_TRANSACTIONS = 'get_subscription_transactions'; public const GET_TRANSACTION = 'get_transaction'; - public const POST_TRANSACTION = 'get_transaction'; + public const POST_TRANSACTION = 'post_transaction'; public const DELETE_TRANSACTION = 'delete_transactions'; /** diff --git a/src/Resource/Factory/Transaction/EventFactory.php b/src/Resource/Factory/Transaction/EventFactory.php index 1d88026..21fbba3 100644 --- a/src/Resource/Factory/Transaction/EventFactory.php +++ b/src/Resource/Factory/Transaction/EventFactory.php @@ -10,5 +10,6 @@ final class EventFactory implements EventFactoryInterface { public function fromArray(array $data): array { + return []; } } diff --git a/src/eCurringClient.php b/src/eCurringClient.php index ac3e9c4..244dedc 100644 --- a/src/eCurringClient.php +++ b/src/eCurringClient.php @@ -191,10 +191,15 @@ public function getSubscriptionTransactions(Subscription $subscription, ?Paginat ); } + /** + * @param UuidInterface $id + * @return Transaction + * @throws Http\Exception\ApiCallException + */ public function getTransaction(UuidInterface $id): Transaction { $json = $this->httpClient->getJson( - $this->httpClient->getEndpoint(MapperInterface::GET_SUBSCRIPTION_PLAN, [$id]) + $this->httpClient->getEndpoint(MapperInterface::GET_TRANSACTION, [$id]) ); return $this->transactionFactory->fromData($this->decodeJsonToArray($json)['data']); diff --git a/tests/Features/GetTransactionTest.php b/tests/Features/GetTransactionTest.php new file mode 100644 index 0000000..9297c62 --- /dev/null +++ b/tests/Features/GetTransactionTest.php @@ -0,0 +1,22 @@ +toString(); + + $url = $production->map(MapperInterface::GET_TRANSACTION, [$id]); + + $this->assertEquals(Production::BASE_URL . '/transactions/' . $id, $url); + } +} \ No newline at end of file