<?php require_once dirname(__FILE__) . "/../../PSPInterface.php"; $data = PSP::GetCallbackData(); // Obtain data passed to callback $transactionId = $data["TransactionId"]; // String $orderId = $data["OrderId"]; // String $amount = $data["Amount"]; // Integer $currency = $data["Currency"]; // String PSP::Log("DIBS - custom callback invoked:\nTransactionId: " . $transactionId . "\nOrderId: " . $orderId . "\nAmount: " . $amount . "\nCurrency: " . $currency); // Immediately capture or cancel payment if ($transactionId !== "") { $p = PSP::GetPaymentProvider("DIBS"); $result = false; if ($amount <= 30000) { // Capture payment if equal to or below DKK 300.00 $result = $p->CapturePayment($transactionId, $amount); } else { // Cancel, we do not accept payments larger than DK 300.00 $result = $p->CancelPayment($transactionId); } }
<?php // This file is responsible for receiving the response from DIBS // and forward it to the application in a standardized way. require_once dirname(__FILE__) . "/../PSPInterface.php"; // Callback is called directly by Payment Service Provider, so we need to include PSPInterface.php if ($_SERVER["REMOTE_ADDR"] === "85.236.67.1") { $config = PSP::GetConfig("DIBS"); // Checksum (if keys are configured) $checksum = ""; if (isset($config["Encryption Key 1"]) && $config["Encryption Key 1"] !== "" && isset($config["Encryption Key 2"]) && $config["Encryption Key 2"] !== "") { $k1 = $config["Encryption Key 1"]; $k2 = $config["Encryption Key 2"]; $checksum = md5($k2 . md5($k1 . "transact=" . $_POST["transact"] . "&amount=" . $_POST["amount"] . "¤cy=" . $_POST["currency"])); if ($checksum !== $_POST["authkey"]) { throw new Exception("SecurityException: Integrity check failed - mismatching checksums"); } } // Invoke applicaton callback specified in RedirectToPaymentForm(..). // Using PSP::InvokeCallback(..) which implements security measures // to prevent man-in-the-middle attacks. PSP::Log("DIBS - invoking callback:\nTransactionId: " . $_POST["transact"] . "\nOrderId: " . $_POST["orderid"] . "\nAmount: " . $_POST["amount"] . "\nCurrency: " . $_POST["currency"]); PSP::InvokeCallback($_POST["CUSTOM_Callback"], $_POST["transact"] . ";" . $_POST["orderid"], $_POST["orderid"], (int) $_POST["amount"], $_POST["currency"]); } else { if (isset($_POST["CUSTOM_ContinueUrl"]) === true) { PSP::RedirectToContinueUrl($_POST["CUSTOM_ContinueUrl"]); } }
function PSPExceptionHandler(Exception $ex) { $errNo = $ex->getCode(); $errMsg = $ex->getMessage(); $errFile = $ex->getFile(); $errLine = $ex->getLine(); try { PSP::Log("PSP - unhandled exception occurred:\nError ID: " . $errNo . "\nError message: " . $errMsg . "\nFile: " . $errFile . "\nLine: " . $errLine . (PSP::GetLogMode() === "Full" ? "\nStackTrace: " . $ex->getTraceAsString() : "")); } catch (Exception $excp) { } header("HTTP/1.1 500 Internal Server Error"); header("Content-Type: text/html; charset=ISO-8859-1"); echo "<b>An unhandled exception occurred</b><br><br>"; echo $ex->getMessage(); echo "<br><br><b>Stack trace</b><br><pre>"; echo $ex->getTraceAsString(); echo "</pre>"; }
private function apiCall($type, $transactionId, $amount = -1) { $transactionInfo = explode(";", $transactionId); $transactionId = $transactionInfo[0]; $orderId = $transactionInfo[1]; $cfg = PSP::GetConfig("DIBS"); $checksum = ""; if (isset($cfg["Encryption Key 1"]) && $cfg["Encryption Key 1"] !== "" && isset($cfg["Encryption Key 2"]) && $cfg["Encryption Key 2"] !== "") { $check = ""; $check .= "merchant=" . $cfg["Merchant ID"]; $check .= "&orderid=" . $orderId; $check .= "&transact=" . $transactionId; if ($type === "Capture") { $check .= "&amount=" . $amount; } $checksum = md5($cfg["Encryption Key 2"] . md5($cfg["Encryption Key 1"] . $check)); } $data = array("merchant" => $cfg["Merchant ID"], "transact" => $transactionId, "orderid" => $orderId, "md5key" => $checksum); if ($type === "Capture") { $data["amount"] = (string) $amount; } $url = null; if ($type === "Capture") { $url = "https://payment.architrade.com/cgi-bin/capture.cgi"; } else { if ($type === "Cancel") { $url = "https://" . $cfg["API User: Username"] . ":" . $cfg["API User: Password"] . "@payment.architrade.com/cgi-adm/cancel.cgi"; } } $response = PSP::Post($url, $data); $result = strpos($response, "status=ACCEPTED") !== false; PSP::Log("DIBS - API call result: " . "\nType: " . $type . "\nSuccess: " . ($result === true ? "true" : "false") . "\nResponse: " . $response); return $result; }