From 35bbfc9ca4144b8d6c9bf642ad45bff996d49a0c Mon Sep 17 00:00:00 2001 From: Alessandro Vegna Date: Wed, 8 Jun 2016 14:16:10 +0100 Subject: [PATCH 1/8] HPP_VERSION and HPP_SELECT_STORED_CARD fields --- .gitignore | 14 ++- .../domain/HppRequest.php | 94 +++++++++++++++ .../utils/RequestMapper.php | 4 + .../validators/ValidationMessages.php | 5 + .../SampleJsonData.php | 10 +- .../utils/JsonUtilsTest.php | 74 ++++++++++++ .../utils/ValidationUtilsTest.php | 112 ++++++++++++++++++ .../hpp-request-hpp-version-fail.json | 32 +++++ .../hpp-request-hpp-version-valid.json | 32 +++++ .../sample-json/hpp-request-hpp-version2.json | 31 +++++ 10 files changed, 406 insertions(+), 2 deletions(-) create mode 100644 test/main/resources/sample-json/hpp-request-hpp-version-fail.json create mode 100644 test/main/resources/sample-json/hpp-request-hpp-version-valid.json create mode 100644 test/main/resources/sample-json/hpp-request-hpp-version2.json diff --git a/.gitignore b/.gitignore index 8b13789..b7f65b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,13 @@ - +vendor/* +vm-config/* +.vagrant/ +Vagrantfile +composer.lock +composer.phar +phpunit.phar +Would skip repository vendor/apache/log4php +vendor/autoload.php +vendor/composer +vendor/doctrine +vendor/symfony +vm-config/ 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 7d39f51..300add5 100644 --- a/src/main/php/com-realexpayments-hpp-sdk/domain/HppRequest.php +++ b/src/main/php/com-realexpayments-hpp-sdk/domain/HppRequest.php @@ -277,6 +277,25 @@ class HppRequest { */ private $dccEnable; + /** + * @var As per the commit reference, can only have the value 1 or 2. Passing 2 enables the new skin for the HPP. + * It also allows HPP_SELECT_STORED_CARD to be sent. + * + * @Assert\Length(min = 0, max = 1, maxMessage = ValidationMessages::hppRequest_hppVersion_size) + * @Assert\Regex(pattern="/^[1-2]*$/", message=ValidationMessages::hppRequest_hppVersion_pattern ) + */ + private $hppVersion; + + /** + * @var As per the commit reference, must contain the Payer reference of the customer whose cards the merchant wishes + * to display on the HPP. If sent correctly, all of the customer’s saved cards will be displayed and they can choose + * which one they wish to complete the payment with. + * + * @Assert\Length(min = 0, max = 50, maxMessage = ValidationMessages::hppRequest_hppSelectStoredCard_size) + * @Assert\Regex(pattern="/^[A-Za-z0-9\_\-\\ ]*$/", message=ValidationMessages::hppRequest_hppSelectStoredCard_pattern ) + */ + private $hppSelectedStoredCard; + /** * Getter for merchantId * @@ -1201,6 +1220,74 @@ public function addPayerExists( $payerExists ) { return $this; } + /** + * Helper method for adding the Hpp Version + * + * @param string|bool $hppVersion + * + * @return HppRequest + */ + public function addHppVersion( $hppVersion ){ + $this->hppVersion = $hppVersion; + + return $this; + } + + /** + * Helper method for setting the Hpp Version + * + * @param string|bool $hppVersion + * + * @return void + */ + public function setHppVersion( $hppVersion ){ + $this->hppVersion = $hppVersion; + + } + + /** + * Helper method for adding the Hpp Version + * + * @return hppVersion + */ + public function getHppVersion(){ + return $this->hppVersion ; + } + /** + * Helper method for adding the Hpp Selected Stored Card + * + * @param string|bool $hppSelectedStoredCard + * + * @return HppRequest + */ + public function addHppSelectedStoredCard( $hppSelectedStoredCard ){ + if(isset($this->hppVersion) && !empty($this->hppVersion)) + $this->hppSelectedStoredCard = $hppSelectedStoredCard; + + return $this; + } + + /** + * Helper method for setting the Hpp Selected Stored Card + * + * @param string|bool $hppSelectedStoredCard + * + * @return void + */ + public function setHppSelectedStoredCard( $hppSelectedStoredCard ){ + if(isset($this->hppVersion) && !empty($this->hppVersion)) + $this->hppSelectedStoredCard = $hppSelectedStoredCard; + + } + + /** + * Helper method for adding the Hpp Selected Stored Card + * + * @return hppSelectedStoredCard + */ + public function getHppSelectedStoredCard( ){ + return $this->hppSelectedStoredCard ; + } /** * Generates default values for fields such as hash, timestamp and order ID. @@ -1314,6 +1401,7 @@ public function encode( $charSet ) { $this->timeStamp = base64_encode( $this->timeStamp ); $this->variableReference = base64_encode( $this->variableReference ); + if ( is_array( $this->supplementaryData ) ) { foreach ( $this->supplementaryData as $key => $value ) { $this->supplementaryData[ $key ] = base64_encode( $value ); @@ -1322,6 +1410,9 @@ public function encode( $charSet ) { $this->validateCardOnly = base64_encode( $this->validateCardOnly ); $this->dccEnable = base64_encode( $this->dccEnable ); + $this->hppVersion = base64_encode( $this->hppVersion ); + $this->hppSelectedStoredCard = base64_encode( $this->hppSelectedStoredCard ); + return $this; } @@ -1366,6 +1457,9 @@ public function decode( $charSet ) { $this->validateCardOnly = base64_decode( $this->validateCardOnly ); $this->dccEnable = base64_decode( $this->dccEnable ); + $this->hppVersion = base64_decode( $this->hppVersion ); + $this->hppSelectedStoredCard = base64_decode( $this->hppSelectedStoredCard ); + return $this; } diff --git a/src/main/php/com-realexpayments-hpp-sdk/utils/RequestMapper.php b/src/main/php/com-realexpayments-hpp-sdk/utils/RequestMapper.php index 15316f5..17cc81d 100644 --- a/src/main/php/com-realexpayments-hpp-sdk/utils/RequestMapper.php +++ b/src/main/php/com-realexpayments-hpp-sdk/utils/RequestMapper.php @@ -133,6 +133,7 @@ public function ReadValue( $value ) { $hppRequest->setPaymentReference( $array['PMT_REF'] ); $hppRequest->setPayerExists( $array['PAYER_EXIST'] ); + $supplementaryData = array(); foreach ( $array->getUnderLayingArray() as $key => $value ) { @@ -143,6 +144,9 @@ public function ReadValue( $value ) { } $hppRequest->setSupplementaryData( $supplementaryData ); + + $hppRequest->setHppVersion( $array['HPP_VERSION'] ); + $hppRequest->setHppSelectedStoredCard( $array['HPP_SELECT_STORED_CARD'] ); return $hppRequest; } diff --git a/src/main/php/com-realexpayments-hpp-sdk/validators/ValidationMessages.php b/src/main/php/com-realexpayments-hpp-sdk/validators/ValidationMessages.php index ed1ffa2..d458d64 100644 --- a/src/main/php/com-realexpayments-hpp-sdk/validators/ValidationMessages.php +++ b/src/main/php/com-realexpayments-hpp-sdk/validators/ValidationMessages.php @@ -89,4 +89,9 @@ class ValidationMessages { const hppRequest_supplementary_data_pattern = "Supplementary data text must only contain the characters a-z A-Z 0-9 ' , + \\u201C \\u201D ._ - & \\ / @!? % ( ) * :� $ & \\u20AC # [] | =\""; const hppRequest_supplementary_data_size = "Supplementary data must not be more than 255 character in length"; + const hppRequest_hppVersion_size = "Version flag must not be more than 1 character in length"; + const hppRequest_hppVersion_pattern = "Version must only contain the numbers between 1 and 2"; + + const hppRequest_hppSelectStoredCard_size = "Select stored card must not be more than 50 characters in length"; + const hppRequest_hppSelectStoredCard_pattern = "Select stored card must only contain the characters a-z A-Z/0-9 _ spaces"; } \ No newline at end of file diff --git a/test/main/php/com-realexpayments-hpp-sdk/SampleJsonData.php b/test/main/php/com-realexpayments-hpp-sdk/SampleJsonData.php index 6da88ec..dae186f 100644 --- a/test/main/php/com-realexpayments-hpp-sdk/SampleJsonData.php +++ b/test/main/php/com-realexpayments-hpp-sdk/SampleJsonData.php @@ -29,6 +29,9 @@ class SampleJsonData const VALID_HPP_RESPONSE_NO_ECI_FIELD_ENCODED_JSON_PATH = "/sample-json/hpp-response-no-ECI-field-encoded.json"; const VALID_HPP_RESPONSE_NO_TSS_JSON_PATH = "/sample-json/hpp-response-no-TSS.json"; const VALID_HPP_RESPONSE_NO_TSS_ENCODED_JSON_PATH = "/sample-json/hpp-response-no-TSS-encoded.json"; + const VALID_HPP_REQUEST_HPP_VERSION_JSON_PATH = "/sample-json/hpp-request-hpp-version-valid.json"; + const INVALID_HPP_REQUEST_HPP_VERSION_JSON_PATH = "/sample-json/hpp-request-hpp-version-fail.json"; + const VALID_HPP_REQUEST_HPP_VERSION_JSON_PATH2 = "/sample-json/hpp-request-hpp-version-fail2.json"; //valid JSON constants const SECRET = "mysecret"; const ACCOUNT = "myAccount"; @@ -96,6 +99,9 @@ class SampleJsonData const AVS_ADDRESS = "M"; const AVS_POSTCODE = "P"; + const HPP_VERSION = "1"; + const HPP_SELECT_STORED_CARD = "PayerRef"; + /** * Generates {@link HppRequest} object. @@ -148,7 +154,9 @@ public static function generateValidHppRequestWithEmptyDefaults($cardStorage) ->addShippingCountry(self::SHIPPING_COUNTRY) ->addVariableReference(self::VARIABLE_REFERENCE) ->addValidateCardOnly(self::VALIDATE_CARD_ONLY) - ->addDccEnable(self::DCC_ENABLE); + ->addDccEnable(self::DCC_ENABLE) + ->addHppVersion(self::HPP_VERSION) + ->addHppSelectedStoredCard(self::HPP_SELECT_STORED_CARD); diff --git a/test/main/php/com-realexpayments-hpp-sdk/utils/JsonUtilsTest.php b/test/main/php/com-realexpayments-hpp-sdk/utils/JsonUtilsTest.php index c773963..df6b434 100644 --- a/test/main/php/com-realexpayments-hpp-sdk/utils/JsonUtilsTest.php +++ b/test/main/php/com-realexpayments-hpp-sdk/utils/JsonUtilsTest.php @@ -4,7 +4,9 @@ namespace com\realexpayments\hpp\sdk\utils; use com\realexpayments\hpp\sdk\RealexHpp; +use com\realexpayments\hpp\sdk\RealexValidationException; use com\realexpayments\hpp\sdk\SampleJsonData; +use com\realexpayments\hpp\sdk\validators\ValidationMessages; /** @@ -169,4 +171,76 @@ public function testFromJsonHppResponseNoTSSEncoded() { $this->assertEquals( "", $hppResponseConverted->getTss() ); } + + /** + * Test converting {@link HppRequest} to JSON. + * Testing import from json, decode and encode + */ + public function testToJsonHppRequestWithHppVersion() { + + $path = SampleJsonData::VALID_HPP_REQUEST_HPP_VERSION_JSON_PATH; + $prefix = __DIR__ . '/../../../resources'; + $json = file_get_contents( $prefix . $path ); + + + $hppRequestConverted = JsonUtils::fromJsonHppRequest( $json ); + + $this->assertEquals( SampleJsonData::HPP_VERSION, $hppRequestConverted->getHppVersion() ); + $this->assertEquals( SampleJsonData::HPP_SELECT_STORED_CARD, $hppRequestConverted->getHppSelectedStoredCard() ); + + $hppRequestConverted = $hppRequestConverted->encode(RealexHpp::ENCODING_CHARSET); + $hppRequestConverted = $hppRequestConverted->decode(RealexHpp::ENCODING_CHARSET); + + $this->assertEquals( SampleJsonData::HPP_VERSION, $hppRequestConverted->getHppVersion() ); + $this->assertEquals( SampleJsonData::HPP_SELECT_STORED_CARD, $hppRequestConverted->getHppSelectedStoredCard() ); + + } + + /** + * Test converting {@link HppRequest} to JSON. + * Testing import from json, validate errors + */ + public function testToJsonHppRequestWithHppVersionFail() { + + $path = SampleJsonData::INVALID_HPP_REQUEST_HPP_VERSION_JSON_PATH; + $prefix = __DIR__ . '/../../../resources'; + $json = file_get_contents( $prefix . $path ); + + + $hppRequestConverted = JsonUtils::fromJsonHppRequest( $json ); + + try { + ValidationUtils::validate( $hppRequestConverted ); + $this->fail( "This HppRequest should have validation errors." ); + } catch ( RealexValidationException $e ) { + $validationMessages = $e->getValidationMessages(); + $this->assertEquals( ValidationMessages::hppRequest_hppVersion_pattern, $validationMessages[0] ); + $this->assertEquals( ValidationMessages::hppRequest_hppSelectStoredCard_size, $validationMessages[1] ); + } + } + + /** + * Test converting {@link HppRequest} to JSON. + * Testing import from json, NO Hpp_version => so you are not allow to put the hpp selected stored card + */ + public function testToJsonHppRequestWithHppVersion2() { + + $path = SampleJsonData::VALID_HPP_REQUEST_HPP_VERSION_JSON_PATH2; + $prefix = __DIR__ . '/../../../resources'; + $json = file_get_contents( $prefix . $path ); + + + $hppRequestConverted = JsonUtils::fromJsonHppRequest( $json ); + + try { + ValidationUtils::validate( $hppRequestConverted ); + } catch ( RealexValidationException $e ) { + $this->fail( "This HppRequest should not have validation errors." ); + } + + $this->assertEmpty( $hppRequestConverted->getHppVersion()); + $this->assertEmpty( $hppRequestConverted->getHppSelectedStoredCard()); + } + + } diff --git a/test/main/php/com-realexpayments-hpp-sdk/utils/ValidationUtilsTest.php b/test/main/php/com-realexpayments-hpp-sdk/utils/ValidationUtilsTest.php index 8cad5f7..03157ad 100644 --- a/test/main/php/com-realexpayments-hpp-sdk/utils/ValidationUtilsTest.php +++ b/test/main/php/com-realexpayments-hpp-sdk/utils/ValidationUtilsTest.php @@ -1910,5 +1910,117 @@ public function testCardSupplementaryData2() { } + /** + * Test HPP Version + */ + public function testHppVersion() { + + $hppRequest = SampleJsonData::generateValidHppRequest( false ); + $hppRequest->generateDefaults( SampleJsonData::SECRET ); + + $hppRequest->setHppVersion(1); + + try { + ValidationUtils::validate( $hppRequest ); + } catch ( RealexValidationException $e ) { + $this->fail( "This HppRequest should not have validation errors." ); + } + + $hppRequest->setHppVersion("2"); + + try { + ValidationUtils::validate( $hppRequest ); + } catch ( RealexValidationException $e ) { + $this->fail( "This HppRequest should not have validation errors." ); + } + + + $hppRequest->setHppVersion(0); + + try { + ValidationUtils::validate( $hppRequest ); + $this->fail( "This HppRequest should have validation errors." ); + } catch ( RealexValidationException $e ) { + $validationMessages = $e->getValidationMessages(); + $this->assertEquals( ValidationMessages::hppRequest_hppVersion_pattern, $validationMessages[0] ); + } + + $hppRequest->setHppVersion(12); + + try { + ValidationUtils::validate( $hppRequest ); + $this->fail( "This HppRequest should have validation errors." ); + } catch ( RealexValidationException $e ) { + $validationMessages = $e->getValidationMessages(); + $this->assertEquals( ValidationMessages::hppRequest_hppVersion_size, $validationMessages[0] ); + } + + $hppRequest->setHppVersion('a'); + + try { + ValidationUtils::validate( $hppRequest ); + $this->fail( "This HppRequest should have validation errors." ); + } catch ( RealexValidationException $e ) { + $validationMessages = $e->getValidationMessages(); + $this->assertEquals( ValidationMessages::hppRequest_hppVersion_pattern, $validationMessages[0] ); + } + + $hppRequest->setHppVersion('1 a'); + + try { + ValidationUtils::validate( $hppRequest ); + $this->fail( "This HppRequest should have validation errors." ); + } catch ( RealexValidationException $e ) { + $validationMessages = $e->getValidationMessages(); + $this->assertEquals( ValidationMessages::hppRequest_hppVersion_size, $validationMessages[0] ); + } + } + + /** + * Test HPP Version + */ + public function testHppSelectedStoredCard() { + + $hppRequest = SampleJsonData::generateValidHppRequest( false ); + $hppRequest->generateDefaults( SampleJsonData::SECRET ); + + $hppRequest->setHppSelectedStoredCard("payerref123"); + + try { + ValidationUtils::validate( $hppRequest ); + } catch ( RealexValidationException $e ) { + $this->fail( "This HppRequest should not have validation errors." ); + } + + $hppRequest->setHppSelectedStoredCard(str_repeat('a',50)); + + try { + ValidationUtils::validate( $hppRequest ); + } catch ( RealexValidationException $e ) { + $this->fail( "This HppRequest should not have validation errors." ); + } + + + $hppRequest->setHppSelectedStoredCard(str_repeat('a',51)); + + try { + ValidationUtils::validate( $hppRequest ); + $this->fail( "This HppRequest should have validation errors." ); + } catch ( RealexValidationException $e ) { + $validationMessages = $e->getValidationMessages(); + $this->assertEquals( ValidationMessages::hppRequest_hppSelectStoredCard_size, $validationMessages[0] ); + } + + $hppRequest->setHppSelectedStoredCard("!!!"); + + try { + ValidationUtils::validate( $hppRequest ); + $this->fail( "This HppRequest should have validation errors." ); + } catch ( RealexValidationException $e ) { + $validationMessages = $e->getValidationMessages(); + $this->assertEquals( ValidationMessages::hppRequest_hppSelectStoredCard_pattern, $validationMessages[0] ); + } + + } } diff --git a/test/main/resources/sample-json/hpp-request-hpp-version-fail.json b/test/main/resources/sample-json/hpp-request-hpp-version-fail.json new file mode 100644 index 0000000..d6b49eb --- /dev/null +++ b/test/main/resources/sample-json/hpp-request-hpp-version-fail.json @@ -0,0 +1,32 @@ +{ + "MERCHANT_ID":"MerchantID", + "ACCOUNT":"myAccount", + "ORDER_ID":"OrderID", + "AMOUNT":"100", + "CURRENCY":"EUR", + "TIMESTAMP":"20990101120000", + "SHA1HASH":"5d8f05abd618e50db4861a61cc940112786474cf", + "AUTO_SETTLE_FLAG":"1", + "COMMENT1":"a-z A-Z 0-9 ' \", + “” ._ - & \\ / @ ! ? % ( )* : £ $ & € # [ ] | = ;ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷ø¤ùúûüýþÿŒŽšœžŸ¥", + "COMMENT2":"Comment Two", + "RETURN_TSS":"0", + "SHIPPING_CODE":"56|987", + "SHIPPING_CO":"IRELAND", + "BILLING_CODE":"123|56", + "BILLING_CO":"IRELAND", + "CUST_NUM":"123456", + "VAR_REF":"VariableRef", + "PROD_ID":"ProductID", + "HPP_LANG":"EN", + "CARD_PAYMENT_BUTTON":"Submit Payment", + "CARD_STORAGE_ENABLE":"0", + "OFFER_SAVE_CARD":"0", + "PAYER_REF":"PayerRef", + "PMT_REF":"PaymentRef", + "PAYER_EXIST":"0", + "VALIDATE_CARD_ONLY":"0", + "DCC_ENABLE":"0", + "HPP_VERSION":"5", + "HPP_SELECT_STORED_CARD":"kslkjfnskljfnskljfnskljfnbsklhfbslkhfbskhlbfsjklhbflkshbfskhlfbsjlhfbsjlhfbsjfuwyebaddbajhdbajhdbjahbdajkbdjahbf jhsd djhabjd baj" + +} \ No newline at end of file diff --git a/test/main/resources/sample-json/hpp-request-hpp-version-valid.json b/test/main/resources/sample-json/hpp-request-hpp-version-valid.json new file mode 100644 index 0000000..c55aa12 --- /dev/null +++ b/test/main/resources/sample-json/hpp-request-hpp-version-valid.json @@ -0,0 +1,32 @@ +{ + "MERCHANT_ID":"MerchantID", + "ACCOUNT":"myAccount", + "ORDER_ID":"OrderID", + "AMOUNT":"100", + "CURRENCY":"EUR", + "TIMESTAMP":"20990101120000", + "SHA1HASH":"5d8f05abd618e50db4861a61cc940112786474cf", + "AUTO_SETTLE_FLAG":"1", + "COMMENT1":"a-z A-Z 0-9 ' \", + “” ._ - & \\ / @ ! ? % ( )* : £ $ & € # [ ] | = ;ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷ø¤ùúûüýþÿŒŽšœžŸ¥", + "COMMENT2":"Comment Two", + "RETURN_TSS":"0", + "SHIPPING_CODE":"56|987", + "SHIPPING_CO":"IRELAND", + "BILLING_CODE":"123|56", + "BILLING_CO":"IRELAND", + "CUST_NUM":"123456", + "VAR_REF":"VariableRef", + "PROD_ID":"ProductID", + "HPP_LANG":"EN", + "CARD_PAYMENT_BUTTON":"Submit Payment", + "CARD_STORAGE_ENABLE":"0", + "OFFER_SAVE_CARD":"0", + "PAYER_REF":"PayerRef", + "PMT_REF":"PaymentRef", + "PAYER_EXIST":"0", + "VALIDATE_CARD_ONLY":"0", + "DCC_ENABLE":"0", + "HPP_VERSION":"1", + "HPP_SELECT_STORED_CARD":"PayerRef" + +} \ No newline at end of file diff --git a/test/main/resources/sample-json/hpp-request-hpp-version2.json b/test/main/resources/sample-json/hpp-request-hpp-version2.json new file mode 100644 index 0000000..418ba80 --- /dev/null +++ b/test/main/resources/sample-json/hpp-request-hpp-version2.json @@ -0,0 +1,31 @@ +{ + "MERCHANT_ID":"MerchantID", + "ACCOUNT":"myAccount", + "ORDER_ID":"OrderID", + "AMOUNT":"100", + "CURRENCY":"EUR", + "TIMESTAMP":"20990101120000", + "SHA1HASH":"5d8f05abd618e50db4861a61cc940112786474cf", + "AUTO_SETTLE_FLAG":"1", + "COMMENT1":"a-z A-Z 0-9 ' \", + “” ._ - & \\ / @ ! ? % ( )* : £ $ & € # [ ] | = ;ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷ø¤ùúûüýþÿŒŽšœžŸ¥", + "COMMENT2":"Comment Two", + "RETURN_TSS":"0", + "SHIPPING_CODE":"56|987", + "SHIPPING_CO":"IRELAND", + "BILLING_CODE":"123|56", + "BILLING_CO":"IRELAND", + "CUST_NUM":"123456", + "VAR_REF":"VariableRef", + "PROD_ID":"ProductID", + "HPP_LANG":"EN", + "CARD_PAYMENT_BUTTON":"Submit Payment", + "CARD_STORAGE_ENABLE":"0", + "OFFER_SAVE_CARD":"0", + "PAYER_REF":"PayerRef", + "PMT_REF":"PaymentRef", + "PAYER_EXIST":"0", + "VALIDATE_CARD_ONLY":"0", + "DCC_ENABLE":"0", + "HPP_SELECT_STORED_CARD":"PayerRef" + +} \ No newline at end of file From 01bd84ac619c437d3caa954973b5e92379735c62 Mon Sep 17 00:00:00 2001 From: Alessandro Vegna Date: Thu, 9 Jun 2016 14:56:08 +0100 Subject: [PATCH 2/8] HPP_POST_DIMENSIONS and HPP_POST_RESPONSE fields --- .gitignore | 1 + .../domain/HppRequest.php | 221 ++++++++++++++---- .../utils/RequestMapper.php | 28 ++- .../validators/ValidationMessages.php | 7 + .../RealexHppTest.php | 2 + .../SampleJsonData.php | 40 +++- .../domain/HppRequestTest.php | 39 +++- .../utils/JsonUtilsTest.php | 46 +--- .../utils/ValidationUtilsTest.php | 179 ++++++++++++++ .../hpp-request-post-both-invalid-both.json | 32 +++ .../hpp-request-post-both-valid-both.json | 33 +++ ...quest-post-dimensions-invalid-pattern.json | 30 +++ ...-request-post-dimensions-invalid-size.json | 31 +++ .../hpp-request-post-dimensions-valid.json | 30 +++ ...pp-request-post-response-invalid-size.json | 31 +++ .../hpp-request-post-response-valid.json | 31 +++ 16 files changed, 686 insertions(+), 95 deletions(-) create mode 100644 test/main/resources/sample-json/hpp-request-post-both-invalid-both.json create mode 100644 test/main/resources/sample-json/hpp-request-post-both-valid-both.json create mode 100644 test/main/resources/sample-json/hpp-request-post-dimensions-invalid-pattern.json create mode 100644 test/main/resources/sample-json/hpp-request-post-dimensions-invalid-size.json create mode 100644 test/main/resources/sample-json/hpp-request-post-dimensions-valid.json create mode 100644 test/main/resources/sample-json/hpp-request-post-response-invalid-size.json create mode 100644 test/main/resources/sample-json/hpp-request-post-response-valid.json diff --git a/.gitignore b/.gitignore index b7f65b6..6da56fa 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ vendor/composer vendor/doctrine vendor/symfony vm-config/ +adhoc/ \ No newline at end of file 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 300add5..dbbf217 100644 --- a/src/main/php/com-realexpayments-hpp-sdk/domain/HppRequest.php +++ b/src/main/php/com-realexpayments-hpp-sdk/domain/HppRequest.php @@ -296,6 +296,29 @@ class HppRequest { */ private $hppSelectedStoredCard; + /** + * @var string This field should contain the domain of the page hosting the iFrame calling HPP. If sent correctly, + * every time the height or width of the card form changes (e.g. an error message appears), + * the HPP will send this back as a JSON string to the parent iFrame. + * This is to facilitate developers who wish to resize their iFrame accordingly on increases or decreases of the HPP form’s size. + * @Assert\Length(min = 0, max = 255, maxMessage = ValidationMessages::hppRequest_postDimensions_size, charset="ISO-8859-1") + * @Assert\Regex(pattern="/^[\s \x{0020}-\x{003B} \x{003D} \x{003F}-\x{007E} \x{00A1}-\x{00FF}\x{20AC}\x{201A}\x{0192}\x{201E}\x{2026}\x{2020}\x{2021}\x{02C6}\x{2030}\x{0160}\x{2039}\x{0152}\x{017D}\x{2018}\x{2019}\x{201C}\x{201D}\x{2022}\x{2013}\x{2014}\x{02DC}\x{2122}\x{0161}\x{203A}\x{0153}\x{017E}\x{0178}]*$/iu", message=ValidationMessages::hppRequest_postDimensions_pattern ) + + */ + private $postDimensions ; + + /** + * @var string This field should contain the domain of the page hosting the iFrame calling HPP. If sent correctly, + * every time the height or width of the card form changes (e.g. an error message appears), + * the HPP will send this back as a JSON string to the parent iFrame. + * This is to facilitate developers who wish to resize their iFrame accordingly on increases or decreases of the HPP form’s size. + * + * @Assert\Length(min = 0, max = 255, maxMessage = ValidationMessages::hppRequest_postResponse_size, charset="ISO-8859-1") + * @Assert\Regex(pattern="/^[\s \x{0020}-\x{003B} \x{003D} \x{003F}-\x{007E} \x{00A1}-\x{00FF}\x{20AC}\x{201A}\x{0192}\x{201E}\x{2026}\x{2020}\x{2021}\x{02C6}\x{2030}\x{0160}\x{2039}\x{0152}\x{017D}\x{2018}\x{2019}\x{201C}\x{201D}\x{2022}\x{2013}\x{2014}\x{02DC}\x{2122}\x{0161}\x{203A}\x{0153}\x{017E}\x{0178}]*$/iu", message=ValidationMessages::hppRequest_postResponse_pattern ) + */ + + private $postResponse; + /** * Getter for merchantId * @@ -1223,12 +1246,17 @@ public function addPayerExists( $payerExists ) { /** * Helper method for adding the Hpp Version * - * @param string|bool $hppVersion + * @param string $hppVersion * * @return HppRequest */ public function addHppVersion( $hppVersion ){ - $this->hppVersion = $hppVersion; + if ( is_bool( $hppVersion ) ) { + $this->cardStorageEnable = $hppVersion ? Flag::TRUE : Flag::FALSE; + } else { + $this->hppVersion = $hppVersion; + } + return $this; } @@ -1236,7 +1264,7 @@ public function addHppVersion( $hppVersion ){ /** * Helper method for setting the Hpp Version * - * @param string|bool $hppVersion + * @param string $hppVersion * * @return void */ @@ -1252,17 +1280,18 @@ public function setHppVersion( $hppVersion ){ */ public function getHppVersion(){ return $this->hppVersion ; + } + /** * Helper method for adding the Hpp Selected Stored Card * - * @param string|bool $hppSelectedStoredCard + * @param string $hppSelectedStoredCard * * @return HppRequest */ public function addHppSelectedStoredCard( $hppSelectedStoredCard ){ - if(isset($this->hppVersion) && !empty($this->hppVersion)) - $this->hppSelectedStoredCard = $hppSelectedStoredCard; + $this->hppSelectedStoredCard = $hppSelectedStoredCard; return $this; } @@ -1270,14 +1299,12 @@ public function addHppSelectedStoredCard( $hppSelectedStoredCard ){ /** * Helper method for setting the Hpp Selected Stored Card * - * @param string|bool $hppSelectedStoredCard + * @param string $hppSelectedStoredCard * * @return void */ public function setHppSelectedStoredCard( $hppSelectedStoredCard ){ - if(isset($this->hppVersion) && !empty($this->hppVersion)) - $this->hppSelectedStoredCard = $hppSelectedStoredCard; - + $this->hppSelectedStoredCard = $hppSelectedStoredCard; } /** @@ -1287,8 +1314,81 @@ public function setHppSelectedStoredCard( $hppSelectedStoredCard ){ */ public function getHppSelectedStoredCard( ){ return $this->hppSelectedStoredCard ; + + } + + /** + * Helper method for adding the Hpp Post Dimension + * + * @param string $postDimensions + * + * @return HppRequest + */ + public function addPostDimensions( $postDimensions ){ + $this->postDimensions = $postDimensions; + + return $this; + } + + /** + * Helper method for setting the Hpp Post Dimension + * + * @param string $postDimensions + * + * @return void + */ + public function setPostDimensions( $postDimensions ){ + $this->postDimensions = $postDimensions; + + } + + /** + * Helper method for adding the Hpp Post Dimension + * + * @return postDimensions + */ + public function getPostDimensions( ){ + return $this->postDimensions ; + } + /** + * Helper method for adding the Hpp Post Dimension + * + * @param string $postResponse + * + * @return HppRequest + */ + public function addPostResponse( $postResponse ){ + $this->postResponse = $postResponse; + + return $this; + } + + /** + * Helper method for setting the Hpp Post Dimension + * + * @param string $postResponse + * + * @return void + */ + public function setPostResponse( $postResponse ){ + $this->postResponse = $postResponse; + + } + + /** + * Helper method for adding the Hpp Post Dimension + * + * @return postDimensions + */ + public function getPostResponse(){ + return $this->postResponse ; + + } + + + /** * Generates default values for fields such as hash, timestamp and order ID. * @@ -1331,34 +1431,66 @@ public function hash( $secret ) { $currency = null == $this->currency ? "" : $this->currency; $payerReference = null == $this->payerReference ? "" : $this->payerReference; $paymentReference = null == $this->paymentReference ? "" : $this->paymentReference; + $hppSelectedStoredCard = null == $this->hppSelectedStoredCard ? "" : $this->hppSelectedStoredCard; //create String to hash + $payRefORStoredCard = empty($hppSelectedStoredCard) ? $payerReference : $hppSelectedStoredCard; + if ( $this->cardStorageEnable ) { $toHash = $timeStamp - . "." - . $merchantId - . "." - . $orderId - . "." - . $amount - . "." - . $currency - . "." - . $payerReference - . "." - . $paymentReference; - } else { + . "." + . $merchantId + . "." + . $orderId + . "." + . $amount + . "." + . $currency + . "." + . $payerReference + . "." + . $paymentReference; + } else if ($payRefORStoredCard && empty($paymentReference) ) { + $toHash = $timeStamp + . "." + . $merchantId + . "." + . $orderId + . "." + . $amount + . "." + . $currency + . "." + . $payRefORStoredCard + . "."; + + } else if ( $payRefORStoredCard && !empty($paymentReference) ) { $toHash = $timeStamp - . "." - . $merchantId - . "." - . $orderId - . "." - . $amount - . "." - . $currency; + . "." + . $merchantId + . "." + . $orderId + . "." + . $amount + . "." + . $currency + . "." + . $payRefORStoredCard + . "." + . $paymentReference; + + }else { + $toHash = $timeStamp + . "." + . $merchantId + . "." + . $orderId + . "." + . $amount + . "." + . $currency; } $this->hash = GenerationUtils::generateHash( $toHash, $secret ); @@ -1367,6 +1499,7 @@ public function hash( $secret ) { } + /** * Base64 encodes all Hpp Request values. * @@ -1400,18 +1533,21 @@ public function encode( $charSet ) { $this->shippingCountry = base64_encode( $this->shippingCountry ); $this->timeStamp = base64_encode( $this->timeStamp ); $this->variableReference = base64_encode( $this->variableReference ); - + $this->validateCardOnly = base64_encode( $this->validateCardOnly ); + $this->dccEnable = base64_encode( $this->dccEnable ); + $this->hppVersion = base64_encode( $this->hppVersion ); + $this->hppSelectedStoredCard = base64_encode( $this->hppSelectedStoredCard ); + $this->postResponse = base64_encode( $this->postResponse ); + $this->postDimensions = base64_encode( $this->postDimensions ); if ( is_array( $this->supplementaryData ) ) { foreach ( $this->supplementaryData as $key => $value ) { $this->supplementaryData[ $key ] = base64_encode( $value ); } } - $this->validateCardOnly = base64_encode( $this->validateCardOnly ); - $this->dccEnable = base64_encode( $this->dccEnable ); - $this->hppVersion = base64_encode( $this->hppVersion ); - $this->hppSelectedStoredCard = base64_encode( $this->hppSelectedStoredCard ); + + return $this; } @@ -1449,16 +1585,21 @@ public function decode( $charSet ) { $this->shippingCountry = base64_decode( $this->shippingCountry ); $this->timeStamp = base64_decode( $this->timeStamp ); $this->variableReference = base64_decode( $this->variableReference ); + $this->validateCardOnly = base64_decode( $this->validateCardOnly ); + $this->dccEnable = base64_decode( $this->dccEnable ); + $this->hppVersion = base64_decode( $this->hppVersion ); + $this->hppSelectedStoredCard = base64_decode( $this->hppSelectedStoredCard ); + $this->postResponse = base64_decode( $this->postResponse ); + $this->postDimensions = base64_decode( $this->postDimensions ); + + if ( is_array( $this->supplementaryData ) ) { foreach ( $this->supplementaryData as $key => $value ) { $this->supplementaryData[ $key ] = base64_decode( $value ); } } - $this->validateCardOnly = base64_decode( $this->validateCardOnly ); - $this->dccEnable = base64_decode( $this->dccEnable ); - $this->hppVersion = base64_decode( $this->hppVersion ); - $this->hppSelectedStoredCard = base64_decode( $this->hppSelectedStoredCard ); + return $this; } diff --git a/src/main/php/com-realexpayments-hpp-sdk/utils/RequestMapper.php b/src/main/php/com-realexpayments-hpp-sdk/utils/RequestMapper.php index 17cc81d..04244cb 100644 --- a/src/main/php/com-realexpayments-hpp-sdk/utils/RequestMapper.php +++ b/src/main/php/com-realexpayments-hpp-sdk/utils/RequestMapper.php @@ -35,7 +35,11 @@ class RequestMapper implements iMapper { 'PMT_REF', 'PAYER_EXIST', 'VALIDATE_CARD_ONLY', - 'DCC_ENABLE' + 'DCC_ENABLE', + 'HPP_VERSION', + 'HPP_SELECT_STORED_CARD', + 'HPP_POST_DIMENSIONS', + 'HPP_POST_RESPONSE', ); /** @@ -85,6 +89,18 @@ public function WriteValueAsString( $hppRequest ) { } } + if($hppRequest->getHppVersion() != null) + $prop['HPP_VERSION'] = $hppRequest->getHppVersion(); + + if($hppRequest->getHppSelectedStoredCard() != null) + $prop['HPP_SELECT_STORED_CARD'] = $hppRequest->getHppSelectedStoredCard(); + + if($hppRequest->getPostDimensions() != null) + $prop['HPP_POST_DIMENSIONS'] = $hppRequest->getPostDimensions(); + + if($hppRequest->getPostResponse() != null) + $prop['HPP_POST_RESPONSE'] = $hppRequest->getPostResponse(); + return json_encode( $prop ); } @@ -132,7 +148,10 @@ public function ReadValue( $value ) { $hppRequest->setPayerReference( $array['PAYER_REF'] ); $hppRequest->setPaymentReference( $array['PMT_REF'] ); $hppRequest->setPayerExists( $array['PAYER_EXIST'] ); - + $hppRequest->setHppVersion( $array['HPP_VERSION'] ); + $hppRequest->setHppSelectedStoredCard( $array['HPP_SELECT_STORED_CARD'] ); + $hppRequest->setPostDimensions( $array['HPP_POST_DIMENSIONS'] ); + $hppRequest->setPostResponse( $array['HPP_POST_RESPONSE'] ); $supplementaryData = array(); @@ -144,9 +163,7 @@ public function ReadValue( $value ) { } $hppRequest->setSupplementaryData( $supplementaryData ); - - $hppRequest->setHppVersion( $array['HPP_VERSION'] ); - $hppRequest->setHppSelectedStoredCard( $array['HPP_SELECT_STORED_CARD'] ); + return $hppRequest; } @@ -158,4 +175,5 @@ private function isKnownProperty( $key ) { return in_array( strtoupper( $key ), self::$KNOWN_FIELDS ); } + } \ No newline at end of file diff --git a/src/main/php/com-realexpayments-hpp-sdk/validators/ValidationMessages.php b/src/main/php/com-realexpayments-hpp-sdk/validators/ValidationMessages.php index d458d64..91eaeda 100644 --- a/src/main/php/com-realexpayments-hpp-sdk/validators/ValidationMessages.php +++ b/src/main/php/com-realexpayments-hpp-sdk/validators/ValidationMessages.php @@ -94,4 +94,11 @@ class ValidationMessages { const hppRequest_hppSelectStoredCard_size = "Select stored card must not be more than 50 characters in length"; const hppRequest_hppSelectStoredCard_pattern = "Select stored card must only contain the characters a-z A-Z/0-9 _ spaces"; + + const hppRequest_postDimensions_size = "Post Dimensions must be less than 255 characters in length"; + const hppRequest_postDimensions_pattern = "Post Dimensions must only contain the characters a-z A-Z 0-9 ' \", + \\u201C\\u201D ._ - & \\ / @ ! ? % ( ) * : £ $ & \\u20AC # [ ] | = ; ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷ø¤ùúûüýþÿ\\u0152\\u017D\\u0161\\u0153\\u017E\\u0178¥"; + + const hppRequest_postResponse_size = "Post Response must be less than 255 characters in length"; + const hppRequest_postResponse_pattern = "Post Dimensions must only contain the characters a-z A-Z 0-9 ' \", + \\u201C\\u201D ._ - & \\ / @ ! ? % ( ) * : £ $ & \\u20AC # [ ] | = ; ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷ø¤ùúûüýþÿ\\u0152\\u017D\\u0161\\u0153\\u017E\\u0178¥"; + } \ No newline at end of file diff --git a/test/main/php/com-realexpayments-hpp-sdk/RealexHppTest.php b/test/main/php/com-realexpayments-hpp-sdk/RealexHppTest.php index a297480..c74c4da 100644 --- a/test/main/php/com-realexpayments-hpp-sdk/RealexHppTest.php +++ b/test/main/php/com-realexpayments-hpp-sdk/RealexHppTest.php @@ -150,4 +150,6 @@ public function testResponseFromJsonDecodedSuccessWithUnknown() SampleJsonData::checkValidHppResponse($hppResponseExpected, $hppResponseConverted, $this); SampleJsonData::checkValidHppResponseSupplementaryData($hppResponseConverted, $this); } + + } diff --git a/test/main/php/com-realexpayments-hpp-sdk/SampleJsonData.php b/test/main/php/com-realexpayments-hpp-sdk/SampleJsonData.php index dae186f..cfd5a60 100644 --- a/test/main/php/com-realexpayments-hpp-sdk/SampleJsonData.php +++ b/test/main/php/com-realexpayments-hpp-sdk/SampleJsonData.php @@ -32,6 +32,14 @@ class SampleJsonData const VALID_HPP_REQUEST_HPP_VERSION_JSON_PATH = "/sample-json/hpp-request-hpp-version-valid.json"; const INVALID_HPP_REQUEST_HPP_VERSION_JSON_PATH = "/sample-json/hpp-request-hpp-version-fail.json"; const VALID_HPP_REQUEST_HPP_VERSION_JSON_PATH2 = "/sample-json/hpp-request-hpp-version-fail2.json"; + const VALID_HPP_REQUEST_HPP_POST_DIMENSIONS_JSON_PATH = "/sample-json/hpp-request-post-dimensions-valid.json"; + const INVALID_SIZE_HPP_REQUEST_HPP_POST_DIMENSIONS_JSON_PATH = "/sample-json/hpp-request-post-dimensions-invalid-size.json"; + const INVALID_PATTERN_HPP_REQUEST_HPP_POST_DIMENSIONS_JSON_PATH = "/sample-json/hpp-request-post-dimensions-invalid-pattern.json"; + const VALID_HPP_REQUEST_HPP_POST_RESPONSE_JSON_PATH = "/sample-json/hpp-request-post-response-valid.json"; + const INVALID_HPP_REQUEST_HPP_POST_RESPONSE_JSON_PATH = "/sample-json/hpp-request-post-response-invalid-size.json"; + const INVALID_HPP_REQUEST_HPP_POST_BOTH_JSON_PATH = "/sample-json/hpp-request-post-both-invalid-both.json"; + const VALID_HPP_REQUEST_HPP_POST_BOTH_JSON_PATH = "/sample-json/hpp-request-post-both-valid-both.json"; + //valid JSON constants const SECRET = "mysecret"; const ACCOUNT = "myAccount"; @@ -96,13 +104,14 @@ class SampleJsonData const UNKNOWN_FOUR_VALUE = "Unknown value 4"; private static $SUPPLEMENTARY_DATA; + const POST_DIMENSIONS = "{\"iframe\":{\"height\":\"544px\",\"width\":\"768px\"}}"; + const AVS_ADDRESS = "M"; const AVS_POSTCODE = "P"; const HPP_VERSION = "1"; const HPP_SELECT_STORED_CARD = "PayerRef"; - /** * Generates {@link HppRequest} object. * @@ -159,6 +168,8 @@ public static function generateValidHppRequestWithEmptyDefaults($cardStorage) ->addHppSelectedStoredCard(self::HPP_SELECT_STORED_CARD); + $hppRequest->setTimeStamp(self::TIMESTAMP); + $hppRequest->setHash(self::HASH_REQUEST); if ($cardStorage) { $hppRequest->setCardStorageEnable(Flag::TRUE); @@ -205,6 +216,7 @@ public static function generateTSS() } + /** * Checks expected and converted {@link HppRequest} objects. * @@ -398,6 +410,32 @@ public static function checkValidHppResponseSupplementaryData(HppResponse $hppRe } + + /** + * Checks request post dimensions matches expected values. + * + * @param HppRequest $hppRequestConverted + * @param PHPUnit_Framework_TestCase $testCase + */ + public static function checkValidHppRequestPostDimensions(HppRequest $hppRequestConverted, PHPUnit_Framework_TestCase $testCase){ + + $postDimensions = $hppRequestConverted->getPostDimensions(); + + $testCase->assertEquals(self::POST_DIMENSIONS, $postDimensions, "Json conversion incorrect "); + $testCase->assertEquals(sizeof(self::POST_DIMENSIONS), sizeof($postDimensions), "Json conversion incorrect size"); + + $hppRequestConverted = $hppRequestConverted->encode(RealexHpp::ENCODING_CHARSET); + $hppRequestConverted = $hppRequestConverted->decode(RealexHpp::ENCODING_CHARSET); + + $postDimensions = $hppRequestConverted->getPostDimensions(); + $testCase->assertEquals(self::POST_DIMENSIONS, $postDimensions, "Json conversion incorrect "); + + + } + + + + } SampleJsonData::Init(); \ No newline at end of file diff --git a/test/main/php/com-realexpayments-hpp-sdk/domain/HppRequestTest.php b/test/main/php/com-realexpayments-hpp-sdk/domain/HppRequestTest.php index 220bfa5..3af49e6 100644 --- a/test/main/php/com-realexpayments-hpp-sdk/domain/HppRequestTest.php +++ b/test/main/php/com-realexpayments-hpp-sdk/domain/HppRequestTest.php @@ -19,6 +19,7 @@ class HppRequestTest extends \PHPUnit_Framework_TestCase const CURRENCY = "EUR"; const PAYER_REFERENCE = "newpayer1"; const PAYMENT_REFERENCE = "mycard1"; + const SELECTED_STORED_CARD = "newpayer1"; public function testHash() { @@ -29,15 +30,45 @@ public function testHash() $hppRequest->setAmount(self::AMOUNT); $hppRequest->setCurrency(self::CURRENCY); - $expectedHash = "cc72c08e529b3bc153481eda9533b815cef29de3"; + $expectedHash = "e96eed4869a6d682e8fdbb88703ed81faa58f4df"; $actualHash = $hppRequest->hash("mysecret")->getHash(); $this->assertEquals($expectedHash, $actualHash,"Card storage hash does not match expected."); } - /* - * TODO: Next iteration: cardStoreHashTest - */ + + public function testHashHppSelectedCard() + { + $hppRequest = new HppRequest(); + $hppRequest = $hppRequest->addTimeStamp(self::TIMESTAMP) + ->addMerchantId(self::MERCHANT_ID) + ->addOrderId(self::ORDER_ID) + ->addAmount(self::AMOUNT) + ->addCurrency(self::CURRENCY) + ->addHppSelectedStoredCard(self::SELECTED_STORED_CARD); + + $expectedHash = "099b6ef236391d8bdc642488fc5e9c54ac31cd80"; + $actualHash = $hppRequest->hash("mysecret")->getHash(); + + $this->assertEquals($expectedHash, $actualHash,"Card storage hash does not match expected."); + } + + public function testHashHppSelectedCardAndPaymentReference() + { + $hppRequest = new HppRequest(); + $hppRequest = $hppRequest->addTimeStamp(self::TIMESTAMP) + ->addMerchantId(self::MERCHANT_ID) + ->addOrderId(self::ORDER_ID) + ->addAmount(self::AMOUNT) + ->addCurrency(self::CURRENCY) + ->addHppSelectedStoredCard(self::SELECTED_STORED_CARD) + ->addPaymentReference(self::PAYMENT_REFERENCE); + + $expectedHash = "4106afc4666c6145b623089b1ad4098846badba2"; + $actualHash = $hppRequest->hash("mysecret")->getHash(); + + $this->assertEquals($expectedHash, $actualHash,"Card storage hash does not match expected."); + } } diff --git a/test/main/php/com-realexpayments-hpp-sdk/utils/JsonUtilsTest.php b/test/main/php/com-realexpayments-hpp-sdk/utils/JsonUtilsTest.php index df6b434..3856f61 100644 --- a/test/main/php/com-realexpayments-hpp-sdk/utils/JsonUtilsTest.php +++ b/test/main/php/com-realexpayments-hpp-sdk/utils/JsonUtilsTest.php @@ -196,51 +196,7 @@ public function testToJsonHppRequestWithHppVersion() { } - /** - * Test converting {@link HppRequest} to JSON. - * Testing import from json, validate errors - */ - public function testToJsonHppRequestWithHppVersionFail() { - - $path = SampleJsonData::INVALID_HPP_REQUEST_HPP_VERSION_JSON_PATH; - $prefix = __DIR__ . '/../../../resources'; - $json = file_get_contents( $prefix . $path ); - - - $hppRequestConverted = JsonUtils::fromJsonHppRequest( $json ); - - try { - ValidationUtils::validate( $hppRequestConverted ); - $this->fail( "This HppRequest should have validation errors." ); - } catch ( RealexValidationException $e ) { - $validationMessages = $e->getValidationMessages(); - $this->assertEquals( ValidationMessages::hppRequest_hppVersion_pattern, $validationMessages[0] ); - $this->assertEquals( ValidationMessages::hppRequest_hppSelectStoredCard_size, $validationMessages[1] ); - } - } - - /** - * Test converting {@link HppRequest} to JSON. - * Testing import from json, NO Hpp_version => so you are not allow to put the hpp selected stored card - */ - public function testToJsonHppRequestWithHppVersion2() { - - $path = SampleJsonData::VALID_HPP_REQUEST_HPP_VERSION_JSON_PATH2; - $prefix = __DIR__ . '/../../../resources'; - $json = file_get_contents( $prefix . $path ); - - - $hppRequestConverted = JsonUtils::fromJsonHppRequest( $json ); - - try { - ValidationUtils::validate( $hppRequestConverted ); - } catch ( RealexValidationException $e ) { - $this->fail( "This HppRequest should not have validation errors." ); - } - - $this->assertEmpty( $hppRequestConverted->getHppVersion()); - $this->assertEmpty( $hppRequestConverted->getHppSelectedStoredCard()); - } + } diff --git a/test/main/php/com-realexpayments-hpp-sdk/utils/ValidationUtilsTest.php b/test/main/php/com-realexpayments-hpp-sdk/utils/ValidationUtilsTest.php index 03157ad..5479cb7 100644 --- a/test/main/php/com-realexpayments-hpp-sdk/utils/ValidationUtilsTest.php +++ b/test/main/php/com-realexpayments-hpp-sdk/utils/ValidationUtilsTest.php @@ -1910,6 +1910,7 @@ public function testCardSupplementaryData2() { } + /** * Test HPP Version */ @@ -2022,5 +2023,183 @@ public function testHppSelectedStoredCard() { } } + /** + * Test converting {@link HppRequest} to JSON. + * Testing import from json, validate errors + */ + public function testToJsonHppRequestWithHppVersionFail() { + + $path = SampleJsonData::INVALID_HPP_REQUEST_HPP_VERSION_JSON_PATH; + $prefix = __DIR__ . '/../../../resources'; + $json = file_get_contents( $prefix . $path ); + + + $hppRequestConverted = JsonUtils::fromJsonHppRequest( $json ); + + try { + ValidationUtils::validate( $hppRequestConverted ); + $this->fail( "This HppRequest should have validation errors." ); + } catch ( RealexValidationException $e ) { + $validationMessages = $e->getValidationMessages(); + $this->assertEquals( ValidationMessages::hppRequest_hppVersion_pattern, $validationMessages[0] ); + $this->assertEquals( ValidationMessages::hppRequest_hppSelectStoredCard_size, $validationMessages[1] ); + } + } + + /** + * Test converting {@link HppRequest} to JSON. + * Testing import from json, NO Hpp_version => so you are not allow to put the hpp selected stored card + */ + public function testToJsonHppRequestWithHppVersion2() { + + $path = SampleJsonData::VALID_HPP_REQUEST_HPP_VERSION_JSON_PATH2; + $prefix = __DIR__ . '/../../../resources'; + $json = file_get_contents( $prefix . $path ); + + + $hppRequestConverted = JsonUtils::fromJsonHppRequest( $json ); + + try { + ValidationUtils::validate( $hppRequestConverted ); + } catch ( RealexValidationException $e ) { + $this->fail( "This HppRequest should not have validation errors." ); + } + + $this->assertEmpty( $hppRequestConverted->getHppVersion()); + $this->assertNotEmpty( $hppRequestConverted->getHppSelectedStoredCard()); + } + + /** + * Test converting {@link HppRequest} to JSON. + * Testing import from json + */ + public function testToJsonPostDimensions2() { + + $path = SampleJsonData::VALID_HPP_REQUEST_HPP_POST_DIMENSIONS_JSON_PATH; + $prefix = __DIR__ . '/../../../resources'; + $json = file_get_contents( $prefix . $path ); + + $hppRequestConverted = JsonUtils::fromJsonHppRequest( $json ); + + SampleJsonData::checkValidHppRequestPostDimensions($hppRequestConverted,$this); + + } + + /** + * Test validation post dimensions pass + */ + public function testValidationPassedPostDimensions() { + $path = SampleJsonData::VALID_HPP_REQUEST_HPP_POST_DIMENSIONS_JSON_PATH; + $prefix = __DIR__ . '/../../../resources'; + $json = file_get_contents( $prefix . $path ); + + $hppRequestConverted = JsonUtils::fromJsonHppRequest( $json ); + $hppRequestConverted->generateDefaults( SampleJsonData::SECRET ); + + try { + ValidationUtils::validate( $hppRequestConverted ); + } catch ( RealexValidationException $e ) { + $this->fail( "This HppRequest should have no validation errors." ); + } + } + + /** + * Test converting a {@link HppRequest} object to JSON. Includes validation and generation of defaults. + */ + public function testValidationFailsPostDimensions() + { + $hppRequest = SampleJsonData::generateValidHppRequestWithEmptyDefaults(false); + //limit is 255 + $postDimensions = str_repeat('a',256); + //testing add method + $hppRequest = $hppRequest->addPostDimensions($postDimensions); + + + try { + ValidationUtils::validate( $hppRequest ); + $this->fail( "This HppRequest should have validation errors." ); + } catch ( RealexValidationException $e ) { + $validationMessages = $e->getValidationMessages(); + $this->assertEquals( ValidationMessages::hppRequest_postDimensions_size, $validationMessages[0] ); + } + } + + /** + * Test validation post dimensions pass + */ + public function testValidationPassedPostResponse() { + $path = SampleJsonData::VALID_HPP_REQUEST_HPP_POST_RESPONSE_JSON_PATH; + $prefix = __DIR__ . '/../../../resources'; + $json = file_get_contents( $prefix . $path ); + + $hppRequestConverted = JsonUtils::fromJsonHppRequest( $json ); + $hppRequestConverted->generateDefaults( SampleJsonData::SECRET ); + + try { + ValidationUtils::validate( $hppRequestConverted ); + } catch ( RealexValidationException $e ) { + $this->fail( "This HppRequest should have no validation errors." ); + } + } + + /** + * Test validation post dimensions fails + */ + public function testValidationPassedPostResponseFails() { + $path = SampleJsonData::INVALID_HPP_REQUEST_HPP_POST_RESPONSE_JSON_PATH; + $prefix = __DIR__ . '/../../../resources'; + $json = file_get_contents( $prefix . $path ); + + $hppRequestConverted = JsonUtils::fromJsonHppRequest( $json ); + $hppRequestConverted->generateDefaults( SampleJsonData::SECRET ); + try { + ValidationUtils::validate( $hppRequestConverted ); + $this->fail( "This HppRequest should have validation errors." ); + } catch ( RealexValidationException $e ) { + $validationMessages = $e->getValidationMessages(); + $this->assertEquals( ValidationMessages::hppRequest_postResponse_size, $validationMessages[0] ); + } + } + + /** + * Test validation post dimensions fails + */ + public function testValidationPassedFails() { + $path = SampleJsonData::INVALID_HPP_REQUEST_HPP_POST_BOTH_JSON_PATH; + $prefix = __DIR__ . '/../../../resources'; + $json = file_get_contents( $prefix . $path ); + + $hppRequestConverted = JsonUtils::fromJsonHppRequest( $json ); + $hppRequestConverted->generateDefaults( SampleJsonData::SECRET ); + + try { + ValidationUtils::validate( $hppRequestConverted ); + $this->fail( "This HppRequest should have validation errors." ); + } catch ( RealexValidationException $e ) { + $validationMessages = $e->getValidationMessages(); + $this->assertEquals( ValidationMessages::hppRequest_postDimensions_size, $validationMessages[0] ); + $this->assertEquals( ValidationMessages::hppRequest_postResponse_size, $validationMessages[1] ); + } + } + + + /** + * Test validation post dimensions fails + */ + public function testValidationPassedSuccess() { + $path = SampleJsonData::VALID_HPP_REQUEST_HPP_POST_BOTH_JSON_PATH; + $prefix = __DIR__ . '/../../../resources'; + $json = file_get_contents( $prefix . $path ); + + $hppRequestConverted = JsonUtils::fromJsonHppRequest( $json ); + $hppRequestConverted->generateDefaults( SampleJsonData::SECRET ); + + try { + ValidationUtils::validate( $hppRequestConverted ); + } catch ( RealexValidationException $e ) { + $this->fail( "This HppRequest shouldn't have validation errors." ); + } + + } } diff --git a/test/main/resources/sample-json/hpp-request-post-both-invalid-both.json b/test/main/resources/sample-json/hpp-request-post-both-invalid-both.json new file mode 100644 index 0000000..b2f40e7 --- /dev/null +++ b/test/main/resources/sample-json/hpp-request-post-both-invalid-both.json @@ -0,0 +1,32 @@ +{ + "MERCHANT_ID":"MerchantID", + "ACCOUNT":"myAccount", + "ORDER_ID":"OrderID", + "AMOUNT":"100", + "CURRENCY":"EUR", + "TIMESTAMP":"20990101120000", + "SHA1HASH":"5d8f05abd618e50db4861a61cc940112786474cf", + "AUTO_SETTLE_FLAG":"1", + "COMMENT1":"a-z A-Z 0-9 ' \", + “” ._ - & \\ / @ ! ? % ( )* : £ $ & € # [ ] | = ;À", + "COMMENT2":"Comment Two", + "RETURN_TSS":"0", + "SHIPPING_CODE":"56|987", + "SHIPPING_CO":"IRELAND", + "BILLING_CODE":"123|56", + "BILLING_CO":"IRELAND", + "CUST_NUM":"123456", + "VAR_REF":"VariableRef", + "PROD_ID":"ProductID", + "HPP_LANG":"EN", + "CARD_PAYMENT_BUTTON":"Submit Payment", + "CARD_STORAGE_ENABLE":"0", + "OFFER_SAVE_CARD":"0", + "PAYER_REF":"PayerRef", + "PMT_REF":"PaymentRef", + "PAYER_EXIST":"0", + "VALIDATE_CARD_ONLY":"0", + "DCC_ENABLE":"0", + "HPP_POST_DIMENSIONS":"width\":\"lwtaqzoqysgzcrfvqqldasxutaswhyqamfogquocmwzucsttgfmplgnejydkwpbgxbuswwhggnhbxoyrbbvdrmfvhfpxpvksvlpelanmihfbztllqqcxlzrqgwjzbsimnszxbrlkeurbpxkbtgenlxmhfbfuugqhqkdzhxsvkxemrtipxafotbbasafrpqnyyuwzrxcsycisqufjvlqzhsgwfaaqtscxkyqwoqdyrzseesymwqrgvludmqhwfzbqzmh", + "HPP_POST_RESPONSE": "{\"DCCCOMMISSIONPERCENTAGE\": \"lwtaqzoqysgzcrfvqqldasxutaswhyqamfogquocmwzucsttgfmplgnejydkwpbgxbuswwhggnhbxoyrbbvdrmfvhfpxpvksvlpelanmihfbztllqqcxlzrqgwjzbsimnszxbrlkeurbpxkbtgenlxmhfbfuugqhqkdzhxsvkxemrtipxafotbbasafrpqnyyuwzrxcsycisqufjvlqzhsgwfaaqtscxkyqwoqdyrzseesymwqrgvludmqhwfzbqzmh\"}" + +} \ No newline at end of file diff --git a/test/main/resources/sample-json/hpp-request-post-both-valid-both.json b/test/main/resources/sample-json/hpp-request-post-both-valid-both.json new file mode 100644 index 0000000..c8ca450 --- /dev/null +++ b/test/main/resources/sample-json/hpp-request-post-both-valid-both.json @@ -0,0 +1,33 @@ +{ + "MERCHANT_ID":"MerchantID", + "ACCOUNT":"myAccount", + "ORDER_ID":"OrderID", + "AMOUNT":"100", + "CURRENCY":"EUR", + "TIMESTAMP":"20990101120000", + "SHA1HASH":"5d8f05abd618e50db4861a61cc940112786474cf", + "AUTO_SETTLE_FLAG":"1", + "COMMENT1":"a-z A-Z 0-9 ' \", + “” ._ - & \\ / @ ! ? % ( )* : £ $ & € # [ ] | = ;ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷ø¤ùúûüýþÿŒŽšœžŸ¥", + "COMMENT2":"Comment Two", + "RETURN_TSS":"0", + "SHIPPING_CODE":"56|987", + "SHIPPING_CO":"IRELAND", + "BILLING_CODE":"123|56", + "BILLING_CO":"IRELAND", + "CUST_NUM":"123456", + "VAR_REF":"VariableRef", + "PROD_ID":"ProductID", + "HPP_LANG":"EN", + "CARD_PAYMENT_BUTTON":"Submit Payment", + "CARD_STORAGE_ENABLE":"0", + "OFFER_SAVE_CARD":"0", + "PAYER_REF":"PayerRef", + "PMT_REF":"PaymentRef", + "PAYER_EXIST":"0", + "VALIDATE_CARD_ONLY":"0", + "DCC_ENABLE":"0", + "HPP_POST_DIMENSIONS":"{\"iframe\":{\"height\":\"544px\",\"width\":\"768px\"}}", + "HPP_POST_RESPONSE": "{ \"DCCCOMMISSI1lbGlzdGVuZXIzRFM=\",\"AVSADDRESSRESULT\": \"VQ==\",\"CVNRESULT\": \"TQ==\",\"CARD_PAYMENT_BUTTON\": \"Q29tcGxldGUgUGF5bWVudA==\",\"MESSAGE\": \"QVVUSCBDT0RFIEFQMTIzNA==\"}", + "HPP_VERSION":"1", + "HPP_SELECT_STORED_CARD":"PayerRef" +} \ No newline at end of file diff --git a/test/main/resources/sample-json/hpp-request-post-dimensions-invalid-pattern.json b/test/main/resources/sample-json/hpp-request-post-dimensions-invalid-pattern.json new file mode 100644 index 0000000..a3f79d1 --- /dev/null +++ b/test/main/resources/sample-json/hpp-request-post-dimensions-invalid-pattern.json @@ -0,0 +1,30 @@ +{ + "MERCHANT_ID":"MerchantID", + "ACCOUNT":"myAccount", + "ORDER_ID":"OrderID", + "AMOUNT":"100", + "CURRENCY":"EUR", + "TIMESTAMP":"20990101120000", + "SHA1HASH":"5d8f05abd618e50db4861a61cc940112786474cf", + "AUTO_SETTLE_FLAG":"1", + "COMMENT1":"a-z A-Z 0-9 ' \", + “” ._ - & \\ / @ ! ? % ( )* : £ $ & € # [ ] | = ;ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷ø¤ùúûüýþÿŒŽšœžŸ¥", + "COMMENT2":"Comment Two", + "RETURN_TSS":"0", + "SHIPPING_CODE":"56|987", + "SHIPPING_CO":"IRELAND", + "BILLING_CODE":"123|56", + "BILLING_CO":"IRELAND", + "CUST_NUM":"123456", + "VAR_REF":"VariableRef", + "PROD_ID":"ProductID", + "HPP_LANG":"EN", + "CARD_PAYMENT_BUTTON":"Submit Payment", + "CARD_STORAGE_ENABLE":"0", + "OFFER_SAVE_CARD":"0", + "PAYER_REF":"PayerRef", + "PMT_REF":"PaymentRef", + "PAYER_EXIST":"0", + "VALIDATE_CARD_ONLY":"0", + "DCC_ENABLE":"0", + "HPP_POST_DIMENSIONS":"{\"height\":\"a-z A-Z 0-9 ' \", + “” ._ - & \\ / @ ! ? % ( )* : £ $ & € # [ ] | = ;ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷ø¤ùúûüýþÿŒŽšœžŸ¥\"}" +} \ No newline at end of file diff --git a/test/main/resources/sample-json/hpp-request-post-dimensions-invalid-size.json b/test/main/resources/sample-json/hpp-request-post-dimensions-invalid-size.json new file mode 100644 index 0000000..e284ebd --- /dev/null +++ b/test/main/resources/sample-json/hpp-request-post-dimensions-invalid-size.json @@ -0,0 +1,31 @@ +{ + "MERCHANT_ID":"MerchantID", + "ACCOUNT":"myAccount", + "ORDER_ID":"OrderID", + "AMOUNT":"100", + "CURRENCY":"EUR", + "TIMESTAMP":"20990101120000", + "SHA1HASH":"5d8f05abd618e50db4861a61cc940112786474cf", + "AUTO_SETTLE_FLAG":"1", + "COMMENT1":"a-z A-Z 0-9 ' \", + “” ._ - & \\ / @ ! ? % ( )* : £ $ & € # [ ] | = ;ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷ø¤ùúûüýþÿŒŽšœžŸ¥", + "COMMENT2":"Comment Two", + "RETURN_TSS":"0", + "SHIPPING_CODE":"56|987", + "SHIPPING_CO":"IRELAND", + "BILLING_CODE":"123|56", + "BILLING_CO":"IRELAND", + "CUST_NUM":"123456", + "VAR_REF":"VariableRef", + "PROD_ID":"ProductID", + "HPP_LANG":"EN", + "CARD_PAYMENT_BUTTON":"Submit Payment", + "CARD_STORAGE_ENABLE":"0", + "OFFER_SAVE_CARD":"0", + "PAYER_REF":"PayerRef", + "PMT_REF":"PaymentRef", + "PAYER_EXIST":"0", + "VALIDATE_CARD_ONLY":"0", + "DCC_ENABLE":"0", + "HPP_POST_DIMENSIONS":"{\"width\":\"lwtaqzoqysgzcrfvqqlxutaswhyqamfogquocmwzucsttgfmplgnejydkwpbgxbuswwhggnhbxoyrbbvdrmfvhfpxpvksvlpelanmihfbztllqqcxlzrqgwjzbsimnszxbrlkeurbpxkbtgenlxmhfbfuugqhqkdzhxsvkxemrtipxafotbbasafrpqnyyuwzrxcsycisqufjvlqzhsgwfaaqtscxkyqwoqdyrzseesymwqrgvludmqhwfzbqzmh\"}" + +} \ No newline at end of file diff --git a/test/main/resources/sample-json/hpp-request-post-dimensions-valid.json b/test/main/resources/sample-json/hpp-request-post-dimensions-valid.json new file mode 100644 index 0000000..6aaad7b --- /dev/null +++ b/test/main/resources/sample-json/hpp-request-post-dimensions-valid.json @@ -0,0 +1,30 @@ +{ + "MERCHANT_ID":"MerchantID", + "ACCOUNT":"myAccount", + "ORDER_ID":"OrderID", + "AMOUNT":"100", + "CURRENCY":"EUR", + "TIMESTAMP":"20990101120000", + "SHA1HASH":"5d8f05abd618e50db4861a61cc940112786474cf", + "AUTO_SETTLE_FLAG":"1", + "COMMENT1":"a-z A-Z 0-9 ' \", + “” ._ - & \\ / @ ! ? % ( )* : £ $ & € # [ ] | = ;ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷ø¤ùúûüýþÿŒŽšœžŸ¥", + "COMMENT2":"Comment Two", + "RETURN_TSS":"0", + "SHIPPING_CODE":"56|987", + "SHIPPING_CO":"IRELAND", + "BILLING_CODE":"123|56", + "BILLING_CO":"IRELAND", + "CUST_NUM":"123456", + "VAR_REF":"VariableRef", + "PROD_ID":"ProductID", + "HPP_LANG":"EN", + "CARD_PAYMENT_BUTTON":"Submit Payment", + "CARD_STORAGE_ENABLE":"0", + "OFFER_SAVE_CARD":"0", + "PAYER_REF":"PayerRef", + "PMT_REF":"PaymentRef", + "PAYER_EXIST":"0", + "VALIDATE_CARD_ONLY":"0", + "DCC_ENABLE":"0", + "HPP_POST_DIMENSIONS":"{\"iframe\":{\"height\":\"544px\",\"width\":\"768px\"}}" +} \ No newline at end of file diff --git a/test/main/resources/sample-json/hpp-request-post-response-invalid-size.json b/test/main/resources/sample-json/hpp-request-post-response-invalid-size.json new file mode 100644 index 0000000..bb28bca --- /dev/null +++ b/test/main/resources/sample-json/hpp-request-post-response-invalid-size.json @@ -0,0 +1,31 @@ +{ + "MERCHANT_ID":"MerchantID", + "ACCOUNT":"myAccount", + "ORDER_ID":"OrderID", + "AMOUNT":"100", + "CURRENCY":"EUR", + "TIMESTAMP":"20990101120000", + "SHA1HASH":"5d8f05abd618e50db4861a61cc940112786474cf", + "AUTO_SETTLE_FLAG":"1", + "COMMENT1":"a-z A-Z 0-9 ' \", + “” ._ - & \\ / @ ÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷ø¤ùúûüýþÿŒŽšœžŸ¥", + "COMMENT2":"Comment Two", + "RETURN_TSS":"0", + "SHIPPING_CODE":"56|987", + "SHIPPING_CO":"IRELAND", + "BILLING_CODE":"123|56", + "BILLING_CO":"IRELAND", + "CUST_NUM":"123456", + "VAR_REF":"VariableRef", + "PROD_ID":"ProductID", + "HPP_LANG":"EN", + "CARD_PAYMENT_BUTTON":"Submit Payment", + "CARD_STORAGE_ENABLE":"0", + "OFFER_SAVE_CARD":"0", + "PAYER_REF":"PayerRef", + "PMT_REF":"PaymentRef", + "PAYER_EXIST":"0", + "VALIDATE_CARD_ONLY":"0", + "DCC_ENABLE":"0", + "HPP_POST_DIMENSIONS":"{\"iframe\":{\"height\":\"544px\",\"width\":\"768px\"}}", + "HPP_POST_RESPONSE": "{\"DCCCOMMISSIONPERCENTAGE\": \"lwtaqzoqysgzcrfvqqldasxutaswhyqamfogquocmwzucsttgfmplgnejydkwpbgxbuswwhggnhbxoyrbbvdrmfvhfpxpvksvlpelanmihfbztllqqcxlzrqgwjzbsimnszxbrlkeurbpxkbtgenlxmhfbfuugqhqkdzhxsvkxemrtipxafotbbasafrpqnyyuwzrxcsycisqufjvlqzhsgwfaaqtscxkyqwoqdyrzseesymwqrgvludmqhwfzbqzmh\"}" +} \ No newline at end of file diff --git a/test/main/resources/sample-json/hpp-request-post-response-valid.json b/test/main/resources/sample-json/hpp-request-post-response-valid.json new file mode 100644 index 0000000..4b52c63 --- /dev/null +++ b/test/main/resources/sample-json/hpp-request-post-response-valid.json @@ -0,0 +1,31 @@ +{ + "MERCHANT_ID":"MerchantID", + "ACCOUNT":"myAccount", + "ORDER_ID":"OrderID", + "AMOUNT":"100", + "CURRENCY":"EUR", + "TIMESTAMP":"20990101120000", + "SHA1HASH":"5d8f05abd618e50db4861a61cc940112786474cf", + "AUTO_SETTLE_FLAG":"1", + "COMMENT1":"a-z A-Z 0-9 ' \", + “” ._ - & \\ / @ ! ? % ( )* : £ $ & € # [ ] | = ;ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷ø¤ùúûüýþÿŒŽšœžŸ¥", + "COMMENT2":"Comment Two", + "RETURN_TSS":"0", + "SHIPPING_CODE":"56|987", + "SHIPPING_CO":"IRELAND", + "BILLING_CODE":"123|56", + "BILLING_CO":"IRELAND", + "CUST_NUM":"123456", + "VAR_REF":"VariableRef", + "PROD_ID":"ProductID", + "HPP_LANG":"EN", + "CARD_PAYMENT_BUTTON":"Submit Payment", + "CARD_STORAGE_ENABLE":"0", + "OFFER_SAVE_CARD":"0", + "PAYER_REF":"PayerRef", + "PMT_REF":"PaymentRef", + "PAYER_EXIST":"0", + "VALIDATE_CARD_ONLY":"0", + "DCC_ENABLE":"0", + "HPP_POST_DIMENSIONS":"{\"iframe\":{\"height\":\"544px\",\"width\":\"768px\"}}", + "HPP_POST_RESPONSE": "{ \"DCCCOMMISSIONPERCENTAGE\": MA==NRESULT\": \"TQ==\",\"CARD_PAYMENT_BUTTON\": \"Q29tcGxldGUgUGF5bWVudA==\",\"MESSAGE\": \"QVVUSCBDT0RFIEFQMTIzNA==\"}" +} \ No newline at end of file From e612339515a3e839eac914793c4919e8c8305b15 Mon Sep 17 00:00:00 2001 From: Alessandro Vegna Date: Thu, 30 Jun 2016 16:06:31 +0100 Subject: [PATCH 3/8] Updated README.md --- README.md | 33 ++++++++++++++++ .../domain/HppRequest.php | 38 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/README.md b/README.md index 3dc6d0c..33b90b2 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,39 @@ $requestJson = $realexHpp->requestToJson($hppRequest); $realexHpp = new RealexHpp("secret"); $hppResponse = $realexHpp->responseFromJson(responseJson); ``` +### HPP Version and HPP Selected Stored Card +```php +$hppRequest = new HppRequest(); +$hppRequest + ->addAmount("1001") + ->addCurrency("EUR") + ->addAccount("accountId") + ->addMerchantId("merchantId") + ->addAutoSettleFlag("1") + ->addPayerExists("1") + ->addPayerReference("payerRef") + ->addHppSelectedStoredCard("storedCardRef"); + +$realexHpp = new RealexHpp("secret"); +$requestJson = $realexHpp->requestToJson($hppRequest); +``` +### HPP Post Dimension and HPP Post Response +```php +$hppRequest = new HppRequest(); +$hppRequest + ->addAmount("1001") + ->addCurrency("EUR") + ->addAccount("accountId") + ->addMerchantId("merchantId") + ->addAutoSettleFlag("1") + ->addPayerExists("payerRef") + ->addPayerReference("payerRef") + ->addPostDimensions("{\"iframe\":{\"height\":\"544px\",\"width\":\"768px\"}}") + ->addPostResponse("{ DCCCOMMISSIONPERCENTAGE: \"MA==\", BATCHID: \"MjAyNzc2\"}"); + +$realexHpp = new RealexHpp("secret"); +$requestJson = $realexHpp->requestToJson($hppRequest); +``` ## License See the LICENSE file. 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 dbbf217..14e639f 100644 --- a/src/main/php/com-realexpayments-hpp-sdk/domain/HppRequest.php +++ b/src/main/php/com-realexpayments-hpp-sdk/domain/HppRequest.php @@ -25,6 +25,44 @@ * *

* + *

+ * HPP Version and HPP Selected Stored Card + *

+ *

+ * Example usage: + *

+ * $hppRequest = new HppRequest();
+ * $hppRequest
+ *   ->addAmount("1001")
+ *   ->addCurrency("EUR")
+ *   ->addAccount("accountId")
+ *   ->addMerchantId("merchantId")
+ *   ->addAutoSettleFlag("1")
+ *   ->addPayerExists("1")
+ *   ->addPayerReference("payerRef")
+ *   ->addHppSelectedStoredCard("storedCardRef");
+ * 
+ *

+ * + *

+ * HPP Post Dimension and HPP Post Response + *

+ *

+ * Example usage: + *

+ * $hppRequest = new HppRequest();
+ * $hppRequest
+ *   ->addAmount("1001")
+ *   ->addCurrency("EUR")
+ *   ->addAccount("accountId")
+ *   ->addMerchantId("merchantId")
+ *   ->addAutoSettleFlag("1")
+ *   ->addPayerExists("payerRef")
+ *   ->addPayerReference("payerRef")
+ *   ->addPostDimensions("{\"iframe\":{\"height\":\"544px\",\"width\":\"768px\"}}")
+ *   ->addPostResponse("{ DCCCOMMISSIONPERCENTAGE: \"MA==\", BATCHID: \"MjAyNzc2\"}");
+ * 
+ *

* @author vicpada * @AssertHPP\OtbAmount * @AssertHPP\SupplementaryDataLength From 4bf2ce280dfc99c2cc7ade000e34056089fc8236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=C3=A1n=20MacDomhnall?= Date: Thu, 7 Jul 2016 15:21:53 +0100 Subject: [PATCH 4/8] Small changes to readme and field descriptions. --- .../domain/HppRequest.php | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) 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 14e639f..2dc51d0 100644 --- a/src/main/php/com-realexpayments-hpp-sdk/domain/HppRequest.php +++ b/src/main/php/com-realexpayments-hpp-sdk/domain/HppRequest.php @@ -59,8 +59,8 @@ * ->addAutoSettleFlag("1") * ->addPayerExists("payerRef") * ->addPayerReference("payerRef") - * ->addPostDimensions("{\"iframe\":{\"height\":\"544px\",\"width\":\"768px\"}}") - * ->addPostResponse("{ DCCCOMMISSIONPERCENTAGE: \"MA==\", BATCHID: \"MjAyNzc2\"}"); + * ->addPostDimensions("https://www.example.com") + * ->addPostResponse("https://www.example.com"); * *

* @author vicpada @@ -71,7 +71,7 @@ class HppRequest { /** - * @var String The merchant ID supplied by Realex Payments – note this is not the merchant number + * @var String The merchant or client ID supplied by Realex Payments – note this is not the merchant number * supplied by your bank. * * @Assert\Length(min = 1, max = 50, minMessage = ValidationMessages::hppRequest_merchantId_size, maxMessage = ValidationMessages::hppRequest_merchantId_size) @@ -299,7 +299,7 @@ class HppRequest { private $supplementaryData = array(); /** - * @var String Used to identify an OTB transaction. + * @var string Used to identify an OTB transaction. * * @Assert\Length(min = 0, max = 1, maxMessage = ValidationMessages::hppRequest_validateCardOnly_size) * @Assert\Regex(pattern="/^[01]*$/", message=ValidationMessages::hppRequest_validateCardOnly_pattern ) @@ -307,7 +307,7 @@ class HppRequest { private $validateCardOnly; /** - * @var String Transaction level configuration to enable/disable a DCC request. + * @var string Transaction level configuration to enable/disable a DCC request. * (Only if the merchant is configured). * * @Assert\Length(min = 0, max = 1, maxMessage = ValidationMessages::hppRequest_dccEnable_size) @@ -316,7 +316,7 @@ class HppRequest { private $dccEnable; /** - * @var As per the commit reference, can only have the value 1 or 2. Passing 2 enables the new skin for the HPP. + * @var string Can only have the value 1 or 2. Passing 2 enables the new skin for the HPP. * It also allows HPP_SELECT_STORED_CARD to be sent. * * @Assert\Length(min = 0, max = 1, maxMessage = ValidationMessages::hppRequest_hppVersion_size) @@ -325,7 +325,7 @@ class HppRequest { private $hppVersion; /** - * @var As per the commit reference, must contain the Payer reference of the customer whose cards the merchant wishes + * @var string Must contain the Payer reference of the customer whose cards the merchant wishes * to display on the HPP. If sent correctly, all of the customer’s saved cards will be displayed and they can choose * which one they wish to complete the payment with. * @@ -336,7 +336,7 @@ class HppRequest { /** * @var string This field should contain the domain of the page hosting the iFrame calling HPP. If sent correctly, - * every time the height or width of the card form changes (e.g. an error message appears), + * every time the height or width of the card form changes (e.g. an error message is displayed), * the HPP will send this back as a JSON string to the parent iFrame. * This is to facilitate developers who wish to resize their iFrame accordingly on increases or decreases of the HPP form’s size. * @Assert\Length(min = 0, max = 255, maxMessage = ValidationMessages::hppRequest_postDimensions_size, charset="ISO-8859-1") @@ -347,9 +347,10 @@ class HppRequest { /** * @var string This field should contain the domain of the page hosting the iFrame calling HPP. If sent correctly, - * every time the height or width of the card form changes (e.g. an error message appears), - * the HPP will send this back as a JSON string to the parent iFrame. - * This is to facilitate developers who wish to resize their iFrame accordingly on increases or decreases of the HPP form’s size. + * when the transaction is complete the HPP will send the response as a + * Base64 encoded JSON string to the parent iFrame. + * This is to facilitate developers who wish to not have to rely on a Response URL + * to accept the transaction response and would prefer to have the parent iFrame capture it * * @Assert\Length(min = 0, max = 255, maxMessage = ValidationMessages::hppRequest_postResponse_size, charset="ISO-8859-1") * @Assert\Regex(pattern="/^[\s \x{0020}-\x{003B} \x{003D} \x{003F}-\x{007E} \x{00A1}-\x{00FF}\x{20AC}\x{201A}\x{0192}\x{201E}\x{2026}\x{2020}\x{2021}\x{02C6}\x{2030}\x{0160}\x{2039}\x{0152}\x{017D}\x{2018}\x{2019}\x{201C}\x{201D}\x{2022}\x{2013}\x{2014}\x{02DC}\x{2122}\x{0161}\x{203A}\x{0153}\x{017E}\x{0178}]*$/iu", message=ValidationMessages::hppRequest_postResponse_pattern ) From 28102e9ad76bcb5180732fc43671958a6bb527ba Mon Sep 17 00:00:00 2001 From: Alessandro Vegna Date: Thu, 21 Jul 2016 12:43:43 +0100 Subject: [PATCH 5/8] PHPSDK&HPPCS003: Updated references to Hpp Selected Stored Card --- README.md | 2 +- .../domain/HppRequest.php | 46 +++++++++---------- .../utils/RequestMapper.php | 6 +-- .../SampleJsonData.php | 2 +- .../domain/HppRequestTest.php | 8 ++-- .../utils/JsonUtilsTest.php | 8 +++- .../utils/ValidationUtilsTest.php | 12 ++--- 7 files changed, 44 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index 33b90b2..84aa373 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ $hppRequest ->addAutoSettleFlag("1") ->addPayerExists("1") ->addPayerReference("payerRef") - ->addHppSelectedStoredCard("storedCardRef"); + ->addHppSelectStoredCard("storedCardRef"); $realexHpp = new RealexHpp("secret"); $requestJson = $realexHpp->requestToJson($hppRequest); 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 14e639f..e6c029a 100644 --- a/src/main/php/com-realexpayments-hpp-sdk/domain/HppRequest.php +++ b/src/main/php/com-realexpayments-hpp-sdk/domain/HppRequest.php @@ -40,7 +40,7 @@ * ->addAutoSettleFlag("1") * ->addPayerExists("1") * ->addPayerReference("payerRef") - * ->addHppSelectedStoredCard("storedCardRef"); + * ->addHppSelectStoredCard("storedCardRef"); * *

* @@ -316,7 +316,7 @@ class HppRequest { private $dccEnable; /** - * @var As per the commit reference, can only have the value 1 or 2. Passing 2 enables the new skin for the HPP. + * @var string Used to indicate the SDK version. Can only have the value 1 or 2. Passing 2 enables the new skin for the HPP. * It also allows HPP_SELECT_STORED_CARD to be sent. * * @Assert\Length(min = 0, max = 1, maxMessage = ValidationMessages::hppRequest_hppVersion_size) @@ -325,14 +325,14 @@ class HppRequest { private $hppVersion; /** - * @var As per the commit reference, must contain the Payer reference of the customer whose cards the merchant wishes - * to display on the HPP. If sent correctly, all of the customer’s saved cards will be displayed and they can choose + * @var string Must contain the Payer reference of the customer whose cards the merchant wishes + * to display on the HPP. If sent correctly, all of the customer's saved cards will be displayed and they can choose * which one they wish to complete the payment with. * * @Assert\Length(min = 0, max = 50, maxMessage = ValidationMessages::hppRequest_hppSelectStoredCard_size) * @Assert\Regex(pattern="/^[A-Za-z0-9\_\-\\ ]*$/", message=ValidationMessages::hppRequest_hppSelectStoredCard_pattern ) */ - private $hppSelectedStoredCard; + private $hppSelectStoredCard; /** * @var string This field should contain the domain of the page hosting the iFrame calling HPP. If sent correctly, @@ -1314,7 +1314,7 @@ public function setHppVersion( $hppVersion ){ /** * Helper method for adding the Hpp Version * - * @return hppVersion + * @return string */ public function getHppVersion(){ return $this->hppVersion ; @@ -1324,12 +1324,12 @@ public function getHppVersion(){ /** * Helper method for adding the Hpp Selected Stored Card * - * @param string $hppSelectedStoredCard + * @param string $hppSelectStoredCard * * @return HppRequest */ - public function addHppSelectedStoredCard( $hppSelectedStoredCard ){ - $this->hppSelectedStoredCard = $hppSelectedStoredCard; + public function addHppSelectStoredCard( $hppSelectStoredCard ){ + $this->hppSelectStoredCard = $hppSelectStoredCard; return $this; } @@ -1337,21 +1337,21 @@ public function addHppSelectedStoredCard( $hppSelectedStoredCard ){ /** * Helper method for setting the Hpp Selected Stored Card * - * @param string $hppSelectedStoredCard + * @param string $hppSelectStoredCard * * @return void */ - public function setHppSelectedStoredCard( $hppSelectedStoredCard ){ - $this->hppSelectedStoredCard = $hppSelectedStoredCard; + public function setHppSelectStoredCard( $hppSelectStoredCard ){ + $this->hppSelectStoredCard = $hppSelectStoredCard; } /** * Helper method for adding the Hpp Selected Stored Card * - * @return hppSelectedStoredCard + * @return string */ - public function getHppSelectedStoredCard( ){ - return $this->hppSelectedStoredCard ; + public function getHppSelectStoredCard( ){ + return $this->hppSelectStoredCard ; } @@ -1383,7 +1383,7 @@ public function setPostDimensions( $postDimensions ){ /** * Helper method for adding the Hpp Post Dimension * - * @return postDimensions + * @return string */ public function getPostDimensions( ){ return $this->postDimensions ; @@ -1418,7 +1418,7 @@ public function setPostResponse( $postResponse ){ /** * Helper method for adding the Hpp Post Dimension * - * @return postDimensions + * @return string */ public function getPostResponse(){ return $this->postResponse ; @@ -1469,13 +1469,13 @@ public function hash( $secret ) { $currency = null == $this->currency ? "" : $this->currency; $payerReference = null == $this->payerReference ? "" : $this->payerReference; $paymentReference = null == $this->paymentReference ? "" : $this->paymentReference; - $hppSelectedStoredCard = null == $this->hppSelectedStoredCard ? "" : $this->hppSelectedStoredCard; - - //create String to hash + $hppSelectStoredCard = null == $this->hppSelectStoredCard ? "" : $this->hppSelectStoredCard; - $payRefORStoredCard = empty($hppSelectedStoredCard) ? $payerReference : $hppSelectedStoredCard; + // Override payerRef with hppSelectStoredCard if present. + $payRefORStoredCard = empty($hppSelectStoredCard) ? $payerReference : $hppSelectStoredCard; + //create String to hash if ( $this->cardStorageEnable ) { $toHash = $timeStamp . "." @@ -1574,7 +1574,7 @@ public function encode( $charSet ) { $this->validateCardOnly = base64_encode( $this->validateCardOnly ); $this->dccEnable = base64_encode( $this->dccEnable ); $this->hppVersion = base64_encode( $this->hppVersion ); - $this->hppSelectedStoredCard = base64_encode( $this->hppSelectedStoredCard ); + $this->hppSelectStoredCard = base64_encode( $this->hppSelectStoredCard ); $this->postResponse = base64_encode( $this->postResponse ); $this->postDimensions = base64_encode( $this->postDimensions ); @@ -1626,7 +1626,7 @@ public function decode( $charSet ) { $this->validateCardOnly = base64_decode( $this->validateCardOnly ); $this->dccEnable = base64_decode( $this->dccEnable ); $this->hppVersion = base64_decode( $this->hppVersion ); - $this->hppSelectedStoredCard = base64_decode( $this->hppSelectedStoredCard ); + $this->hppSelectStoredCard = base64_decode( $this->hppSelectStoredCard ); $this->postResponse = base64_decode( $this->postResponse ); $this->postDimensions = base64_decode( $this->postDimensions ); diff --git a/src/main/php/com-realexpayments-hpp-sdk/utils/RequestMapper.php b/src/main/php/com-realexpayments-hpp-sdk/utils/RequestMapper.php index 04244cb..338a0e8 100644 --- a/src/main/php/com-realexpayments-hpp-sdk/utils/RequestMapper.php +++ b/src/main/php/com-realexpayments-hpp-sdk/utils/RequestMapper.php @@ -92,8 +92,8 @@ public function WriteValueAsString( $hppRequest ) { if($hppRequest->getHppVersion() != null) $prop['HPP_VERSION'] = $hppRequest->getHppVersion(); - if($hppRequest->getHppSelectedStoredCard() != null) - $prop['HPP_SELECT_STORED_CARD'] = $hppRequest->getHppSelectedStoredCard(); + if($hppRequest->getHppSelectStoredCard() != null) + $prop['HPP_SELECT_STORED_CARD'] = $hppRequest->getHppSelectStoredCard(); if($hppRequest->getPostDimensions() != null) $prop['HPP_POST_DIMENSIONS'] = $hppRequest->getPostDimensions(); @@ -149,7 +149,7 @@ public function ReadValue( $value ) { $hppRequest->setPaymentReference( $array['PMT_REF'] ); $hppRequest->setPayerExists( $array['PAYER_EXIST'] ); $hppRequest->setHppVersion( $array['HPP_VERSION'] ); - $hppRequest->setHppSelectedStoredCard( $array['HPP_SELECT_STORED_CARD'] ); + $hppRequest->setHppSelectStoredCard( $array['HPP_SELECT_STORED_CARD'] ); $hppRequest->setPostDimensions( $array['HPP_POST_DIMENSIONS'] ); $hppRequest->setPostResponse( $array['HPP_POST_RESPONSE'] ); diff --git a/test/main/php/com-realexpayments-hpp-sdk/SampleJsonData.php b/test/main/php/com-realexpayments-hpp-sdk/SampleJsonData.php index cfd5a60..ee088b6 100644 --- a/test/main/php/com-realexpayments-hpp-sdk/SampleJsonData.php +++ b/test/main/php/com-realexpayments-hpp-sdk/SampleJsonData.php @@ -165,7 +165,7 @@ public static function generateValidHppRequestWithEmptyDefaults($cardStorage) ->addValidateCardOnly(self::VALIDATE_CARD_ONLY) ->addDccEnable(self::DCC_ENABLE) ->addHppVersion(self::HPP_VERSION) - ->addHppSelectedStoredCard(self::HPP_SELECT_STORED_CARD); + ->addhppSelectStoredCard(self::HPP_SELECT_STORED_CARD); $hppRequest->setTimeStamp(self::TIMESTAMP); diff --git a/test/main/php/com-realexpayments-hpp-sdk/domain/HppRequestTest.php b/test/main/php/com-realexpayments-hpp-sdk/domain/HppRequestTest.php index 3af49e6..d480070 100644 --- a/test/main/php/com-realexpayments-hpp-sdk/domain/HppRequestTest.php +++ b/test/main/php/com-realexpayments-hpp-sdk/domain/HppRequestTest.php @@ -37,7 +37,7 @@ public function testHash() } - public function testHashHppSelectedCard() + public function testHashHppSelectCard() { $hppRequest = new HppRequest(); $hppRequest = $hppRequest->addTimeStamp(self::TIMESTAMP) @@ -45,7 +45,7 @@ public function testHashHppSelectedCard() ->addOrderId(self::ORDER_ID) ->addAmount(self::AMOUNT) ->addCurrency(self::CURRENCY) - ->addHppSelectedStoredCard(self::SELECTED_STORED_CARD); + ->addHppSelectStoredCard(self::SELECTED_STORED_CARD); $expectedHash = "099b6ef236391d8bdc642488fc5e9c54ac31cd80"; $actualHash = $hppRequest->hash("mysecret")->getHash(); @@ -53,7 +53,7 @@ public function testHashHppSelectedCard() $this->assertEquals($expectedHash, $actualHash,"Card storage hash does not match expected."); } - public function testHashHppSelectedCardAndPaymentReference() + public function testHashHppSelectCardAndPaymentReference() { $hppRequest = new HppRequest(); $hppRequest = $hppRequest->addTimeStamp(self::TIMESTAMP) @@ -61,7 +61,7 @@ public function testHashHppSelectedCardAndPaymentReference() ->addOrderId(self::ORDER_ID) ->addAmount(self::AMOUNT) ->addCurrency(self::CURRENCY) - ->addHppSelectedStoredCard(self::SELECTED_STORED_CARD) + ->addHppSelectStoredCard(self::SELECTED_STORED_CARD) ->addPaymentReference(self::PAYMENT_REFERENCE); $expectedHash = "4106afc4666c6145b623089b1ad4098846badba2"; diff --git a/test/main/php/com-realexpayments-hpp-sdk/utils/JsonUtilsTest.php b/test/main/php/com-realexpayments-hpp-sdk/utils/JsonUtilsTest.php index 3856f61..0626550 100644 --- a/test/main/php/com-realexpayments-hpp-sdk/utils/JsonUtilsTest.php +++ b/test/main/php/com-realexpayments-hpp-sdk/utils/JsonUtilsTest.php @@ -3,6 +3,7 @@ namespace com\realexpayments\hpp\sdk\utils; +use com\realexpayments\hpp\sdk\domain\HppRequest; use com\realexpayments\hpp\sdk\RealexHpp; use com\realexpayments\hpp\sdk\RealexValidationException; use com\realexpayments\hpp\sdk\SampleJsonData; @@ -183,16 +184,19 @@ public function testToJsonHppRequestWithHppVersion() { $json = file_get_contents( $prefix . $path ); + /** + * @var HppRequest $hppRequestConverted + */ $hppRequestConverted = JsonUtils::fromJsonHppRequest( $json ); $this->assertEquals( SampleJsonData::HPP_VERSION, $hppRequestConverted->getHppVersion() ); - $this->assertEquals( SampleJsonData::HPP_SELECT_STORED_CARD, $hppRequestConverted->getHppSelectedStoredCard() ); + $this->assertEquals( SampleJsonData::HPP_SELECT_STORED_CARD, $hppRequestConverted->getHppSelectStoredCard() ); $hppRequestConverted = $hppRequestConverted->encode(RealexHpp::ENCODING_CHARSET); $hppRequestConverted = $hppRequestConverted->decode(RealexHpp::ENCODING_CHARSET); $this->assertEquals( SampleJsonData::HPP_VERSION, $hppRequestConverted->getHppVersion() ); - $this->assertEquals( SampleJsonData::HPP_SELECT_STORED_CARD, $hppRequestConverted->getHppSelectedStoredCard() ); + $this->assertEquals( SampleJsonData::HPP_SELECT_STORED_CARD, $hppRequestConverted->getHppSelectStoredCard() ); } diff --git a/test/main/php/com-realexpayments-hpp-sdk/utils/ValidationUtilsTest.php b/test/main/php/com-realexpayments-hpp-sdk/utils/ValidationUtilsTest.php index 5479cb7..527ab91 100644 --- a/test/main/php/com-realexpayments-hpp-sdk/utils/ValidationUtilsTest.php +++ b/test/main/php/com-realexpayments-hpp-sdk/utils/ValidationUtilsTest.php @@ -1980,12 +1980,12 @@ public function testHppVersion() { /** * Test HPP Version */ - public function testHppSelectedStoredCard() { + public function testHppSelectStoredCard() { $hppRequest = SampleJsonData::generateValidHppRequest( false ); $hppRequest->generateDefaults( SampleJsonData::SECRET ); - $hppRequest->setHppSelectedStoredCard("payerref123"); + $hppRequest->setHppSelectStoredCard("payerref123"); try { ValidationUtils::validate( $hppRequest ); @@ -1993,7 +1993,7 @@ public function testHppSelectedStoredCard() { $this->fail( "This HppRequest should not have validation errors." ); } - $hppRequest->setHppSelectedStoredCard(str_repeat('a',50)); + $hppRequest->setHppSelectStoredCard(str_repeat('a',50)); try { ValidationUtils::validate( $hppRequest ); @@ -2002,7 +2002,7 @@ public function testHppSelectedStoredCard() { } - $hppRequest->setHppSelectedStoredCard(str_repeat('a',51)); + $hppRequest->setHppSelectStoredCard(str_repeat('a',51)); try { ValidationUtils::validate( $hppRequest ); @@ -2012,7 +2012,7 @@ public function testHppSelectedStoredCard() { $this->assertEquals( ValidationMessages::hppRequest_hppSelectStoredCard_size, $validationMessages[0] ); } - $hppRequest->setHppSelectedStoredCard("!!!"); + $hppRequest->setHppSelectStoredCard("!!!"); try { ValidationUtils::validate( $hppRequest ); @@ -2066,7 +2066,7 @@ public function testToJsonHppRequestWithHppVersion2() { } $this->assertEmpty( $hppRequestConverted->getHppVersion()); - $this->assertNotEmpty( $hppRequestConverted->getHppSelectedStoredCard()); + $this->assertNotEmpty( $hppRequestConverted->getHppSelectStoredCard()); } /** From 134494f207301f068111ebacab71879374c4bb1b Mon Sep 17 00:00:00 2001 From: Alessandro Vegna Date: Tue, 26 Jul 2016 15:49:29 +0100 Subject: [PATCH 6/8] PHPSDK&HPPCS003: Updated references to Hpp Selected Stored Card [update] --- README.md | 2 +- .../php/com-realexpayments-hpp-sdk/domain/HppRequest.php | 8 ++++---- .../com-realexpayments-hpp-sdk/domain/HppRequestTest.php | 6 +++--- .../utils/ValidationUtilsTest.php | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 84aa373..23c63d1 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ $requestJson = $realexHpp->requestToJson($hppRequest); $realexHpp = new RealexHpp("secret"); $hppResponse = $realexHpp->responseFromJson(responseJson); ``` -### HPP Version and HPP Selected Stored Card +### HPP Version and HPP Select Stored Card ```php $hppRequest = new HppRequest(); $hppRequest 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 e6c029a..817d927 100644 --- a/src/main/php/com-realexpayments-hpp-sdk/domain/HppRequest.php +++ b/src/main/php/com-realexpayments-hpp-sdk/domain/HppRequest.php @@ -26,7 +26,7 @@ *

* *

- * HPP Version and HPP Selected Stored Card + * HPP Version and HPP Select Stored Card *

*

* Example usage: @@ -1322,7 +1322,7 @@ public function getHppVersion(){ } /** - * Helper method for adding the Hpp Selected Stored Card + * Helper method for adding the Hpp Select Stored Card * * @param string $hppSelectStoredCard * @@ -1335,7 +1335,7 @@ public function addHppSelectStoredCard( $hppSelectStoredCard ){ } /** - * Helper method for setting the Hpp Selected Stored Card + * Helper method for setting the Hpp Select Stored Card * * @param string $hppSelectStoredCard * @@ -1346,7 +1346,7 @@ public function setHppSelectStoredCard( $hppSelectStoredCard ){ } /** - * Helper method for adding the Hpp Selected Stored Card + * Helper method for adding the Hpp Select Stored Card * * @return string */ diff --git a/test/main/php/com-realexpayments-hpp-sdk/domain/HppRequestTest.php b/test/main/php/com-realexpayments-hpp-sdk/domain/HppRequestTest.php index d480070..8c880bc 100644 --- a/test/main/php/com-realexpayments-hpp-sdk/domain/HppRequestTest.php +++ b/test/main/php/com-realexpayments-hpp-sdk/domain/HppRequestTest.php @@ -19,7 +19,7 @@ class HppRequestTest extends \PHPUnit_Framework_TestCase const CURRENCY = "EUR"; const PAYER_REFERENCE = "newpayer1"; const PAYMENT_REFERENCE = "mycard1"; - const SELECTED_STORED_CARD = "newpayer1"; + const SELECT_STORED_CARD = "newpayer1"; public function testHash() { @@ -45,7 +45,7 @@ public function testHashHppSelectCard() ->addOrderId(self::ORDER_ID) ->addAmount(self::AMOUNT) ->addCurrency(self::CURRENCY) - ->addHppSelectStoredCard(self::SELECTED_STORED_CARD); + ->addHppSelectStoredCard(self::SELECT_STORED_CARD); $expectedHash = "099b6ef236391d8bdc642488fc5e9c54ac31cd80"; $actualHash = $hppRequest->hash("mysecret")->getHash(); @@ -61,7 +61,7 @@ public function testHashHppSelectCardAndPaymentReference() ->addOrderId(self::ORDER_ID) ->addAmount(self::AMOUNT) ->addCurrency(self::CURRENCY) - ->addHppSelectStoredCard(self::SELECTED_STORED_CARD) + ->addHppSelectStoredCard(self::SELECT_STORED_CARD) ->addPaymentReference(self::PAYMENT_REFERENCE); $expectedHash = "4106afc4666c6145b623089b1ad4098846badba2"; diff --git a/test/main/php/com-realexpayments-hpp-sdk/utils/ValidationUtilsTest.php b/test/main/php/com-realexpayments-hpp-sdk/utils/ValidationUtilsTest.php index 527ab91..e14f631 100644 --- a/test/main/php/com-realexpayments-hpp-sdk/utils/ValidationUtilsTest.php +++ b/test/main/php/com-realexpayments-hpp-sdk/utils/ValidationUtilsTest.php @@ -2048,7 +2048,7 @@ public function testToJsonHppRequestWithHppVersionFail() { /** * Test converting {@link HppRequest} to JSON. - * Testing import from json, NO Hpp_version => so you are not allow to put the hpp selected stored card + * Testing import from json, NO Hpp_version => so you are not allow to put the hpp select stored card */ public function testToJsonHppRequestWithHppVersion2() { From 9a372dea01c44bb8ef724922db498a542f3450ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=C3=A1n=20MacDomhnall?= Date: Tue, 13 Sep 2016 12:14:05 +0100 Subject: [PATCH 7/8] Amended HPP Select Stored Card --- README.md | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index cc0d400..c5ad632 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ use com\realexpayments\hpp\sdk\RealexHpp; $realexHpp = new RealexHpp( "mySecret" ); $hppResponse = $realexHpp->responseFromJson( responseJson ); ``` -### HPP Version and HPP Select Stored Card +### HPP Select Stored Card ```php $hppRequest = new HppRequest(); $hppRequest @@ -91,26 +91,9 @@ $hppRequest ->addAccount("accountId") ->addMerchantId("merchantId") ->addAutoSettleFlag("1") - ->addPayerExists("1") - ->addPayerReference("payerRef") - ->addHppSelectStoredCard("storedCardRef"); - -$realexHpp = new RealexHpp("secret"); -$requestJson = $realexHpp->requestToJson($hppRequest); -``` -### HPP Post Dimension and HPP Post Response -```php -$hppRequest = new HppRequest(); -$hppRequest - ->addAmount("1001") - ->addCurrency("EUR") - ->addAccount("accountId") - ->addMerchantId("merchantId") - ->addAutoSettleFlag("1") - ->addPayerExists("payerRef") - ->addPayerReference("payerRef") - ->addPostDimensions("{\"iframe\":{\"height\":\"544px\",\"width\":\"768px\"}}") - ->addPostResponse("{ DCCCOMMISSIONPERCENTAGE: \"MA==\", BATCHID: \"MjAyNzc2\"}"); + ->addHppSelectStoredCard("payerRef") + ->addPayerExists("1") + ->addOfferSaveCard("1"); $realexHpp = new RealexHpp("secret"); $requestJson = $realexHpp->requestToJson($hppRequest); From 2d71b9752b8e43cceadd1e31f6806a2495588145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=C3=A1n=20MacDomhnall?= Date: Mon, 12 Dec 2016 13:01:53 +0000 Subject: [PATCH 8/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c5ad632..b0d0df4 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ You can sign up for a free Realex Payments sandbox account at https://www.realex ``` { "require": { - "realexpayments/rxp-hpp-php": "1.0.0" + "realexpayments/rxp-hpp-php": "1.1.0" } } ```