Skip to content

Commit 2236464

Browse files
Initial Support for HPP
for use in testing
1 parent 7a8e642 commit 2236464

File tree

56 files changed

+5466
-596
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+5466
-596
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
$PHP_input = file_get_contents('php://input');
3+
$jsonData = json_decode($PHP_input, true);
4+
error_log("iframe_callback.php file_get_contents('php://input') data:" . print_r($jsonData, true));
5+
if($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST)) {
6+
7+
$jsonData = json_decode($_POST, true);
8+
9+
error_log("iframe_callback.php POST request received with data: " . print_r($jsonData, true));
10+
}
11+
?>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
$PHP_input = file_get_contents('php://input');
3+
$jsonData = json_decode($PHP_input, true);
4+
error_log("cancel_url.php file_get_contents('php://input') data:" . print_r($jsonData, true));
5+
if($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST)) {
6+
7+
$jsonData = json_decode($_POST, true);
8+
9+
error_log("cancel_url.php POST request received with data: " . print_r($jsonData, true));
10+
}
11+
?>

examples/gp-api/hosted-payment-pages/error_log

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<h1>Transaction Results</h1>
2+
<?php
3+
function validate_request($gateway_response_json, $GP_signature) {
4+
if (!$gateway_response_json || !$GP_signature) {
5+
return false;
6+
}
7+
8+
$parsed_data = json_decode($gateway_response_json, true);
9+
if (!$parsed_data) {
10+
error_log("Failed to parse gateway response JSON");
11+
return false;
12+
}
13+
if(isset($gateway_response_json['X-GP-Signature'])) {
14+
unset($gateway_response_json['X-GP-Signature']);
15+
}
16+
$minified_input = json_encode($parsed_data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
17+
18+
return hash("sha512", $minified_input . "ALiN55xYMwbVsCla") === $GP_signature;
19+
}
20+
$validation_result = validate_request($_POST['gateway_response'] ?? '', $_POST['X-GP-Signature'] ?? false);
21+
22+
if (!$validation_result) {
23+
http_response_code(403);
24+
die("Invalid Request");
25+
}
26+
$gateway_data = json_decode($_POST['gateway_response'] ?? '{}', true);
27+
echo "<h3>Gateway Response Data:</h3>";
28+
echo "<pre>" . print_r($gateway_data, true) . "</pre>";
29+
?>
30+

examples/gp-api/hosted-payment-pages/index.php

Lines changed: 437 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
$GP_signature = getallheaders()['X-GP-Signature'] ?? false;
4+
$raw_input = trim(file_get_contents('php://input')) ?? false;
5+
$input = json_decode($raw_input, true);
6+
7+
function validate_request($raw_input, $GP_signature) {
8+
if (!$raw_input || !$GP_signature) {
9+
error_log("X-GP-Signature header not found, or no post data");
10+
return false;
11+
}
12+
$parsed_input = json_decode($raw_input, true);
13+
if (!$parsed_input) {
14+
error_log("Failed to parse JSON input");
15+
return false;
16+
}
17+
$minified_input = json_encode($parsed_input, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
18+
19+
return hash("sha512", $minified_input . "ALiN55xYMwbVsCla") === $GP_signature;
20+
}
21+
22+
// Validate the request signature
23+
$is_valid_request = validate_request($raw_input, $GP_signature);
24+
25+
if (!$is_valid_request) {
26+
http_response_code(403);
27+
die("Invalid Request");
28+
}
29+
30+
//Please note that this javascript is rendered on the payment form page,
31+
// any 404 405 errors will be down to the server configuration.
32+
?>
33+
<h1>Return URL</h1>
34+
<script>
35+
const form = document.createElement("form");
36+
form.method = "POST";
37+
form.id = "paymentForm";
38+
form.action = "https://dev.bee-online.com/gp-hpp-installments/examples/gp-api/hosted-payment-pages/final_page.php"; // Change this to your final processing URL
39+
40+
//Include the signature in the POST request, so it can be verified on the again final page.
41+
const signatureKey = document.createElement("input");
42+
signatureKey.type = "hidden";
43+
signatureKey.name = "X-GP-Signature";
44+
signatureKey.value = <?php echo json_encode($GP_signature, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP); ?>;
45+
form.appendChild(signatureKey);
46+
47+
const gatewayResponse = document.createElement("input");
48+
gatewayResponse.type = "hidden";
49+
gatewayResponse.name = "gateway_response";
50+
gatewayResponse.value = JSON.stringify(<?php echo json_encode($input, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); ?>);
51+
form.appendChild(gatewayResponse);
52+
53+
document.body.appendChild(form);
54+
form.submit();
55+
</script>;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
$PHP_input = file_get_contents('php://input');
3+
$jsonData = json_decode($PHP_input, true);
4+
error_log("status_url.php file_get_contents('php://input') data:" . print_r($jsonData, true));
5+
if($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST)) {
6+
7+
$jsonData = json_decode($_POST, true);
8+
9+
error_log("status_url.php POST request received with data: " . print_r($jsonData, true));
10+
}
11+
?>

0 commit comments

Comments
 (0)