我无法使用Realex付款灯箱

时间:2018-04-16 13:56:59

标签: php realex-payments-api

我真的需要一些帮助来弄清楚为什么带有付款方式的灯箱不起作用。

我一直在关注Hosted Payment Page(Html + JS with PHP)的快速指南,我通过composer和rxp-js + jQuery库手动安装了rxp-hpp-php库。

我认为我做的一切都好,但由于某种原因,弹出窗口没有显示。没有错误和资源似乎被加载。任何人都可以帮助我,发现我错过了什么?

这是我的代码,最后我还附上了一张图片。

本地主机/插件支付/ index.php的

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>HPP Lightbox Demo</title>
    <meta charset="UTF-8">
    <style>
      body { background-color: lightsalmon; }
      button { padding: 10px 20px; border-color: #fff; }
    </style>
    <script src="jquery-1.11.3.min.js"></script>
    <script src="rxp-js/dist/rxp-js.js"></script>
    <script>
      // get the HPP JSON from the server-side SDK
      $(document).ready(function () {
        $.getJSON("requestUrl/", function (jsonFromServerSdk) {
          RealexHpp.setHppUrl('https://hpp.sandbox.addonpayments.com/pay');
          RealexHpp.init("payButtonId", "responseUrl/", jsonFromServerSdk);
        });
      });
    </script>
  </head>
  <body>
    <button type="button" id="payButtonId">Checkout Now</button>
  </body>
</html>

本地主机/ requestUrl / index.php的

    <?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;

      var_dump("Request...");

      $hppRequest = ( new HppRequest() )
        ->addMerchantId( "merchant id" )
        ->addAccount( "internet" )
        ->addAmount( "1001" )
        ->addCurrency( "EUR" )
        ->addAutoSettleFlag( "1" );

      $realexHpp = new RealexHpp( "secret number" );

      try {
        $requestJson = $realexHpp->requestToJson($hppRequest);
        echo $requestJson;
        // here goes custom code
        return $requestJson;
      }
      catch (RealexValidationException $e) {
        return $e->getMessage();
      }
      catch (RealexException $e) {
        return $e->getMessage();
      }

    ?>

本地主机/ responseUrl / index.php的

 <?php

  require_once ('../vendor/autoload.php');

  use com\realexpayments\hpp\sdk\domain\HppResponse;
  use com\realexpayments\hpp\sdk\RealexHpp;
  use com\realexpayments\hpp\sdk\RealexValidationException;
  use com\realexpayments\hpp\sdk\RealexException;

  $realexHpp = new RealexHpp("secret number");
  $responseJson = $_POST['hppResponse'];

  try {
    // create the response object
    $hppResponse = $realexHpp->responseFromJson($responseJson);
    $result = $hppResponse->getResult(); // 00
    $message = $hppResponse->getMessage(); // [ test system ] Authorised
    $authCode = $hppResponse->getAuthCode(); // 12345

    return $hppResponse;
  }
  catch (RealexValidationException $e) {
    return $e->getMessage();
  }
  catch (RealexException $e) {
    return $e->getMessage();
  }

?>

Image of resources

1 个答案:

答案 0 :(得分:0)

感谢您的提问。 JS库期待一个JSON字符串(或者更正确的是,jQuery是)。所以它不会接受:

string(10) "Request..."

在实际请求JSON字符串开始之前。您的请求端点应该传递给JS库的是:

{"MERCHANT_ID":"bWVyY2hhbnRJZA==",...etc}

最佳,

肖恩

全球付款