This repository has been archived by the owner on Mar 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from heidelpay/develop
Develop
- Loading branch information
Showing
9 changed files
with
397 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
?> |
Oops, something went wrong.