From d8d0638eb36e59f913972b213f37e99981fb7c7d Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 11 Jan 2021 13:03:30 +0100 Subject: [PATCH 01/17] [fix] (UMCS-56) - tests: Failed tests which depend on another test did not log debug messages as expected, when debug mode has been disabled. --- CHANGELOG.md | 10 ++++++++-- phpunit.xml | 2 +- test/BaseIntegrationTest.php | 3 +-- test/BasePaymentTest.php | 16 +++++++++++++++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef6797a1..0232a506 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,13 +3,18 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [1.1.1.0][1.1.1.0] +## [1.1.1.1] + +### Fix +* Change debug logging of failed tests that depend on another one to work as expected. + +## [1.1.1.0] ### Changed * Add email property to payment type `card` to meet 3Ds2.x regulations. * Several minor changes. -## [1.1.0.0][1.1.0.0] +## [1.1.0.0] ### Changed * Rebranding of the SDK. @@ -43,3 +48,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [1.1.0.0]: https://github.com/unzerdev/php-sdk/compare/1260b8314af1ac461e33f0cfb382ffcd0e87c105..1.1.0.0 [1.1.1.0]: https://github.com/unzerdev/php-sdk/compare/1.1.0.0..1.1.1.0 +[1.1.1.1]: https://github.com/unzerdev/php-sdk/compare/1.1.1.0..1.1.1.1 diff --git a/phpunit.xml b/phpunit.xml index d0d58a86..58ad4061 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,6 @@ unzer->getDebugHandler(); + $debugHandler = self::getDebugHandler(); if ($this->getStatus() === BaseTestRunner::STATUS_PASSED) { $debugHandler->clearTempLog(); diff --git a/test/BasePaymentTest.php b/test/BasePaymentTest.php index 91a28b90..f06d539d 100755 --- a/test/BasePaymentTest.php +++ b/test/BasePaymentTest.php @@ -52,6 +52,20 @@ class BasePaymentTest extends TestCase /** @var Unzer $unzer */ protected $unzer; + protected static $debughandler; + + /** + * @return TestDebugHandler + */ + public static function getDebugHandler(): TestDebugHandler + { + if (!self::$debughandler instanceof TestDebugHandler) { + self::$debughandler = new TestDebugHandler(); + } + return self::$debughandler; + } + + /** * Creates and returns an Unzer object if it does not exist yet. * Uses an invalid but well formed default key if no key is given. @@ -66,7 +80,7 @@ protected function getUnzerObject($privateKey = 's-priv-1234'): Unzer { if (!$this->unzer instanceof Unzer) { $this->unzer = (new Unzer($privateKey)) - ->setDebugHandler(new TestDebugHandler()) + ->setDebugHandler(self::getDebugHandler()) ->setDebugMode(true); } return $this->unzer; From fec06c500c2d699e4224ce3d3f6a519d60d470b0 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 18 Jan 2021 15:21:18 +0100 Subject: [PATCH 02/17] [fix] (UMCS-56) - update changelog - correct charge variable in installment example. --- CHANGELOG.md | 1 + examples/InstallmentSecured/PlaceOrderController.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0232a506..6798f765 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ### Fix * Change debug logging of failed tests that depend on another one to work as expected. +* Several minor changes. ## [1.1.1.0] diff --git a/examples/InstallmentSecured/PlaceOrderController.php b/examples/InstallmentSecured/PlaceOrderController.php index 615f7a23..998f359a 100644 --- a/examples/InstallmentSecured/PlaceOrderController.php +++ b/examples/InstallmentSecured/PlaceOrderController.php @@ -72,7 +72,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '') } // Check the result message of the transaction to find out what went wrong. - $merchantMessage = $authorize->getMessage()->getCustomer(); + $merchantMessage = $charge->getMessage()->getCustomer(); } catch (UnzerApiException $e) { $merchantMessage = $e->getMerchantMessage(); $clientMessage = $e->getClientMessage(); From 20c414c9f61de6637904c40262e52641dd1b3dd4 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 18 Jan 2021 16:04:46 +0100 Subject: [PATCH 03/17] [fix] (UMCS-56) - code style. --- test/BasePaymentTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/test/BasePaymentTest.php b/test/BasePaymentTest.php index f06d539d..69407b6a 100755 --- a/test/BasePaymentTest.php +++ b/test/BasePaymentTest.php @@ -65,7 +65,6 @@ public static function getDebugHandler(): TestDebugHandler return self::$debughandler; } - /** * Creates and returns an Unzer object if it does not exist yet. * Uses an invalid but well formed default key if no key is given. From 763526d9837d50b17cd7306c5de7d10d8e919502 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Wed, 17 Feb 2021 17:05:45 +0100 Subject: [PATCH 04/17] [fix] (UMCS-70) - Use an extra ReturnController for PayPal recurring example to handle result of recurring activation. --- examples/PayPalRecurring/Constants.php | 1 + examples/PayPalRecurring/Controller.php | 2 +- examples/PayPalRecurring/ReturnController.php | 79 +++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 examples/PayPalRecurring/ReturnController.php diff --git a/examples/PayPalRecurring/Constants.php b/examples/PayPalRecurring/Constants.php index d0fd6277..68f70111 100644 --- a/examples/PayPalRecurring/Constants.php +++ b/examples/PayPalRecurring/Constants.php @@ -27,3 +27,4 @@ define('EXAMPLE_URL', EXAMPLE_BASE_FOLDER . 'PayPalRecurring'); define('CONTROLLER_URL', EXAMPLE_URL . '/Controller.php'); +define('MY_RETURN_CONTROLLER_URL', EXAMPLE_URL . '/ReturnController.php'); diff --git a/examples/PayPalRecurring/Controller.php b/examples/PayPalRecurring/Controller.php index 8fb8535d..990b2e60 100644 --- a/examples/PayPalRecurring/Controller.php +++ b/examples/PayPalRecurring/Controller.php @@ -61,7 +61,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '') $unzer = new Unzer(UNZER_PAPI_PRIVATE_KEY); $unzer->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - $recurring = $unzer->activateRecurringPayment($paymentTypeId, RETURN_CONTROLLER_URL); + $recurring = $unzer->activateRecurringPayment($paymentTypeId, MY_RETURN_CONTROLLER_URL); // You'll need to remember the paymentId for later in the ReturnController (in case of 3ds) $_SESSION['PaymentTypeId'] = $paymentTypeId; diff --git a/examples/PayPalRecurring/ReturnController.php b/examples/PayPalRecurring/ReturnController.php new file mode 100644 index 00000000..13beb304 --- /dev/null +++ b/examples/PayPalRecurring/ReturnController.php @@ -0,0 +1,79 @@ + + * + * @package UnzerSDK\examples + */ + +/** Require the constants of this example */ +require_once __DIR__ . '/Constants.php'; + +/** @noinspection PhpIncludeInspection */ +/** Require the composer autoloader file */ +require_once __DIR__ . '/../../../../autoload.php'; + +use UnzerSDK\examples\ExampleDebugHandler; +use UnzerSDK\Exceptions\UnzerApiException; +use UnzerSDK\Unzer; +use UnzerSDK\Resources\PaymentTypes\Card; + +session_start(); + +$clientMessage = 'Something went wrong. Please try again later.'; +$merchantMessage = 'Something went wrong. Please try again later.'; + +function redirect($url, $merchantMessage = '', $clientMessage = '') +{ + $_SESSION['merchantMessage'] = $merchantMessage; + $_SESSION['clientMessage'] = $clientMessage; + header('Location: ' . $url); + die(); +} + +// Retrieve the paymentId you remembered within the Controller +if (!isset($_SESSION['PaymentTypeId'])) { + redirect(FAILURE_URL, 'The payment type id is missing.', $clientMessage); +} +$paymentTypeId = $_SESSION['PaymentTypeId']; + +// Catch API errors, write the message to your log and show the ClientMessage to the client. +try { + // Create an Unzer object using your private key and register a debug handler if you want to. + $unzer = new Unzer(UNZER_PAPI_PRIVATE_KEY); + $unzer->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); + + // Redirect to success if the payment has been successfully completed or is still in handled. + /** @var Card $paymentType */ + $paymentType = $unzer->fetchPaymentType($paymentTypeId); + + if ($paymentType->isRecurring()) { + redirect(SUCCESS_URL); + } + +} catch (UnzerApiException $e) { + $merchantMessage = $e->getMerchantMessage(); + $clientMessage = $e->getClientMessage(); +} catch (RuntimeException $e) { + $merchantMessage = $e->getMessage(); +} + +redirect(FAILURE_URL, $merchantMessage, $clientMessage); From 713ef007e137b4b80955693f614773fd647ea3dc Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Mon, 22 Feb 2021 16:02:48 +0100 Subject: [PATCH 05/17] Add integration tests for instalment cancel after shipment. --- CHANGELOG.md | 3 + .../PaymentTypes/InstallmentSecuredTest.php | 71 +++++++++++++++++-- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6798f765..cc669337 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a * Change debug logging of failed tests that depend on another one to work as expected. * Several minor changes. +### Added +* Extended testing for Instalment payment type. + ## [1.1.1.0] ### Changed diff --git a/test/integration/PaymentTypes/InstallmentSecuredTest.php b/test/integration/PaymentTypes/InstallmentSecuredTest.php index 72152aa3..15e43147 100644 --- a/test/integration/PaymentTypes/InstallmentSecuredTest.php +++ b/test/integration/PaymentTypes/InstallmentSecuredTest.php @@ -29,6 +29,7 @@ use UnzerSDK\Constants\ApiResponseCodes; use UnzerSDK\Exceptions\UnzerApiException; +use UnzerSDK\Resources\AbstractUnzerResource; use UnzerSDK\Resources\Customer; use UnzerSDK\Resources\CustomerFactory; use UnzerSDK\Resources\EmbeddedResources\Address; @@ -81,7 +82,7 @@ public function instalmentPlanShouldBeSelectable(): void * * @test */ - public function hddTypeShouldBeFechable(): InstallmentSecured + public function hddTypeShouldBeFetchable(): InstallmentSecured { // Mock a hdd Type $date = $this->getTodaysDateString(); @@ -130,17 +131,18 @@ public function hddTypeShouldBeFechable(): InstallmentSecured * Verify fetched hdd type can be authorized and charged * * @test - * @depends hddTypeShouldBeFechable + * @depends hddTypeShouldBeFetchable * - * @param InvoiceSecured $hddType fetched ins type. + * @param InstallmentSecured $hddType fetched ins type. * + * @return AbstractUnzerResource|Charge * @throws UnzerApiException */ public function hddTypeAuthorizeAndCharge(InstallmentSecured $hddType) { $customer = $this->getMaximumCustomer(); $basket = $this->createBasket(); - /** @var Authorization $auth */ + $auth = $hddType->authorize(119.00, 'EUR', 'https://unzer.com', $customer, null, null, $basket); $charge = $auth->getPayment()->charge(); $this->assertNotNull($auth); @@ -320,6 +322,67 @@ public function verifyPartlyCancelChargedInstallmentSecured(): void $this->assertTrue($payment->isCompleted()); } + /** + * Verify full cancel of charged HP after shipment. + * + * @test + * + * @depends verifyChargingAnInitializedInstallmentSecured + */ + public function verifyChargeAndFullCancelAnInitializedInstallmentSecuredAfterShipment(): void + { + $yesterday = $this->getYesterdaysTimestamp(); + $plans = $this->unzer->fetchInstallmentPlans(119.0, 'EUR', 4.99, $yesterday); + $this->assertGreaterThan(0, count($plans->getPlans())); + + /** @var InstalmentPlan $selectedPlan */ + $selectedPlan = $plans->getPlans()[0]; + $ins = new InstallmentSecured($selectedPlan, 'DE46940594210000012345', 'Manuel Weißmann', $yesterday, 'COBADEFFXXX', $yesterday, $this->getTomorrowsTimestamp()); + $this->unzer->createPaymentType($ins); + + $authorize = $ins->authorize(119.0, 'EUR', self::RETURN_URL, $this->getCustomer(), null, null, $basket = $this->createBasket()); + $payment = $authorize->getPayment(); + + $hddCharge = $payment->charge(); + $invoiceId = 'i' . self::generateRandomId(); + $ship = $this->unzer->ship($hddCharge->getPayment(), $invoiceId); + $this->assertNotNull($ship); + + $cancel = $payment->cancelAmount(); + $this->assertGreaterThan(0, count($cancel)); + } + + /** + * Verify full cancel of charged HP after shipment. + * + * @test + * + * @depends verifyChargingAnInitializedInstallmentSecured + */ + public function verifyPartlyCancelChargedInstallmentSecuredAfterShipment(): void + { + $yesterday = $this->getYesterdaysTimestamp(); + $plans = $this->unzer->fetchInstallmentPlans(119.0, 'EUR', 4.99, $yesterday); + $this->assertGreaterThan(0, count($plans->getPlans())); + + /** @var InstalmentPlan $selectedPlan */ + $selectedPlan = $plans->getPlans()[0]; + $ins = new InstallmentSecured($selectedPlan, 'DE89370400440532013000', 'Manuel Weißmann', $yesterday, 'COBADEFFXXX', $this->getTodaysDateString(), $this->getTomorrowsTimestamp()); + $this->unzer->createPaymentType($ins); + + $authorize = $ins->authorize(119.0, 'EUR', self::RETURN_URL, $this->getCustomer(), null, null, $basket = $this->createBasket()); + $payment = $authorize->getPayment(); + + $hddCharge = $payment->charge(); + $invoiceId = 'i' . self::generateRandomId(); + $ship = $this->unzer->ship($hddCharge->getPayment(), $invoiceId); + $this->assertNotNull($ship); + + $cancel = $payment->cancelAmount(59.5, null, null, 50.0, 9.5); + $this->assertCount(1, $cancel); + $this->assertTrue($payment->isCompleted()); + } + // // From 01e3b506ff147b9c8ade98aca6bc999395470223 Mon Sep 17 00:00:00 2001 From: sixer1182 Date: Mon, 22 Feb 2021 16:37:28 +0100 Subject: [PATCH 06/17] Add integration tests for instalment cancel after shipment. --- CHANGELOG.md | 3 +++ composer.json | 2 +- test/integration/PaymentTypes/InstallmentSecuredTest.php | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc669337..5ff6f731 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ### Added * Extended testing for Instalment payment type. +### Changed +* Remove PhpUnit 8 support. + ## [1.1.1.0] ### Changed diff --git a/composer.json b/composer.json index c9927508..56c11db6 100755 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "ext-json": "*" }, "require-dev": { - "phpunit/phpunit": ">6.5 <9.0", + "phpunit/phpunit": ">6.5 <8.0", "friendsofphp/php-cs-fixer": "^2.0" }, "suggest": { diff --git a/test/integration/PaymentTypes/InstallmentSecuredTest.php b/test/integration/PaymentTypes/InstallmentSecuredTest.php index 15e43147..c074cc3a 100644 --- a/test/integration/PaymentTypes/InstallmentSecuredTest.php +++ b/test/integration/PaymentTypes/InstallmentSecuredTest.php @@ -337,7 +337,7 @@ public function verifyChargeAndFullCancelAnInitializedInstallmentSecuredAfterShi /** @var InstalmentPlan $selectedPlan */ $selectedPlan = $plans->getPlans()[0]; - $ins = new InstallmentSecured($selectedPlan, 'DE46940594210000012345', 'Manuel Weißmann', $yesterday, 'COBADEFFXXX', $yesterday, $this->getTomorrowsTimestamp()); + $ins = new InstallmentSecured($selectedPlan, 'DE89370400440532013000', 'Manuel Weißmann', $yesterday, 'COBADEFFXXX', $this->getTodaysDateString(), $this->getTomorrowsTimestamp()); $this->unzer->createPaymentType($ins); $authorize = $ins->authorize(119.0, 'EUR', self::RETURN_URL, $this->getCustomer(), null, null, $basket = $this->createBasket()); From ce13e5dcc00c923e5663c6345bf790f3572d5cb3 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 1 Mar 2021 17:32:16 +0100 Subject: [PATCH 07/17] - run cs-fixer. --- test/integration/PaymentTypes/InstallmentSecuredTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/test/integration/PaymentTypes/InstallmentSecuredTest.php b/test/integration/PaymentTypes/InstallmentSecuredTest.php index c074cc3a..4eb5f5c0 100644 --- a/test/integration/PaymentTypes/InstallmentSecuredTest.php +++ b/test/integration/PaymentTypes/InstallmentSecuredTest.php @@ -136,6 +136,7 @@ public function hddTypeShouldBeFetchable(): InstallmentSecured * @param InstallmentSecured $hddType fetched ins type. * * @return AbstractUnzerResource|Charge + * * @throws UnzerApiException */ public function hddTypeAuthorizeAndCharge(InstallmentSecured $hddType) From 5c05b37e46ad82ba1d5ed975ca0b88c9c164e436 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 1 Mar 2021 17:55:07 +0100 Subject: [PATCH 08/17] [chang](UMCS-49) - Add card example using complete form for cards payment type. --- CHANGELOG.md | 4 +- examples/CardCompleteForm/Constants.php | 29 ++++ examples/CardCompleteForm/Controller.php | 112 +++++++++++++ examples/CardCompleteForm/index.php | 200 +++++++++++++++++++++++ examples/index.php | 13 ++ 5 files changed, 357 insertions(+), 1 deletion(-) create mode 100644 examples/CardCompleteForm/Constants.php create mode 100644 examples/CardCompleteForm/Controller.php create mode 100644 examples/CardCompleteForm/index.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ff6f731..57d9dcfe 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,13 +7,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ### Fix * Change debug logging of failed tests that depend on another one to work as expected. -* Several minor changes. +* PayPal recurring example: Response handling changed to check the recurring status of the payment type. ### Added * Extended testing for Instalment payment type. +* Cards example using email UI element. ### Changed * Remove PhpUnit 8 support. +* Several minor changes. ## [1.1.1.0] diff --git a/examples/CardCompleteForm/Constants.php b/examples/CardCompleteForm/Constants.php new file mode 100644 index 00000000..58f01411 --- /dev/null +++ b/examples/CardCompleteForm/Constants.php @@ -0,0 +1,29 @@ + + * + * @package UnzerSDK\examples + */ + +require_once __DIR__ . '/../Constants.php'; + +define('EXAMPLE_URL', EXAMPLE_BASE_FOLDER . 'Card'); +define('CONTROLLER_URL', EXAMPLE_URL . '/Controller.php'); diff --git a/examples/CardCompleteForm/Controller.php b/examples/CardCompleteForm/Controller.php new file mode 100644 index 00000000..a4af2676 --- /dev/null +++ b/examples/CardCompleteForm/Controller.php @@ -0,0 +1,112 @@ + + * + * @package UnzerSDK\examples + */ + +/** Require the constants of this example */ +require_once __DIR__ . '/Constants.php'; + +/** @noinspection PhpIncludeInspection */ +/** Require the composer autoloader file */ +require_once __DIR__ . '/../../../../autoload.php'; + +use UnzerSDK\examples\ExampleDebugHandler; +use UnzerSDK\Exceptions\UnzerApiException; +use UnzerSDK\Unzer; +use UnzerSDK\Resources\CustomerFactory; + +session_start(); +session_unset(); + +$clientMessage = 'Something went wrong. Please try again later.'; +$merchantMessage = 'Something went wrong. Please try again later.'; + +function redirect($url, $merchantMessage = '', $clientMessage = '') +{ + $_SESSION['merchantMessage'] = $merchantMessage; + $_SESSION['clientMessage'] = $clientMessage; + header('Location: ' . $url); + die(); +} + +// You will need the id of the payment type created in the frontend (index.php) +if (!isset($_POST['resourceId'])) { + redirect(FAILURE_URL, 'Resource id is missing!', $clientMessage); +} +$paymentTypeId = $_POST['resourceId']; + +// These lines are just for this example +$transactionType = $_POST['transaction_type'] ?? 'authorize'; + +// Catch API errors, write the message to your log and show the ClientMessage to the client. +try { + // Create an Unzer object using your private key and register a debug handler if you want to. + $unzer = new Unzer(UNZER_PAPI_PRIVATE_KEY); + $unzer->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); + + // Create a charge/authorize transaction + // For 3Ds2 compliance an email need to be set either in card type or in customer resource. + // If your merchant is only configured for one of those you can omit the flag. + $customer = CustomerFactory::createCustomer('Max', 'Mustermann'); + switch ($transactionType) { + case 'charge': + $transaction = $unzer->charge(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer, null, null, null, true); + break; + case 'payout': + $transaction = $unzer->payout(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer); + break; + default: + $transaction = $unzer->authorize(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer, null, null, null, true); + break; + } + + // You'll need to remember the paymentId for later in the ReturnController (in case of 3ds) + $_SESSION['PaymentId'] = $transaction->getPaymentId(); + $_SESSION['ShortId'] = $transaction->getShortId(); + + // Redirect to the 3ds page or to success depending on the state of the transaction + $payment = $transaction->getPayment(); + $redirect = !empty($transaction->getRedirectUrl()); + + switch (true) { + case (!$redirect && $transaction->isSuccess()): + redirect(SUCCESS_URL); + break; + case (!$redirect && $transaction->isPending()): + redirect(PENDING_URL); + break; + case ($redirect && $transaction->isPending()): + redirect($transaction->getRedirectUrl()); + break; + } + + // Check the result message of the transaction to find out what went wrong. + $merchantMessage = $transaction->getMessage()->getCustomer(); +} catch (UnzerApiException $e) { + $merchantMessage = $e->getMerchantMessage(); + $clientMessage = $e->getClientMessage(); +} catch (RuntimeException $e) { + $merchantMessage = $e->getMessage(); +} +redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/CardCompleteForm/index.php b/examples/CardCompleteForm/index.php new file mode 100644 index 00000000..1acf4d15 --- /dev/null +++ b/examples/CardCompleteForm/index.php @@ -0,0 +1,200 @@ + + * + * @package UnzerSDK\examples + */ + +/** Require the constants of this example */ +require_once __DIR__ . '/Constants.php'; + +/** @noinspection PhpIncludeInspection */ +/** Require the composer autoloader file */ +require_once __DIR__ . '/../../../../autoload.php'; +?> + + + + + + Unzer UI Examples + + + + + + + +

Example Data for VISA:

+
    +
  • Number: 4711100000000000
  • +
  • Expiry date: Date in the future
  • +
  • Cvc: 123
  • +
  • Secret: secret3
  • +
+ +

Example Data for Mastercard:

+
    +
  • Number: 5453010000059543
  • +
  • Expiry date: Date in the future
  • +
  • Cvc: 123
  • +
  • Secret: secret3
  • +
+ +

Click here to open our test data in new tab.

+ +
+ +
+ +
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ + + +
+
+ +
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+ + + + diff --git a/examples/index.php b/examples/index.php index 7dc8360f..ebc876b7 100755 --- a/examples/index.php +++ b/examples/index.php @@ -88,12 +88,25 @@ function printMessage($type, $title, $text)
Card
You can try authorize, charge and payout transactions with or without 3Ds. + This example submits email via customer resource.
Try
+
+
+
Card (Complete form)
+
+ You can try authorize, charge and payout transactions. + This example submits email via payment type resource. +
+
+
+ Try +
+
Card Recurring
From dedfdc77b0e06c436d5e01813a69e07e44da556b Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Tue, 2 Mar 2021 16:11:52 +0100 Subject: [PATCH 09/17] [change] (UMCS-49) - Add dummy customer-email to examples of card and paypages. --- CHANGELOG.md | 4 +++- examples/Card/Controller.php | 2 ++ examples/EmbeddedPayPage/Controller.php | 1 + examples/HostedPayPage/Controller.php | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57d9dcfe..89ccfe31 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,10 +11,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ### Added * Extended testing for Instalment payment type. -* Cards example using email UI element. +* Cards (extended) example using email UI element. ### Changed * Remove PhpUnit 8 support. +* Card recurring example using email UI element. +* Card example and paypage examples use a dummy customer-email to ensure they work with 3ds2. * Several minor changes. ## [1.1.1.0] diff --git a/examples/Card/Controller.php b/examples/Card/Controller.php index 28d599a7..60f79664 100644 --- a/examples/Card/Controller.php +++ b/examples/Card/Controller.php @@ -70,6 +70,8 @@ function redirect($url, $merchantMessage = '', $clientMessage = '') // The 3D secured flag can be used to switch between 3ds and non-3ds. // If your merchant is only configured for one of those you can omit the flag. $customer = CustomerFactory::createCustomer('Max', 'Mustermann'); + $customer->setEmail('test@test.com'); + switch ($transactionType) { case 'charge': $transaction = $unzer->charge(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL, $customer, null, null, null, $use3Ds); diff --git a/examples/EmbeddedPayPage/Controller.php b/examples/EmbeddedPayPage/Controller.php index d1ba78ef..937b71ec 100644 --- a/examples/EmbeddedPayPage/Controller.php +++ b/examples/EmbeddedPayPage/Controller.php @@ -59,6 +59,7 @@ // Create a charge/authorize transaction $customer = CustomerFactory::createCustomer('Max', 'Mustermann'); + $customer->setEmail('test@test.com'); // These are the mandatory parameters for the payment page ... $paypage = new Paypage(119.00, 'EUR', RETURN_CONTROLLER_URL); diff --git a/examples/HostedPayPage/Controller.php b/examples/HostedPayPage/Controller.php index f8a275a7..f14ba82c 100644 --- a/examples/HostedPayPage/Controller.php +++ b/examples/HostedPayPage/Controller.php @@ -64,6 +64,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '') // Create a charge/authorize transaction $customer = CustomerFactory::createCustomer('Max', 'Mustermann'); + $customer->setEmail('test@test.com'); // These are the mandatory parameters for the payment page ... $paypage = new Paypage(119.0, 'EUR', RETURN_CONTROLLER_URL); From cf22a4e1b11fdd7d4a8012d61c8c7883d3660843 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Tue, 2 Mar 2021 16:55:41 +0100 Subject: [PATCH 10/17] [change] (UMCS-49) - rename card (complete) to card (extended) --- examples/{CardCompleteForm => CardExtended}/Constants.php | 0 examples/{CardCompleteForm => CardExtended}/Controller.php | 0 examples/{CardCompleteForm => CardExtended}/index.php | 0 examples/index.php | 7 ++++--- 4 files changed, 4 insertions(+), 3 deletions(-) rename examples/{CardCompleteForm => CardExtended}/Constants.php (100%) rename examples/{CardCompleteForm => CardExtended}/Controller.php (100%) rename examples/{CardCompleteForm => CardExtended}/index.php (100%) diff --git a/examples/CardCompleteForm/Constants.php b/examples/CardExtended/Constants.php similarity index 100% rename from examples/CardCompleteForm/Constants.php rename to examples/CardExtended/Constants.php diff --git a/examples/CardCompleteForm/Controller.php b/examples/CardExtended/Controller.php similarity index 100% rename from examples/CardCompleteForm/Controller.php rename to examples/CardExtended/Controller.php diff --git a/examples/CardCompleteForm/index.php b/examples/CardExtended/index.php similarity index 100% rename from examples/CardCompleteForm/index.php rename to examples/CardExtended/index.php diff --git a/examples/index.php b/examples/index.php index ebc876b7..1564cdcf 100755 --- a/examples/index.php +++ b/examples/index.php @@ -97,13 +97,14 @@ function printMessage($type, $title, $text)
-
Card (Complete form)
+
Card (extended)
- You can try authorize, charge and payout transactions. + Including email and holder fields. + Adding more information to the card can improve risk acceptance. This example submits email via payment type resource.
-
+
Try
From de42ce7a6ccd05334198b13aca77cbd68fb85850 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Tue, 2 Mar 2021 16:56:24 +0100 Subject: [PATCH 11/17] [change] (UMCS-49) - rename card (complete) to card (extended) --- examples/CardRecurring/index.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/CardRecurring/index.php b/examples/CardRecurring/index.php index 7c81f33f..b69f0a20 100644 --- a/examples/CardRecurring/index.php +++ b/examples/CardRecurring/index.php @@ -80,6 +80,9 @@
+
+ +
@@ -102,6 +105,10 @@ containerId: 'card-element-id-cvc', onlyIframe: false }); + Card.create('email', { + containerId: 'card-element-id-email', + onlyIframe: false + }); // General event handling let formFieldValid = {}; @@ -119,7 +126,7 @@ formFieldValid[e.type] = false; $errorHolder.html(e.error) } - payButton.disabled = !(formFieldValid.number && formFieldValid.expiry && formFieldValid.cvc); + payButton.disabled = !(formFieldValid.number && formFieldValid.expiry && formFieldValid.cvc && formFieldValid.email); }; Card.addEventListener('change', eventHandlerCardInput); From 466e35e2b3b581b0857d643d6beb0fa1382119ba Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Tue, 2 Mar 2021 17:38:50 +0100 Subject: [PATCH 12/17] [change] (UMCS-49) - intend list items i changelog. --- CHANGELOG.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89ccfe31..5fb5409e 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,18 +6,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [1.1.1.1] ### Fix -* Change debug logging of failed tests that depend on another one to work as expected. -* PayPal recurring example: Response handling changed to check the recurring status of the payment type. +* Change debug logging of failed tests that depend on another one to work as expected. +* PayPal recurring example: Response handling changed to check the recurring status of the payment type. ### Added -* Extended testing for Instalment payment type. -* Cards (extended) example using email UI element. +* Extended testing for Instalment payment type. +* Cards (extended) example using email UI element. ### Changed -* Remove PhpUnit 8 support. -* Card recurring example using email UI element. -* Card example and paypage examples use a dummy customer-email to ensure they work with 3ds2. -* Several minor changes. +* Remove PhpUnit 8 support. +* Card recurring example using email UI element. +* Card example and paypage examples use a dummy customer-email to ensure they work with 3ds2. +* Several minor changes. ## [1.1.1.0] From c9bea0ec25a7016de14a30948865d48acabe35a0 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Tue, 2 Mar 2021 17:50:55 +0100 Subject: [PATCH 13/17] [change] (UMCS-49) - fixing intend of changelog. --- CHANGELOG.md | 58 ++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fb5409e..409acb52 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,40 +22,40 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ## [1.1.1.0] ### Changed -* Add email property to payment type `card` to meet 3Ds2.x regulations. -* Several minor changes. +* Add email property to payment type `card` to meet 3Ds2.x regulations. +* Several minor changes. ## [1.1.0.0] ### Changed -* Rebranding of the SDK. -* Removed payment type string from URL when fetching a payment type resource. -* Replace payment methods guaranteed/factoring by secured payment methods, i.e.: - * `InvoiceGuaranteed` and `InvoiceFactoring` replaced by `InvoiceSecured` - * `SepaDirectDebitGuaranteed` replaced by `SepaDirectDebitSecured` - * `HirePurchaseDirectDebit` replaced by `InstallmentSecured` - * Basket is now mandatory for all those payment types above. -* Added mapping of old payment type ids to the new payment type resources. -* Constant in `\UnzerSDK\Constants\ApiResponseCodes` got renamed: - * `API_ERROR_IVF_REQUIRES_CUSTOMER` renamed to `API_ERROR_FACTORING_REQUIRES_CUSTOMER`. - * `API_ERROR_IVF_REQUIRES_BASKET` renamed to `API_ERROR_FACTORING_REQUIRES_BASKET`. -* Several minor changes. +* Rebranding of the SDK. +* Removed payment type string from URL when fetching a payment type resource. +* Replace payment methods guaranteed/factoring by secured payment methods, i.e.: + * `InvoiceGuaranteed` and `InvoiceFactoring` replaced by `InvoiceSecured` + * `SepaDirectDebitGuaranteed` replaced by `SepaDirectDebitSecured` + * `HirePurchaseDirectDebit` replaced by `InstallmentSecured` + * Basket is now mandatory for all those payment types above. +* Added mapping of old payment type ids to the new payment type resources. +* Constant in `\UnzerSDK\Constants\ApiResponseCodes` got renamed: + * `API_ERROR_IVF_REQUIRES_CUSTOMER` renamed to `API_ERROR_FACTORING_REQUIRES_CUSTOMER`. + * `API_ERROR_IVF_REQUIRES_BASKET` renamed to `API_ERROR_FACTORING_REQUIRES_BASKET`. +* Several minor changes. ### Remove -* Remove deprecated methods: - * getAmountTotal - * setAmountTotal - * getCardHolder - * setHolder - * cancel - * cancelAllCharges - * cancelAuthorization - * getResource - * fetchResource -* Remove deprecated constants: - * API_ERROR_AUTHORIZE_ALREADY_CANCELLED - * API_ERROR_CHARGE_ALREADY_CHARGED_BACK - * API_ERROR_BASKET_ITEM_IMAGE_INVALID_EXTENSION - * ENV_VAR_NAME_DISABLE_TEST_LOGGING +* Remove deprecated methods: + * getAmountTotal + * setAmountTotal + * getCardHolder + * setHolder + * cancel + * cancelAllCharges + * cancelAuthorization + * getResource + * fetchResource +* Remove deprecated constants: + * API_ERROR_AUTHORIZE_ALREADY_CANCELLED + * API_ERROR_CHARGE_ALREADY_CHARGED_BACK + * API_ERROR_BASKET_ITEM_IMAGE_INVALID_EXTENSION + * ENV_VAR_NAME_DISABLE_TEST_LOGGING [1.1.0.0]: https://github.com/unzerdev/php-sdk/compare/1260b8314af1ac461e33f0cfb382ffcd0e87c105..1.1.0.0 [1.1.1.0]: https://github.com/unzerdev/php-sdk/compare/1.1.0.0..1.1.1.0 From 30620e889520ac9cc0779a8ef296d5d0ac7b7786 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Wed, 3 Mar 2021 16:28:14 +0100 Subject: [PATCH 14/17] Update examples/CardExtended/Constants.php Co-authored-by: Simon Gabriel --- examples/CardExtended/Constants.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/CardExtended/Constants.php b/examples/CardExtended/Constants.php index 58f01411..7c71b8da 100644 --- a/examples/CardExtended/Constants.php +++ b/examples/CardExtended/Constants.php @@ -1,6 +1,6 @@ Date: Wed, 3 Mar 2021 16:28:41 +0100 Subject: [PATCH 15/17] Update examples/CardExtended/Controller.php Co-authored-by: Simon Gabriel --- examples/CardExtended/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/CardExtended/Controller.php b/examples/CardExtended/Controller.php index a4af2676..ecc18524 100644 --- a/examples/CardExtended/Controller.php +++ b/examples/CardExtended/Controller.php @@ -1,6 +1,6 @@ Date: Fri, 5 Mar 2021 16:51:32 +0100 Subject: [PATCH 16/17] [change] (UMCS-49) - set correct controller url for card extended example. --- examples/CardExtended/Constants.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/CardExtended/Constants.php b/examples/CardExtended/Constants.php index 7c71b8da..fc0ac781 100644 --- a/examples/CardExtended/Constants.php +++ b/examples/CardExtended/Constants.php @@ -25,5 +25,5 @@ require_once __DIR__ . '/../Constants.php'; -define('EXAMPLE_URL', EXAMPLE_BASE_FOLDER . 'Card'); +define('EXAMPLE_URL', EXAMPLE_BASE_FOLDER . 'CardExtended'); define('CONTROLLER_URL', EXAMPLE_URL . '/Controller.php'); From 3a8b7ce4dbefb707c92d6064e5edfcf0d3ad4499 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Thu, 11 Mar 2021 11:18:00 +0100 Subject: [PATCH 17/17] [change] (UMCS-49) update version 1.1.1.1 --- src/Unzer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Unzer.php b/src/Unzer.php index a23adf1a..65faadf8 100644 --- a/src/Unzer.php +++ b/src/Unzer.php @@ -63,7 +63,7 @@ class Unzer implements UnzerParentInterface, PaymentServiceInterface, ResourceSe public const BASE_URL = 'api.unzer.com'; public const API_VERSION = 'v1'; public const SDK_TYPE = 'UnzerPHP'; - public const SDK_VERSION = '1.1.1.0'; + public const SDK_VERSION = '1.1.1.1'; /** @var string $key */ private $key;