Giter VIP home page Giter VIP logo

Comments (11)

philcook avatar philcook commented on July 29, 2024 6

@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.

chuanxie avatar chuanxie commented on July 29, 2024 4

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.

peppeocchi avatar peppeocchi commented on July 29, 2024 3

@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.

adamisntdead avatar adamisntdead commented on July 29, 2024 2

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.

philcook avatar philcook commented on July 29, 2024 1

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:

  1. The server cannot cope with encoded values as it should be doing
  2. 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.

rxp-developers avatar rxp-developers commented on July 29, 2024

@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.

marcoblos avatar marcoblos commented on July 29, 2024

@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.

Opa- avatar Opa- commented on July 29, 2024

@rxp-developers Any update on Base64 encoded values ?

from rxp-js.

kemsky avatar kemsky commented on July 29, 2024

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.

rxp-developers avatar rxp-developers commented on July 29, 2024

@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.

Opa- avatar Opa- commented on July 29, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.