Skip to content

Commit

Permalink
Added the PHP library and demo website
Browse files Browse the repository at this point in the history
  • Loading branch information
vladiliescu committed Mar 5, 2018
1 parent 27405a0 commit 82585ae
Show file tree
Hide file tree
Showing 63 changed files with 16,832 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Library/B2BCommunicator.php
@@ -0,0 +1,62 @@
<?php

require_once 'CoreCommunicator.php';

/**
* Description of Communicator
*/
class B2BCommunicator extends CoreCommunicator {

const LOCAL_INSTRUMENT = 'B2B';
const PRODUCT_ID = 'NL:BVN:eMandatesB2B:1.0';

/** Initiates a new B2BCommunicator
*
* @param Configuration $configuration
* @param bool $logger
*/
function __construct(Configuration $configuration = null, $logger = false){
parent::__construct($configuration, $logger);
}

/**
* Performs a CancellationRequest and returns the appropiate CancellationResponse
*
* @param CancellationRequest $cancellationRequest
* @return \CancellationResponse
*/
public function Cancel(CancellationRequest $cancellationRequest) {
$cancellationRequest->logger = $this->logger;
$this->logger->Log("sending cancellation transaction request");
$c = get_called_class();

$AcquirerTrxReq = new AcquirerTrxRequest(
$c::PRODUCT_ID, $c::VERSION, new AcquirerTrxReqMerchant(
$this->Configuration->contractID, $this->Configuration->contractSubID, $this->Configuration->merchantReturnURL
), $cancellationRequest->DebtorBankId, new AcquirerTrxReqTransaction(
$cancellationRequest->EntranceCode, !empty($cancellationRequest->ExpirationPeriod) ? $cancellationRequest->ExpirationPeriod : null, $cancellationRequest->Language, $cancellationRequest
)
);

try {
$this->logger->Log("building idx message");
// Serialize
$docTree = $AcquirerTrxReq->toXml($c::LOCAL_INSTRUMENT);

// Send the Request
$response = $this->PerformRequest($docTree, $this->Configuration->AcquirerUrl_TransactionReq);
// Validate the Response and validate signature
XmlValidator::isValidatXML($response, XmlValidator::SCHEMA_IDX, $this->logger);
try {
$this->signer->verify($response, $this->Configuration->crtFileAquirer);
} catch (Exception $e) {
$this->signer->verify($response, $this->Configuration->crtFileAquirerAlternative);
}

return new CancellationResponse($response);
} catch (Exception $ex) {
return new CancellationResponse($ex->getMessage(), (!empty($response) ? $response : ''));
}
}

}
195 changes: 195 additions & 0 deletions Library/Configuration/Configuration.php
@@ -0,0 +1,195 @@
<?php

require_once dirname(__FILE__) . '/../../../config/eMandatesConfig.php';

/**
* Description of Configuration
*/
class Configuration {

/**
* A passphrase for the keyFile
* @var string
*/
public $passphrase;

/**
* A string which specifies the path to the private key file used by the crtFile to sign messages to the creditor bank.
* @var string
*/
public $keyFile;

/**
* A string which specifies the path to the certificate to use to sign messages to the creditor bank.
* @var string
*/
public $crtFile;

/**
* A string which specifies the path to the certificate to use to validate messages from the creditor bank.
* @var string
*/
public $crtFileAquirer;

/**
* An alternative string which specifies the path to the certificate to use to validate messages from the creditor bank.
* @var string
*/
public $crtFileAquirerAlternative;

/**
* eMandate.ContractID as supplied to you by the creditor bank.
* If the eMandate.ContractID has less than 9 digits, use leading zeros to fill out the field.
* @var string
*/
public $contractID;

/**
* eMandate.ContractSubId as supplied to you by the creditor bank.
* If you do not have a ContractSubId, use 0 for this field.
* @var string
*/
public $contractSubID;

/**
* A valid URL to which the debtor banks redirects to, after the debtor has authorized a transaction.
* @var string
*/
public $merchantReturnURL;

/**
* The URL to which the library sends Directory request messages
* @var string
*/
public $AcquirerUrl_DirectoryReq;

/**
* The URL to which the library sends Transaction messages (including eMandates messages).
* @var string
*/
public $AcquirerUrl_TransactionReq;

/**
* The URL to which the library sends Status request messages.
* @var string
*/
public $AcquirerUrl_StatusReq;

/**
* Enables or Disables the xml logs
* @var bool
*/
public $enableXMLLogs;

/**
* Path to the logs folder
* eg: logs/
* @var string
*/
public $logPath;

/**
* Folder name pattern for date() function
* eg: "Y-m-d" will produce: "2015-03-11"
* eg: end result will be: "logs/2015-03-11/115423.321-DirectoryRes.xml"
* @var string
*/
public $folderNamePattern;

/**
* File name prefix pattern for date() function
* eg: "His.u" will produce: "115423.321"
* eg: end result will be: "logs/2015-03-11/115423.321-DirectoryRes.xml"
* @var string
*/
public $fileNamePrefix;

/**
* Enables or Disables the internal logs
* @var bool
*/
public $enableInternalLogs;

/**
* The file name for internal logs
* This file will be saved in the same path as the xml logs
* eg: "emandates.txt" will produce: "logs/2015-03-11/emandates.txt"
* @var type
*/
public $fileName;

/**
* Constructor that highlights all required fields for this object
*
* @param string $passphrase
* @param string $keyFile
* @param string $crtFile
* @param string $crtFileAquirer
* @param string $crtFileAquirerAlternative
* @param string $contractID
* @param string $contractSubID
* @param string $merchantReturnURL
* @param string $AcquirerUrl_DirectoryReq
* @param string $AcquirerUrl_TransactionReq
* @param bool $enableXMLLogs
* @param string $logPath
* @param string $folderNamePattern
* @param string $fileNamePrefix
* @param bool $enableInternalLogs
* @param string $fileName
*/
public function __construct($passphrase, $keyFile, $crtFile, $crtFileAquirer, $crtFileAquirerAlternative, $contractID, $contractSubID, $merchantReturnURL, $AcquirerUrl_DirectoryReq, $AcquirerUrl_TransactionReq, $AcquirerUrl_StatusReq, $enableXMLLogs, $logPath, $folderNamePattern, $fileNamePrefix, $enableInternalLogs, $fileName) {
$this->passphrase = $passphrase;
$this->keyFile = $keyFile;
$this->crtFile = $crtFile;
$this->crtFileAquirer = $crtFileAquirer;
$this->crtFileAquirerAlternative = $crtFileAquirerAlternative;
$this->contractID = $contractID;
$this->contractSubID = $contractSubID;
$this->merchantReturnURL = $merchantReturnURL;
$this->AcquirerUrl_DirectoryReq = $AcquirerUrl_DirectoryReq;
$this->AcquirerUrl_TransactionReq = $AcquirerUrl_TransactionReq;
$this->AcquirerUrl_StatusReq = $AcquirerUrl_StatusReq;
$this->enableXMLLogs = $enableXMLLogs;
$this->logPath = $logPath;
$this->folderNamePattern = $folderNamePattern;
$this->fileNamePrefix = $fileNamePrefix;
$this->enableInternalLogs = $enableInternalLogs;
$this->fileName = $fileName;
}

/**
* Returns the Configuration object base on the configuration file settings
*
* @global array $emandates_config_params
* @return \Configuration
*/
public static function getDefault() {
global $emandates_config_params;

return new Configuration(
$emandates_config_params['passphrase'],
$emandates_config_params['keyFile'],
$emandates_config_params['crtFile'],
$emandates_config_params['crtFileAquirer'],
$emandates_config_params['crtFileAquirerAlternative'],

$emandates_config_params['contractID'],
$emandates_config_params['contractSubID'],
$emandates_config_params['merchantReturnURL'],

$emandates_config_params['AcquirerUrl_DirectoryReq'],
$emandates_config_params['AcquirerUrl_TransactionReq'],
$emandates_config_params['AcquirerUrl_StatusReq'],

$emandates_config_params['enableXMLLogs'],
$emandates_config_params['logPath'],
$emandates_config_params['folderNamePattern'],
$emandates_config_params['fileNamePrefix'],

$emandates_config_params['enableInternalLogs'],
$emandates_config_params['fileName']
);
}

}

0 comments on commit 82585ae

Please sign in to comment.