Skip to content

Commit

Permalink
Merge pull request #14 from slogsdon/hpp-embedded-redirect
Browse files Browse the repository at this point in the history
HPP embedded and redirect options + tests
  • Loading branch information
RealexITSO authored Jun 14, 2018
2 parents 7639bd8 + b8ff063 commit 1f19a01
Show file tree
Hide file tree
Showing 17 changed files with 1,567 additions and 566 deletions.
34 changes: 31 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,37 @@ module.exports = function(grunt) {
tasks: ['jshint:lib', 'jasmine']
},
specs: {
files: 'specs/*.js',
files: 'specs/unit/*.js',
tasks: ['jasmine']
}
},
jasmine : {
src : 'lib/*.js',
options: {
specs: 'specs/*spec.js',
helpers: 'specs/*helper.js'
specs: 'specs/unit/*spec.js',
helpers: 'specs/unit/*helper.js'
}
},
intern: {
client: {
options: {
config: 'specs/intern.config'
}
},
runner: {
options: {
config: 'specs/intern.config',
runType: 'runner',
// leaveRemoteOpen: true
}
}
},
php: {
test: {
options: {
port: '8989',
silent: true,
}
}
}
});
Expand All @@ -74,6 +96,12 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('intern');
grunt.loadNpmTasks('grunt-php');

grunt.registerTask('test:functional', ['php', 'intern:runner']);
grunt.registerTask('test:unit', ['jasmine']);
grunt.registerTask('test', ['test:unit', 'test:functional']);

// Default task.
grunt.registerTask('default', ['jshint', 'jasmine', 'concat', 'uglify']);
Expand Down
749 changes: 472 additions & 277 deletions dist/rxp-js.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/rxp-js.min.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions examples/hpp/json/process-a-payment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"MERCHANT_ID": "heartlandgpsandbox",
"ACCOUNT": "hpp",
"AMOUNT": "1001",
"CURRENCY": "EUR",
"AUTO_SETTLE_FLAG": "1",
"PM_METHODS": "cards"
}
29 changes: 29 additions & 0 deletions examples/hpp/process-a-payment-embedded.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<title>HPP Lightbox Demo</title>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="/dist/rxp-js.js"></script>
<script>
RealexHpp.setHppUrl('https://pay.sandbox.realexpayments.com/pay');
// get the HPP JSON from the server-side SDK
$(document).ready(function () {
$.getJSON("/examples/hpp/proxy-request.php?slug=process-a-payment", function (jsonFromServerSdk) {
RealexHpp.embedded.init(
"payButtonId",
"targetIframe",
"https://dev.rlxcarts.com/mobileSDKsV2/response.php",
jsonFromServerSdk
);
$('body').addClass('loaded');
});
});
</script>
</head>
<body>
<input type="submit" id="payButtonId" value="Checkout Now" />
<br />
<iframe id="targetIframe" style="display:none;"></iframe>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
RealexHpp.setHppUrl('https://pay.sandbox.realexpayments.com/pay');
// get the HPP JSON from the server-side SDK
$(document).ready(function () {
$.getJSON("/examples/hpp/proxy-request.php", function (jsonFromServerSdk) {
RealexHpp.init("payButtonId", "https://dev.rlxcarts.com/mobileSDKs/response.php", jsonFromServerSdk);
$.getJSON("/examples/hpp/proxy-request.php?slug=process-a-payment", function (jsonFromServerSdk) {
RealexHpp.lightbox.init("payButtonId", "https://dev.rlxcarts.com/mobileSDKsV2/response.php", jsonFromServerSdk);
$('body').addClass('loaded');
});
});
</script>
</head>
<body>
<button type="button" id="payButtonId">Checkout Now</button>
<input type="submit" id="payButtonId" value="Checkout Now" />
</body>
</html>
</html>
74 changes: 71 additions & 3 deletions examples/hpp/proxy-request.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,79 @@
<?php

$json = file_get_contents('https://dev.rlxcarts.com/mobileSDKs/request.php');
function generateHash($data, $secret)
{
$toHash = [];
$timeStamp = !isset($data['TIMESTAMP']) ? "" : $data['TIMESTAMP'];
$merchantId = !isset($data['MERCHANT_ID']) ? "" : $data['MERCHANT_ID'];
$orderId = !isset($data['ORDER_ID']) ? "" : $data['ORDER_ID'];
$amount = !isset($data['AMOUNT']) ? "" : $data['AMOUNT'];
$currency = !isset($data['CURRENCY']) ? "" : $data['CURRENCY'];
$payerReference = !isset($data['PAYER_REF']) ? "" : $data['PAYER_REF'];
$paymentReference = !isset($data['PMT_REF']) ? "" : $data['PMT_REF'];
$hppSelectStoredCard = !isset($data['HPP_SELECT_STORED_CARD']) ? "" : $data['HPP_SELECT_STORED_CARD'];
$payRefORStoredCard = empty($hppSelectStoredCard) ? $payerReference : $hppSelectStoredCard;

if (isset($data['CARD_STORAGE_ENABLE']) && $data['CARD_STORAGE_ENABLE'] === '1') {
$toHash = [
$timeStamp,
$merchantId,
$orderId,
$amount,
$currency,
$payerReference,
$paymentReference,
];
} elseif ($payRefORStoredCard && empty($paymentReference)) {
$toHash = [
$timeStamp,
$merchantId,
$orderId,
$amount,
$currency,
$payRefORStoredCard,
""
];
} elseif ($payRefORStoredCard && !empty($paymentReference)) {
$toHash = [
$timeStamp,
$merchantId,
$orderId,
$amount,
$currency,
$payRefORStoredCard,
$paymentReference,
];
} else {
$toHash = [
$timeStamp,
$merchantId,
$orderId,
$amount,
$currency,
];
}

return sha1(sha1(implode('.', $toHash)) . '.' . $secret);
}

$json = file_get_contents(sprintf('./json/%s.json', $_GET['slug']));
error_log('received: ' . $json);

$data = json_decode($json);

$response = array();
foreach ($data as $key => $value) {
$response[$key] = base64_decode($value);
if (!$value) {
continue;
}
$response[$key] = $value;
}

echo json_encode($response);
$response["ORDER_ID"] = substr(str_shuffle('abcdefghijklmnopqrstuvwxyz0123456789'), 0, 22);
$response["TIMESTAMP"] = (new DateTime())->format("YmdHis");
$response["SHA1HASH"] = generateHash($response, 'secret');

$jsonResponse = json_encode($response);

error_log('sending: ' . $jsonResponse);
echo $jsonResponse;
22 changes: 22 additions & 0 deletions examples/hpp/redirect-for-payment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<title>HPP Redirect Demo</title>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="/dist/rxp-js.js"></script>
<script>
RealexHpp.setHppUrl('https://pay.sandbox.realexpayments.com/pay');
// get the HPP JSON from the server-side SDK
$(document).ready(function () {
$.getJSON("/examples/hpp/proxy-request.php?slug=process-a-payment", function (jsonFromServerSdk) {
RealexHpp.redirect.init("payButtonId", "https://dev.rlxcarts.com/mobileSDKsV2/response.php", jsonFromServerSdk);
$('body').addClass('loaded');
});
});
</script>
</head>
<body>
<input type="submit" id="payButtonId" value="Checkout Now" />
</body>
</html>
Loading

0 comments on commit 1f19a01

Please sign in to comment.