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 #46 from heidelpay/develop
Develop
- Loading branch information
Showing
36 changed files
with
1,197 additions
and
33 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
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,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'; |
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; | ||
|
||
/** | ||
* 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.
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,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 |
Oops, something went wrong.