From 975d134e555ee5b40ac3bb7a13ca282260016f94 Mon Sep 17 00:00:00 2001
From: seanmacdomhnall
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