diff --git a/src/Entities/Enums/IsoCountries.php b/src/Entities/Enums/IsoCountries.php index 1913376e..e621200e 100644 --- a/src/Entities/Enums/IsoCountries.php +++ b/src/Entities/Enums/IsoCountries.php @@ -164,6 +164,7 @@ class IsoCountries ["name" => "Nauru", "numeric" => "520", "alpha2" => "NR", "alpha3" => "NRU"], ["name" => "Nepal", "numeric" => "524", "alpha2" => "NP", "alpha3" => "NPL"], ["name" => "Netherlands", "numeric" => "528", "alpha2" => "NL", "alpha3" => "NLD"], + ["name" => "Netherlands Antilles", "numeric" => "530", "alpha2" => "AN", "alpha3" => "ANT"], ["name" => "New Caledonia", "numeric" => "540", "alpha2" => "NC", "alpha3" => "NCL"], ["name" => "New Zealand", "numeric" => "554", "alpha2" => "NZ", "alpha3" => "NZL"], ["name" => "Nicaragua", "numeric" => "558", "alpha2" => "NI", "alpha3" => "NIC"], diff --git a/src/Gateways/Gp3DSProvider.php b/src/Gateways/Gp3DSProvider.php index 4e2422cf..e6e0983f 100644 --- a/src/Gateways/Gp3DSProvider.php +++ b/src/Gateways/Gp3DSProvider.php @@ -15,6 +15,7 @@ use GlobalPayments\Api\PaymentMethods\CreditCardData; use GlobalPayments\Api\PaymentMethods\RecurringPaymentMethod; use GlobalPayments\Api\Utils\GenerationUtils; +use GlobalPayments\Api\Utils\StringUtils; class Gp3DSProvider extends RestGateway implements ISecure3dProvider { @@ -239,15 +240,15 @@ public function processSecure3d(Secure3dBuilder $builder) // home phone if (!empty($builder->getHomeNumber())) { $request['payer']['home_phone'] = []; - $request['payer']['home_phone'] = $this->maybeSetKey($request['payer']['home_phone'], 'country_code', $builder->getHomeCountryCode()); - $request['payer']['home_phone'] = $this->maybeSetKey($request['payer']['home_phone'], 'subscriber_number', $builder->getHomeNumber()); + $request['payer']['home_phone'] = $this->maybeSetKey($request['payer']['home_phone'], 'country_code', StringUtils::validateToNumber($builder->getHomeCountryCode())); + $request['payer']['home_phone'] = $this->maybeSetKey($request['payer']['home_phone'], 'subscriber_number', StringUtils::validateToNumber($builder->getHomeNumber())); } // work phone if (!empty($builder->getWorkNumber())) { $request['payer']['work_phone'] = []; - $request['payer']['work_phone'] = $this->maybeSetKey($request['payer']['work_phone'], 'country_code', $builder->getWorkCountryCode()); - $request['payer']['work_phone'] = $this->maybeSetKey($request['payer']['work_phone'], 'subscriber_number', $builder->getWorkNumber()); + $request['payer']['work_phone'] = $this->maybeSetKey($request['payer']['work_phone'], 'country_code', StringUtils::validateToNumber($builder->getWorkCountryCode())); + $request['payer']['work_phone'] = $this->maybeSetKey($request['payer']['work_phone'], 'subscriber_number', StringUtils::validateToNumber($builder->getWorkNumber())); } // payer login data @@ -291,8 +292,8 @@ public function processSecure3d(Secure3dBuilder $builder) // mobile phone if (!empty($builder->getMobileNumber())) { $request['payer']['mobile_phone'] = []; - $request['payer']['mobile_phone'] = $this->maybeSetKey($request['payer']['mobile_phone'], 'country_code', $builder->getMobileCountryCode()); - $request['payer']['mobile_phone'] = $this->maybeSetKey($request['payer']['mobile_phone'], 'subscriber_number', $builder->getMobileNumber()); + $request['payer']['mobile_phone'] = $this->maybeSetKey($request['payer']['mobile_phone'], 'country_code', StringUtils::validateToNumber($builder->getMobileCountryCode())); + $request['payer']['mobile_phone'] = $this->maybeSetKey($request['payer']['mobile_phone'], 'subscriber_number', StringUtils::validateToNumber($builder->getMobileNumber())); } // browser_data diff --git a/src/Utils/StringUtils.php b/src/Utils/StringUtils.php index 801c77ed..2a840f3f 100644 --- a/src/Utils/StringUtils.php +++ b/src/Utils/StringUtils.php @@ -73,4 +73,16 @@ public static function toAmount($str) return $str / 100; } + + /** + * Strip all non-numeric characters + * + * @param string $value + * + * @return mixed + */ + public static function validateToNumber($value) + { + return preg_replace("/[^0-9]/", "", $value); + } } diff --git a/test/Integration/Gateways/RealexConnector/HppTest.php b/test/Integration/Gateways/RealexConnector/HppTest.php index f11f199b..fe0f39fb 100644 --- a/test/Integration/Gateways/RealexConnector/HppTest.php +++ b/test/Integration/Gateways/RealexConnector/HppTest.php @@ -757,4 +757,42 @@ public function testSupplementaryDataWithTwoValuesSerialized() $expectedJson = '{"MERCHANT_ID":"MerchantId","ACCOUNT":"internet","ORDER_ID":"GTI5Yxb0SumL_TkDMCAxQA","AMOUNT":"1999","CURRENCY":"EUR","TIMESTAMP":"20170725154824","AUTO_SETTLE_FLAG":"1","COMMENT1":"Mobile Channel","CUST_NUM":"a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa","OFFER_SAVE_CARD":"1","PAYER_EXIST":"0","PROD_ID":"a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f","VAR_REF":"My Legal Entity","HPP_LANG":"GB","MERCHANT_RESPONSE_URL":"https:\/\/www.example.com\/response","HPP_VERSION":"2","RANDOM_KEY1":"VALUE_1","RANDOM_KEY2":"VALUE_2","SHA1HASH":"7116c49826367c6513efdc0cc81e243b8095d78f"}'; $this->assertEquals($json, $expectedJson); } + + public function testNetherlandsAntillesCountry() + { + $config = new GpEcomConfig(); + $config->merchantId = "MerchantId"; + $config->accountId = "internet"; + $config->sharedSecret = "secret"; + $config->serviceUrl = "https://pay.sandbox.realexpayments.com/pay"; + + $config->hostedPaymentConfig = new HostedPaymentConfig(); + $config->hostedPaymentConfig->language = "GB"; + $config->hostedPaymentConfig->responseUrl = "https://www.example.com/response"; + $config->hostedPaymentConfig->version = HppVersion::VERSION_2; + $config->gatewayProvider = GatewayProvider::GP_ECOM; + + $service = new HostedService($config); + + // billing address + $billingAddress = new Address(); + $billingAddress->streetAddress1 = 'Flat 123'; + $billingAddress->streetAddress2 = 'House 456'; + $billingAddress->postalCode = "50001"; + $billingAddress->country = "AN"; + + $hostedPaymentData = new HostedPaymentData(); + $hostedPaymentData->customerNumber = 'a028774f-beff-47bc-bd6e-ed7e04f5d758a028774f-btefa'; + $hostedPaymentData->productId = 'a0b38df5-b23c-4d82-88fe-2e9c47438972-b23c-4d82-88f'; + + $json = $service->charge(19.99) + ->withCurrency("EUR") + ->withHostedPaymentData($hostedPaymentData) + ->withAddress($billingAddress, AddressType::BILLING) + ->serialize(); + + $response = json_decode($json, true); + $this->assertEquals('AN', $response['BILLING_CO']); + $this->assertEquals('530', $response['HPP_BILLING_COUNTRY']); + } } diff --git a/test/Integration/Gateways/RealexConnector/Secure3dServiceTests.php b/test/Integration/Gateways/RealexConnector/Secure3dServiceTests.php index 1d2c93f2..7a5245ff 100644 --- a/test/Integration/Gateways/RealexConnector/Secure3dServiceTests.php +++ b/test/Integration/Gateways/RealexConnector/Secure3dServiceTests.php @@ -177,6 +177,9 @@ public function testFullCycle_v2() ->withBrowserData($this->browserData) ->withMethodUrlCompletion(MethodUrlCompletion::NO) ->withChallengeRequestIndicator(ChallengeRequestIndicator::NO_PREFERENCE) + ->withMobileNumber('+44','11 33 44 44') + ->withHomeNumber('44', '12444555') + ->withWorkNumber('+44','345 6667') ->execute(); $this->assertNotNull($initAuth);