From 975d134e555ee5b40ac3bb7a13ca282260016f94 Mon Sep 17 00:00:00 2001 From: seanmacdomhnall Date: Thu, 30 Aug 2018 16:24:04 +0100 Subject: [PATCH] Add method to create non-Base64 encoded requests. --- LICENSE.txt | 2 +- README.md | 2 +- .../com-realexpayments-hpp-sdk/RealexHpp.php | 15 ++-- .../domain/HppRequest.php | 75 +++++++++++++++++-- 4 files changed, 80 insertions(+), 14 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 2a942cc..ac6b533 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2017 Pay and Shop Ltd t/a Realex Payments +Copyright (c) 2018 Pay and Shop Ltd t/a Global Payments Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal diff --git a/README.md b/README.md index 83cd02f..30c07e3 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ You can sign up for a free Realex Payments sandbox account at https://developer. ``` { "require": { - "realexpayments/rxp-hpp-php": "1.1.1" + "realexpayments/rxp-hpp-php": "1.1.2" } } ``` diff --git a/src/main/php/com-realexpayments-hpp-sdk/RealexHpp.php b/src/main/php/com-realexpayments-hpp-sdk/RealexHpp.php index 9525ebd..ee5e6c6 100644 --- a/src/main/php/com-realexpayments-hpp-sdk/RealexHpp.php +++ b/src/main/php/com-realexpayments-hpp-sdk/RealexHpp.php @@ -53,7 +53,6 @@ class RealexHpp */ private $secret; - /** * RealexHpp constructor * @@ -78,9 +77,10 @@ public function __construct($secret) *

* * @param HppRequest $hppRequest - * @return string + * @param bool $encoded true if the JSON values will be encoded. + * @return HppRequest */ - public function requestToJson(HppRequest $hppRequest) + public function requestToJson(HppRequest $hppRequest, $encoded = true) { $this->logger->info("Converting HppRequest to JSON."); @@ -95,10 +95,15 @@ public function requestToJson(HppRequest $hppRequest) $this->logger->debug("Validating request."); ValidationUtils::validate($hppRequest); - //encode + // build request $this->logger->debug("Encoding object."); try { - $hppRequest = $hppRequest->encode(self::ENCODING_CHARSET); + if ($encoded === true) { + $hppRequest = $hppRequest->encode(self::ENCODING_CHARSET); + } + else { + $hppRequest = $hppRequest->formatRequest(self::ENCODING_CHARSET); + } } catch (Exception $e) { $this->logger->error("Exception encoding HPP request.", $e); throw new RealexException("Exception encoding HPP request.", $e); diff --git a/src/main/php/com-realexpayments-hpp-sdk/domain/HppRequest.php b/src/main/php/com-realexpayments-hpp-sdk/domain/HppRequest.php index 0d2e89a..3f0b070 100644 --- a/src/main/php/com-realexpayments-hpp-sdk/domain/HppRequest.php +++ b/src/main/php/com-realexpayments-hpp-sdk/domain/HppRequest.php @@ -357,7 +357,7 @@ class HppRequest { */ private $postResponse; - + /** * Getter for merchantId * @@ -1426,8 +1426,6 @@ public function getPostResponse(){ } - - /** * Generates default values for fields such as hash, timestamp and order ID. * @@ -1638,11 +1636,75 @@ public function decode( $charSet ) { } } - - return $this; } + /** + * Format (non-encoded) request, remove null values + * + * @param string $charSet + * + * @return HppRequest + */ + public function formatRequest($charSet) + { + $this->account = $this->nullToEmptyString($this->account); + $this->amount = $this->nullToEmptyString($this->amount); + $this->autoSettleFlag = $this->nullToEmptyString($this->autoSettleFlag); + $this->billingCode = $this->nullToEmptyString($this->billingCode); + $this->billingCountry = $this->nullToEmptyString($this->billingCountry); + $this->cardPaymentButtonText = $this->nullToEmptyString($this->cardPaymentButtonText); + $this->cardStorageEnable = $this->nullToEmptyString($this->cardStorageEnable); + $this->commentOne = $this->nullToEmptyString($this->commentOne); + $this->commentTwo = $this->nullToEmptyString($this->commentTwo); + $this->currency = $this->nullToEmptyString($this->currency); + $this->customerNumber = $this->nullToEmptyString($this->customerNumber); + $this->hash = $this->nullToEmptyString($this->hash); + $this->language = $this->nullToEmptyString($this->language); + $this->merchantId = $this->nullToEmptyString($this->merchantId); + $this->offerSaveCard = $this->nullToEmptyString($this->offerSaveCard); + $this->orderId = $this->nullToEmptyString($this->orderId); + $this->payerExists = $this->nullToEmptyString($this->payerExists); + $this->payerReference = $this->nullToEmptyString($this->payerReference); + $this->paymentReference = $this->nullToEmptyString($this->paymentReference); + $this->productId = $this->nullToEmptyString($this->productId); + $this->returnTss = $this->nullToEmptyString($this->returnTss); + $this->shippingCode = $this->nullToEmptyString($this->shippingCode); + $this->shippingCountry = $this->nullToEmptyString($this->shippingCountry); + $this->timeStamp = $this->nullToEmptyString($this->timeStamp); + $this->variableReference = $this->nullToEmptyString($this->variableReference); + $this->validateCardOnly = $this->nullToEmptyString($this->validateCardOnly); + $this->dccEnable = $this->nullToEmptyString($this->dccEnable); + $this->hppVersion = $this->nullToEmptyString($this->hppVersion); + $this->hppSelectStoredCard = $this->nullToEmptyString($this->hppSelectStoredCard); + $this->postResponse = $this->nullToEmptyString($this->postResponse); + $this->postDimensions = $this->nullToEmptyString($this->postDimensions); + + if (is_array($this->supplementaryData)) { + foreach ($this->supplementaryData as $key => $value) { + $this->supplementaryData[$key] = $this->nullToEmptyString($value); + } + } + + return $this; + } + + /** + * Convert null values to empty strings + * + * @param string request $parameter + * + * @return $parameter + */ + public function nullToEmptyString($parameter) + { + if (is_null($parameter)) { + $parameter = ""; + } + + return $parameter; + } + /** * @return string The class name */ @@ -1651,5 +1713,4 @@ public static function GetClassName() { } -} - +} \ No newline at end of file