From df5417d57f266fdfcea3cd4eeefef225e7a94495 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Wed, 5 Sep 2018 16:47:14 +0200 Subject: [PATCH 1/9] [change] (PHPLIB-41) Add example for easyCredit paymentMethod. --- example/EasyCredit.php | 124 +++++++++++++++++++++++++++++++++ example/EasyCreditResponse.php | 79 +++++++++++++++++++++ 2 files changed, 203 insertions(+) create mode 100755 example/EasyCredit.php create mode 100755 example/EasyCreditResponse.php diff --git a/example/EasyCredit.php b/example/EasyCredit.php new file mode 100755 index 0000000..aefa87d --- /dev/null +++ b/example/EasyCredit.php @@ -0,0 +1,124 @@ +getRequest()->authentification( + '31HA07BC8181E8CCFDAD64E8A4B3B766', // SecuritySender + '31ha07bc8181e8ccfdad73fd513d2a53', // UserLogin + '4B2D4BE3', // UserPassword + '31HA07BC8179C95F6B59366492FD253D', // TransactionChannel credit card without 3d secure + true // Enable sandbox mode +); +/** + * Set up asynchronous request parameters + */ +$easyCredit->getRequest()->async( + 'EN', // Language code for the Frame + HEIDELPAY_PHP_PAYMENT_API_URL . + HEIDELPAY_PHP_PAYMENT_API_FOLDER . + 'EasyCreditResponse.php' // Response url from your application +); +/** + * Set up customer information required for risk checks + */ +$easyCredit->getRequest()->customerAddress( + 'Heidel', // Given name + 'Berger-Payment', // Family name + null, // Company Name + '12344', // Customer id of your application + 'Vagerowstr. 18', // Billing address street + 'DE-BW', // Billing address state + '69115', // Billing address post code + 'Heidelberg', // Billing address city + 'DE', // Billing address country code + 'support@heidelpay.com' // Customer mail address +); +/** + * Set up basket or transaction information + */ +$easyCredit->getRequest()->basketData( + '2843294932', // Reference Id of your application + 203.12, // Amount of this request + 'EUR', // Currency code of this request + '39542395235ßfsokkspreipsr' // A secret passphrase from your application +); +/** + * Set up risk information. + */ +$easyCredit->getRequest()->getRiskInformation() + ->setCustomerGuestCheckout('false') + ->setCustomerOrderCount('23') + ->setCustomerSince('2005-08-12'); +/** + * Set necessary parameters for Heidelpay payment and send the request + */ +$easyCredit->initialize(); + +?> + + + EasyCredit example + + +getResponse(); +if ($response->isSuccess()) { + echo '

'; + echo $response->getConfig()->getOptinText(); + echo'

Weiter zu easyCredit...'; + } else { + echo '
'. print_r($response->getError(), 1).'
'; + } + ?> +

It is not necessary to show the redirect url to your customer. You can + use php header to forward your customer directly.
+ For example:
+ header('Location: '.$Invoice->getResponse()->getPaymentFromUrl()); +

+ + + + + \ No newline at end of file diff --git a/example/EasyCreditResponse.php b/example/EasyCreditResponse.php new file mode 100755 index 0000000..8464c17 --- /dev/null +++ b/example/EasyCreditResponse.php @@ -0,0 +1,79 @@ +getCriterion()->get('EASYCREDIT_AMORTISATIONTEXT')); + + +//$easyCredit->initialize(); +// +//?> + + + + + +getResponse(); +//if ($response->isSuccess()) { +// echo '

'; +// echo $response->getConfig()->getOptinText(); +// echo'

Weiter zu easyCredit...'; +// } else { +// echo '
'. print_r($response->getError(), 1).'
'; +// } +// ?> + + + + + + + From 74ffad303074d37ed42d7548b4f1b0a343922b7c Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 6 Sep 2018 08:20:21 +0200 Subject: [PATCH 2/9] [change] (PHPLIB-41) Add path to codecept executable and extend test section in readme. --- README.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a5bd4e0..68120fa 100755 --- a/README.md +++ b/README.md @@ -55,19 +55,25 @@ Please visit [http://dev.heidelpay.com/heidelpay-php-payment-api/](http://dev.he This library comes with a set of unit and integration tests. Please do not run the integration tests on each build. Run prior to tests: -`codecept build` +`vendor/bin/codecept build` Run unit tests: -`codecept run unit` +`vendor/bin/codecept run unit` Run unit tests with code coverage report: -`codecept run unit --coverage --coverage-html` +`vendor/bin/codecept run unit --coverage --coverage-html` Run integration tests: -`codecept run integration` +`vendor/bin/codecept run integration` Run integration tests with debug output: -`codecept run integration --debug` +`vendor/bin/codecept run integration --debug` + +Run all integration test of a specific class: +`vendor/bin/codecept run tests/integration/PaymentMethods/EasyCreditPaymentMethodTest` + +Run a specific integration test: +`vendor/bin/codecept run tests/integration/PaymentMethods/EasyCreditPaymentMethodTest:initialRequest` For coverage analysis results see: `./tests/_output/coverage/index.html` From 0fd87ced03f7253b00b3602f746901c39f4d2dc7 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 6 Sep 2018 15:18:00 +0200 Subject: [PATCH 3/9] [change] (PHPLIB-41) Add easyCredit reservation to example. --- composer.json | 1 + example/EasyCreditReservation.php | 103 ++++++++++++++++++++++++++++++ example/EasyCreditResponse.php | 76 ++++++++++------------ 3 files changed, 139 insertions(+), 41 deletions(-) create mode 100755 example/EasyCreditReservation.php diff --git a/composer.json b/composer.json index 697f4e7..44cab28 100755 --- a/composer.json +++ b/composer.json @@ -26,6 +26,7 @@ "ext-SimpleXML": "*" }, "require-dev": { + "ext-json": "*", "friendsofphp/php-cs-fixer": "^2.0", "heidelpay/phpdocumentor": "2.9.1", "codeception/codeception": "~2.3.9", diff --git a/example/EasyCreditReservation.php b/example/EasyCreditReservation.php new file mode 100755 index 0000000..1904452 --- /dev/null +++ b/example/EasyCreditReservation.php @@ -0,0 +1,103 @@ +getRequest(); + +/** + * Set up your authentification data for Heidepay api + * + * @link https://dev.heidelpay.com/testumgebung/#Authentifizierungsdaten + */ +$request->authentification( + '31HA07BC8181E8CCFDAD64E8A4B3B766', // SecuritySender + '31ha07bc8181e8ccfdad73fd513d2a53', // UserLogin + '4B2D4BE3', // UserPassword + '31HA07BC8179C95F6B59366492FD253D', // TransactionChannel credit card without 3d secure + true // Enable sandbox mode +); + +/** + * Set up asynchronous request parameters + */ +$request->getFrontend()->setEnabled('FALSE'); + +/** + * Set up customer information required for risk checks + */ +$request->customerAddress( + 'Heidel', // Given name + 'Berger-Payment', // Family name + null, // Company Name + '12344', // Customer id of your application + 'Vagerowstr. 18', // Billing address street + 'DE-BW', // Billing address state + '69115', // Billing address post code + 'Heidelberg', // Billing address city + 'DE', // Billing address country code + 'support@heidelpay.com' // Customer mail address +); +/** + * Set up basket or transaction information + */ +$request->basketData( + '2843294932', // Reference Id of your application + 203.12, // Amount of this request + 'EUR', // Currency code of this request + '39542395235ßfsokkspreipsr' // A secret passphrase from your application +); + +/** + * Set up risk information. + */ +$request->getRiskInformation() + ->setCustomerGuestCheckout('false') + ->setCustomerOrderCount('23') + ->setCustomerSince('2005-08-12'); + +/** + * Set necessary parameters for Heidelpay payment and send the request + */ +$easyCredit->authorizeOnRegistration($response->getIdentification()->getUniqueId()); + +$url = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . '/HeidelpaySuccess.php'; + +if ($response->isError()) { + $url = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . '/HeidelpayError.php'; +} +Header('Location: ' . $url); +?> \ No newline at end of file diff --git a/example/EasyCreditResponse.php b/example/EasyCreditResponse.php index 8464c17..7257b8b 100755 --- a/example/EasyCreditResponse.php +++ b/example/EasyCreditResponse.php @@ -29,51 +29,45 @@ require_once __DIR__ . '/../vendor/autoload.php'; if (!empty($_POST)) { - echo HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'EasyCreditResponse.php'; -// mail('simon.gabriel@heidelpay.com', 'betreff', print_r($_POST,1)); - file_put_contents (EASY_CREDIT_RESPONSE_PARAMS_TXT, print_r($_POST, 1)); + $responseURL = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'EasyCreditResponse.php'; + echo $responseURL; + file_put_contents (EASY_CREDIT_RESPONSE_PARAMS_TXT, json_encode($_POST)); exit(); } +$reservationURL = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'EasyCreditReservation.php'; -$params = file_get_contents(EASY_CREDIT_RESPONSE_PARAMS_TXT); +$params = json_decode(file_get_contents(EASY_CREDIT_RESPONSE_PARAMS_TXT),1); -echo print_r($params,1); +$response = Response::fromPost($params); +//var_dump($response); -///** -// * Load a new instance of the payment method -// */ -// $easyCredit = new EasyCreditPaymentMethod(); -// -// /** @var Response $response */ -// $response = Response::fromPost($_POST); - -// var_dump($_POST); -// var_dump($response); -// var_dump($response->getCriterion()->get('EASYCREDIT_AMORTISATIONTEXT')); - - -//$easyCredit->initialize(); -// -//?> - - - - - +?> + + + EasyCredit example + + getResponse(); -//if ($response->isSuccess()) { -// echo '

'; -// echo $response->getConfig()->getOptinText(); -// echo'

Weiter zu easyCredit...'; -// } else { -// echo '
'. print_r($response->getError(), 1).'
'; -// } -// ?> - - - - - - - +if ($response->isSuccess()) { + echo 'Hier Ihr ausgewählter Ratenplan: ' . '
'; + $amortisationtext = $response->getCriterion()->get('EASYCREDIT_AMORTISATIONTEXT'); + $precontractInformationUrl = $response->getCriterion()->get('EASYCREDIT_PRECONTRACTINFORMATIONURL'); + echo $amortisationtext . '

'; + echo 'Ihre vorvertraglichen Informationen zum Download...
'; + echo 'Rechnungsbetrag: ' . $response->getCriterion()->get('EASYCREDIT_TOTALORDERAMOUNT') . '
'; + echo 'Zinsen: '. $response->getCriterion()->get('EASYCREDIT_ACCRUINGINTEREST') . '
'; + echo 'Gesamt inkl. Zinsen: '. $response->getCriterion()->get('EASYCREDIT_TOTALAMOUNT') . '
'; + + echo'

Bestellen...'; +} else { + echo '
'. print_r($response->getError(), 1).'
'; +} +?> +

It is not necessary to show the redirect url to your customer. You can + use php header to forward your customer directly.
+ For example:
+ header('Location: '.$Invoice->getResponse()->getPaymentFromUrl()); +

+ + From c434b419ac042afb414c0c2c7831745e1023da60 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 6 Sep 2018 15:31:05 +0200 Subject: [PATCH 4/9] [change] (PHPLIB-41) Move easyCredit files to dedicated folder. --- example/EasyCredit.php | 2 +- example/{ => EasyCredit}/EasyCreditReservation.php | 8 ++++---- example/{ => EasyCredit}/EasyCreditResponse.php | 13 ++++++------- example/EasyCredit/EasyCreditResponseParams.txt | 0 4 files changed, 11 insertions(+), 12 deletions(-) rename example/{ => EasyCredit}/EasyCreditReservation.php (95%) rename example/{ => EasyCredit}/EasyCreditResponse.php (83%) create mode 100755 example/EasyCredit/EasyCreditResponseParams.txt diff --git a/example/EasyCredit.php b/example/EasyCredit.php index aefa87d..e70b399 100755 --- a/example/EasyCredit.php +++ b/example/EasyCredit.php @@ -58,7 +58,7 @@ 'EN', // Language code for the Frame HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . - 'EasyCreditResponse.php' // Response url from your application + 'EasyCredit/EasyCreditResponse.php' // Response url from your application ); /** * Set up customer information required for risk checks diff --git a/example/EasyCreditReservation.php b/example/EasyCredit/EasyCreditReservation.php similarity index 95% rename from example/EasyCreditReservation.php rename to example/EasyCredit/EasyCreditReservation.php index 1904452..88b4a7c 100755 --- a/example/EasyCreditReservation.php +++ b/example/EasyCredit/EasyCreditReservation.php @@ -21,12 +21,12 @@ use Heidelpay\PhpPaymentApi\Response; const EASY_CREDIT_RESPONSE_PARAMS_TXT = __DIR__ . '/EasyCreditResponseParams.txt'; -require_once './_enableExamples.php'; +require_once './../_enableExamples.php'; /** * Require the composer autoloader file */ -require_once __DIR__ . '/../vendor/autoload.php'; +require_once __DIR__ . '/../../vendor/autoload.php'; $params = json_decode(file_get_contents(EASY_CREDIT_RESPONSE_PARAMS_TXT),1); @@ -94,10 +94,10 @@ */ $easyCredit->authorizeOnRegistration($response->getIdentification()->getUniqueId()); -$url = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . '/HeidelpaySuccess.php'; +$url = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'HeidelpaySuccess.php'; if ($response->isError()) { - $url = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . '/HeidelpayError.php'; + $url = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'HeidelpayError.php'; } Header('Location: ' . $url); ?> \ No newline at end of file diff --git a/example/EasyCreditResponse.php b/example/EasyCredit/EasyCreditResponse.php similarity index 83% rename from example/EasyCreditResponse.php rename to example/EasyCredit/EasyCreditResponse.php index 7257b8b..41fc701 100755 --- a/example/EasyCreditResponse.php +++ b/example/EasyCredit/EasyCreditResponse.php @@ -21,25 +21,24 @@ use Heidelpay\PhpPaymentApi\Response; const EASY_CREDIT_RESPONSE_PARAMS_TXT = __DIR__ . '/EasyCreditResponseParams.txt'; -require_once './_enableExamples.php'; +require_once './../_enableExamples.php'; /** * Require the composer autoloader file */ -require_once __DIR__ . '/../vendor/autoload.php'; +require_once __DIR__ . '/../../vendor/autoload.php'; if (!empty($_POST)) { - $responseURL = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'EasyCreditResponse.php'; + $responseURL = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'EasyCredit/EasyCreditResponse.php'; echo $responseURL; file_put_contents (EASY_CREDIT_RESPONSE_PARAMS_TXT, json_encode($_POST)); exit(); } -$reservationURL = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'EasyCreditReservation.php'; +$reservationURL = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'EasyCredit/EasyCreditReservation.php'; $params = json_decode(file_get_contents(EASY_CREDIT_RESPONSE_PARAMS_TXT),1); $response = Response::fromPost($params); -//var_dump($response); ?> @@ -54,12 +53,12 @@ $amortisationtext = $response->getCriterion()->get('EASYCREDIT_AMORTISATIONTEXT'); $precontractInformationUrl = $response->getCriterion()->get('EASYCREDIT_PRECONTRACTINFORMATIONURL'); echo $amortisationtext . '

'; - echo 'Ihre vorvertraglichen Informationen zum Download...
'; + echo 'Ihre vorvertraglichen Informationen zum Download...
'; echo 'Rechnungsbetrag: ' . $response->getCriterion()->get('EASYCREDIT_TOTALORDERAMOUNT') . '
'; echo 'Zinsen: '. $response->getCriterion()->get('EASYCREDIT_ACCRUINGINTEREST') . '
'; echo 'Gesamt inkl. Zinsen: '. $response->getCriterion()->get('EASYCREDIT_TOTALAMOUNT') . '
'; - echo'

Bestellen...'; + echo'

Zahlungspflichtig bestellen...'; } else { echo '
'. print_r($response->getError(), 1).'
'; } diff --git a/example/EasyCredit/EasyCreditResponseParams.txt b/example/EasyCredit/EasyCreditResponseParams.txt new file mode 100755 index 0000000..e69de29 From e4e03703b573a1f5bd93b0a8c803b45b89c8c354 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 6 Sep 2018 16:16:06 +0200 Subject: [PATCH 5/9] [change] (PHPLIB-41) Finish example. --- example/EasyCredit.php | 48 +++++++++++--------- example/EasyCredit/EasyCreditReservation.php | 10 ++-- example/EasyCredit/EasyCreditResponse.php | 15 ++---- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/example/EasyCredit.php b/example/EasyCredit.php index e70b399..55fcad4 100755 --- a/example/EasyCredit.php +++ b/example/EasyCredit.php @@ -28,12 +28,17 @@ exit(); } - /** * Require the composer autoloader file */ require_once __DIR__ . '/../vendor/autoload.php'; +if (!is_writable(__DIR__ . '/EasyCredit/EasyCreditResponseParams.txt')) { + echo '

EasyCredit example

'; + echo 'File: ' . __DIR__ . '/EasyCredit/EasyCreditResponseParams.txt' . ' is not writable or does not exist. Please change permissions.'; + exit; +} + /** * Load a new instance of the payment method */ @@ -51,6 +56,7 @@ '31HA07BC8179C95F6B59366492FD253D', // TransactionChannel credit card without 3d secure true // Enable sandbox mode ); + /** * Set up asynchronous request parameters */ @@ -60,30 +66,33 @@ HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'EasyCredit/EasyCreditResponse.php' // Response url from your application ); + /** * Set up customer information required for risk checks */ $easyCredit->getRequest()->customerAddress( 'Heidel', // Given name - 'Berger-Payment', // Family name - null, // Company Name + 'Berger-Payment', // Family name + null, // Company Name '12344', // Customer id of your application 'Vagerowstr. 18', // Billing address street 'DE-BW', // Billing address state '69115', // Billing address post code 'Heidelberg', // Billing address city 'DE', // Billing address country code - 'support@heidelpay.com' // Customer mail address + 'support@heidelpay.com' // Customer mail address ); + /** * Set up basket or transaction information */ $easyCredit->getRequest()->basketData( - '2843294932', // Reference Id of your application - 203.12, // Amount of this request - 'EUR', // Currency code of this request - '39542395235ßfsokkspreipsr' // A secret passphrase from your application + '2843294932', // Reference Id of your application + 203.12, // Amount of this request + 'EUR', // Currency code of this request + '39542395235ßfsokkspreipsr' // A secret passphrase from your application ); + /** * Set up risk information. */ @@ -91,6 +100,7 @@ ->setCustomerGuestCheckout('false') ->setCustomerOrderCount('23') ->setCustomerSince('2005-08-12'); + /** * Set necessary parameters for Heidelpay payment and send the request */ @@ -103,22 +113,18 @@ EasyCredit example'; $response = $easyCredit->getResponse(); if ($response->isSuccess()) { - echo '

'; - echo $response->getConfig()->getOptinText(); - echo'

Weiter zu easyCredit...'; + echo '
'; + echo '

'; + echo '

'; + echo ''; + echo '
'; } else { echo '
'. print_r($response->getError(), 1).'
'; } ?> -

It is not necessary to show the redirect url to your customer. You can - use php header to forward your customer directly.
- For example:
- header('Location: '.$Invoice->getResponse()->getPaymentFromUrl()); -

- - - - - \ No newline at end of file + + diff --git a/example/EasyCredit/EasyCreditReservation.php b/example/EasyCredit/EasyCreditReservation.php index 88b4a7c..0d3ae54 100755 --- a/example/EasyCredit/EasyCreditReservation.php +++ b/example/EasyCredit/EasyCreditReservation.php @@ -2,7 +2,7 @@ namespace Heidelpay\Example\PhpPaymentApi; /** - * Handles response for EasyCredit example + * Performs the reservation transaction for the EasyCredit example * * This is a coding example for invoice authorize using heidelpay php-payment-api * extension. @@ -28,7 +28,7 @@ */ require_once __DIR__ . '/../../vendor/autoload.php'; -$params = json_decode(file_get_contents(EASY_CREDIT_RESPONSE_PARAMS_TXT),1); +$params = json_decode(file_get_contents(EASY_CREDIT_RESPONSE_PARAMS_TXT), 1); $response = Response::fromPost($params); @@ -71,6 +71,7 @@ 'DE', // Billing address country code 'support@heidelpay.com' // Customer mail address ); + /** * Set up basket or transaction information */ @@ -95,9 +96,10 @@ $easyCredit->authorizeOnRegistration($response->getIdentification()->getUniqueId()); $url = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'HeidelpaySuccess.php'; - if ($response->isError()) { $url = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'HeidelpayError.php'; } + +// Redirect to failure or success page Header('Location: ' . $url); -?> \ No newline at end of file +?> diff --git a/example/EasyCredit/EasyCreditResponse.php b/example/EasyCredit/EasyCreditResponse.php index 41fc701..022fcfb 100755 --- a/example/EasyCredit/EasyCreditResponse.php +++ b/example/EasyCredit/EasyCreditResponse.php @@ -32,11 +32,11 @@ $responseURL = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'EasyCredit/EasyCreditResponse.php'; echo $responseURL; file_put_contents (EASY_CREDIT_RESPONSE_PARAMS_TXT, json_encode($_POST)); - exit(); + exit; } $reservationURL = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'EasyCredit/EasyCreditReservation.php'; -$params = json_decode(file_get_contents(EASY_CREDIT_RESPONSE_PARAMS_TXT),1); +$params = json_decode(file_get_contents(EASY_CREDIT_RESPONSE_PARAMS_TXT), 1); $response = Response::fromPost($params); @@ -47,7 +47,7 @@ getResponse(); +echo '

EasyCredit example

'; if ($response->isSuccess()) { echo 'Hier Ihr ausgewählter Ratenplan: ' . '
'; $amortisationtext = $response->getCriterion()->get('EASYCREDIT_AMORTISATIONTEXT'); @@ -63,10 +63,5 @@ echo '
'. print_r($response->getError(), 1).'
'; } ?> -

It is not necessary to show the redirect url to your customer. You can - use php header to forward your customer directly.
- For example:
- header('Location: '.$Invoice->getResponse()->getPaymentFromUrl()); -

- - + + From 24538d3ad9bde1b7051094f3d0720f1af7968fba Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 6 Sep 2018 16:35:45 +0200 Subject: [PATCH 6/9] [change] (PHPLIB-41) Update changelog and version. --- CHANGELOG.md | 12 +++++++++++- lib/Constants/ApiConfig.php | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c075d2e..b042464 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,15 @@ 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). +## [v1.6.1][v1.6.1] + +### Added +- Example implementation for easyCredit payment method. +- Json extension dependency to composer.json. + +### Changed +- Updated readme file. + ## [v1.6.0][v1.6.0] ### Added @@ -129,5 +138,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a [v1.3.0]: https://github.com/heidelpay/php-payment-api/compare/v1.2.0...v1.3.0 [v1.4.0]: https://github.com/heidelpay/php-payment-api/compare/v1.3.0...v1.4.0 [v1.4.1]: https://github.com/heidelpay/php-payment-api/compare/v1.4.0...v1.4.1 -[v1.5.0]: https://github.com/heidelpay/php-payment-api/compare/v1.4.0...v1.5.0 +[v1.5.0]: https://github.com/heidelpay/php-payment-api/compare/v1.4.1...v1.5.0 [v1.6.0]: https://github.com/heidelpay/php-payment-api/compare/v1.5.0...v1.6.0 +[v1.6.1]: https://github.com/heidelpay/php-payment-api/compare/v1.6.0...v1.6.1 diff --git a/lib/Constants/ApiConfig.php b/lib/Constants/ApiConfig.php index f762b61..fa5d0b3 100755 --- a/lib/Constants/ApiConfig.php +++ b/lib/Constants/ApiConfig.php @@ -18,7 +18,7 @@ */ class ApiConfig { - const SDK_VERSION = 'v1.6.0'; + const SDK_VERSION = 'v1.6.1'; const LIVE_URL = 'https://heidelpay.hpcgw.net/ngw/post'; const TEST_URL = 'https://test-heidelpay.hpcgw.net/ngw/post'; From fc1fdb37ae1bf443f62678c779dd9f1a4260d3b0 Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Thu, 6 Sep 2018 16:41:17 +0200 Subject: [PATCH 7/9] [change] (PHPLIB-41) Update readme with info on easyCredit example. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 68120fa..2b5f960 100755 --- a/README.md +++ b/README.md @@ -92,3 +92,5 @@ to Please make sure to switch it off again, after you launch your application. +To enable the easyCredit example you might have to change the file permissions for the file "example/EasyCredit/EasyCreditResponseParams.txt".\ +It will be used to store the post-parameters send asynchronously by the payment which otherwise would not be accessable in the client session. From 35601546090d57d76151c7b5e46aac5e171eca8d Mon Sep 17 00:00:00 2001 From: Simon Gabriel Date: Fri, 7 Sep 2018 10:23:43 +0200 Subject: [PATCH 8/9] [refactor] (PHPLIB-41) Improve readability by refactoring and adding descriptions. --- example/EasyCredit.php | 35 +++++++++----- example/EasyCredit/EasyCreditConstants.php | 25 ++++++++++ example/EasyCredit/EasyCreditReservation.php | 26 +++++++---- example/EasyCredit/EasyCreditResponse.php | 48 ++++++++++++++------ 4 files changed, 101 insertions(+), 33 deletions(-) create mode 100755 example/EasyCredit/EasyCreditConstants.php diff --git a/example/EasyCredit.php b/example/EasyCredit.php index 55fcad4..ac354b5 100755 --- a/example/EasyCredit.php +++ b/example/EasyCredit.php @@ -23,27 +23,36 @@ use Heidelpay\PhpPaymentApi\PaymentMethods\EasyCreditPaymentMethod; -require_once './_enableExamples.php'; -if (defined('HEIDELPAY_PHP_PAYMENT_API_EXAMPLES') and HEIDELPAY_PHP_PAYMENT_API_EXAMPLES !== true) { - exit(); -} +//####### Checks whether examples are enabled. ####################################################################### +require_once __DIR__ . '/EasyCredit/EasyCreditConstants.php'; /** * Require the composer autoloader file */ require_once __DIR__ . '/../vendor/autoload.php'; -if (!is_writable(__DIR__ . '/EasyCredit/EasyCreditResponseParams.txt')) { +//####### Checks whether the response file is writable. ############################################################## +//####### The results from the easyCredit payment plan selection will be sent via POST in a server-to-server request.# +//####### Normally the information will be stored within the database to make them accessable in the customer session# +//####### in order to safe the information in this example we use the file defined in RESPONSE_FILE_NAME constant. # +//####### Only necessary for this example. # +if (!is_writable(RESPONSE_FILE_NAME)) { echo '

EasyCredit example

'; - echo 'File: ' . __DIR__ . '/EasyCredit/EasyCreditResponseParams.txt' . ' is not writable or does not exist. Please change permissions.'; + echo 'File: ' . RESPONSE_FILE_NAME . ' is not writable or does not exist. Please change permissions.'; exit; } +//####### 1. Create an instance of the easyCredit payment method. ###################################################### /** * Load a new instance of the payment method */ $easyCredit = new EasyCreditPaymentMethod(); +//####### 2. Prepare and send an initialization request. ###################################################### +//####### The response will provide a redirectUrl to a form where the customer can select the payment plan # +//####### And an opt-in text the customer needs to agree to before redirecting him to the redirectUrl. # +//####### Please make sure to set the riskinformation (see below) in order to increase acceptance rate. # + /** * Set up your authentification data for Heidepay api * @@ -62,9 +71,7 @@ */ $easyCredit->getRequest()->async( 'EN', // Language code for the Frame - HEIDELPAY_PHP_PAYMENT_API_URL . - HEIDELPAY_PHP_PAYMENT_API_FOLDER . - 'EasyCredit/EasyCreditResponse.php' // Response url from your application + RESPONSE_URL // Response url from your application ); /** @@ -113,14 +120,18 @@ EasyCredit example'; $response = $easyCredit->getResponse(); if ($response->isSuccess()) { - echo '
'; + echo ''; echo '

'; echo '

'; - echo ''; + echo ''; echo '
'; } else { echo '
'. print_r($response->getError(), 1).'
'; diff --git a/example/EasyCredit/EasyCreditConstants.php b/example/EasyCredit/EasyCreditConstants.php new file mode 100755 index 0000000..39b6d70 --- /dev/null +++ b/example/EasyCredit/EasyCreditConstants.php @@ -0,0 +1,25 @@ + + * + * @package heidelpay/${Package} + */ + +require_once __DIR__ . '/../_enableExamples.php'; +if (defined('HEIDELPAY_PHP_PAYMENT_API_EXAMPLES') && HEIDELPAY_PHP_PAYMENT_API_EXAMPLES !== true) { + exit(); +} + +const EXAMPLE_BASE_FOLDER = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER; +define('RESPONSE_URL', EXAMPLE_BASE_FOLDER . 'EasyCredit/EasyCreditResponse.php'); +define('RESERVATION_URL', EXAMPLE_BASE_FOLDER . 'EasyCredit/EasyCreditReservation.php'); +define('RESPONSE_FILE_NAME', __DIR__ . '/EasyCreditResponseParams.txt'); +define('HEIDELPAY_SUCCESS_PAGE', EXAMPLE_BASE_FOLDER . 'HeidelpaySuccess.php'); +define('HEIDELPAY_FAILURE_PAGE', EXAMPLE_BASE_FOLDER . 'HeidelpayError.php'); diff --git a/example/EasyCredit/EasyCreditReservation.php b/example/EasyCredit/EasyCreditReservation.php index 0d3ae54..ebed983 100755 --- a/example/EasyCredit/EasyCreditReservation.php +++ b/example/EasyCredit/EasyCreditReservation.php @@ -20,18 +20,19 @@ use Heidelpay\PhpPaymentApi\PaymentMethods\EasyCreditPaymentMethod; use Heidelpay\PhpPaymentApi\Response; -const EASY_CREDIT_RESPONSE_PARAMS_TXT = __DIR__ . '/EasyCreditResponseParams.txt'; -require_once './../_enableExamples.php'; +//####### Checks whether examples are enabled. ####################################################################### +require_once __DIR__ . '/EasyCreditConstants.php'; /** * Require the composer autoloader file */ require_once __DIR__ . '/../../vendor/autoload.php'; -$params = json_decode(file_get_contents(EASY_CREDIT_RESPONSE_PARAMS_TXT), 1); - +//####### 10. Since we again need the information on the payment plan we again load it from the response file. ######### +$params = json_decode(file_get_contents(RESPONSE_FILE_NAME), 1); $response = Response::fromPost($params); +//####### 11. We now prepare a similare request as in the beginning however this has a few differences: ################ /** * Load a new instance of the payment method */ @@ -51,6 +52,10 @@ true // Enable sandbox mode ); +//####### 11.1. This time we do a sync request rather than an async request as before. We do this for the sake of the ## +//####### readability of the example. This results in the payment server sending the response to the request # +//####### immediately in the http-response of this request rather then sending it asyncronuously to the responseUrl # +//####### (as seen before). /** * Set up asynchronous request parameters */ @@ -90,16 +95,21 @@ ->setCustomerOrderCount('23') ->setCustomerSince('2005-08-12'); +//####### 11.2. This time we call the method authorizeOnRegistration passing along the uinqueId of the previouse ####### +//####### initialization as a reference to let the payment server know which payment plan to use. # /** * Set necessary parameters for Heidelpay payment and send the request */ $easyCredit->authorizeOnRegistration($response->getIdentification()->getUniqueId()); -$url = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'HeidelpaySuccess.php'; +//####### 12. Now we redirect to the success or error page depending on the result of the request. ##################### +//####### Keep in mind there are three possible results: Success, Pending and Error. # +//####### Since both pending and success indicate a successfull handling by the payment server both should # +//####### redirect to the success page. # +$url = HEIDELPAY_SUCCESS_PAGE; if ($response->isError()) { - $url = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'HeidelpayError.php'; + $url = HEIDELPAY_FAILURE_PAGE; } -// Redirect to failure or success page -Header('Location: ' . $url); +header('Location: ' . $url); // perform the redirect ?> diff --git a/example/EasyCredit/EasyCreditResponse.php b/example/EasyCredit/EasyCreditResponse.php index 022fcfb..c192c77 100755 --- a/example/EasyCredit/EasyCreditResponse.php +++ b/example/EasyCredit/EasyCreditResponse.php @@ -20,26 +20,48 @@ use Heidelpay\PhpPaymentApi\PaymentMethods\EasyCreditPaymentMethod; use Heidelpay\PhpPaymentApi\Response; -const EASY_CREDIT_RESPONSE_PARAMS_TXT = __DIR__ . '/EasyCreditResponseParams.txt'; -require_once './../_enableExamples.php'; +//####### Checks whether examples are enabled. ####################################################################### +require_once __DIR__ . '/EasyCreditConstants.php'; /** * Require the composer autoloader file */ require_once __DIR__ . '/../../vendor/autoload.php'; +//####### 4. This page is called in a server-to-server request as soon as the customer selected a payment plan. # +//####### 6. This page will be called a second time when the customer is redirected back to the "shop" which in reality# +//####### would probably be a different page. Since this will be done without any POST-data the next step will be #7# + +//####### 5. The server-to-server request after the payment plan selection will provide the selected information # +//####### as post data. # +//####### In this request we will two things: # +//####### 1. We will store the post data withing the reponse file (see RESPONSE_FILE_NAME constant) to make it # +//####### available in the customer session. # +//####### 2. We will provide the redirectUrl the customer will be redirected to. It is crutial to just return # +//####### the Url and nothing else, no html tags no comments, no newlines, just the url. # if (!empty($_POST)) { - $responseURL = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'EasyCredit/EasyCreditResponse.php'; - echo $responseURL; - file_put_contents (EASY_CREDIT_RESPONSE_PARAMS_TXT, json_encode($_POST)); + file_put_contents (RESPONSE_FILE_NAME, json_encode($_POST)); + echo RESPONSE_URL; exit; } -$reservationURL = HEIDELPAY_PHP_PAYMENT_API_URL . HEIDELPAY_PHP_PAYMENT_API_FOLDER . 'EasyCredit/EasyCreditReservation.php'; -$params = json_decode(file_get_contents(EASY_CREDIT_RESPONSE_PARAMS_TXT), 1); +//####### 7. We read the post data from the response file (see RESPONSE_FILE_NAME constant), since this ist the # +//####### customer session where we need the information. # +$params = json_decode(file_get_contents(RESPONSE_FILE_NAME), 1); +//####### 8. We creates a heidelpay response object from the post data to conveniently access the information we need. # $response = Response::fromPost($params); +//####### 9. This renders the information on the payment plan sent by easyCredit. ###################################### +//####### It is necessary to show the information again to the customer prior to him placing the order. # +//####### The rendered information consists of... +//####### 1. ... the amortisation text +//####### 2. ... a link to download precontract information +//####### 3. ... the order total +//####### 4. ... the interest due to the payment plan +//####### 5. ... the total incl. the interest +//####### After that the customer can place the order which will send a reservation command to our payment server. ## +//####### For the next step see the file defined with the RESERVATION_URL constant. ?> @@ -49,16 +71,16 @@ EasyCredit example'; if ($response->isSuccess()) { - echo 'Hier Ihr ausgewählter Ratenplan: ' . '
'; + echo 'Please approve your payment plan: ' . '
'; $amortisationtext = $response->getCriterion()->get('EASYCREDIT_AMORTISATIONTEXT'); $precontractInformationUrl = $response->getCriterion()->get('EASYCREDIT_PRECONTRACTINFORMATIONURL'); echo $amortisationtext . '

'; - echo 'Ihre vorvertraglichen Informationen zum Download...
'; - echo 'Rechnungsbetrag: ' . $response->getCriterion()->get('EASYCREDIT_TOTALORDERAMOUNT') . '
'; - echo 'Zinsen: '. $response->getCriterion()->get('EASYCREDIT_ACCRUINGINTEREST') . '
'; - echo 'Gesamt inkl. Zinsen: '. $response->getCriterion()->get('EASYCREDIT_TOTALAMOUNT') . '
'; + echo 'Download the precontract information here...
'; + echo 'Order total: ' . $response->getCriterion()->get('EASYCREDIT_TOTALORDERAMOUNT') . '
'; + echo 'Interest: '. $response->getCriterion()->get('EASYCREDIT_ACCRUINGINTEREST') . '
'; + echo 'Total incl. interest: '. $response->getCriterion()->get('EASYCREDIT_TOTALAMOUNT') . '
'; - echo'

Zahlungspflichtig bestellen...'; + echo'

Place order...'; } else { echo '
'. print_r($response->getError(), 1).'
'; } From ec1df130853002c40f57db6d6eb4d5db2f00c2dd Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Fri, 7 Sep 2018 11:14:05 +0200 Subject: [PATCH 9/9] correct the response used after reservation. --- example/EasyCredit/EasyCreditReservation.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/example/EasyCredit/EasyCreditReservation.php b/example/EasyCredit/EasyCreditReservation.php index ebed983..4367fab 100755 --- a/example/EasyCredit/EasyCreditReservation.php +++ b/example/EasyCredit/EasyCreditReservation.php @@ -95,20 +95,21 @@ ->setCustomerOrderCount('23') ->setCustomerSince('2005-08-12'); -//####### 11.2. This time we call the method authorizeOnRegistration passing along the uinqueId of the previouse ####### +//####### 11.2. This time we call the method authorizeOnRegistration passing along the uniqueId of the previous ####### //####### initialization as a reference to let the payment server know which payment plan to use. # /** * Set necessary parameters for Heidelpay payment and send the request */ $easyCredit->authorizeOnRegistration($response->getIdentification()->getUniqueId()); +$authorizationResponse = $easyCredit->getResponse(); //####### 12. Now we redirect to the success or error page depending on the result of the request. ##################### //####### Keep in mind there are three possible results: Success, Pending and Error. # -//####### Since both pending and success indicate a successfull handling by the payment server both should # +//####### Since both pending and success indicate a successful handling by the payment server both should # //####### redirect to the success page. # $url = HEIDELPAY_SUCCESS_PAGE; -if ($response->isError()) { - $url = HEIDELPAY_FAILURE_PAGE; +if ($authorizationResponse->isError()) { + $url = HEIDELPAY_FAILURE_PAGE . '?errorMessage=' . $authorizationResponse->getError()['message']; } header('Location: ' . $url); // perform the redirect