Comments (11)
@adamisntdead thanks for this, however this didn't work for me sadly, I am unsure why.
However I have modified the PHP side to decode it for me before giving it to the client JS.
This is the documented code from Realex
<?php
require_once ('vendor/autoload.php');
use com\realexpayments\hpp\sdk\domain\HppRequest;
use com\realexpayments\hpp\sdk\RealexHpp;
use com\realexpayments\hpp\sdk\RealexValidationException;
use com\realexpayments\hpp\sdk\RealexException;
$hppRequest = (new HppRequest())
->addMerchantId("Merchant ID")
->addAccount("internet")
->addAmount("1001")
->addCurrency("EUR")
->addAutoSettleFlag(TRUE);
$realexHpp = new RealexHpp("Shared Secret");
try {
$requestJson = $realexHpp->requestToJson($hppRequest);
echo $requestJson;
// code here for your application to pass the JSON string to the client-side library
return $requestJson;
}
catch (RealexValidationException $e) {
return $e->getMessage();
}
catch (RealexException $e) {
return $e->getMessage();
}
?>
This is my modified version
require_once ('vendor/autoload.php');
use com\realexpayments\hpp\sdk\domain\HppRequest;
use com\realexpayments\hpp\sdk\RealexHpp;
use com\realexpayments\hpp\sdk\RealexValidationException;
use com\realexpayments\hpp\sdk\RealexException;
$hppRequest = (new HppRequest())
->addMerchantId("Merchant ID")
->addAccount("internet")
->addAmount("1001")
->addCurrency("EUR")
->addAutoSettleFlag(TRUE);
$realexHpp = new RealexHpp("Shared Secret");
try {
$requestJson = json_decode($realexHpp->requestToJson($hppRequest));
foreach ($requestJson as $key=>$value) {
$requestJson->$key = base64_decode($value);
}
$requestJson = json_encode($requestJson);
echo $requestJson;
// code here for your application to pass the JSON string to the client-side library
return $requestJson;
}
catch (RealexValidationException $e) {
return $e->getMessage();
}
catch (RealexException $e) {
return $e->getMessage();
}
?>
Hopefully that helps someone if they are struggling like I was!
from rxp-js.
ok on their rxp-js
the place where createForm: function (doc, token, ignorePostMessage) {
added token = JSON.parse(atob(token));
to convert the base64 string to object.
and then change form.appendChild(internal.createFormHiddenInput(key,token[key]))
to form.appendChild(internal.createFormHiddenInput(key, atob(token[key])))
now the JS is working. Thanks Realex developers, i wasted so much time and now it's not my bug.
from rxp-js.
@rxp-developers this should be part of the official documentation, in the Readme or at least in the initial email when requesting a test account. I spent (wasted) 1 day trying to understand why the merchant_id/secret received via email weren't working.
from rxp-js.
I had the same issue but I found a fix!
The PHP SDK is outputting base64 encoded values for the javascript object, so you need to decode them before using the client side library.
This one liner should do it (where json
is the object containing all of those base64 encoded strings)
// Decode each key
Object.keys(json).forEach(key => json[key] = atob(json[key]))
And as an example for what this looks like for the whole request,
$(document).ready(function () {
const json = <?= $requestJson ?>;
// Decode each key
Object.keys(json).forEach(key => json[key] = atob(json[key]))
RealexHpp.setHppUrl('https://pay.sandbox.realexpayments.com/pay');
RealexHpp.init('pay', window.location, json)
})
So that should get you working before this gets sorted by @RealexITSO
CC: @philcook @marcoblos
from rxp-js.
I have the same issue with the PHP version of this, when its base64 encoded as per the PHP SDK it keeps giving me the same 506 error!
Again I followed the same tutorial.
I even checked the examples given in the rxp-js repo and these return plain, not encoded strings and work!
Therefore I can only conclude that one of two things is happening here:
- The server cannot cope with encoded values as it should be doing
- The docs are simply incorrect and need to be updated to reflect current setup.
@RealexITSO can you please comment on this as I need to resolve this issue before I am able to move forward.
from rxp-js.
@marcoblos, to remove the null vaules from the request can you please upgrade to the latest version of the Java HPP SDK (1.3.2)
@philcook and @adamisntdead, the developers are going to have a look at the JS Library, it should be able to handle both Base64 and non-Base64 encoded values.
from rxp-js.
@rxp-developers I removed the null values but the problem persists (I made this test some days ago when I create this issue) and the unique way to solve is to pass data as a plain text.
My problem is the same that @philcook and @adamisntdead is.
from rxp-js.
@rxp-developers Any update on Base64 encoded values ?
from rxp-js.
In my case this library simply does not work, it does not work with or without base64 encoding on backend, manually created curl requests work fine with the same data.
from rxp-js.
@Opa-, can you please upgrade to the latest version of both the JS Library and whichever server-side SDK you are using. Version 1.3+ of the JS Library points at HPP Version 2, which expects non-Base64 encoded values.
The latest versions of the SDKs allow for the easy creation of non-Base64 encoded request strings:
PHP SDK
$requestJson = $realexHpp->requestToJson($hppRequest, false);
Java SDK
String requestJson = realexHpp.requestToJson(hppRequest, false);
So this can be passed to JS Library.
from rxp-js.
@rxp-developers Thanks for the quick update & release of Java SDK 1.3.3 which allow passing a boolean to requestToJson
method.
Now it works fine, no need to decode it before sending it to the javscript library.
from rxp-js.
Related Issues (20)
- Pay By Link possible?
- Iframe not showing in the first click of the button
- hppResponse is not render
- How to use rxp-js in react? HOT 4
- React JS, Having to double click to open Hpp payment function
- Abandoned Repo? HOT 1
- Recent commits
- rxp-js 3D Secure page css
- Can not Run the examples
- safari mobile window.open() doesn't work
- v1.5.0 is broken!
- How do I install this package for React project? HOT 3
- Direct Post - hpp-listener-loaded message may send too early to cause the event can't be caught
- Uncaught TypeError: can't access property "removeChild", this.parentElement is null HOT 2
- Getting 508 error HOT 1
- Malware in rxp-js?
- iFrame is not responsive in big screens
- CONFIGURATION_DOES_NOT_EXIST error HOT 1
- Best practices to integrate this library in a Next.js application?
- Can't access the result of the HPP form submission. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rxp-js.