Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #35 from heidelpay/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sixer1182 authored Sep 10, 2018
2 parents 462c08a + 8fa6d27 commit 583da51
Show file tree
Hide file tree
Showing 9 changed files with 397 additions and 7 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -86,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.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
141 changes: 141 additions & 0 deletions example/EasyCredit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?php
namespace Heidelpay\Example\PhpPaymentApi;

/**
* EasyCredit example
*
* This is a coding example for invoice authorize using heidelpay php-payment-api
* extension.
*
* @license Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
* @copyright Copyright © 2016-present heidelpay GmbH. All rights reserved.
*
* @link http://dev.heidelpay.com/heidelpay-php-payment-api/
*
* @author Simon Gabriel
*
* @category example
*/

/**
* For security reason all examples are disabled by default.
*/

use Heidelpay\PhpPaymentApi\PaymentMethods\EasyCreditPaymentMethod;

//####### Checks whether examples are enabled. #######################################################################
require_once __DIR__ . '/EasyCredit/EasyCreditConstants.php';

/**
* Require the composer autoloader file
*/
require_once __DIR__ . '/../vendor/autoload.php';

//####### 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 '<h1>EasyCredit example</h1>';
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
*
* @link https://dev.heidelpay.com/testumgebung/#Authentifizierungsdaten
*/
$easyCredit->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
RESPONSE_URL // 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();

?>
<html>
<head>
<title>EasyCredit example</title>
</head>
<body>
<?php
//####### 3. Render a form containing a locally validated checkbox for the opt-in (see #2). ############################
//####### Submit will redirect to the redirectUrl (see #2). #########################################################
//####### When the customer selected a payment plan the responseUrl which is send with the above request will be #
//####### called by the heidelpay payment server.
//####### For next steps see the file defined with the RESPONSE_URL constant.
echo '<h1>EasyCredit example</h1>';
$response = $easyCredit->getResponse();
if ($response->isSuccess()) {
echo '<form action="' . $response->getPaymentFormUrl() . '" method="POST">';
echo '<p> <input id="opt_in_cb" type="checkbox" required value="true"/>';
echo '<label for="opt_in_cb">' . $response->getConfig()->getOptinText() . '*</label></p>';
echo '<input type="submit" value="To easyCredit..."/>';
echo '</form>';
} else {
echo '<pre>'. print_r($response->getError(), 1).'</pre>';
}
?>
</body>
</html>
25 changes: 25 additions & 0 deletions example/EasyCredit/EasyCreditConstants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Defines the constants needed through out this example.
*
* @license Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
* @copyright Copyright © 2016-present heidelpay GmbH. All rights reserved.
*
* @link http://dev.heidelpay.com/
*
* @author Simon Gabriel <development@heidelpay.de>
*
* @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');
116 changes: 116 additions & 0 deletions example/EasyCredit/EasyCreditReservation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php
namespace Heidelpay\Example\PhpPaymentApi;

/**
* Performs the reservation transaction for the EasyCredit example
*
* This is a coding example for invoice authorize using heidelpay php-payment-api
* extension.
*
* @license Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
* @copyright Copyright © 2016-present heidelpay GmbH. All rights reserved.
*
* @link http://dev.heidelpay.com/heidelpay-php-payment-api/
*
* @author Simon Gabriel
*
* @category example
*/

use Heidelpay\PhpPaymentApi\PaymentMethods\EasyCreditPaymentMethod;
use Heidelpay\PhpPaymentApi\Response;

//####### Checks whether examples are enabled. #######################################################################
require_once __DIR__ . '/EasyCreditConstants.php';

/**
* Require the composer autoloader file
*/
require_once __DIR__ . '/../../vendor/autoload.php';

//####### 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
*/
$easyCredit = new EasyCreditPaymentMethod();
$request = $easyCredit->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
);

//####### 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
*/
$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');

//####### 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 successful handling by the payment server both should #
//####### redirect to the success page. #
$url = HEIDELPAY_SUCCESS_PAGE;
if ($authorizationResponse->isError()) {
$url = HEIDELPAY_FAILURE_PAGE . '?errorMessage=' . $authorizationResponse->getError()['message'];
}

header('Location: ' . $url); // perform the redirect
?>
Loading

0 comments on commit 583da51

Please sign in to comment.