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 #46 from heidelpay/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Ryouzanpaku authored Feb 25, 2019
2 parents 46acadf + da380f7 commit 30b5be4
Show file tree
Hide file tree
Showing 36 changed files with 1,197 additions and 33 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ 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.7.1][v1.7.1]

### Added
- Support for factoring.

## [v1.7.0][v1.7.0]

### Fixed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This is the php payment api for heidelpay. The library will help you to easily i
* EPS
* invoice
* invoice secured b2c
* invoice secured b2b
* direct debit secured b2c
* Santander invoice
* Santander hire purchase
Expand Down
4 changes: 2 additions & 2 deletions example/CreditCardRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
);

/**
* Set necessary parameters for Heidelpay payment Frame and send a registration request
* Set necessary parameters for heidelpay payment Frame and send a registration request
*/
$CreditCard->registration(
HEIDELPAY_PHP_PAYMENT_API_URL,
Expand All @@ -97,7 +97,7 @@
// PreventAsyncRedirect - this will tell the payment weather it should redirect the customer or not
HEIDELPAY_PHP_PAYMENT_API_URL .
HEIDELPAY_PHP_PAYMENT_API_FOLDER .
'style.css' // CSSPath - css url to style the Heidelpay payment frame
'style.css' // CSSPath - css url to style the heidelpay payment frame
);
?>
<html>
Expand Down
4 changes: 2 additions & 2 deletions example/DebitCardDebit.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@
);

/**
* Set necessary parameters for Heidelpay payment Frame and send a registration request
* Set necessary parameters for heidelpay payment Frame and send a registration request
*/
$DebitCard->debit(
HEIDELPAY_PHP_PAYMENT_API_URL, // PaymentFrameOrigin - uri of your application like https://dev.heidelpay.com
'FALSE', // PreventAsyncRedirect - this will tell the payment weather it should redirect the customer or not
HEIDELPAY_PHP_PAYMENT_API_URL .
HEIDELPAY_PHP_PAYMENT_API_FOLDER // CSSPath - css url to style the Heidelpay payment frame
HEIDELPAY_PHP_PAYMENT_API_FOLDER // CSSPath - css url to style the heidelpay payment frame
);
?>
<html>
Expand Down
2 changes: 1 addition & 1 deletion example/DirectDebitRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
);

/**
* Set necessary parameters for Heidelpay payment Frame and send a registration request
* Set necessary parameters for heidelpay payment Frame and send a registration request
*/
$DirectDebit->registration();
?>
Expand Down
2 changes: 1 addition & 1 deletion example/EasyCredit.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
->setCustomerSince('2005-08-12');

/**
* Set necessary parameters for Heidelpay payment and send the request
* Set necessary parameters for heidelpay payment and send the request
*/
$easyCredit->initialize();

Expand Down
2 changes: 1 addition & 1 deletion example/EasyCredit/EasyCreditReservation.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
//####### 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
* Set necessary parameters for heidelpay payment and send the request
*/
$easyCredit->authorizeOnRegistration($response->getIdentification()->getUniqueId());
$authorizationResponse = $easyCredit->getResponse();
Expand Down
29 changes: 29 additions & 0 deletions example/FactoringInvoice/FactoringInvoiceConstants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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 David Owusu <[email protected]>
*
* @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 . 'FactoringInvoice/FactoringInvoiceResponse.php');
define('REVERSAL_URL', EXAMPLE_BASE_FOLDER . 'FactoringInvoice/FactoringInvoiceReversal.php');
define('RESPONSE_FILE_NAME', __DIR__ . '/FactoringInvoiceResponseParams.txt');
define('HEIDELPAY_SUCCESS_PAGE', EXAMPLE_BASE_FOLDER . 'HeidelpaySuccess.php');
define('HEIDELPAY_FAILURE_PAGE', EXAMPLE_BASE_FOLDER . 'HeidelpayError.php');

define('HEIDELPAY_TRANSACTION_CHANNEL', '31HA07BC8129FBA7AF65A35EC4E540C2');

require_once __DIR__ . '/../_HeidelpayConstants.php';
116 changes: 116 additions & 0 deletions example/FactoringInvoice/FactoringInvoiceResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php
namespace Heidelpay\Example\PhpPaymentApi;

/**
* Handles response for invoice reservation with factoring 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 David Owusu
*
* @category example
*/

use Heidelpay\PhpPaymentApi\PaymentMethods\InvoiceB2CSecuredPaymentMethod;
use Heidelpay\PhpPaymentApi\Response;

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

/**
* Require the composer autoloader file
*/
$path = __DIR__;
$splitpath = str_replace('heidelpay/php-payment-api/example/FactoringInvoice',"",$path);
require_once $splitpath . '/autoload.php';

//####### 4. This page is called in a server-to-server request as soon as the customer selected a payment plan. #

//####### 5. In this request we will do following: #
//####### We will store the post data withing the reponse file (see RESPONSE_FILE_NAME constant) to make it #
//####### available in the customer session.


if (!empty($_POST)) {
file_put_contents (RESPONSE_FILE_NAME, json_encode($_POST));
echo RESPONSE_URL;
exit;
}

//####### 6. We read the post data from the response file (see RESPONSE_FILE_NAME constant), since this is the #
//####### customer session where we need the information. #
$params = json_decode(file_get_contents(RESPONSE_FILE_NAME), 1);

//####### 7. We creates a heidelpay response object from the post data to conveniently access the information we need. #
$response = Response::fromPost($params);

//####### 8. Show the customer the transaction result. #
?>
<html>
<head>
<title>Factoring example</title>
</head>
<body>
<?php
echo '<h1>Invoice Factoring example</h1>';
if ($response->isSuccess()) {
$paymentCode = explode('.', $response->getPayment()->getCode());
if($paymentCode[1] === 'PA') {
echo '<strong>Reservation Sucessful: </strong>' . '</br>';
echo 'The Customer journey ends here.' . '</br>';

/** ####### 9. Here finalize the order directly after successful reservation. In your case this should happen
* together with the shipping.
*/

$basketData = [
'2843294932',
$response->getPresentation()->getAmount(),
$response->getPresentation()->getCurrency(),
'39542395235ßfsokkspreipsr'
];

$invoicePaymentMethod = new InvoiceB2CSecuredPaymentMethod();
$invoicePaymentMethod->getRequest()->basketData(...$basketData);
$invoicePaymentMethod->getRequest()->authentification(
HEIDELPAY_SECURITY_SENDER, // SecuritySender
HEIDELPAY_USER_LOGIN, // UserLogin
HEIDELPAY_USER_PASSWORD, // UserPassword
HEIDELPAY_TRANSACTION_CHANNEL, // TransactionChannel
true // Enable sandbox mode
);

/**
* Following steps are done by the Merchant:
* Order was shipped and finalized automatically.
* Insurance is active from now on.
* Sometimes a reversal is necessary.
*/
$invoicePaymentMethod->finalize($response->getPaymentReferenceId());
$finalizeResponse = $invoicePaymentMethod->getResponse();
if ($finalizeResponse->isSuccess() || $finalizeResponse->getError()['cod'] === '700.400.800') {
echo"<p>Following steps are done by the Merchant: \n
Usually the merchant finalizes the order with the shipping. In this example we did this automatically. <br/>
Insurance is active from now on.
</p>";

echo '<p>Sometimes a reversal is necessary. This can be done here. <a href="'
. REVERSAL_URL .'">Continue with Reversal</a>
</p>';
} else {
echo '<pre>'. print_r($finalizeResponse->getError(), 1).'</pre>';
}
}

} else {
echo '<pre>'. print_r($response->getError(), 1).'</pre>';
}
?>
</body>
</html>
Empty file.
121 changes: 121 additions & 0 deletions example/FactoringInvoice/FactoringInvoiceReversal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php
namespace Heidelpay\Example\PhpPaymentApi;

/**
* The reversal is done by the Merchant and not the Customer. Therefore this step belongs to the backend of the Shop,
* only accessible by the Merchant.
*
* Performs the reversal transaction for the last Reservation saved in FactoringInvoiceResponseParams.txt
* This is a coding example for reversal 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 David Owusu
*
* @category example
*/

use Heidelpay\PhpPaymentApi\Constants\ReversalType;
use Heidelpay\PhpPaymentApi\PaymentMethods\InvoiceB2CSecuredPaymentMethod;
use Heidelpay\PhpPaymentApi\Response;

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

// Require the composer autoloader file
$path = __DIR__;
$splitpath = str_replace('heidelpay/php-payment-api/example/FactoringInvoice',"",$path);
require_once $splitpath . '/autoload.php';

//####### 10. Since we again need the information of the reservation transaction #########
$params = json_decode(file_get_contents(RESPONSE_FILE_NAME), 1);
$response = Response::fromPost($params);

// Display button to trigger the reversal request.
if (empty($_POST) && !empty($response)) {
echo'Should the Transaction: ShortID: ' . $response->getIdentification()->getShortId() . ' and the amount of '
. $response->getPresentation()->getAmount() .' ' . $response->getPresentation()->getCurrency()
. ' be reversed?';
echo '<form action="' . REVERSAL_URL . '" method="POST">';
echo '<input type="submit" name="reversal_last_transaction" value="Reversal"/>';
echo '</form>';
return;
}

// Check whether reversal was confirmed my merchant.
if(empty($_POST['reversal_last_transaction'])) {
echo print_r($_POST, 1);
return;
}

//####### 11.1 We now prepare a reversal request however this has a few differences: ###############
/**
* Load a new instance of the payment method
*/
$factoringInvoice = new InvoiceB2CSecuredPaymentMethod();

/**
* Set up your authentification data for heidepay api
*
* @link https://dev.heidelpay.com/testumgebung/#Authentifizierungsdaten
*/
$factoringInvoice->getRequest()->authentification(
HEIDELPAY_SECURITY_SENDER, // SecuritySender
HEIDELPAY_USER_LOGIN, // UserLogin
HEIDELPAY_USER_PASSWORD, // UserPassword
HEIDELPAY_TRANSACTION_CHANNEL, // 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 asynchronously to the responseUrl
* ####### (as seen before).
*
* Set up synchronous request parameters
*/
$factoringInvoice->getRequest()->getFrontend()->setEnabled('FALSE');

// Set up basket for transaction information. The amount that is set here will be the amount of the reversal.
$factoringInvoice->getRequest()->basketData(
'2843294932', // Reference Id of your application
$response->getPresentation()->getAmount(), // Amount of reversal:
$response->getPresentation()->getCurrency(), // Currency code of this request
'39542395235ßfsokkspreipsr' // A secret passphrase from your application
);

/* ###### 11.2. This time we call the method reversal passing along the uniqueId of the previous #######
* ###### reservation as a reference to let the payment server know which payment we want to reversal.
* ###### The difference to a normal reversal is the additional Parameter $reversalType
* ###### The api provides a Class to provide the available reversal types as constants.
*
*
*/

// Set necessary parameters for heidelpay payment and send the request.
// For an other reversalType please enable code below. (only one reversal at a time)
$factoringInvoice->reversal($response->getPaymentReferenceId(), ReversalType::RT_CANCEL);
//$factoringInvoice->reversal($response->getPaymentReferenceId(), ReversalType::RT_CREDIT);
//$factoringInvoice->reversal($response->getPaymentReferenceId(), ReversalType::RT_RETURN);

$reversalResponse = $factoringInvoice->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 ($reversalResponse->isError()) {
$url = HEIDELPAY_FAILURE_PAGE . '?errorMessage=' . $reversalResponse->getError()['message'];
}

// Clear transaction. This is only necessary for this for this example since we only safe the one transaction at a time.
if ($reversalResponse->isSuccess()) {
file_put_contents (RESPONSE_FILE_NAME, null);
}

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

0 comments on commit 30b5be4

Please sign in to comment.