From 96f4afd47b98fa17e85afb41031b2cbe974a9afe Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Thu, 8 Aug 2019 13:50:26 +0200 Subject: [PATCH 01/10] [change] (PHPLIB-203) Remove obsolete code. --- src/Resources/PaymentTypes/Paypage.php | 55 -------------------------- 1 file changed, 55 deletions(-) diff --git a/src/Resources/PaymentTypes/Paypage.php b/src/Resources/PaymentTypes/Paypage.php index 0336e719..f62b2c82 100644 --- a/src/Resources/PaymentTypes/Paypage.php +++ b/src/Resources/PaymentTypes/Paypage.php @@ -407,23 +407,6 @@ public function getBasket() return $this->payment->getBasket(); } - /** - * @param Basket $basket - * - * @return Paypage - * - * @throws HeidelpayApiException - * @throws RuntimeException - */ - protected function setBasket(Basket $basket): Paypage - { - if (!$this->payment instanceof Payment) { - throw new RuntimeException('The payment resource is missing.'); - } - $this->payment->setBasket($basket); - return $this; - } - /** * @return Customer|null */ @@ -435,23 +418,6 @@ public function getCustomer() return $this->payment->getCustomer(); } - /** - * @param Customer|null $customer - * - * @return Paypage - * - * @throws RuntimeException - * @throws HeidelpayApiException - */ - protected function setCustomer($customer): Paypage - { - if (!$this->payment instanceof Payment) { - throw new RuntimeException('The payment resource is missing.'); - } - $this->payment->setCustomer($customer); - return $this; - } - /** * @return Metadata|null */ @@ -463,23 +429,6 @@ public function getMetadata() return $this->payment->getMetadata(); } - /** - * @param Metadata|null $metadata - * - * @return Paypage - * - * @throws HeidelpayApiException - * @throws RuntimeException - */ - protected function setMetadata($metadata): Paypage - { - if (!$this->payment instanceof Payment) { - throw new RuntimeException('The payment resource is missing.'); - } - $this->payment->setMetadata($metadata); - return $this; - } - /** * @return string|null */ @@ -567,10 +516,6 @@ public function handleResponse(stdClass $response, $method = HttpAdapterInterfac $payment->setId($response->resources->paymentId); } - if (isset($response->redirectUrl)) { - $payment->setRedirectUrl($response->redirectUrl); - } - if ($method !== HttpAdapterInterface::REQUEST_GET) { $this->fetchPayment(); } From f5e078f9f49b6ef4782ff9f94e5e77cd052f9724 Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Thu, 8 Aug 2019 13:50:58 +0200 Subject: [PATCH 02/10] [change] (PHPLIB-203) PayPage: Add missing tests. --- .../Resources/PaymentTypes/PayPageTest.php | 197 +++++++++++++++++- 1 file changed, 195 insertions(+), 2 deletions(-) diff --git a/test/unit/Resources/PaymentTypes/PayPageTest.php b/test/unit/Resources/PaymentTypes/PayPageTest.php index 5f0176fb..eafa91f6 100644 --- a/test/unit/Resources/PaymentTypes/PayPageTest.php +++ b/test/unit/Resources/PaymentTypes/PayPageTest.php @@ -24,13 +24,20 @@ */ namespace heidelpayPHP\test\unit\Resources\PaymentTypes; +use heidelpayPHP\Adapter\HttpAdapterInterface; use heidelpayPHP\Constants\TransactionTypes; +use heidelpayPHP\Exceptions\HeidelpayApiException; use heidelpayPHP\Resources\Payment; use heidelpayPHP\Resources\PaymentTypes\Paypage; -use heidelpayPHP\test\BaseUnitTest; +use heidelpayPHP\Services\ResourceService; +use heidelpayPHP\test\BasePaymentTest; use PHPUnit\Framework\Exception; +use PHPUnit\Framework\MockObject\MockObject; +use ReflectionException; +use RuntimeException; +use stdClass; -class PayPageTest extends BaseUnitTest +class PayPageTest extends BasePaymentTest { /** * Verify setter and getter work. @@ -114,4 +121,190 @@ public function getterAndSetterWorkAsExpected() $this->assertEquals('my privacy policy url', $paypage->getPrivacyPolicyUrl()); $this->assertEquals('my tac url', $paypage->getTermsAndConditionUrl()); } + + /** + * Verify handling of response and property setters/getters. + * + * @test + * + * @throws RuntimeException + * @throws HeidelpayApiException + */ + public function responseHandlingShouldWorkProperly() + { + // when + $paypage = new Paypage(123.4, 'EUR', 'https://docs.heidelpay.com'); + $payment = new Payment(); + $paypage->setPayment($payment); + + // then + $this->assertEquals(123.4, $paypage->getAmount()); + $this->assertEquals('EUR', $paypage->getCurrency()); + $this->assertEquals('https://docs.heidelpay.com', $paypage->getReturnUrl()); + + $this->assertNull($paypage->getPaymentId()); + $this->assertSame($payment, $paypage->getPayment()); + $this->assertEquals(TransactionTypes::CHARGE, $paypage->getAction()); + $this->assertNull($paypage->getRedirectUrl()); + + $this->assertNull($paypage->getFullPageImage()); + $this->assertNull($paypage->getLogoImage()); + $this->assertNull($paypage->getShopDescription()); + $this->assertNull($paypage->getShopName()); + $this->assertNull($paypage->getTagline()); + + $this->assertNull($paypage->getContactUrl()); + $this->assertNull($paypage->getHelpUrl()); + $this->assertNull($paypage->getImprintUrl()); + $this->assertNull($paypage->getPrivacyPolicyUrl()); + $this->assertNull($paypage->getTermsAndConditionUrl()); + + // when + $response = new stdClass(); + $response->amount = 765.4; + $response->currency = 'CHF'; + $response->returnUrl = 'another return url'; + $response->action = TransactionTypes::AUTHORIZATION; + $response->redirectUrl = 'redirect url'; + $response->fullPageImage = 'full page image'; + $response->logoImage = 'logo image'; + $response->shopDescription = 'shop description'; + $response->shopName = 'shop name'; + $response->tagline = 'tagline'; + $response->contactUrl = 'contact url'; + $response->helpUrl = 'help url'; + $response->imprintUrl = 'imprint url'; + $response->privacyPolicyUrl = 'privacy policy url'; + $response->termsAndConditionUrl = 'tac url'; + $paypage->handleResponse($response); + + // then + $this->assertEquals(765.4, $paypage->getAmount()); + $this->assertEquals('CHF', $paypage->getCurrency()); + $this->assertEquals('another return url', $paypage->getReturnUrl()); + + $this->assertSame($payment, $paypage->getPayment()); + $this->assertEquals(TransactionTypes::AUTHORIZATION, $paypage->getAction()); + $this->assertEquals('redirect url', $paypage->getRedirectUrl()); + + $this->assertEquals('full page image', $paypage->getFullPageImage()); + $this->assertEquals('logo image', $paypage->getLogoImage()); + $this->assertEquals('shop description', $paypage->getShopDescription()); + $this->assertEquals('shop name', $paypage->getShopName()); + $this->assertEquals('tagline', $paypage->getTagline()); + + $this->assertEquals('contact url', $paypage->getContactUrl()); + $this->assertEquals('help url', $paypage->getHelpUrl()); + $this->assertEquals('imprint url', $paypage->getImprintUrl()); + $this->assertEquals('privacy policy url', $paypage->getPrivacyPolicyUrl()); + $this->assertEquals('tac url', $paypage->getTermsAndConditionUrl()); + } + + /** + * Verify handling of payment object. + * + * @test + * + * @throws RuntimeException + * @throws HeidelpayApiException + */ + public function paymentObjectShouldBeUpdatedProperly() + { + // when + $paypage = new Paypage(123.4, 'EUR', 'https://docs.heidelpay.com'); + $payment = new Payment(); + $paypage->setPayment($payment); + + // then + $this->assertNull($paypage->getPaymentId()); + $this->assertSame($payment, $paypage->getPayment()); + + // when + $payment->setId('test id'); + + // then + $this->assertEquals('test id', $paypage->getPaymentId()); + + // when + $response = new stdClass(); + $response->resources = new stdClass(); + $response->resources->paymentId = 'new payment id'; + $paypage->handleResponse($response); + + // then + $this->assertEquals('new payment id', $paypage->getPaymentId()); + } + + /** + * Verify handling of response in case of special fields. + * + * @test + * + * @throws RuntimeException + * @throws HeidelpayApiException + */ + public function responseHandlingShouldMapSpecialFieldsProperly() + { + // when + $paypage = new Paypage(123.4, 'EUR', 'https://docs.heidelpay.com'); + + $response = new stdClass(); + $response->impressumUrl = 'impressum url'; + $paypage->handleResponse($response); + + // then + $this->assertEquals('impressum url', $paypage->getImprintUrl()); + } + + /** + * Verify payment is fetched if it is no GET request. + * + * @test + * + * @dataProvider paymentShouldBeFetchedWhenItIsNoGetRequestDP + * + * @param string $method + * @param mixed $fetchCallCount + * + *@throws ReflectionException + * @throws RuntimeException + * @throws HeidelpayApiException + */ + public function paymentShouldBeFetchedWhenItIsNoGetRequest($method, $fetchCallCount) + { + // mock resource service to check whether fetch is called on it with the payment object. + /** @var ResourceService|MockObject $resourceSrvMock */ + $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->disableOriginalConstructor()->setMethods(['fetch'])->getMock(); + + // when + $paypage = new Paypage(123.4, 'EUR', 'https://docs.heidelpay.com'); + $payment = (new Payment())->setParentResource($this->heidelpay->setResourceService($resourceSrvMock)); + $paypage->setPayment($payment)->setParentResource($payment); + + // should + $resourceSrvMock->expects($this->exactly($fetchCallCount))->method('fetch')->with($payment); + + // when + $response = new stdClass(); + $response->resources = new stdClass(); + $response->resources->paymentId = 'payment id'; + $paypage->handleResponse($response, $method); + } + + // + + /** + * @return array + */ + public function paymentShouldBeFetchedWhenItIsNoGetRequestDP(): array + { + return [ + 'GET' => [HttpAdapterInterface::REQUEST_GET, 0], + 'PUT' => [HttpAdapterInterface::REQUEST_PUT, 1], + 'DELETE' => [HttpAdapterInterface::REQUEST_DELETE, 1], + 'POST' => [HttpAdapterInterface::REQUEST_POST, 1], + ]; + } + + // } From c54d0532ddf09cba2a0e27145c4462da0c8bcacd Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Thu, 8 Aug 2019 14:07:30 +0200 Subject: [PATCH 03/10] [change] (PHPLIB-203) PayPage: Add tests to verify expose method. --- .../Resources/PaymentTypes/PayPageTest.php | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/test/unit/Resources/PaymentTypes/PayPageTest.php b/test/unit/Resources/PaymentTypes/PayPageTest.php index eafa91f6..c6a67fac 100644 --- a/test/unit/Resources/PaymentTypes/PayPageTest.php +++ b/test/unit/Resources/PaymentTypes/PayPageTest.php @@ -27,6 +27,9 @@ use heidelpayPHP\Adapter\HttpAdapterInterface; use heidelpayPHP\Constants\TransactionTypes; use heidelpayPHP\Exceptions\HeidelpayApiException; +use heidelpayPHP\Resources\Basket; +use heidelpayPHP\Resources\Customer; +use heidelpayPHP\Resources\Metadata; use heidelpayPHP\Resources\Payment; use heidelpayPHP\Resources\PaymentTypes\Paypage; use heidelpayPHP\Services\ResourceService; @@ -291,6 +294,71 @@ public function paymentShouldBeFetchedWhenItIsNoGetRequest($method, $fetchCallCo $paypage->handleResponse($response, $method); } + /** + * Verify expose behaves as expected. + * + * @test + * + * @throws Exception + * @throws HeidelpayApiException + * @throws RuntimeException + */ + public function exposeShouldSetBasicParams() + { + // when + $basket = (new Basket())->setId('basketId'); + $customer = (new Customer())->setId('customerId'); + $metadata = (new Metadata())->setId('metadataId'); + $payment = (new Payment()) + ->setParentResource($this->heidelpay) + ->setId('my payment id') + ->setBasket($basket) + ->setMetadata($metadata) + ->setCustomer($customer); + $paypage = (new Paypage(123.4567, 'EUR', self::RETURN_URL)) + ->setParentResource($payment) + ->setFullPageImage('full page image') + ->setLogoImage('logo image') + ->setShopDescription('my shop description') + ->setShopName('my shop name') + ->setTagline('my shops tag line') + ->setContactUrl('my contact url') + ->setHelpUrl('my help url') + ->setImprintUrl('my imprint url') + ->setPrivacyPolicyUrl('my privacy policy url') + ->setTermsAndConditionUrl('my tac url') + ->setPayment($payment) + ->setRedirectUrl('https://redirect.url') + ->setOrderId('my order id') + ->setInvoiceId('my invoice id'); + + // then + $expected = [ + 'resources' => [ + 'basketId' => 'basketId', + 'metadataId' => 'metadataId', + 'paymentId' => 'my payment id', + 'customerId' => 'customerId' + ], + 'amount' => 123.4567, + 'currency' => 'EUR', + 'returnUrl' => self::RETURN_URL, + 'fullPageImage' => 'full page image', + 'logoImage' => 'logo image', + 'shopDescription' => 'my shop description', + 'shopName' => 'my shop name', + 'tagline' => 'my shops tag line', + 'contactUrl' => 'my contact url', + 'helpUrl' => 'my help url', + 'impressumUrl' => 'my imprint url', + 'privacyPolicyUrl' => 'my privacy policy url', + 'termsAndConditionUrl' => 'my tac url', + 'orderId' => 'my order id', + 'invoiceId' => 'my invoice id' + ]; + $this->assertEquals($expected, $paypage->expose()); + } + // /** From 061e2766cade61a6f8897a4142951babde4b4763 Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Thu, 8 Aug 2019 14:21:01 +0200 Subject: [PATCH 04/10] [change] (PHPLIB-203) PayPage: Verify url. --- test/unit/Resources/AbstractHeidelpayResourceTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/unit/Resources/AbstractHeidelpayResourceTest.php b/test/unit/Resources/AbstractHeidelpayResourceTest.php index 6f0fe0c2..d8ba2ef4 100755 --- a/test/unit/Resources/AbstractHeidelpayResourceTest.php +++ b/test/unit/Resources/AbstractHeidelpayResourceTest.php @@ -28,6 +28,7 @@ use heidelpayPHP\Constants\CompanyCommercialSectorItems; use heidelpayPHP\Constants\CompanyRegistrationTypes; use heidelpayPHP\Constants\Salutations; +use heidelpayPHP\Constants\TransactionTypes; use heidelpayPHP\Heidelpay; use heidelpayPHP\Resources\AbstractHeidelpayResource; use heidelpayPHP\Resources\Basket; @@ -44,6 +45,7 @@ use heidelpayPHP\Resources\PaymentTypes\EPS; use heidelpayPHP\Resources\PaymentTypes\Invoice; use heidelpayPHP\Resources\PaymentTypes\InvoiceGuaranteed; +use heidelpayPHP\Resources\PaymentTypes\Paypage; use heidelpayPHP\Resources\PaymentTypes\SepaDirectDebit; use heidelpayPHP\Resources\PaymentTypes\SepaDirectDebitGuaranteed; use heidelpayPHP\Resources\Recurring; @@ -400,6 +402,8 @@ public function uriDataProvider(): array 'Webhooks' => [new Webhook(), 'parent/resource/path/webhooks/'], 'Recurring' => [new Recurring('s-crd-123', ''), 'parent/resource/path/types/s-crd-123/recurring/'], 'Payout' => [new Payout(), 'parent/resource/path/payouts/'], + 'PayPage charge' => [new Paypage(123.4567, 'EUR', 'url'), 'parent/resource/path/paypage/charge/'], + 'PayPage authorize' => [(new Paypage(123.4567, 'EUR', 'url'))->setAction(TransactionTypes::AUTHORIZATION), 'parent/resource/path/paypage/authorize/'] ]; } From 5d2badcd767a3afec4993d2144de1c8128c4ee49 Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Thu, 8 Aug 2019 14:49:51 +0200 Subject: [PATCH 05/10] [change] (PHPLIB-203) PayPage: Add unit test to verify resources are null if payment does not exist. --- .../Resources/PaymentTypes/PayPageTest.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/unit/Resources/PaymentTypes/PayPageTest.php b/test/unit/Resources/PaymentTypes/PayPageTest.php index c6a67fac..b3746ed0 100644 --- a/test/unit/Resources/PaymentTypes/PayPageTest.php +++ b/test/unit/Resources/PaymentTypes/PayPageTest.php @@ -359,6 +359,39 @@ public function exposeShouldSetBasicParams() $this->assertEquals($expected, $paypage->expose()); } + /** + * Verify resources are returned as null if no payment object exists. + * + * @test + * + * @throws HeidelpayApiException + * @throws RuntimeException + */ + public function resourcesAreNullWithoutPaymentObject() + { + // when + $paypage = new Paypage(123.4567, 'EUR', self::RETURN_URL); + + // then + $this->assertNull($paypage->getPayment()); + $this->assertNull($paypage->getCustomer()); + $this->assertNull($paypage->getMetadata()); + $this->assertNull($paypage->getBasket()); + + // when + $basket = (new Basket())->setId('basketId'); + $customer = (new Customer())->setId('customerId'); + $metadata = (new Metadata())->setId('metadataId'); + $payment = (new Payment())->setParentResource($this->heidelpay)->setBasket($basket)->setMetadata($metadata)->setCustomer($customer); + $paypage->setPayment($payment); + + // then + $this->assertSame($payment, $paypage->getPayment()); + $this->assertSame($payment->getCustomer(), $paypage->getCustomer()); + $this->assertSame($payment->getMetadata(), $paypage->getMetadata()); + $this->assertSame($payment->getBasket(), $paypage->getBasket()); + } + // /** From 7e541ca442e74764d6dfc58d5f194bbe811cf3fa Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Thu, 8 Aug 2019 15:09:57 +0200 Subject: [PATCH 06/10] [change] (PHPLIB-203) PayPage: Add PaymentService test for initPayPage. --- test/unit/Services/PaymentServiceTest.php | 64 +++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/test/unit/Services/PaymentServiceTest.php b/test/unit/Services/PaymentServiceTest.php index e446d3a7..225986dd 100755 --- a/test/unit/Services/PaymentServiceTest.php +++ b/test/unit/Services/PaymentServiceTest.php @@ -24,12 +24,14 @@ */ namespace heidelpayPHP\test\unit\Services; +use heidelpayPHP\Constants\TransactionTypes; use heidelpayPHP\Exceptions\HeidelpayApiException; use heidelpayPHP\Heidelpay; use heidelpayPHP\Resources\Basket; use heidelpayPHP\Resources\Customer; use heidelpayPHP\Resources\Metadata; use heidelpayPHP\Resources\Payment; +use heidelpayPHP\Resources\PaymentTypes\Paypage; use heidelpayPHP\Resources\PaymentTypes\SepaDirectDebit; use heidelpayPHP\Resources\PaymentTypes\Sofort; use heidelpayPHP\Resources\TransactionTypes\Authorization; @@ -40,6 +42,8 @@ use heidelpayPHP\Services\PaymentService; use heidelpayPHP\Services\ResourceService; use heidelpayPHP\test\BaseUnitTest; +use PHPUnit\Framework\Exception; +use PHPUnit\Framework\MockObject\MockObject; use function in_array; use ReflectionException; use RuntimeException; @@ -590,6 +594,55 @@ static function ($payout) use ($customer, $payment, $basket, $metadata) { // + // + + /** + * Verify initPayPage creates a payment with resources and calls create with said payment. + * + * @test + * + * @dataProvider paymentShouldBeCreatedByInitPayPageDP + * + * @param string $action + * + * @throws HeidelpayApiException + * @throws ReflectionException + * @throws RuntimeException + * @throws Exception + * @throws \PHPUnit\Framework\MockObject\RuntimeException + */ + public function paymentShouldBeCreatedByInitPayPage(string $action) + { + /** @var ResourceService|MockObject $resourceSrvMock */ + $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->setMethods(['create'])->disableOriginalConstructor()->getMock(); + $paymentSrv = (new PaymentService(new Heidelpay('s-priv-1234')))->setResourceService($resourceSrvMock); + + // when + $paypage = new Paypage(123.4, 'CHF', 'url'); + $basket = (new Basket())->setId('basketId'); + $customer = (new Customer())->setId('customerId'); + $metadata = (new Metadata())->setId('metadataId'); + + // should + $resourceSrvMock->expects($this->once())->method('create')->with( + $this->callback( + static function ($paypage) use ($basket, $customer, $metadata, $action) { + return $paypage instanceof Paypage && + $paypage->getPayment() instanceof Payment && + $basket === $paypage->getBasket() && + $customer === $paypage->getCustomer() && + $metadata === $paypage->getMetadata() && + $action === $paypage->getAction(); + } + ) + ); + + // when + $paymentSrv->initPayPage($paypage, $action, $customer, $basket, $metadata); + } + + // + // /** @@ -604,5 +657,16 @@ public function card3dsDataProvider(): array ]; } + /** + * @return array + */ + public function paymentShouldBeCreatedByInitPayPageDP(): array + { + return [ + TransactionTypes::CHARGE => [TransactionTypes::CHARGE], + TransactionTypes::AUTHORIZATION => [TransactionTypes::AUTHORIZATION] + ]; + } + // } From 663014269729a519fd60c8bfc0421f34495552db Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Thu, 8 Aug 2019 15:45:31 +0200 Subject: [PATCH 07/10] [change] (PHPLIB-203) PayPage: Add PaymentService test for initPayPage. --- test/unit/HeidelpayTest.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/test/unit/HeidelpayTest.php b/test/unit/HeidelpayTest.php index 5b38b034..7a0ac18b 100755 --- a/test/unit/HeidelpayTest.php +++ b/test/unit/HeidelpayTest.php @@ -25,12 +25,14 @@ */ namespace heidelpayPHP\test\unit; +use heidelpayPHP\Constants\TransactionTypes; use heidelpayPHP\Heidelpay; use heidelpayPHP\Resources\Basket; use heidelpayPHP\Resources\Customer; use heidelpayPHP\Resources\Metadata; use heidelpayPHP\Resources\Payment; use heidelpayPHP\Resources\PaymentTypes\Card; +use heidelpayPHP\Resources\PaymentTypes\Paypage; use heidelpayPHP\Resources\PaymentTypes\Sofort; use heidelpayPHP\Resources\TransactionTypes\Authorization; use heidelpayPHP\Resources\TransactionTypes\Cancellation; @@ -291,7 +293,8 @@ public function heidelpayShouldForwardResourceActionCallsToTheResourceServiceDP( 'fetchRefund' => ['fetchRefund', [$chargeMock, $cancelId], 'fetch', [$cancellation]], 'fetchShipment' => ['fetchShipment', [$payment, 'shipId'], 'fetchShipment', [$payment, 'shipId']], 'activateRecurring' => ['activateRecurringPayment', [$card, 'returnUrl'], 'createRecurring', [$card, 'returnUrl']], - 'activateRecurringWithId' => ['activateRecurringPayment', [$paymentTypeId, 'returnUrl'], 'createRecurring', [$paymentTypeId, 'returnUrl']] + 'activateRecurringWithId' => ['activateRecurringPayment', [$paymentTypeId, 'returnUrl'], 'createRecurring', [$paymentTypeId, 'returnUrl']], + 'fetchPayout' => ['fetchPayout', [$payment], 'fetchPayout', [$payment]] ]; } @@ -308,12 +311,14 @@ public function heidelpayShouldForwardPaymentActionCallsToThePaymentServiceDP(): $customerId = 'customerId'; $paymentId = 'paymentId'; $chargeId = 'chargeId'; - $customer = new Customer(); + $customer = (new Customer())->setId('123'); $sofort = new Sofort(); - $metadata = new Metadata(); + $metadata = (new Metadata())->setId('123'); $payment = new Payment(); $authorization = new Authorization(); $charge = new Charge(); + $paypage = new Paypage(123.1234, 'EUR', 'url'); + $basket = (new Basket())->setId('123'); return [ 'auth' => ['authorize', [1.234, 'AFN', $sofort, $url, $customer, $orderId, $metadata], 'authorize', [1.234, 'AFN', $sofort, $url, $customer, $orderId, $metadata]], @@ -338,12 +343,15 @@ public function heidelpayShouldForwardPaymentActionCallsToThePaymentServiceDP(): 'cancelChargeByIdAlt' => ['cancelChargeById', [$paymentId, $chargeId], 'cancelChargeById', [$paymentId, $chargeId]], 'cancelCharge' => ['cancelCharge', [$charge, 1.234], 'cancelCharge', [$charge, 1.234]], 'cancelChargeAlt' => ['cancelCharge', [$charge], 'cancelCharge', [$charge]], - 'ship' => ['ship', [$payment], 'ship', [$payment]] + 'ship' => ['ship', [$payment], 'ship', [$payment]], + 'payout' => ['payout', [123, 'EUR', $paymentTypeId, 'url', $customer, $orderId, $metadata, 'basketId'], 'payout', [123, 'EUR', $paymentTypeId, 'url', $customer, $orderId, $metadata, 'basketId']], + 'initPayPageCharge' => ['initPayPageCharge', [$paypage, $customer, $basket, $metadata], 'initPayPage', [$paypage, TransactionTypes::CHARGE, $customer, $basket, $metadata]], + 'initPayPageAuthorize' => ['initPayPageAuthorize', [$paypage, $customer, $basket, $metadata], 'initPayPage', [$paypage, TransactionTypes::AUTHORIZATION, $customer, $basket, $metadata]] ]; } /** - * Provide test data for heidelpayShouldForwardWebhookActionCallsToTheWebhookService. + * Provide test data for heidelpayShouldForwardWebhookActionCallsToTheWebhookServic * * @return array */ From 7243cc6530e98c0a7ebc52955d651746f4e9edc8 Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Thu, 8 Aug 2019 15:56:59 +0200 Subject: [PATCH 08/10] [change] (PHPLIB-203) Update changelog. --- CHANGELOG.md | 12 +++++++++++- examples/InvoiceGuaranteed/Controller.php | 4 ---- test/unit/HeidelpayTest.php | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 302e749f..8e3ce845 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,9 +12,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a * Version and Type of the SDK are now sent to the API with every request. * Add missing feature to readme. * Renamed property `Basket::amountTotal` to `Basket::amountTotalGross` to follow the change in the API. +* Refactor tests. +* Set `Paypage` default action to 'charge' and restrict values to 'charge' and 'authorize'. ### Added -* Property `type` to `BasketItem`. +* Property `type` to `BasketItem`. +* An exception is now thrown in case of a `CURL` timeout. +* The `CURL` timeout can now be changed via environment variable. + +### Removed +* Unnecessary resource setters in `Paypage`. + +### Fixed +* Unit tests work now even in `development` or `staging` environment. ## [1.1.6.0][1.1.6.0] diff --git a/examples/InvoiceGuaranteed/Controller.php b/examples/InvoiceGuaranteed/Controller.php index 45b461c4..8445f075 100755 --- a/examples/InvoiceGuaranteed/Controller.php +++ b/examples/InvoiceGuaranteed/Controller.php @@ -35,11 +35,7 @@ use heidelpayPHP\Exceptions\HeidelpayApiException; use heidelpayPHP\Heidelpay; use heidelpayPHP\Resources\Basket; -use heidelpayPHP\Resources\Customer; -use heidelpayPHP\Resources\EmbeddedResources\Address; use heidelpayPHP\Resources\EmbeddedResources\BasketItem; -use heidelpayPHP\Resources\PaymentTypes\InvoiceFactoring; -use heidelpayPHP\Resources\PaymentTypes\InvoiceGuaranteed; session_start(); session_unset(); diff --git a/test/unit/HeidelpayTest.php b/test/unit/HeidelpayTest.php index 7a0ac18b..1dc7d343 100755 --- a/test/unit/HeidelpayTest.php +++ b/test/unit/HeidelpayTest.php @@ -351,7 +351,7 @@ public function heidelpayShouldForwardPaymentActionCallsToThePaymentServiceDP(): } /** - * Provide test data for heidelpayShouldForwardWebhookActionCallsToTheWebhookServic + * Provide test data for heidelpayShouldForwardWebhookActionCallsToTheWebhookService. * * @return array */ From e44f78fbb30fb09178dcad65615e1bf56348aa3c Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Thu, 8 Aug 2019 16:07:18 +0200 Subject: [PATCH 09/10] [change] Add curl errno to error message in generic curl error. --- src/Adapter/CurlAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapter/CurlAdapter.php b/src/Adapter/CurlAdapter.php index e23579c2..a112bfb6 100755 --- a/src/Adapter/CurlAdapter.php +++ b/src/Adapter/CurlAdapter.php @@ -86,7 +86,7 @@ public function execute() $errorMessage = 'Timeout: The Payment API seems to be not available at the moment!'; break; default: - $errorMessage = 'An error occurred sending the request.'; + $errorMessage = 'An error occurred sending the request (curl_errno: '. $error . ').'; break; } throw new HeidelpayApiException($errorMessage); From 5b7d17f33308b7164ec165dc059c9bd0bfaf32ea Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Thu, 8 Aug 2019 17:32:19 +0200 Subject: [PATCH 10/10] [change] Simplify unit tests. --- test/unit/HeidelpayTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/HeidelpayTest.php b/test/unit/HeidelpayTest.php index 1dc7d343..5ad5afc8 100755 --- a/test/unit/HeidelpayTest.php +++ b/test/unit/HeidelpayTest.php @@ -311,14 +311,14 @@ public function heidelpayShouldForwardPaymentActionCallsToThePaymentServiceDP(): $customerId = 'customerId'; $paymentId = 'paymentId'; $chargeId = 'chargeId'; - $customer = (new Customer())->setId('123'); + $customer = new Customer(); $sofort = new Sofort(); - $metadata = (new Metadata())->setId('123'); + $metadata = new Metadata(); $payment = new Payment(); $authorization = new Authorization(); $charge = new Charge(); $paypage = new Paypage(123.1234, 'EUR', 'url'); - $basket = (new Basket())->setId('123'); + $basket = new Basket(); return [ 'auth' => ['authorize', [1.234, 'AFN', $sofort, $url, $customer, $orderId, $metadata], 'authorize', [1.234, 'AFN', $sofort, $url, $customer, $orderId, $metadata]],