From 3334c9436ad01b668203a82043b0b4353ff0c9d8 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 2 May 2019 13:36:18 +0200 Subject: [PATCH 01/57] [change] Update SAQ-A keypair to fix test case. --- test/BasePaymentTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/BasePaymentTest.php b/test/BasePaymentTest.php index 4ec1a91b..acabae50 100755 --- a/test/BasePaymentTest.php +++ b/test/BasePaymentTest.php @@ -53,8 +53,8 @@ class BasePaymentTest extends TestCase // in which case the merchant has to embed our iFrame via JS (UIComponents). const PRIVATE_KEY_SAQ_D = 's-priv-2a102ZMq3gV4I3zJ888J7RR6u75oqK3n'; const PUBLIC_KEY_SAQ_D = 's-pub-2a10ifVINFAjpQJ9qW8jBe5OJPBx6Gxa'; - const PRIVATE_KEY_SAQ_A = 's-priv-2a10Fms2uloMzEvPs84trtEkGuv7reSG'; - const PUBLIC_KEY_SAQ_A = 's-pub-2a10YMoLIZ82Dg5eWFrKWRrbkuoQ2OzN'; + const PRIVATE_KEY_SAQ_A = 's-priv-2a1095rIVXy4IrNFXG6yQiguSAqNjciC'; + const PUBLIC_KEY_SAQ_A = 's-pub-2a10xITCUtmO2FlTP8RKB3OhdnKI4RmU'; /** * {@inheritDoc} From 763998dc6036734f71289c6c65c7e955d2dead12 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 2 May 2019 17:11:33 +0200 Subject: [PATCH 02/57] [change] Add missing invoiceId parameter to Payment::ship method. --- CHANGELOG.md | 8 ++ src/Heidelpay.php | 2 +- src/Resources/Payment.php | 6 +- .../PaymentTypes/InvoiceFactoringTest.php | 129 ++++++++++++++++-- 4 files changed, 130 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c19dd15..6b91f4f6 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ 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). +## [XXXX][XXXX] + +### Fixed +* Added missing parameter `invoiceId` to `payment::ship` method. + +### Change +* Change key pair for SAQ-A integration test. + ## [1.1.1.0][1.1.1.0] ### Added diff --git a/src/Heidelpay.php b/src/Heidelpay.php index eee1863c..167ab6a8 100755 --- a/src/Heidelpay.php +++ b/src/Heidelpay.php @@ -1091,7 +1091,7 @@ public function cancelCharge(Charge $charge, $amount = null, string $reasonCode * Performs a Shipment transaction and returns the resulting Shipment object. * * @param Payment|string $payment The Payment object the the id of the Payment to ship. - * @param string|null $invoiceId + * @param string|null $invoiceId The id of the invoice in the shop. * * @return Shipment The resulting Shipment object. * diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index 01557894..e22241cc 100755 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -680,14 +680,16 @@ public function charge($amount = null, $currency = null): Charge /** * Performs a Shipment transaction on this Payment. * + * @param string|null $invoiceId The id of the invoice in the shop. + * * @return AbstractHeidelpayResource|Shipment The resulting Shipment object. * * @throws HeidelpayApiException A HeidelpayApiException is thrown if there is an error returned on API-request. * @throws RuntimeException A RuntimeException is thrown when there is a error while using the SDK. */ - public function ship() + public function ship($invoiceId = null) { - return $this->getHeidelpayObject()->ship($this); + return $this->getHeidelpayObject()->ship($this, $invoiceId); } // diff --git a/test/integration/PaymentTypes/InvoiceFactoringTest.php b/test/integration/PaymentTypes/InvoiceFactoringTest.php index e6504cdc..60d5a8e7 100755 --- a/test/integration/PaymentTypes/InvoiceFactoringTest.php +++ b/test/integration/PaymentTypes/InvoiceFactoringTest.php @@ -159,40 +159,109 @@ public function invoiceFactoringShouldBeChargeable(InvoiceFactoring $invoiceFact } /** - * Verify Invoice Factoring is not shippable. + * Verify Invoice Factoring is not shippable on heidelpay object. * * @test * - * @param Charge $charge - * * @throws HeidelpayApiException * @throws RuntimeException * @throws Exception - * @depends invoiceFactoringShouldBeChargeable */ - public function verifyInvoiceFactoringIsNotShippableWoInvoiceId(Charge $charge) + public function verifyInvoiceFactoringIsNotShippableWoInvoiceIdOnHeidelpayObject() { - $payment = $charge->getPayment(); + // create payment type + /** @var InvoiceFactoring $invoiceFactoring */ + $invoiceFactoring = $this->heidelpay->createPaymentType(new InvoiceFactoring()); + + // perform charge + $customer = $this->getMaximumCustomer(); + $customer->setShippingAddress($customer->getBillingAddress()); + + $basket = $this->createBasket(); + $charge = $invoiceFactoring->charge( + 100.0, + 'EUR', + self::RETURN_URL, + $customer, + $basket->getOrderId(), + null, + $basket + ); + // perform shipment + $payment = $charge->getPayment(); $this->expectException(HeidelpayApiException::class); $this->expectExceptionCode(ApiResponseCodes::API_ERROR_SHIPPING_REQUIRES_INVOICE_ID); - $this->heidelpay->ship($payment); } /** - * Verify Invoice Factoring shipment with invoice id. + * Verify Invoice Factoring is not shippable on payment object. * * @test * - * @param Charge $charge + * @throws HeidelpayApiException + * @throws RuntimeException + * @throws Exception + */ + public function verifyInvoiceFactoringIsNotShippableWoInvoiceIdOnPaymentObject() + { + // create payment type + /** @var InvoiceFactoring $invoiceFactoring */ + $invoiceFactoring = $this->heidelpay->createPaymentType(new InvoiceFactoring()); + + // perform charge + $customer = $this->getMaximumCustomer(); + $customer->setShippingAddress($customer->getBillingAddress()); + + $basket = $this->createBasket(); + $charge = $invoiceFactoring->charge( + 100.0, + 'EUR', + self::RETURN_URL, + $customer, + $basket->getOrderId(), + null, + $basket + ); + + // perform shipment + $payment = $charge->getPayment(); + $this->expectException(HeidelpayApiException::class); + $this->expectExceptionCode(ApiResponseCodes::API_ERROR_SHIPPING_REQUIRES_INVOICE_ID); + $payment->ship(); + } + + /** + * Verify Invoice Factoring shipment with invoice id on heidelpay object. + * + * @test * * @throws HeidelpayApiException * @throws RuntimeException - * @depends invoiceFactoringShouldBeChargeable */ - public function verifyInvoiceFactoringShipmentWithInvoiceId(Charge $charge) + public function verifyInvoiceFactoringShipmentWithInvoiceIdOnHeidelpayObject() { + // create payment type + /** @var InvoiceFactoring $invoiceFactoring */ + $invoiceFactoring = $this->heidelpay->createPaymentType(new InvoiceFactoring()); + + // perform charge + $customer = $this->getMaximumCustomer(); + $customer->setShippingAddress($customer->getBillingAddress()); + + $basket = $this->createBasket(); + $charge = $invoiceFactoring->charge( + 100.0, + 'EUR', + self::RETURN_URL, + $customer, + $basket->getOrderId(), + null, + $basket + ); + + // perform shipment $payment = $charge->getPayment(); $invoiceId = substr(str_replace(['0.',' '], '', microtime(false)), 0, 16); $shipment = $this->heidelpay->ship($payment, $invoiceId); @@ -201,7 +270,43 @@ public function verifyInvoiceFactoringShipmentWithInvoiceId(Charge $charge) } /** - * Verify Invoice Factoring shipment with pre set invoide id + * Verify Invoice Factoring shipment with invoice id on payment object. + * + * @test + * + * @throws HeidelpayApiException + * @throws RuntimeException + */ + public function verifyInvoiceFactoringShipmentWithInvoiceIdOnPaymentObject() + { + // create payment type + /** @var InvoiceFactoring $invoiceFactoring */ + $invoiceFactoring = $this->heidelpay->createPaymentType(new InvoiceFactoring()); + + // perform charge + $customer = $this->getMaximumCustomer(); + $customer->setShippingAddress($customer->getBillingAddress()); + + $basket = $this->createBasket(); + $charge = $invoiceFactoring->charge( + 100.0, + 'EUR', + self::RETURN_URL, + $customer, + $basket->getOrderId(), + null, + $basket + ); + + $payment = $charge->getPayment(); + $invoiceId = substr(str_replace(['0.',' '], '', microtime(false)), 0, 16); + $shipment = $payment->ship($invoiceId); + $this->assertNotNull($shipment->getId()); + $this->assertEquals($invoiceId, $shipment->getInvoiceId()); + } + + /** + * Verify Invoice Factoring shipment with pre set invoice id * * @test * From 7e1026f37ad6f91aa1b88b585eb4dfa6f75f4fc1 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 3 May 2019 13:05:10 +0200 Subject: [PATCH 03/57] [cleanup] InvoiceFactoring: Remove unused constant. --- examples/InvoiceFactoring/Constants.php | 1 - examples/InvoiceFactoring/Controller.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/InvoiceFactoring/Constants.php b/examples/InvoiceFactoring/Constants.php index 73453c05..8594a500 100755 --- a/examples/InvoiceFactoring/Constants.php +++ b/examples/InvoiceFactoring/Constants.php @@ -28,4 +28,3 @@ define('EXAMPLE_PATH', __DIR__); define('EXAMPLE_URL', EXAMPLE_BASE_FOLDER . 'InvoiceFactoring'); define('CONTROLLER_URL', EXAMPLE_URL . '/Controller.php'); -define('RETURN_CONTROLLER_URL', EXAMPLE_URL . '/ReturnController.php'); diff --git a/examples/InvoiceFactoring/Controller.php b/examples/InvoiceFactoring/Controller.php index 65eae60b..0001bd08 100755 --- a/examples/InvoiceFactoring/Controller.php +++ b/examples/InvoiceFactoring/Controller.php @@ -78,7 +78,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '') $basketItem = new BasketItem('Hat', 10.0, 10.0, 1); $basket = new Basket($orderId, 10.0, 'EUR', [$basketItem]); - $transaction = $invoiceFactoring->charge(12.99, 'EUR', RETURN_CONTROLLER_URL, $customer, $orderId, null, $basket); + $transaction = $invoiceFactoring->charge(12.99, 'EUR', CONTROLLER_URL, $customer, $orderId, null, $basket); // You'll need to remember the paymentId for later in the ReturnController (in case of 3ds) $_SESSION['PaymentId'] = $transaction->getPaymentId(); From 7ea1caaab37e0cf46ec101f9374ab7006d70486f Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 3 May 2019 13:06:15 +0200 Subject: [PATCH 04/57] [change] (PHPLIB-116) Add basic example for Invoice guaranteed. --- examples/InvoiceGuaranteed/Constants.php | 30 +++++++ examples/InvoiceGuaranteed/Controller.php | 96 ++++++++++++++++++++ examples/InvoiceGuaranteed/index.php | 105 ++++++++++++++++++++++ examples/index.php | 13 +++ 4 files changed, 244 insertions(+) create mode 100755 examples/InvoiceGuaranteed/Constants.php create mode 100755 examples/InvoiceGuaranteed/Controller.php create mode 100755 examples/InvoiceGuaranteed/index.php diff --git a/examples/InvoiceGuaranteed/Constants.php b/examples/InvoiceGuaranteed/Constants.php new file mode 100755 index 00000000..167ecefb --- /dev/null +++ b/examples/InvoiceGuaranteed/Constants.php @@ -0,0 +1,30 @@ + + * + * @package heidelpayPHP/examples + */ + +require_once __DIR__ . '/../Constants.php'; + +define('EXAMPLE_PATH', __DIR__); +define('EXAMPLE_URL', EXAMPLE_BASE_FOLDER . 'InvoiceGuaranteed'); +define('CONTROLLER_URL', EXAMPLE_URL . '/Controller.php'); diff --git a/examples/InvoiceGuaranteed/Controller.php b/examples/InvoiceGuaranteed/Controller.php new file mode 100755 index 00000000..af9b6504 --- /dev/null +++ b/examples/InvoiceGuaranteed/Controller.php @@ -0,0 +1,96 @@ + + * + * @package heidelpayPHP/examples + */ + +/** Require the constants of this example */ +require_once __DIR__ . '/Constants.php'; + +/** Require the composer autoloader file */ +require_once __DIR__ . '/../../../../autoload.php'; + +use heidelpayPHP\examples\ExampleDebugHandler; +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(); + +$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['paymentTypeId'], $_POST['customerId'])) { + redirect(FAILURE_URL, 'Resource id is missing!', $clientMessage); +} +$paymentTypeId = $_POST['paymentTypeId']; +$customerId = $_POST['customerId']; + +// Catch API errors, write the message to your log and show the ClientMessage to the client. +try { + // Create a heidelpay object using your private key and register a debug handler if you want to. + $heidelpay = new Heidelpay(HEIDELPAY_PHP_PAYMENT_API_PRIVATE_KEY); + $heidelpay->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); + + $orderId = str_replace(['0.', ' '], '', microtime(false)); + + // A Basket is mandatory for Invoice Factoring payment type + $basketItem = new BasketItem('Hat', 10.0, 10.0, 1); + $basket = new Basket($orderId, 10.0, 'EUR', [$basketItem]); + + $transaction = $heidelpay->charge(12.99, 'EUR', $paymentTypeId, CONTROLLER_URL, $customerId, $orderId, null, $basket); + + // 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(); + if ($transaction->isPending()) { + redirect(SUCCESS_URL); + } + + // Check the result message of the transaction to find out what went wrong. + $merchantMessage = $transaction->getMessage()->getCustomer(); +} catch (HeidelpayApiException $e) { + $merchantMessage = $e->getMerchantMessage(); + $clientMessage = $e->getClientMessage(); +} catch (RuntimeException $e) { + $merchantMessage = $e->getMessage(); +} +redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/InvoiceGuaranteed/index.php b/examples/InvoiceGuaranteed/index.php new file mode 100755 index 00000000..e18dc809 --- /dev/null +++ b/examples/InvoiceGuaranteed/index.php @@ -0,0 +1,105 @@ + + * + * @package heidelpayPHP/examples + */ + +/** Require the constants of this example */ +require_once __DIR__ . '/Constants.php'; + +/** Require the composer autoloader file */ +require_once __DIR__ . '/../../../../autoload.php'; +?> + + + + + + + Heidelpay UI Examples + + + + + + + + + +
+
+
+ +
+
+ +
+
+ + + + + diff --git a/examples/index.php b/examples/index.php index 8a6cd437..5d1d5c92 100755 --- a/examples/index.php +++ b/examples/index.php @@ -107,6 +107,19 @@ Try +
+
+
+ Invoice guaranteed +
+
+ Charge +
+
+
+ Try +
+
From 5eef2c87fff5c38645fef3245148fbf52d66d448 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 3 May 2019 13:08:36 +0200 Subject: [PATCH 05/57] [change] (PHPLIB-116) Update version and changelog. --- CHANGELOG.md | 6 +++++- src/Heidelpay.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b91f4f6..30fa62d8 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,10 @@ 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). -## [XXXX][XXXX] +## [1.1.2.0][1.1.2.0] + +### Added +* Added example for invoice guaranteed payment type. ### Fixed * Added missing parameter `invoiceId` to `payment::ship` method. @@ -159,3 +162,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [1.0.2.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.0.1.0..1.0.2.0 [1.1.0.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.0.2.0..1.1.0.0 [1.1.1.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.1.0.0..1.1.1.0 +[1.1.2.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.1.1.0..1.1.2.0 diff --git a/src/Heidelpay.php b/src/Heidelpay.php index 167ab6a8..26c20dcf 100755 --- a/src/Heidelpay.php +++ b/src/Heidelpay.php @@ -53,7 +53,7 @@ class Heidelpay implements HeidelpayParentInterface const BASE_URL = 'https://api.heidelpay.com/'; const API_VERSION = 'v1'; const SDK_TYPE = 'HeidelpayPHP'; - const SDK_VERSION = '1.1.1.0'; + const SDK_VERSION = '1.1.2.0'; /** @var string $key */ private $key; From d68b009e37de67a5217a9a8176819078af6761e7 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 3 May 2019 15:06:53 +0200 Subject: [PATCH 06/57] [bugfix] Wechatpay: Fix folder name. --- examples/Wechatpay/Constants.php | 2 +- examples/index.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Wechatpay/Constants.php b/examples/Wechatpay/Constants.php index e8301888..28bf352d 100755 --- a/examples/Wechatpay/Constants.php +++ b/examples/Wechatpay/Constants.php @@ -26,6 +26,6 @@ require_once __DIR__ . '/../Constants.php'; define('EXAMPLE_PATH', __DIR__); -define('EXAMPLE_URL', EXAMPLE_BASE_FOLDER . 'WeChatPay'); +define('EXAMPLE_URL', EXAMPLE_BASE_FOLDER . 'Wechatpay'); define('CONTROLLER_URL', EXAMPLE_URL . '/Controller.php'); define('RETURN_CONTROLLER_URL', EXAMPLE_URL . '/ReturnController.php'); diff --git a/examples/index.php b/examples/index.php index 5d1d5c92..354e8b6b 100755 --- a/examples/index.php +++ b/examples/index.php @@ -103,7 +103,7 @@ Charge
-
+
Try
From ac7fcb90a42ea2c1dcca9fe680f4ac0c3a616045 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 3 May 2019 15:37:00 +0200 Subject: [PATCH 07/57] [change] Webhooks: Add card to disable all webhooks. --- examples/Webhooks/removeAll.php | 116 ++++++++++++++++++++++++++++++++ examples/index.php | 39 +++++++---- 2 files changed, 142 insertions(+), 13 deletions(-) create mode 100755 examples/Webhooks/removeAll.php diff --git a/examples/Webhooks/removeAll.php b/examples/Webhooks/removeAll.php new file mode 100755 index 00000000..980bfa74 --- /dev/null +++ b/examples/Webhooks/removeAll.php @@ -0,0 +1,116 @@ + + * + * @package heidelpayPHP/examples + */ + +/** Require the constants of this example */ +require_once __DIR__ . '/Constants.php'; + +/** Require the composer autoloader file */ +require_once __DIR__ . '/../../../../autoload.php'; + +use heidelpayPHP\examples\ExampleDebugHandler; +use heidelpayPHP\Exceptions\HeidelpayApiException; +use heidelpayPHP\Heidelpay; + +function printMessage($type, $title, $text) +{ + echo '
'. + '
' . $title . '
'. + '

' . nl2br($text) . '

'. + '
'; +} + +function printError($text) +{ + printMessage('error', 'Error', $text); +} + +function printSuccess($title, $text) +{ + printMessage('success', $title, $text); +} + +function printInfo($title, $text) +{ + printMessage('info', $title, $text); +} + +?> + + + + + + + Heidelpay UI Examples + + + + + + + + +
+

+ +
+ Webhook registration +
+

+ + setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); + + $heidelpay->deleteAllWebhooks(); + printSuccess( + 'De-registered all existing events for this private key', + 'Unsubscribed all events registered for the private key: "' . HEIDELPAY_PHP_PAYMENT_API_PRIVATE_KEY . '".' + ); + + } catch (HeidelpayApiException $e) { + printError($e->getMessage()); + $heidelpay->debugLog('Error: ' . $e->getMessage()); + } catch (RuntimeException $e) { + printError($e->getMessage()); + $heidelpay->debugLog('Error: ' . $e->getMessage()); + } + ?> +
+ + diff --git a/examples/index.php b/examples/index.php index 354e8b6b..66ff5e83 100755 --- a/examples/index.php +++ b/examples/index.php @@ -57,18 +57,18 @@
-
+
Credit Card
You can try authorize and charge transaction with or without 3Ds
-
+
Try
-
+
EPS @@ -77,11 +77,11 @@ Charge
-
+
Try
-
+
Alipay @@ -90,11 +90,11 @@ Charge
-
+
Try
-
+
WeChat Pay @@ -103,11 +103,11 @@ Charge
-
+
Try
-
+
Invoice guaranteed @@ -116,11 +116,11 @@ Charge
-
+
Try
-
+
Invoice Factoring @@ -129,7 +129,7 @@ Charge
-
+
Try
@@ -142,7 +142,20 @@ Enable a log output in ExampleDebugHandler to see the events coming in.
-
+
+ Try +
+
+
+
+
+ Delete all Webhooks +
+
+ Delete all Webhooks corresponding to this key pair. +
+
+
Try
From 1e64fe1ae5afe11cb91cab33ed4b02a3befcc709 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 3 May 2019 15:47:24 +0200 Subject: [PATCH 08/57] [change] Webhooks: Re-organized actions on the start page. --- examples/Webhooks/removeAll.php | 2 ++ examples/index.php | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/Webhooks/removeAll.php b/examples/Webhooks/removeAll.php index 980bfa74..a6c8a6cc 100755 --- a/examples/Webhooks/removeAll.php +++ b/examples/Webhooks/removeAll.php @@ -110,6 +110,8 @@ function printInfo($title, $text) printError($e->getMessage()); $heidelpay->debugLog('Error: ' . $e->getMessage()); } + + printInfo('Back to the payment selection', 'Now Perform payments >> HERE << to trigger events!'); ?>
diff --git a/examples/index.php b/examples/index.php index 66ff5e83..4c9c0cc0 100755 --- a/examples/index.php +++ b/examples/index.php @@ -53,7 +53,7 @@
Payment Implentation Examples -
Choose the Payment Type you want to evaluate...
+
Choose the Payment Type you want to evaluate ...
@@ -133,6 +133,18 @@ Try
+
+
+ +
+

+ +
+ Webhook Implentation Examples +
Enable or disable webhooks ...
+
+

+
From 5fadc98b97e5b7abbfc2ca11e3ad253d60c1d47f Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 3 May 2019 15:51:32 +0200 Subject: [PATCH 09/57] [change] Webhooks: Re-organized actions on the start page even further. --- examples/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/index.php b/examples/index.php index 4c9c0cc0..62e81c18 100755 --- a/examples/index.php +++ b/examples/index.php @@ -56,12 +56,12 @@
Choose the Payment Type you want to evaluate ...
-
+
Credit Card
- You can try authorize and charge transaction with or without 3Ds + You can try authorize and charge transaction with or without 3Ds.
@@ -144,7 +144,7 @@
Enable or disable webhooks ...
-
+
From d6169863a918454013ae48af4812c717d44cedef Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 3 May 2019 16:32:17 +0200 Subject: [PATCH 10/57] [change] Update changelog after example refactoring. --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30fa62d8..35ac5c9b 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a ### Added * Added example for invoice guaranteed payment type. +* Added example for the deletion of all webhooks. ### Fixed * Added missing parameter `invoiceId` to `payment::ship` method. ### Change * Change key pair for SAQ-A integration test. +* Refactored implementation examples. ## [1.1.1.0][1.1.1.0] From 106fb80f8761aab27627970d3fe6c890528337a0 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 3 May 2019 17:00:58 +0200 Subject: [PATCH 11/57] [change] (PHPLIB-117) PayPal: Add basic PayPal example. --- CHANGELOG.md | 1 + examples/PayPal/Constants.php | 31 +++++++++ examples/PayPal/Controller.php | 84 +++++++++++++++++++++++++ examples/PayPal/ReturnController.php | 78 +++++++++++++++++++++++ examples/PayPal/index.php | 94 ++++++++++++++++++++++++++++ examples/index.php | 13 ++++ 6 files changed, 301 insertions(+) create mode 100755 examples/PayPal/Constants.php create mode 100755 examples/PayPal/Controller.php create mode 100755 examples/PayPal/ReturnController.php create mode 100755 examples/PayPal/index.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 35ac5c9b..a37f3dd4 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 ### Added * Added example for invoice guaranteed payment type. +* Added example for PayPal payment type. * Added example for the deletion of all webhooks. ### Fixed diff --git a/examples/PayPal/Constants.php b/examples/PayPal/Constants.php new file mode 100755 index 00000000..e4dd40c0 --- /dev/null +++ b/examples/PayPal/Constants.php @@ -0,0 +1,31 @@ + + * + * @package heidelpayPHP/examples + */ + +require_once __DIR__ . '/../Constants.php'; + +define('EXAMPLE_PATH', __DIR__); +define('EXAMPLE_URL', EXAMPLE_BASE_FOLDER . 'PayPal'); +define('CONTROLLER_URL', EXAMPLE_URL . '/Controller.php'); +define('RETURN_CONTROLLER_URL', EXAMPLE_URL . '/ReturnController.php'); diff --git a/examples/PayPal/Controller.php b/examples/PayPal/Controller.php new file mode 100755 index 00000000..0bdcfa5a --- /dev/null +++ b/examples/PayPal/Controller.php @@ -0,0 +1,84 @@ + + * + * @package heidelpayPHP/examples + */ + +/** Require the constants of this example */ +require_once __DIR__ . '/Constants.php'; + +/** Require the composer autoloader file */ +require_once __DIR__ . '/../../../../autoload.php'; + +use heidelpayPHP\examples\ExampleDebugHandler; +use heidelpayPHP\Exceptions\HeidelpayApiException; +use heidelpayPHP\Heidelpay; +use heidelpayPHP\Resources\Customer; + +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']; + +// Catch API errors, write the message to your log and show the ClientMessage to the client. +try { + // Create a heidelpay object using your private key and register a debug handler if you want to. + $heidelpay = new Heidelpay(HEIDELPAY_PHP_PAYMENT_API_PRIVATE_KEY); + $heidelpay->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); + + // Create a charge to get the redirectUrl. + $charge = $heidelpay->charge(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL); + + // You'll need to remember the paymentId for later in the ReturnController + $_SESSION['PaymentId'] = $charge->getPaymentId(); + $_SESSION['ShortId'] = $charge->getShortId(); + + // Redirect to the Alipay page of the selected bank + if (!$charge->isError() && $charge->getRedirectUrl() !== null) { + redirect($charge->getRedirectUrl()); + } + + // Check the result message of the charge to find out what went wrong. + $merchantMessage = $charge->getMessage()->getCustomer(); +} catch (HeidelpayApiException $e) { + $merchantMessage = $e->getMerchantMessage(); + $clientMessage = $e->getClientMessage(); +} catch (RuntimeException $e) { + $merchantMessage = $e->getMessage(); +} +redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/PayPal/ReturnController.php b/examples/PayPal/ReturnController.php new file mode 100755 index 00000000..e8b511c3 --- /dev/null +++ b/examples/PayPal/ReturnController.php @@ -0,0 +1,78 @@ + + * + * @package heidelpayPHP/examples + */ + +/** Require the constants of this example */ +require_once __DIR__ . '/Constants.php'; + +/** Require the composer autoloader file */ +require_once __DIR__ . '/../../../../autoload.php'; + +use heidelpayPHP\examples\ExampleDebugHandler; +use heidelpayPHP\Exceptions\HeidelpayApiException; +use heidelpayPHP\Heidelpay; + +$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(); +} + +session_start(); + +// Retrieve the paymentId you remembered within the Controller +if (!isset($_SESSION['PaymentId'])) { + redirect(FAILURE_URL, 'The payment id is missing.', $clientMessage); +} +$paymentId = $_SESSION['PaymentId']; + +// Catch API errors, write the message to your log and show the ClientMessage to the client. +try { + // Create a heidelpay object using your private key and register a debug handler if you want to. + $heidelpay = new Heidelpay(HEIDELPAY_PHP_PAYMENT_API_PRIVATE_KEY); + $heidelpay->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); + + // Redirect to success if the payment has been successfully completed. + $payment = $heidelpay->fetchPayment($paymentId); + if ($payment->isCompleted()) { + redirect(SUCCESS_URL); + } + + // Check the result message of the charge to find out what went wrong. + $charge = $payment->getChargeByIndex(0); + $merchantMessage = $charge->getMessage()->getCustomer(); +} catch (HeidelpayApiException $e) { + $merchantMessage = $e->getMerchantMessage(); + $clientMessage = $e->getClientMessage(); +} catch (RuntimeException $e) { + $merchantMessage = $e->getMessage(); +} +redirect(FAILURE_URL, $merchantMessage, $clientMessage); + diff --git a/examples/PayPal/index.php b/examples/PayPal/index.php new file mode 100755 index 00000000..3644e4c1 --- /dev/null +++ b/examples/PayPal/index.php @@ -0,0 +1,94 @@ + + * + * @package heidelpayPHP/examples + */ + +/** Require the constants of this example */ +require_once __DIR__ . '/Constants.php'; + +/** Require the composer autoloader file */ +require_once __DIR__ . '/../../../../autoload.php'; +?> + + + + + + + + Heidelpay UI Examples + + + + + + + + +

Example data:

+
    +
  • Username: paypal-customer@heidelpay.de
  • +
  • Password: heidelpay
  • + Attention: We recommend to create your own PayPal test account here. +
+ +
+
+ +
+ + + + diff --git a/examples/index.php b/examples/index.php index 62e81c18..e1f2e202 100755 --- a/examples/index.php +++ b/examples/index.php @@ -133,6 +133,19 @@ Try
+
+
+
+ PayPal +
+
+ Charge +
+
+
+ Try +
+
From 85d6745310d14e5714991203f4fc0102d1a25283 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 3 May 2019 17:48:46 +0200 Subject: [PATCH 12/57] [change] (PHPLIB-116) Fix version. --- CHANGELOG.md | 4 ++-- src/Heidelpay.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35ac5c9b..b7208336 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ 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.2.0][1.1.2.0] +## [1.1.1.1][1.1.1.1] ### Added * Added example for invoice guaranteed payment type. @@ -164,4 +164,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [1.0.2.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.0.1.0..1.0.2.0 [1.1.0.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.0.2.0..1.1.0.0 [1.1.1.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.1.0.0..1.1.1.0 -[1.1.2.0]: https://github.com/heidelpay/heidelpayPHP/compare/1.1.1.0..1.1.2.0 +[1.1.1.1]: https://github.com/heidelpay/heidelpayPHP/compare/1.1.1.0..1.1.1.1 diff --git a/src/Heidelpay.php b/src/Heidelpay.php index 26c20dcf..da9be2ce 100755 --- a/src/Heidelpay.php +++ b/src/Heidelpay.php @@ -53,7 +53,7 @@ class Heidelpay implements HeidelpayParentInterface const BASE_URL = 'https://api.heidelpay.com/'; const API_VERSION = 'v1'; const SDK_TYPE = 'HeidelpayPHP'; - const SDK_VERSION = '1.1.2.0'; + const SDK_VERSION = '1.1.1.1'; /** @var string $key */ private $key; From 284b90c5eeda31755e679c868aabf12b69236724 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 6 May 2019 10:44:06 +0200 Subject: [PATCH 13/57] [change] (PHPLIB-117) PayPal-Example: Add switching between charge and authorize. --- examples/PayPal/Controller.php | 20 +++++++++++++------- examples/PayPal/ReturnController.php | 14 ++++++++++---- examples/PayPal/index.php | 20 +++++++++++++++++++- examples/index.php | 2 +- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/examples/PayPal/Controller.php b/examples/PayPal/Controller.php index 0bdcfa5a..6be68bd7 100755 --- a/examples/PayPal/Controller.php +++ b/examples/PayPal/Controller.php @@ -55,26 +55,32 @@ function redirect($url, $merchantMessage = '', $clientMessage = '') } $paymentTypeId = $_POST['resourceId']; +$transactionType = $_POST['transaction_type'] ?? 'authorize'; + // Catch API errors, write the message to your log and show the ClientMessage to the client. try { // Create a heidelpay object using your private key and register a debug handler if you want to. $heidelpay = new Heidelpay(HEIDELPAY_PHP_PAYMENT_API_PRIVATE_KEY); $heidelpay->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); - // Create a charge to get the redirectUrl. - $charge = $heidelpay->charge(12.99, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL); + // Create a charge/authorize transaction to get the redirectUrl. + if ($transactionType === 'charge') { + $transaction = $heidelpay->charge(12.32, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL); + } else { + $transaction = $heidelpay->authorize(12.32, 'EUR', $paymentTypeId, RETURN_CONTROLLER_URL); + } // You'll need to remember the paymentId for later in the ReturnController - $_SESSION['PaymentId'] = $charge->getPaymentId(); - $_SESSION['ShortId'] = $charge->getShortId(); + $_SESSION['PaymentId'] = $transaction->getPaymentId(); + $_SESSION['ShortId'] = $transaction->getShortId(); // Redirect to the Alipay page of the selected bank - if (!$charge->isError() && $charge->getRedirectUrl() !== null) { - redirect($charge->getRedirectUrl()); + if (!$transaction->isError() && $transaction->getRedirectUrl() !== null) { + redirect($transaction->getRedirectUrl()); } // Check the result message of the charge to find out what went wrong. - $merchantMessage = $charge->getMessage()->getCustomer(); + $merchantMessage = $transaction->getMessage()->getCustomer(); } catch (HeidelpayApiException $e) { $merchantMessage = $e->getMerchantMessage(); $clientMessage = $e->getClientMessage(); diff --git a/examples/PayPal/ReturnController.php b/examples/PayPal/ReturnController.php index e8b511c3..780b8628 100755 --- a/examples/PayPal/ReturnController.php +++ b/examples/PayPal/ReturnController.php @@ -33,6 +33,7 @@ use heidelpayPHP\examples\ExampleDebugHandler; use heidelpayPHP\Exceptions\HeidelpayApiException; use heidelpayPHP\Heidelpay; +use heidelpayPHP\Resources\TransactionTypes\Authorization; $clientMessage = 'Something went wrong. Please try again later.'; $merchantMessage = 'Something went wrong. Please try again later.'; @@ -61,13 +62,18 @@ function redirect($url, $merchantMessage = '', $clientMessage = '') // Redirect to success if the payment has been successfully completed. $payment = $heidelpay->fetchPayment($paymentId); - if ($payment->isCompleted()) { + if ($payment->isCompleted() || $payment->isPending()) { redirect(SUCCESS_URL); } - // Check the result message of the charge to find out what went wrong. - $charge = $payment->getChargeByIndex(0); - $merchantMessage = $charge->getMessage()->getCustomer(); + // Check the result message of the transaction to find out what went wrong. + $transaction = $payment->getAuthorization(); + if ($transaction instanceof Authorization) { + $merchantMessage = $transaction->getMessage()->getCustomer(); + } else { + $transaction = $payment->getChargeByIndex(0); + $merchantMessage = $transaction->getMessage()->getCustomer(); + } } catch (HeidelpayApiException $e) { $merchantMessage = $e->getMerchantMessage(); $clientMessage = $e->getClientMessage(); diff --git a/examples/PayPal/index.php b/examples/PayPal/index.php index 3644e4c1..edaa5797 100755 --- a/examples/PayPal/index.php +++ b/examples/PayPal/index.php @@ -50,10 +50,28 @@
  • Username: paypal-customer@heidelpay.de
  • Password: heidelpay
  • - Attention: We recommend to create your own PayPal test account here. + Attention: We recommend to create your own PayPal test account here.
+ +
+ +
+
+ + +
+
+
+
+ + +
+
+
+ +
diff --git a/examples/index.php b/examples/index.php index e1f2e202..dcb0444d 100755 --- a/examples/index.php +++ b/examples/index.php @@ -139,7 +139,7 @@ PayPal
- Charge + You can try authorize and direct charge.
From 7e5f9fe44a53636d5dc5ea111c465a0a71c533bc Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 6 May 2019 11:38:20 +0200 Subject: [PATCH 14/57] [refactor] Examples: Add link to test data page and changed descriptions. --- examples/Alipay/index.php | 2 ++ examples/CreditCard/index.php | 2 ++ examples/EPSCharge/index.php | 2 ++ examples/InvoiceFactoring/index.php | 2 +- examples/InvoiceGuaranteed/index.php | 2 ++ examples/PayPal/index.php | 2 ++ examples/Wechatpay/index.php | 2 ++ examples/index.php | 9 ++++----- 8 files changed, 17 insertions(+), 6 deletions(-) diff --git a/examples/Alipay/index.php b/examples/Alipay/index.php index e08f7fca..adfd3a11 100755 --- a/examples/Alipay/index.php +++ b/examples/Alipay/index.php @@ -52,6 +52,8 @@
  • Password: 123
  • +

    Click here to open our test data in new tab.

    +
    diff --git a/examples/CreditCard/index.php b/examples/CreditCard/index.php index 60778b39..19d80500 100755 --- a/examples/CreditCard/index.php +++ b/examples/CreditCard/index.php @@ -63,6 +63,8 @@
  • Secret: secret3
  • +

    Click here to open our test data in new tab.

    +
    diff --git a/examples/EPSCharge/index.php b/examples/EPSCharge/index.php index 165dcf68..dca003f9 100755 --- a/examples/EPSCharge/index.php +++ b/examples/EPSCharge/index.php @@ -54,6 +54,8 @@
  • TAN: 1111
  • +

    Click here to open our test data in new tab.

    +
    diff --git a/examples/InvoiceFactoring/index.php b/examples/InvoiceFactoring/index.php index bceb136d..37692326 100755 --- a/examples/InvoiceFactoring/index.php +++ b/examples/InvoiceFactoring/index.php @@ -48,7 +48,7 @@
    - +
    diff --git a/examples/InvoiceGuaranteed/index.php b/examples/InvoiceGuaranteed/index.php index e18dc809..8122ca1a 100755 --- a/examples/InvoiceGuaranteed/index.php +++ b/examples/InvoiceGuaranteed/index.php @@ -46,6 +46,8 @@ +

    Click here to open our test data in new tab.

    +
    diff --git a/examples/PayPal/index.php b/examples/PayPal/index.php index edaa5797..e8c0451f 100755 --- a/examples/PayPal/index.php +++ b/examples/PayPal/index.php @@ -53,6 +53,8 @@ Attention: We recommend to create your own PayPal test account here. +

    Click here to open our test data in new tab.

    +
    diff --git a/examples/Wechatpay/index.php b/examples/Wechatpay/index.php index dd8a876c..4d867c43 100755 --- a/examples/Wechatpay/index.php +++ b/examples/Wechatpay/index.php @@ -52,6 +52,8 @@
  • Password: 123
  • +

    Click here to open our test data in new tab.

    +
    diff --git a/examples/index.php b/examples/index.php index dcb0444d..e8bfa2df 100755 --- a/examples/index.php +++ b/examples/index.php @@ -74,7 +74,6 @@ EPS
    - Charge
    @@ -87,7 +86,6 @@ Alipay
    - Charge
    @@ -100,7 +98,6 @@ WeChat Pay
    - Charge
    @@ -113,7 +110,8 @@ Invoice guaranteed
    - Charge + This example adds the necessary customer data within the checkout form. + Please refer to the example of Invoice Factoring if you don't want to add the customer via payment form.
    @@ -126,7 +124,8 @@ Invoice Factoring
    - Charge + This example adds the necessary customer data within the php controller. + Please refer to the example of Invoice guaranteed if you want to add the customer data withing the payment form.
    From 4837ab9d18ee0295c877867e2a8ab38a629933cf Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 6 May 2019 13:22:09 +0200 Subject: [PATCH 15/57] [change] (PHPLIB-118) SepaDirectDebitGuaranteed: Add example. --- .../SepaDirectDebitGuaranteed/Constants.php | 30 +++++ .../SepaDirectDebitGuaranteed/Controller.php | 96 +++++++++++++++ examples/SepaDirectDebitGuaranteed/index.php | 115 ++++++++++++++++++ examples/index.php | 12 ++ 4 files changed, 253 insertions(+) create mode 100755 examples/SepaDirectDebitGuaranteed/Constants.php create mode 100755 examples/SepaDirectDebitGuaranteed/Controller.php create mode 100755 examples/SepaDirectDebitGuaranteed/index.php diff --git a/examples/SepaDirectDebitGuaranteed/Constants.php b/examples/SepaDirectDebitGuaranteed/Constants.php new file mode 100755 index 00000000..27f23f51 --- /dev/null +++ b/examples/SepaDirectDebitGuaranteed/Constants.php @@ -0,0 +1,30 @@ + + * + * @package heidelpayPHP/examples + */ + +require_once __DIR__ . '/../Constants.php'; + +define('EXAMPLE_PATH', __DIR__); +define('EXAMPLE_URL', EXAMPLE_BASE_FOLDER . 'SepaDirectDebitGuaranteed'); +define('CONTROLLER_URL', EXAMPLE_URL . '/Controller.php'); diff --git a/examples/SepaDirectDebitGuaranteed/Controller.php b/examples/SepaDirectDebitGuaranteed/Controller.php new file mode 100755 index 00000000..8b450711 --- /dev/null +++ b/examples/SepaDirectDebitGuaranteed/Controller.php @@ -0,0 +1,96 @@ + + * + * @package heidelpayPHP/examples + */ + +/** Require the constants of this example */ +require_once __DIR__ . '/Constants.php'; + +/** Require the composer autoloader file */ +require_once __DIR__ . '/../../../../autoload.php'; + +use heidelpayPHP\examples\ExampleDebugHandler; +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(); + +$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['paymentTypeId'], $_POST['customerId'])) { + redirect(FAILURE_URL, 'Resource id is missing!', $clientMessage); +} +$paymentTypeId = $_POST['paymentTypeId']; +$customerId = $_POST['customerId']; + +// Catch API errors, write the message to your log and show the ClientMessage to the client. +try { + // Create a heidelpay object using your private key and register a debug handler if you want to. + $heidelpay = new Heidelpay(HEIDELPAY_PHP_PAYMENT_API_PRIVATE_KEY); + $heidelpay->setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); + + $orderId = str_replace(['0.', ' '], '', microtime(false)); + + // A Basket is mandatory for Invoice Factoring payment type + $basketItem = new BasketItem('Hat', 10.0, 10.0, 1); + $basket = new Basket($orderId, 10.0, 'EUR', [$basketItem]); + + $transaction = $heidelpay->charge(12.99, 'EUR', $paymentTypeId, CONTROLLER_URL, $customerId, $orderId, null, $basket); + + // 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(); + if ($transaction->isSuccess()) { + redirect(SUCCESS_URL); + } + + // Check the result message of the transaction to find out what went wrong. + $merchantMessage = $transaction->getMessage()->getCustomer(); +} catch (HeidelpayApiException $e) { + $merchantMessage = $e->getMerchantMessage(); + $clientMessage = $e->getClientMessage(); +} catch (RuntimeException $e) { + $merchantMessage = $e->getMessage(); +} +redirect(FAILURE_URL, $merchantMessage, $clientMessage); diff --git a/examples/SepaDirectDebitGuaranteed/index.php b/examples/SepaDirectDebitGuaranteed/index.php new file mode 100755 index 00000000..67523786 --- /dev/null +++ b/examples/SepaDirectDebitGuaranteed/index.php @@ -0,0 +1,115 @@ + + * + * @package heidelpayPHP/examples + */ + +/** Require the constants of this example */ +require_once __DIR__ . '/Constants.php'; + +/** Require the composer autoloader file */ +require_once __DIR__ . '/../../../../autoload.php'; +?> + + + + + + + Heidelpay UI Examples + + + + + + + + + +

    Click here to open our test data in new tab.

    + + +
    + +
    +
    + +
    +
    + +
    + + + + + + diff --git a/examples/index.php b/examples/index.php index e8bfa2df..2f21c3ff 100755 --- a/examples/index.php +++ b/examples/index.php @@ -145,6 +145,18 @@ Try
    +
    +
    +
    + SEPA direct debit guaranteed +
    +
    +
    +
    +
    + Try +
    +
    From eb3ea90066cfa830fc975144e7f3aeab5482004c Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 6 May 2019 13:31:23 +0200 Subject: [PATCH 16/57] [change] (PHPLIB-118) SepaDirectDebitGuaranteed: Fix some comments. --- examples/SepaDirectDebitGuaranteed/Controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/SepaDirectDebitGuaranteed/Controller.php b/examples/SepaDirectDebitGuaranteed/Controller.php index 8b450711..c8142404 100755 --- a/examples/SepaDirectDebitGuaranteed/Controller.php +++ b/examples/SepaDirectDebitGuaranteed/Controller.php @@ -69,7 +69,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '') $orderId = str_replace(['0.', ' '], '', microtime(false)); - // A Basket is mandatory for Invoice Factoring payment type + // A Basket is mandatory for SEPA direct debit guaranteed payment type $basketItem = new BasketItem('Hat', 10.0, 10.0, 1); $basket = new Basket($orderId, 10.0, 'EUR', [$basketItem]); @@ -79,7 +79,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '') $_SESSION['PaymentId'] = $transaction->getPaymentId(); $_SESSION['ShortId'] = $transaction->getShortId(); - // Redirect to the 3ds page or to success depending on the state of the transaction + // Redirect to the success or failure depending on the state of the transaction $payment = $transaction->getPayment(); if ($transaction->isSuccess()) { redirect(SUCCESS_URL); From 1f2482affcb1cce9321d7e0eb2680fb864c15ffd Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 6 May 2019 16:12:11 +0200 Subject: [PATCH 17/57] [change] Examples: Remove icon from cc and fixed button of cc example. --- examples/CreditCard/index.php | 2 +- examples/index.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/CreditCard/index.php b/examples/CreditCard/index.php index 19d80500..a8dc72d2 100755 --- a/examples/CreditCard/index.php +++ b/examples/CreditCard/index.php @@ -114,7 +114,7 @@
    - +
    diff --git a/examples/index.php b/examples/index.php index 2f21c3ff..19405b88 100755 --- a/examples/index.php +++ b/examples/index.php @@ -59,7 +59,7 @@
    -
    Credit Card
    +
    Credit Card
    You can try authorize and charge transaction with or without 3Ds.
    From 05a1dea4b7e7bd815214b8028128dae4e1ccea87 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 6 May 2019 16:35:30 +0200 Subject: [PATCH 18/57] [cleanup] Examples: Optimized code and fix errors in comments. --- examples/Alipay/Controller.php | 2 +- examples/PayPal/Controller.php | 2 +- examples/PayPal/ReturnController.php | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/examples/Alipay/Controller.php b/examples/Alipay/Controller.php index 7be17074..f82ca02e 100755 --- a/examples/Alipay/Controller.php +++ b/examples/Alipay/Controller.php @@ -68,7 +68,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '') $_SESSION['PaymentId'] = $charge->getPaymentId(); $_SESSION['ShortId'] = $charge->getShortId(); - // Redirect to the Alipay page of the selected bank + // Redirect to the Alipay page if (!$charge->isError() && $charge->getRedirectUrl() !== null) { redirect($charge->getRedirectUrl()); } diff --git a/examples/PayPal/Controller.php b/examples/PayPal/Controller.php index 6be68bd7..0bca0673 100755 --- a/examples/PayPal/Controller.php +++ b/examples/PayPal/Controller.php @@ -74,7 +74,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '') $_SESSION['PaymentId'] = $transaction->getPaymentId(); $_SESSION['ShortId'] = $transaction->getShortId(); - // Redirect to the Alipay page of the selected bank + // Redirect to the PayPal page if (!$transaction->isError() && $transaction->getRedirectUrl() !== null) { redirect($transaction->getRedirectUrl()); } diff --git a/examples/PayPal/ReturnController.php b/examples/PayPal/ReturnController.php index 780b8628..e135d3b1 100755 --- a/examples/PayPal/ReturnController.php +++ b/examples/PayPal/ReturnController.php @@ -68,12 +68,10 @@ function redirect($url, $merchantMessage = '', $clientMessage = '') // Check the result message of the transaction to find out what went wrong. $transaction = $payment->getAuthorization(); - if ($transaction instanceof Authorization) { - $merchantMessage = $transaction->getMessage()->getCustomer(); - } else { + if (!$transaction instanceof Authorization) { $transaction = $payment->getChargeByIndex(0); - $merchantMessage = $transaction->getMessage()->getCustomer(); } + $merchantMessage = $transaction->getMessage()->getCustomer(); } catch (HeidelpayApiException $e) { $merchantMessage = $e->getMerchantMessage(); $clientMessage = $e->getClientMessage(); From 8df426e370f169a9d23e41fa91e6744fcc4ee255 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 6 May 2019 16:52:16 +0200 Subject: [PATCH 19/57] [cleanup] Examples: Fix minor errors in code and comments. --- examples/InvoiceFactoring/Controller.php | 5 ++--- examples/InvoiceGuaranteed/Controller.php | 5 ++--- examples/SepaDirectDebitGuaranteed/Controller.php | 3 +-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/examples/InvoiceFactoring/Controller.php b/examples/InvoiceFactoring/Controller.php index 0001bd08..136af93f 100755 --- a/examples/InvoiceFactoring/Controller.php +++ b/examples/InvoiceFactoring/Controller.php @@ -80,11 +80,10 @@ function redirect($url, $merchantMessage = '', $clientMessage = '') $transaction = $invoiceFactoring->charge(12.99, 'EUR', CONTROLLER_URL, $customer, $orderId, null, $basket); - // You'll need to remember the paymentId for later in the ReturnController (in case of 3ds) - $_SESSION['PaymentId'] = $transaction->getPaymentId(); + // You'll need to remember the shortId to show it on the success or failure page $_SESSION['ShortId'] = $transaction->getShortId(); - // Redirect to the 3ds page or to success depending on the state of the transaction + // Redirect to the success or failure page depending on the state of the transaction $payment = $transaction->getPayment(); if ($transaction->isSuccess()) { redirect(SUCCESS_URL); diff --git a/examples/InvoiceGuaranteed/Controller.php b/examples/InvoiceGuaranteed/Controller.php index af9b6504..1ce2025a 100755 --- a/examples/InvoiceGuaranteed/Controller.php +++ b/examples/InvoiceGuaranteed/Controller.php @@ -75,11 +75,10 @@ function redirect($url, $merchantMessage = '', $clientMessage = '') $transaction = $heidelpay->charge(12.99, 'EUR', $paymentTypeId, CONTROLLER_URL, $customerId, $orderId, null, $basket); - // You'll need to remember the paymentId for later in the ReturnController (in case of 3ds) - $_SESSION['PaymentId'] = $transaction->getPaymentId(); + // You'll need to remember the shortId to show it on the success or failure page $_SESSION['ShortId'] = $transaction->getShortId(); - // Redirect to the 3ds page or to success depending on the state of the transaction + // Redirect to the success or failure page depending on the state of the transaction $payment = $transaction->getPayment(); if ($transaction->isPending()) { redirect(SUCCESS_URL); diff --git a/examples/SepaDirectDebitGuaranteed/Controller.php b/examples/SepaDirectDebitGuaranteed/Controller.php index c8142404..71b63601 100755 --- a/examples/SepaDirectDebitGuaranteed/Controller.php +++ b/examples/SepaDirectDebitGuaranteed/Controller.php @@ -75,8 +75,7 @@ function redirect($url, $merchantMessage = '', $clientMessage = '') $transaction = $heidelpay->charge(12.99, 'EUR', $paymentTypeId, CONTROLLER_URL, $customerId, $orderId, null, $basket); - // You'll need to remember the paymentId for later in the ReturnController (in case of 3ds) - $_SESSION['PaymentId'] = $transaction->getPaymentId(); + // You'll need to remember the shortId to show it on the success or failure page $_SESSION['ShortId'] = $transaction->getShortId(); // Redirect to the success or failure depending on the state of the transaction From ae83315450d4200ab8e5bc52266a9cdf3459c8c6 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Mon, 6 May 2019 17:39:45 +0200 Subject: [PATCH 20/57] [cleanup] Examples: Fix minor errors in code and comments. --- examples/Alipay/index.php | 12 ++++------ examples/CreditCard/index.php | 25 +++++++++----------- examples/EPSCharge/index.php | 19 ++++----------- examples/InvoiceFactoring/index.php | 4 +--- examples/InvoiceGuaranteed/index.php | 15 ++++++------ examples/PayPal/index.php | 10 ++++---- examples/SepaDirectDebitGuaranteed/index.php | 18 +++++++------- examples/Wechatpay/index.php | 10 ++++---- 8 files changed, 45 insertions(+), 68 deletions(-) diff --git a/examples/Alipay/index.php b/examples/Alipay/index.php index adfd3a11..5fce183f 100755 --- a/examples/Alipay/index.php +++ b/examples/Alipay/index.php @@ -55,21 +55,19 @@

    Click here to open our test data in new tab.

    -
    +
    diff --git a/examples/CreditCard/index.php b/examples/CreditCard/index.php index a8dc72d2..1da95b60 100755 --- a/examples/CreditCard/index.php +++ b/examples/CreditCard/index.php @@ -94,7 +94,6 @@
    -
    @@ -113,19 +112,15 @@
    -
    - -
    + diff --git a/examples/InvoiceFactoring/index.php b/examples/InvoiceFactoring/index.php index 37692326..6762dfab 100755 --- a/examples/InvoiceFactoring/index.php +++ b/examples/InvoiceFactoring/index.php @@ -47,9 +47,7 @@
    -
    - -
    +
    diff --git a/examples/InvoiceGuaranteed/index.php b/examples/InvoiceGuaranteed/index.php index 8122ca1a..dc397806 100755 --- a/examples/InvoiceGuaranteed/index.php +++ b/examples/InvoiceGuaranteed/index.php @@ -53,22 +53,23 @@
    -
    - -
    +
    + diff --git a/examples/SepaDirectDebitGuaranteed/index.php b/examples/SepaDirectDebitGuaranteed/index.php index 67523786..92d3ae07 100755 --- a/examples/SepaDirectDebitGuaranteed/index.php +++ b/examples/SepaDirectDebitGuaranteed/index.php @@ -55,28 +55,26 @@
    -
    - -
    +
    + diff --git a/examples/Wechatpay/index.php b/examples/Wechatpay/index.php index 4d867c43..97498a70 100755 --- a/examples/Wechatpay/index.php +++ b/examples/Wechatpay/index.php @@ -60,16 +60,14 @@ From f58c838dcb9670164b879438d375bb478617bf0c Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Tue, 7 May 2019 08:31:46 +0200 Subject: [PATCH 21/57] [cleanup] Examples: Add button id. --- examples/Alipay/index.php | 2 +- examples/CreditCard/index.php | 2 +- examples/EPSCharge/index.php | 2 +- examples/InvoiceFactoring/index.php | 2 +- examples/InvoiceGuaranteed/index.php | 2 +- examples/PayPal/index.php | 2 +- examples/SepaDirectDebitGuaranteed/index.php | 2 +- examples/Wechatpay/index.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/Alipay/index.php b/examples/Alipay/index.php index 5fce183f..90104cfd 100755 --- a/examples/Alipay/index.php +++ b/examples/Alipay/index.php @@ -56,7 +56,7 @@
    - +