Skip to content

Commit

Permalink
Merge pull request #18 from realexpayments-developers/master
Browse files Browse the repository at this point in the history
Add method to create non-Base64 encoded requests.
  • Loading branch information
RealexITSO authored Oct 2, 2018
2 parents 5edf273 + 975d134 commit 95437a2
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 14 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
```
Expand Down
15 changes: 10 additions & 5 deletions src/main/php/com-realexpayments-hpp-sdk/RealexHpp.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class RealexHpp
*/
private $secret;


/**
* RealexHpp constructor
*
Expand All @@ -78,9 +77,10 @@ public function __construct($secret)
* </p>
*
* @param HppRequest $hppRequest
* @return string
* @param bool $encoded <code>true</code> 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.");
Expand All @@ -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);
Expand Down
75 changes: 68 additions & 7 deletions src/main/php/com-realexpayments-hpp-sdk/domain/HppRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ class HppRequest {
*/

private $postResponse;

/**
* Getter for merchantId
*
Expand Down Expand Up @@ -1426,8 +1426,6 @@ public function getPostResponse(){

}



/**
* Generates default values for fields such as hash, timestamp and order ID.
*
Expand Down Expand Up @@ -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
*/
Expand All @@ -1651,5 +1713,4 @@ public static function GetClassName() {
}


}

}

0 comments on commit 95437a2

Please sign in to comment.