diff --git a/src/Builders/AuthorizationBuilder.php b/src/Builders/AuthorizationBuilder.php index 22067bcf..aefeee4b 100644 --- a/src/Builders/AuthorizationBuilder.php +++ b/src/Builders/AuthorizationBuilder.php @@ -522,7 +522,7 @@ public function __construct($type, IPaymentMethod $paymentMethod = null) * * @return Transaction */ - public function execute(string $configName = 'default') + public function execute($configName = 'default') { parent::execute($configName); @@ -535,7 +535,7 @@ public function execute(string $configName = 'default') * * @return String */ - public function serialize(string $configName = 'default') + public function serialize($configName = 'default') { $this->transactionModifier = TransactionModifier::HOSTEDREQUEST; parent::execute(); diff --git a/src/Builders/ManagementBuilder.php b/src/Builders/ManagementBuilder.php index fb2da3c4..bb50bd93 100644 --- a/src/Builders/ManagementBuilder.php +++ b/src/Builders/ManagementBuilder.php @@ -202,7 +202,7 @@ public function __isset($name) * * @return Transaction */ - public function execute(string $configName = 'default') + public function execute($configName = 'default') { parent::execute($configName); return ServicesContainer::instance() diff --git a/src/Builders/PayFacBuilder.php b/src/Builders/PayFacBuilder.php index 5ab380fa..2f76e419 100644 --- a/src/Builders/PayFacBuilder.php +++ b/src/Builders/PayFacBuilder.php @@ -68,7 +68,7 @@ public function __construct($type) * * @return mixed */ - public function execute(string $configName = 'default') + public function execute($configName = 'default') { parent::execute($configName); @@ -170,7 +170,7 @@ protected function setupValidations() } /* - * Primary Bank Account Information – Optional. Used to add a bank account to which funds can be settled + * Primary Bank Account Information - Optional. Used to add a bank account to which funds can be settled * * var Object GlobalPayments\Api\Entities\PayFac\BankAccountData; */ @@ -180,7 +180,7 @@ public function withBankAccountData(BankAccountData $bankAccountData) return $this; } /* - * Merchant Beneficiary Owner Information – Required for all merchants validating KYC based off of personal data + * Merchant Beneficiary Owner Information - Required for all merchants validating KYC based off of personal data * * var Object GlobalPayments\Api\Entities\PayFac\BeneficialOwnerData; */ @@ -190,7 +190,7 @@ public function withBeneficialOwnerData(BeneficialOwnerData $beneficialOwnerData return $this; } /* - * Business Data – Required for business validated accounts. May also be required for personal validated accounts + * Business Data - Required for business validated accounts. May also be required for personal validated accounts * by ProPay Risk Team * * var Object GlobalPayments\Api\Entities\PayFac\BusinessData; @@ -201,7 +201,7 @@ public function withBusinessData(BusinessData $businessData) return $this; } /* - * Significant Owner Information – May be required for some partners based on ProPay Risk decision + * Significant Owner Information - May be required for some partners based on ProPay Risk decision * * var Object GlobalPayments\Api\Entities\PayFac\SignificantOwnerData; */ @@ -211,7 +211,7 @@ public function withSignificantOwnerData(SignificantOwnerData $significantOwnerD return $this; } /* - * Threat Risk Assessment Information – May be required based on ProPay Risk Decision + * Threat Risk Assessment Information - May be required based on ProPay Risk Decision * * var Object GlobalPayments\Api\Entities\PayFac\ThreatRiskData; */ @@ -268,7 +268,7 @@ public function withAccountNumber($accountNumber) } /* - * Temporary password which will allow a onetime login to ProPay’s website. Must be at least eight characters. + * Temporary password which will allow a onetime login to ProPay's website. Must be at least eight characters. * Must not contain part or the entire first or last name. Must contain at least one capital letter, * one lower case letter, and either one symbol or one number * diff --git a/src/Builders/RecurringBuilder.php b/src/Builders/RecurringBuilder.php index 94f6e288..0e7dfb58 100644 --- a/src/Builders/RecurringBuilder.php +++ b/src/Builders/RecurringBuilder.php @@ -67,7 +67,7 @@ public function addSearchCriteria($key, $value) * * @return mixed */ - public function execute(string $configName = 'default') + public function execute($configName = 'default') { parent::execute($configName); diff --git a/src/Builders/ReportBuilder.php b/src/Builders/ReportBuilder.php index 6a79d0dc..39ff54cd 100644 --- a/src/Builders/ReportBuilder.php +++ b/src/Builders/ReportBuilder.php @@ -36,7 +36,7 @@ public function __construct($reportType) * * @return mixed */ - public function execute(string $configName = 'default') + public function execute($configName = 'default') { parent::execute($configName); diff --git a/src/Entities/Address.php b/src/Entities/Address.php index 2082da05..abdf2cfb 100644 --- a/src/Entities/Address.php +++ b/src/Entities/Address.php @@ -2,6 +2,9 @@ namespace GlobalPayments\Api\Entities; +use GlobalPayments\Api\Entities\Exceptions\ArgumentException; +use GlobalPayments\Api\Utils\CountryUtils; + /** * Represents a billing or shipping address for the consumer. */ @@ -70,14 +73,56 @@ class Address * * @var string */ - public $country; + protected $country; /** * Consumer's country code. * * @var string */ - public $countryCode; + protected $countryCode; + + public function __get($property) + { + if (property_exists($this, $property)) { + return $this->{$property}; + } + } + + public function __set($property, $value) + { + if (in_array( + $property, + [ + 'countryCode', + 'country', + ] + )) { + $countryInfo = CountryUtils::getCountryInfo($value); + } + + switch ($property) + { + case 'countryCode': + if ($this->country == null && isset($countryInfo)) { + $this->country = !empty($countryInfo['name']) ? $countryInfo['name'] : null; + } + break; + case 'country': + if ($this->countryCode == null && isset($countryInfo)) { + $this->countryCode = !empty($countryInfo['alpha2']) ? $countryInfo['alpha2'] : null; + } + break; + default: + break; + } + + if (property_exists($this, $property)) { + return $this->{$property} = $value; + } + + throw new ArgumentException(sprintf('Property `%s` does not exist on Address', $property)); + } /** * Gets the consumer's province. @@ -93,4 +138,9 @@ public function getProvince() ? $this->province : $this->state; } + + public function isCountry($countryCode) + { + return CountryUtils::isCountry($this, $countryCode); + } } diff --git a/src/Entities/CustomWebProxy.php b/src/Entities/CustomWebProxy.php new file mode 100644 index 00000000..3b32663a --- /dev/null +++ b/src/Entities/CustomWebProxy.php @@ -0,0 +1,36 @@ +uri = $uri; + $this->username = $username; + $this->password = $password; + } + + public function __get($property) + { + if (property_exists($this, $property)) { + return $this->{$property}; + } + } + + public function getProxy($destination) + { + return $destination; + } + + public function isBypassed($host) + { + return false; + } +} \ No newline at end of file diff --git a/src/Entities/Enums/FraudFilterMode.php b/src/Entities/Enums/FraudFilterMode.php index 855583db..3cd50b07 100644 --- a/src/Entities/Enums/FraudFilterMode.php +++ b/src/Entities/Enums/FraudFilterMode.php @@ -9,4 +9,5 @@ class FraudFilterMode extends Enum const NONE = 'NONE'; const OFF = 'OFF'; const PASSIVE = 'PASSIVE'; + const ACTIVE = 'ACTIVE '; } diff --git a/src/Entities/Enums/IsoCountries.php b/src/Entities/Enums/IsoCountries.php new file mode 100644 index 00000000..1913376e --- /dev/null +++ b/src/Entities/Enums/IsoCountries.php @@ -0,0 +1,260 @@ + "Afghanistan", "numeric" => "004", "alpha2" => "AF", "alpha3" => "AFG"], + ["name" => "Ă…land Islands", "numeric" => "248", "alpha2" => "AX", "alpha3" => "ALA"], + ["name" => "Albania", "numeric" => "008", "alpha2" => "AL", "alpha3" => "ALB"], + ["name" => "Algeria", "numeric" => "012", "alpha2" => "DZ", "alpha3" => "DZA"], + ["name" => "American Samoa", "numeric" => "016", "alpha2" => "AS", "alpha3" => "ASM"], + ["name" => "Andorra", "numeric" => "020", "alpha2" => "AD", "alpha3" => "AND"], + ["name" => "Angola", "numeric" => "024", "alpha2" => "AO", "alpha3" => "AGO"], + ["name" => "Anguilla", "numeric" => "660", "alpha2" => "AI", "alpha3" => "AIA"], + ["name" => "Antarctica", "numeric" => "010", "alpha2" => "AQ", "alpha3" => "ATA"], + ["name" => "Antigua and Barbuda", "numeric" => "028", "alpha2" => "AG", "alpha3" => "ATG"], + ["name" => "Argentina", "numeric" => "032", "alpha2" => "AR", "alpha3" => "ARG"], + ["name" => "Armenia", "numeric" => "051", "alpha2" => "AM", "alpha3" => "ARM"], + ["name" => "Aruba", "numeric" => "533", "alpha2" => "AW", "alpha3" => "ABW"], + ["name" => "Australia", "numeric" => "036", "alpha2" => "AU", "alpha3" => "AUS"], + ["name" => "Austria", "numeric" => "040", "alpha2" => "AT", "alpha3" => "AUT"], + ["name" => "Azerbaijan", "numeric" => "031", "alpha2" => "AZ", "alpha3" => "AZE"], + ["name" => "Bahamas", "numeric" => "044", "alpha2" => "BS", "alpha3" => "BHS"], + ["name" => "Bahrain", "numeric" => "048", "alpha2" => "BH", "alpha3" => "BHR"], + ["name" => "Bangladesh", "numeric" => "050", "alpha2" => "BD", "alpha3" => "BGD"], + ["name" => "Barbados", "numeric" => "052", "alpha2" => "BB", "alpha3" => "BRB"], + ["name" => "Belarus", "numeric" => "112", "alpha2" => "BY", "alpha3" => "BLR"], + ["name" => "Belgium", "numeric" => "056", "alpha2" => "BE", "alpha3" => "BEL"], + ["name" => "Belize", "numeric" => "084", "alpha2" => "BZ", "alpha3" => "BLZ"], + ["name" => "Benin", "numeric" => "204", "alpha2" => "BJ", "alpha3" => "BEN"], + ["name" => "Bermuda", "numeric" => "060", "alpha2" => "BM", "alpha3" => "BMU"], + ["name" => "Bhutan", "numeric" => "064", "alpha2" => "BT", "alpha3" => "BTN"], + ["name" => "Bolivia, Plurinational State of", "numeric" => "068", "alpha2" => "BO", "alpha3" => "BOL"], + ["name" => "Bonaire, Sint Eustatius and Saba", "numeric" => "535", "alpha2" => "BQ", "alpha3" => "BES"], + ["name" => "Bosnia and Herzegovina", "numeric" => "070", "alpha2" => "BA", "alpha3" => "BIH"], + ["name" => "Botswana", "numeric" => "072", "alpha2" => "BW", "alpha3" => "BWA"], + ["name" => "Bouvet Island", "numeric" => "074", "alpha2" => "BV", "alpha3" => "BVT"], + ["name" => "Brazil", "numeric" => "076", "alpha2" => "BR", "alpha3" => "BRA"], + ["name" => "British Indian Ocean Territory", "numeric" => "086", "alpha2" => "IO", "alpha3" => "IOT"], + ["name" => "Brunei Darussalam", "numeric" => "096", "alpha2" => "BN", "alpha3" => "BRN"], + ["name" => "Bulgaria", "numeric" => "100", "alpha2" => "BG", "alpha3" => "BGR"], + ["name" => "Burkina Faso", "numeric" => "854", "alpha2" => "BF", "alpha3" => "BFA"], + ["name" => "Burundi", "numeric" => "108", "alpha2" => "BI", "alpha3" => "BDI"], + ["name" => "Cambodia", "numeric" => "116", "alpha2" => "KH", "alpha3" => "KHM"], + ["name" => "Cameroon", "numeric" => "120", "alpha2" => "CM", "alpha3" => "CMR"], + ["name" => "Canada", "numeric" => "124", "alpha2" => "CA", "alpha3" => "CAN"], + ["name" => "Cabo Verde", "numeric" => "132", "alpha2" => "CV", "alpha3" => "CPV"], + ["name" => "Cayman Islands", "numeric" => "136", "alpha2" => "KY", "alpha3" => "CYM"], + ["name" => "Central African Republic", "numeric" => "140", "alpha2" => "CF", "alpha3" => "CAF"], + ["name" => "Chad", "numeric" => "148", "alpha2" => "TD", "alpha3" => "TCD"], + ["name" => "Chile", "numeric" => "152", "alpha2" => "CL", "alpha3" => "CHL"], + ["name" => "China", "numeric" => "156", "alpha2" => "CN", "alpha3" => "CHN"], + ["name" => "Christmas Island", "numeric" => "162", "alpha2" => "CX", "alpha3" => "CXR"], + ["name" => "Cocos (Keeling) Islands", "numeric" => "166", "alpha2" => "CC", "alpha3" => "CCK"], + ["name" => "Colombia", "numeric" => "170", "alpha2" => "CO", "alpha3" => "COL"], + ["name" => "Comoros", "numeric" => "174", "alpha2" => "KM", "alpha3" => "COM"], + ["name" => "Congo", "numeric" => "178", "alpha2" => "CG", "alpha3" => "COG"], + ["name" => "Congo, the Democratic Republic of the", "numeric" => "180", "alpha2" => "CD", "alpha3" => "COD"], + ["name" => "Cook Islands", "numeric" => "184", "alpha2" => "CK", "alpha3" => "COK"], + ["name" => "Costa Rica", "numeric" => "188", "alpha2" => "CR", "alpha3" => "CRI"], + ["name" => "CĂ´te d'Ivoire", "numeric" => "384", "alpha2" => "CI", "alpha3" => "CIV"], + ["name" => "Croatia", "numeric" => "191", "alpha2" => "HR", "alpha3" => "HRV"], + ["name" => "Cuba", "numeric" => "192", "alpha2" => "CU", "alpha3" => "CUB"], + ["name" => "Curaçao", "numeric" => "531", "alpha2" => "CW", "alpha3" => "CUW"], + ["name" => "Cyprus", "numeric" => "196", "alpha2" => "CY", "alpha3" => "CYP"], + ["name" => "Czech Republic", "numeric" => "203", "alpha2" => "CZ", "alpha3" => "CZE"], + ["name" => "Denmark", "numeric" => "208", "alpha2" => "DK", "alpha3" => "DNK"], + ["name" => "Djibouti", "numeric" => "262", "alpha2" => "DJ", "alpha3" => "DJI"], + ["name" => "Dominica", "numeric" => "212", "alpha2" => "DM", "alpha3" => "DMA"], + ["name" => "Dominican Republic", "numeric" => "214", "alpha2" => "DO", "alpha3" => "DOM"], + ["name" => "Ecuador", "numeric" => "218", "alpha2" => "EC", "alpha3" => "ECU"], + ["name" => "Egypt", "numeric" => "818", "alpha2" => "EG", "alpha3" => "EGY"], + ["name" => "El Salvador", "numeric" => "222", "alpha2" => "SV", "alpha3" => "SLV"], + ["name" => "Equatorial Guinea", "numeric" => "226", "alpha2" => "GQ", "alpha3" => "GNQ"], + ["name" => "Eritrea", "numeric" => "232", "alpha2" => "ER", "alpha3" => "ERI"], + ["name" => "Estonia", "numeric" => "233", "alpha2" => "EE", "alpha3" => "EST"], + ["name" => "Ethiopia", "numeric" => "231", "alpha2" => "ET", "alpha3" => "ETH"], + ["name" => "Falkland Islands (Malvinas)", "numeric" => "238", "alpha2" => "FK", "alpha3" => "FLK"], + ["name" => "Faroe Islands", "numeric" => "234", "alpha2" => "FO", "alpha3" => "FRO"], + ["name" => "Fiji", "numeric" => "242", "alpha2" => "FJ", "alpha3" => "FJI"], + ["name" => "Finland", "numeric" => "246", "alpha2" => "FI", "alpha3" => "FIN"], + ["name" => "France", "numeric" => "250", "alpha2" => "FR", "alpha3" => "FRA"], + ["name" => "French Guiana", "numeric" => "254", "alpha2" => "GF", "alpha3" => "GUF"], + ["name" => "French Polynesia", "numeric" => "258", "alpha2" => "PF", "alpha3" => "PYF"], + ["name" => "French Southern Territories", "numeric" => "260", "alpha2" => "TF", "alpha3" => "ATF"], + ["name" => "Gabon", "numeric" => "266", "alpha2" => "GA", "alpha3" => "GAB"], + ["name" => "Gambia", "numeric" => "270", "alpha2" => "GM", "alpha3" => "GMB"], + ["name" => "Georgia", "numeric" => "268", "alpha2" => "GE", "alpha3" => "GEO"], + ["name" => "Germany", "numeric" => "276", "alpha2" => "DE", "alpha3" => "DEU"], + ["name" => "Ghana", "numeric" => "288", "alpha2" => "GH", "alpha3" => "GHA"], + ["name" => "Gibraltar", "numeric" => "292", "alpha2" => "GI", "alpha3" => "GIB"], + ["name" => "Greece", "numeric" => "300", "alpha2" => "GR", "alpha3" => "GRC"], + ["name" => "Greenland", "numeric" => "304", "alpha2" => "GL", "alpha3" => "GRL"], + ["name" => "Grenada", "numeric" => "308", "alpha2" => "GD", "alpha3" => "GRD"], + ["name" => "Guadeloupe", "numeric" => "312", "alpha2" => "GP", "alpha3" => "GLP"], + ["name" => "Guam", "numeric" => "316", "alpha2" => "GU", "alpha3" => "GUM"], + ["name" => "Guatemala", "numeric" => "320", "alpha2" => "GT", "alpha3" => "GTM"], + ["name" => "Guernsey", "numeric" => "831", "alpha2" => "GG", "alpha3" => "GGY"], + ["name" => "Guinea", "numeric" => "324", "alpha2" => "GN", "alpha3" => "GIN"], + ["name" => "Guinea-Bissau", "numeric" => "624", "alpha2" => "GW", "alpha3" => "GNB"], + ["name" => "Guyana", "numeric" => "328", "alpha2" => "GY", "alpha3" => "GUY"], + ["name" => "Haiti", "numeric" => "332", "alpha2" => "HT", "alpha3" => "HTI"], + ["name" => "Heard Island and McDonald Islands", "numeric" => "334", "alpha2" => "HM", "alpha3" => "HMD"], + ["name" => "Holy See (Vatican City State)", "numeric" => "336", "alpha2" => "VA", "alpha3" => "VAT"], + ["name" => "Honduras", "numeric" => "340", "alpha2" => "HN", "alpha3" => "HND"], + ["name" => "Hong Kong", "numeric" => "344", "alpha2" => "HK", "alpha3" => "HKG"], + ["name" => "Hungary", "numeric" => "348", "alpha2" => "HU", "alpha3" => "HUN"], + ["name" => "Iceland", "numeric" => "352", "alpha2" => "IS", "alpha3" => "ISL"], + ["name" => "India", "numeric" => "356", "alpha2" => "IN", "alpha3" => "IND"], + ["name" => "Indonesia", "numeric" => "360", "alpha2" => "ID", "alpha3" => "IDN"], + ["name" => "Iran, Islamic Republic of", "numeric" => "364", "alpha2" => "IR", "alpha3" => "IRN"], + ["name" => "Iraq", "numeric" => "368", "alpha2" => "IQ", "alpha3" => "IRQ"], + ["name" => "Ireland", "numeric" => "372", "alpha2" => "IE", "alpha3" => "IRL"], + ["name" => "Isle of Man", "numeric" => "833", "alpha2" => "IM", "alpha3" => "IMN"], + ["name" => "Israel", "numeric" => "376", "alpha2" => "IL", "alpha3" => "ISR"], + ["name" => "Italy", "numeric" => "380", "alpha2" => "IT", "alpha3" => "ITA"], + ["name" => "Jamaica", "numeric" => "388", "alpha2" => "JM", "alpha3" => "JAM"], + ["name" => "Japan", "numeric" => "392", "alpha2" => "JP", "alpha3" => "JPN"], + ["name" => "Jersey", "numeric" => "832", "alpha2" => "JE", "alpha3" => "JEY"], + ["name" => "Jordan", "numeric" => "400", "alpha2" => "JO", "alpha3" => "JOR"], + ["name" => "Kazakhstan", "numeric" => "398", "alpha2" => "KZ", "alpha3" => "KAZ"], + ["name" => "Kenya", "numeric" => "404", "alpha2" => "KE", "alpha3" => "KEN"], + ["name" => "Kiribati", "numeric" => "296", "alpha2" => "KI", "alpha3" => "KIR"], + ["name" => "Korea, Democratic People's Republic of", "numeric" => "408", "alpha2" => "KP", "alpha3" => "PRK"], + ["name" => "Korea, Republic of", "numeric" => "410", "alpha2" => "KR", "alpha3" => "KOR"], + ["name" => "Kuwait", "numeric" => "414", "alpha2" => "KW", "alpha3" => "KWT"], + ["name" => "Kyrgyzstan", "numeric" => "417", "alpha2" => "KG", "alpha3" => "KGZ"], + ["name" => "Lao People's Democratic Republic", "numeric" => "418", "alpha2" => "LA", "alpha3" => "LAO"], + ["name" => "Latvia", "numeric" => "428", "alpha2" => "LV", "alpha3" => "LVA"], + ["name" => "Lebanon", "numeric" => "422", "alpha2" => "LB", "alpha3" => "LBN"], + ["name" => "Lesotho", "numeric" => "426", "alpha2" => "LS", "alpha3" => "LSO"], + ["name" => "Liberia", "numeric" => "430", "alpha2" => "LR", "alpha3" => "LBR"], + ["name" => "Libya", "numeric" => "434", "alpha2" => "LY", "alpha3" => "LBY"], + ["name" => "Liechtenstein", "numeric" => "438", "alpha2" => "LI", "alpha3" => "LIE"], + ["name" => "Lithuania", "numeric" => "440", "alpha2" => "LT", "alpha3" => "LTU"], + ["name" => "Luxembourg", "numeric" => "442", "alpha2" => "LU", "alpha3" => "LUX"], + ["name" => "Macao", "numeric" => "446", "alpha2" => "MO", "alpha3" => "MAC"], + ["name" => "Macedonia, the former Yugoslav Republic of", "numeric" => "807", "alpha2" => "MK", "alpha3" => "MKD"], + ["name" => "Madagascar", "numeric" => "450", "alpha2" => "MG", "alpha3" => "MDG"], + ["name" => "Malawi", "numeric" => "454", "alpha2" => "MW", "alpha3" => "MWI"], + ["name" => "Malaysia", "numeric" => "458", "alpha2" => "MY", "alpha3" => "MYS"], + ["name" => "Maldives", "numeric" => "462", "alpha2" => "MV", "alpha3" => "MDV"], + ["name" => "Mali", "numeric" => "466", "alpha2" => "ML", "alpha3" => "MLI"], + ["name" => "Malta", "numeric" => "470", "alpha2" => "MT", "alpha3" => "MLT"], + ["name" => "Marshall Islands", "numeric" => "584", "alpha2" => "MH", "alpha3" => "MHL"], + ["name" => "Martinique", "numeric" => "474", "alpha2" => "MQ", "alpha3" => "MTQ"], + ["name" => "Mauritania", "numeric" => "478", "alpha2" => "MR", "alpha3" => "MRT"], + ["name" => "Mauritius", "numeric" => "480", "alpha2" => "MU", "alpha3" => "MUS"], + ["name" => "Mayotte", "numeric" => "175", "alpha2" => "YT", "alpha3" => "MYT"], + ["name" => "Mexico", "numeric" => "484", "alpha2" => "MX", "alpha3" => "MEX"], + ["name" => "Micronesia, Federated States of", "numeric" => "583", "alpha2" => "FM", "alpha3" => "FSM"], + ["name" => "Moldova, Republic of", "numeric" => "498", "alpha2" => "MD", "alpha3" => "MDA"], + ["name" => "Monaco", "numeric" => "492", "alpha2" => "MC", "alpha3" => "MCO"], + ["name" => "Mongolia", "numeric" => "496", "alpha2" => "MN", "alpha3" => "MNG"], + ["name" => "Montenegro", "numeric" => "499", "alpha2" => "ME", "alpha3" => "MNE"], + ["name" => "Montserrat", "numeric" => "500", "alpha2" => "MS", "alpha3" => "MSR"], + ["name" => "Morocco", "numeric" => "504", "alpha2" => "MA", "alpha3" => "MAR"], + ["name" => "Mozambique", "numeric" => "508", "alpha2" => "MZ", "alpha3" => "MOZ"], + ["name" => "Myanmar", "numeric" => "104", "alpha2" => "MM", "alpha3" => "MMR"], + ["name" => "Namibia", "numeric" => "516", "alpha2" => "NA", "alpha3" => "NAM"], + ["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" => "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"], + ["name" => "Niger", "numeric" => "562", "alpha2" => "NE", "alpha3" => "NER"], + ["name" => "Nigeria", "numeric" => "566", "alpha2" => "NG", "alpha3" => "NGA"], + ["name" => "Niue", "numeric" => "570", "alpha2" => "NU", "alpha3" => "NIU"], + ["name" => "Norfolk Island", "numeric" => "574", "alpha2" => "NF", "alpha3" => "NFK"], + ["name" => "Northern Mariana Islands", "numeric" => "580", "alpha2" => "MP", "alpha3" => "MNP"], + ["name" => "Norway", "numeric" => "578", "alpha2" => "NO", "alpha3" => "NOR"], + ["name" => "Oman", "numeric" => "512", "alpha2" => "OM", "alpha3" => "OMN"], + ["name" => "Pakistan", "numeric" => "586", "alpha2" => "PK", "alpha3" => "PAK"], + ["name" => "Palau", "numeric" => "585", "alpha2" => "PW", "alpha3" => "PLW"], + ["name" => "Palestine, State of", "numeric" => "275", "alpha2" => "PS", "alpha3" => "PSE"], + ["name" => "Panama", "numeric" => "591", "alpha2" => "PA", "alpha3" => "PAN"], + ["name" => "Papua New Guinea", "numeric" => "598", "alpha2" => "PG", "alpha3" => "PNG"], + ["name" => "Paraguay", "numeric" => "600", "alpha2" => "PY", "alpha3" => "PRY"], + ["name" => "Peru", "numeric" => "604", "alpha2" => "PE", "alpha3" => "PER"], + ["name" => "Philippines", "numeric" => "608", "alpha2" => "PH", "alpha3" => "PHL"], + ["name" => "Pitcairn", "numeric" => "612", "alpha2" => "PN", "alpha3" => "PCN"], + ["name" => "Poland", "numeric" => "616", "alpha2" => "PL", "alpha3" => "POL"], + ["name" => "Portugal", "numeric" => "620", "alpha2" => "PT", "alpha3" => "PRT"], + ["name" => "Puerto Rico", "numeric" => "630", "alpha2" => "PR", "alpha3" => "PRI"], + ["name" => "Qatar", "numeric" => "634", "alpha2" => "QA", "alpha3" => "QAT"], + ["name" => "RĂ©union", "numeric" => "638", "alpha2" => "RE", "alpha3" => "REU"], + ["name" => "Romania", "numeric" => "642", "alpha2" => "RO", "alpha3" => "ROU"], + ["name" => "Russian Federation", "numeric" => "643", "alpha2" => "RU", "alpha3" => "RUS"], + ["name" => "Rwanda", "numeric" => "646", "alpha2" => "RW", "alpha3" => "RWA"], + ["name" => "Saint BarthĂ©lemy", "numeric" => "652", "alpha2" => "BL", "alpha3" => "BLM"], + ["name" => "Saint Helena, Ascension and Tristan da Cunha", "numeric" => "654", "alpha2" => "SH", "alpha3" => "SHN"], + ["name" => "Saint Kitts and Nevis", "numeric" => "659", "alpha2" => "KN", "alpha3" => "KNA"], + ["name" => "Saint Lucia", "numeric" => "662", "alpha2" => "LC", "alpha3" => "LCA"], + ["name" => "Saint Martin (French part)", "numeric" => "663", "alpha2" => "MF", "alpha3" => "MAF"], + ["name" => "Saint Pierre and Miquelon", "numeric" => "666", "alpha2" => "PM", "alpha3" => "SPM"], + ["name" => "Saint Vincent and the Grenadines", "numeric" => "670", "alpha2" => "VC", "alpha3" => "VCT"], + ["name" => "Samoa", "numeric" => "882", "alpha2" => "WS", "alpha3" => "WSM"], + ["name" => "San Marino", "numeric" => "674", "alpha2" => "SM", "alpha3" => "SMR"], + ["name" => "Sao Tome and Principe", "numeric" => "678", "alpha2" => "ST", "alpha3" => "STP"], + ["name" => "Saudi Arabia", "numeric" => "682", "alpha2" => "SA", "alpha3" => "SAU"], + ["name" => "Senegal", "numeric" => "686", "alpha2" => "SN", "alpha3" => "SEN"], + ["name" => "Serbia", "numeric" => "688", "alpha2" => "RS", "alpha3" => "SRB"], + ["name" => "Seychelles", "numeric" => "690", "alpha2" => "SC", "alpha3" => "SYC"], + ["name" => "Sierra Leone", "numeric" => "694", "alpha2" => "SL", "alpha3" => "SLE"], + ["name" => "Singapore", "numeric" => "702", "alpha2" => "SG", "alpha3" => "SGP"], + ["name" => "Sint Maarten (Dutch part)", "numeric" => "534", "alpha2" => "SX", "alpha3" => "SXM"], + ["name" => "Slovakia", "numeric" => "703", "alpha2" => "SK", "alpha3" => "SVK"], + ["name" => "Slovenia", "numeric" => "705", "alpha2" => "SI", "alpha3" => "SVN"], + ["name" => "Solomon Islands", "numeric" => "090", "alpha2" => "SB", "alpha3" => "SLB"], + ["name" => "Somalia", "numeric" => "706", "alpha2" => "SO", "alpha3" => "SOM"], + ["name" => "South Africa", "numeric" => "710", "alpha2" => "ZA", "alpha3" => "ZAF"], + ["name" => "South Georgia and the South Sandwich Islands", "numeric" => "239", "alpha2" => "GS", "alpha3" => "SGS"], + ["name" => "South Sudan", "numeric" => "728", "alpha2" => "SS", "alpha3" => "SSD"], + ["name" => "Spain", "numeric" => "724", "alpha2" => "ES", "alpha3" => "ESP"], + ["name" => "Sri Lanka", "numeric" => "144", "alpha2" => "LK", "alpha3" => "LKA"], + ["name" => "Sudan", "numeric" => "729", "alpha2" => "SD", "alpha3" => "SDN"], + ["name" => "Suriname", "numeric" => "740", "alpha2" => "SR", "alpha3" => "SUR"], + ["name" => "Svalbard and Jan Mayen", "numeric" => "744", "alpha2" => "SJ", "alpha3" => "SJM"], + ["name" => "Swaziland", "numeric" => "748", "alpha2" => "SZ", "alpha3" => "SWZ"], + ["name" => "Sweden", "numeric" => "752", "alpha2" => "SE", "alpha3" => "SWE"], + ["name" => "Switzerland", "numeric" => "756", "alpha2" => "CH", "alpha3" => "CHE"], + ["name" => "Syrian Arab Republic", "numeric" => "760", "alpha2" => "SY", "alpha3" => "SYR"], + ["name" => "Taiwan, Province of China", "numeric" => "158", "alpha2" => "TW", "alpha3" => "TWN"], + ["name" => "Tajikistan", "numeric" => "762", "alpha2" => "TJ", "alpha3" => "TJK"], + ["name" => "Tanzania, United Republic of", "numeric" => "834", "alpha2" => "TZ", "alpha3" => "TZA"], + ["name" => "Thailand", "numeric" => "764", "alpha2" => "TH", "alpha3" => "THA"], + ["name" => "Timor-Leste", "numeric" => "626", "alpha2" => "TL", "alpha3" => "TLS"], + ["name" => "Togo", "numeric" => "768", "alpha2" => "TG", "alpha3" => "TGO"], + ["name" => "Tokelau", "numeric" => "772", "alpha2" => "TK", "alpha3" => "TKL"], + ["name" => "Tonga", "numeric" => "776", "alpha2" => "TO", "alpha3" => "TON"], + ["name" => "Trinidad and Tobago", "numeric" => "780", "alpha2" => "TT", "alpha3" => "TTO"], + ["name" => "Tunisia", "numeric" => "788", "alpha2" => "TN", "alpha3" => "TUN"], + ["name" => "Turkey", "numeric" => "792", "alpha2" => "TR", "alpha3" => "TUR"], + ["name" => "Turkmenistan", "numeric" => "795", "alpha2" => "TM", "alpha3" => "TKM"], + ["name" => "Turks and Caicos Islands", "numeric" => "796", "alpha2" => "TC", "alpha3" => "TCA"], + ["name" => "Tuvalu", "numeric" => "798", "alpha2" => "TV", "alpha3" => "TUV"], + ["name" => "Uganda", "numeric" => "800", "alpha2" => "UG", "alpha3" => "UGA"], + ["name" => "Ukraine", "numeric" => "804", "alpha2" => "UA", "alpha3" => "UKR"], + ["name" => "United Arab Emirates", "numeric" => "784", "alpha2" => "AE", "alpha3" => "ARE"], + ["name" => "United Kingdom of Great Britain and Northern Ireland", "numeric" => "826", "alpha2" => "GB", "alpha3" => "GBR"], + ["name" => "United States of America", "numeric" => "840", "alpha2" => "US", "alpha3" => "USA"], + ["name" => "United States Minor Outlying Islands", "numeric" => "581", "alpha2" => "UM", "alpha3" => "UMI"], + ["name" => "Uruguay", "numeric" => "858", "alpha2" => "UY", "alpha3" => "URY"], + ["name" => "Uzbekistan", "numeric" => "860", "alpha2" => "UZ", "alpha3" => "UZB"], + ["name" => "Vanuatu", "numeric" => "548", "alpha2" => "VU", "alpha3" => "VUT"], + ["name" => "Venezuela (Bolivarian Republic of)", "numeric" => "862", "alpha2" => "VE", "alpha3" => "VEN"], + ["name" => "Vietnam", "numeric" => "704", "alpha2" => "VN", "alpha3" => "VNM"], + ["name" => "Virgin Islands (British)", "numeric" => "092", "alpha2" => "VG", "alpha3" => "VGB"], + ["name" => "Virgin Islands (U.S.)", "numeric" => "850", "alpha2" => "VI", "alpha3" => "VIR"], + ["name" => "Wallis and Futuna", "numeric" => "876", "alpha2" => "WF", "alpha3" => "WLF"], + ["name" => "Western Sahara", "numeric" => "732", "alpha2" => "EH", "alpha3" => "ESH"], + ["name" => "Yemen", "numeric" => "887", "alpha2" => "YE", "alpha3" => "YEM"], + ["name" => "Zambia", "numeric" => "894", "alpha2" => "ZM", "alpha3" => "ZMB"], + ["name" => "Zimbabwe", "numeric" => "716", "alpha2" => "ZW", "alpha3" => "ZWE"] + ]; +} \ No newline at end of file diff --git a/src/Entities/IWebProxy.php b/src/Entities/IWebProxy.php new file mode 100644 index 00000000..4d65e06b --- /dev/null +++ b/src/Entities/IWebProxy.php @@ -0,0 +1,19 @@ +webProxy)) { + curl_setopt($request, CURLOPT_PROXY, $this->webProxy->uri); + if (!empty($this->webProxy->username) && !empty($this->webProxy->password)) { + curl_setopt($request, CURLOPT_PROXYUSERPWD, $this->webProxy->username . ':' , $this->webProxy->password); + } + } + // Define the constant manually for earlier versions of PHP. // Disable phpcs here since this constant does not exist until PHP 5.5.19. // phpcs:disable diff --git a/src/Gateways/PorticoConnector.php b/src/Gateways/PorticoConnector.php index 76845e69..121d0dfe 100644 --- a/src/Gateways/PorticoConnector.php +++ b/src/Gateways/PorticoConnector.php @@ -41,6 +41,10 @@ use GlobalPayments\Api\Entities\Enums\StoredCredentialInitiator; use GlobalPayments\Api\Entities\Exceptions\BuilderException; use GlobalPayments\Api\Entities\PayFac\PayFacResponseData; +use GlobalPayments\Api\Entities\Reporting\LodgingData; +use GlobalPayments\Api\Entities\Reporting\AltPaymentData; +use GlobalPayments\Api\Entities\Reporting\AltPaymentProcessorInfo; +use GlobalPayments\Api\Entities\Exceptions\NotImplementedException; class PorticoConnector extends XmlGateway implements IPaymentGateway { diff --git a/src/Gateways/RealexConnector.php b/src/Gateways/RealexConnector.php index 98eb78d4..a487d775 100644 --- a/src/Gateways/RealexConnector.php +++ b/src/Gateways/RealexConnector.php @@ -7,6 +7,7 @@ use GlobalPayments\Api\Builders\ManagementBuilder; use GlobalPayments\Api\Builders\RecurringBuilder; use GlobalPayments\Api\Builders\ReportBuilder; +use GlobalPayments\Api\Entities\Address; use GlobalPayments\Api\Entities\Enums\CvnPresenceIndicator; use GlobalPayments\Api\Entities\Enums\PaymentMethodType; use GlobalPayments\Api\Entities\Enums\TransactionModifier; @@ -18,6 +19,7 @@ use GlobalPayments\Api\Entities\Transaction; use GlobalPayments\Api\PaymentMethods\CreditCardData; use GlobalPayments\Api\PaymentMethods\TransactionReference; +use GlobalPayments\Api\Utils\CountryUtils; use GlobalPayments\Api\Utils\GenerationUtils; use GlobalPayments\Api\Entities\Enums\EncyptedMobileType; use GlobalPayments\Api\PaymentMethods\RecurringPaymentMethod; @@ -581,9 +583,12 @@ public function serializeRequest(AuthorizationBuilder $builder) $this->setSerializeData('CUST_NUM', $builder->customerId); } if (!empty($builder->shippingAddress)) { + $countryCode = CountryUtils::getCountryCodeByCountry($builder->shippingAddress->country); + $shippingCode = $this->generateCode($builder->shippingAddress); + // Fraud values - $this->setSerializeData('SHIPPING_CODE', $builder->shippingAddress->postalCode); - $this->setSerializeData('SHIPPING_CO', $builder->shippingAddress->country); + $this->setSerializeData('SHIPPING_CODE', $shippingCode); + $this->setSerializeData('SHIPPING_CO', $countryCode); // 3DS 2.0 values $this->setSerializeData('HPP_SHIPPING_STREET1', $builder->shippingAddress->streetAddress1); @@ -592,12 +597,14 @@ public function serializeRequest(AuthorizationBuilder $builder) $this->setSerializeData('HPP_SHIPPING_CITY', $builder->shippingAddress->city); $this->setSerializeData('HPP_SHIPPING_STATE', $builder->shippingAddress->state); $this->setSerializeData('HPP_SHIPPING_POSTALCODE', $builder->shippingAddress->postalCode); - $this->setSerializeData('HPP_SHIPPING_COUNTRY', $builder->shippingAddress->country); + $this->setSerializeData('HPP_SHIPPING_COUNTRY', CountryUtils::getNumericCodeByCountry($builder->shippingAddress->country)); } if (!empty($builder->billingAddress)) { + $countryCode = CountryUtils::getCountryCodeByCountry($builder->billingAddress->country); + $billingCode = $this->generateCode($builder->billingAddress); // Fraud values - $this->setSerializeData('BILLING_CODE', $builder->billingAddress->postalCode); - $this->setSerializeData('BILLING_CO', $builder->billingAddress->country); + $this->setSerializeData('BILLING_CODE', $billingCode); + $this->setSerializeData('BILLING_CO', $countryCode); // 3DS 2.0 values $this->setSerializeData('HPP_BILLING_STREET1', $builder->billingAddress->streetAddress1); @@ -606,7 +613,10 @@ public function serializeRequest(AuthorizationBuilder $builder) $this->setSerializeData('HPP_BILLING_CITY', $builder->billingAddress->city); $this->setSerializeData('HPP_BILLING_STATE', $builder->billingAddress->state); $this->setSerializeData('HPP_BILLING_POSTALCODE', $builder->billingAddress->postalCode); - $this->setSerializeData('HPP_BILLING_COUNTRY', $builder->billingAddress->country); + $this->setSerializeData( + 'HPP_BILLING_COUNTRY', + CountryUtils::getNumericCodeByCountry($builder->billingAddress->country) + ); } $this->setSerializeData('VAR_REF', $builder->clientTransactionId); @@ -1437,4 +1447,19 @@ private function serializeSupplementaryData($supplementaryData) $this->setSerializeData(strtoupper($key), $value); } } + + private function generateCode(Address $address) + { + $countryCode = CountryUtils::getCountryCodeByCountry($address->country); + switch ($countryCode) + { + case 'GB': + return filter_var($address->postalCode, FILTER_SANITIZE_NUMBER_INT) . '|' . filter_var($address->streetAddress1, FILTER_SANITIZE_NUMBER_INT); + case 'US': + case 'CA': + return $address->postalCode . '|' . $address->streetAddress1; + default: + return null; + } + } } diff --git a/src/Gateways/RestGateway.php b/src/Gateways/RestGateway.php index e9dd12f8..c8b75ade 100644 --- a/src/Gateways/RestGateway.php +++ b/src/Gateways/RestGateway.php @@ -40,7 +40,7 @@ protected function doTransaction( $response = $this->sendRequest($verb, $endpoint, $data, $queryStringParams); if ($this->isGpApi()) { - if (strpos($response->header, 'Content-Encoding: gzip') !== false) { + if (strpos($response->header, ': gzip') !== false) { $response->rawResponse = gzdecode($response->rawResponse); } } diff --git a/src/ServiceConfigs/Configuration.php b/src/ServiceConfigs/Configuration.php index e29d2fcc..d9bd3dea 100644 --- a/src/ServiceConfigs/Configuration.php +++ b/src/ServiceConfigs/Configuration.php @@ -4,6 +4,7 @@ use GlobalPayments\Api\ConfiguredServices; use GlobalPayments\Api\Entities\Enums\Environment; +use GlobalPayments\Api\Entities\IWebProxy; abstract class Configuration { @@ -22,6 +23,11 @@ abstract class Configuration /** @var bool */ public $validated; + /** + * @var IWebProxy + */ + public $webProxy; + abstract public function configureContainer(ConfiguredServices $services); /** @var bool */ diff --git a/src/ServiceConfigs/Gateways/GeniusConfig.php b/src/ServiceConfigs/Gateways/GeniusConfig.php index ef6ffa2c..fb2ac2d3 100644 --- a/src/ServiceConfigs/Gateways/GeniusConfig.php +++ b/src/ServiceConfigs/Gateways/GeniusConfig.php @@ -45,6 +45,7 @@ public function configureContainer(ConfiguredServices $services) $gateway->terminalId = $this->terminalId; $gateway->timeout = $this->timeout; $gateway->serviceUrl = $this->serviceUrl; + $gateway->webProxy = $this->webProxy; $services->gatewayConnector = $gateway; } diff --git a/src/ServiceConfigs/Gateways/GpApiConfig.php b/src/ServiceConfigs/Gateways/GpApiConfig.php index bdbcd6ac..3c246622 100644 --- a/src/ServiceConfigs/Gateways/GpApiConfig.php +++ b/src/ServiceConfigs/Gateways/GpApiConfig.php @@ -73,13 +73,10 @@ public function configureContainer(ConfiguredServices $services) $this->accessTokenInfo->initialize($this); $gateway = new GpApiConnector($this); $gateway->serviceUrl = $this->serviceUrl; - - if (isset($this->requestLogger)) { - $gateway->requestLogger = $this->requestLogger; - } + $gateway->requestLogger = $this->requestLogger; + $gateway->webProxy = $this->webProxy; $services->gatewayConnector = $gateway; - $services->reportingService = $gateway; $services->setSecure3dProvider(Secure3dVersion::ONE, $gateway); diff --git a/src/ServiceConfigs/Gateways/GpEcomConfig.php b/src/ServiceConfigs/Gateways/GpEcomConfig.php index 29562c6c..c3df22d5 100644 --- a/src/ServiceConfigs/Gateways/GpEcomConfig.php +++ b/src/ServiceConfigs/Gateways/GpEcomConfig.php @@ -53,7 +53,8 @@ public function configureContainer(ConfiguredServices $services) $gateway->serviceUrl = $this->serviceUrl; $gateway->refundPassword = $this->refundPassword; $gateway->hostedPaymentConfig = $this->hostedPaymentConfig; - + $gateway->webProxy = $this->webProxy; + $services->gatewayConnector = $gateway; $services->recurringConnector = $gateway; diff --git a/src/ServiceConfigs/Gateways/PorticoConfig.php b/src/ServiceConfigs/Gateways/PorticoConfig.php index 40462f51..9dbe989f 100644 --- a/src/ServiceConfigs/Gateways/PorticoConfig.php +++ b/src/ServiceConfigs/Gateways/PorticoConfig.php @@ -80,6 +80,7 @@ public function configureContainer(ConfiguredServices $services) $gateway->serviceUrl = $this->serviceUrl . '/Hps.Exchange.PosGateway/PosGatewayService.asmx'; $gateway->uniqueDeviceId = $this->uniqueDeviceId; $gateway->requestLogger = $this->requestLogger; + $gateway->webProxy = $this->webProxy; $services->gatewayConnector = $gateway; diff --git a/src/ServiceConfigs/Gateways/TransitConfig.php b/src/ServiceConfigs/Gateways/TransitConfig.php index d43925cd..c49bcf88 100644 --- a/src/ServiceConfigs/Gateways/TransitConfig.php +++ b/src/ServiceConfigs/Gateways/TransitConfig.php @@ -38,6 +38,7 @@ public function configureContainer(ConfiguredServices $services) $gateway->transactionKey = $this->transactionKey; $gateway->userId = $this->username; $gateway->password = $this->password; + $gateway->webProxy = $this->webProxy; if (empty($this->serviceUrl)) { $gateway->serviceUrl = $this->environment == Environment::TEST ? ServiceEndpoints::TRANSIT_TEST : ServiceEndpoints::TRANSIT_PRODUCTION; diff --git a/src/Utils/CountryUtils.php b/src/Utils/CountryUtils.php new file mode 100644 index 00000000..bafa4e4b --- /dev/null +++ b/src/Utils/CountryUtils.php @@ -0,0 +1,219 @@ +countryCode)) { + return $address->countryCode === $countryCode; + } elseif (!is_null($address->country)) { + $code = self::getCountryCodeByCountry($address->country); + if (!is_null($code)) { + return $code === $countryCode; + } + + return false; + } + + return false; + } + + + /** + * Get country name by country code + * @param string $countryCode + * + * @return string|null + */ + public static function getCountryByCode($countryCode) + { + if (empty($countryCode)) { + return null; + } + $countryMapByCode = array_column(IsoCountries::$allCountries, 'alpha2'); + $countryMapByNumericCode = array_column(IsoCountries::$allCountries, 'numeric'); + + if (($key = array_search($countryCode, $countryMapByCode, true)) !== false) { + return IsoCountries::$allCountries[$key]['name']; + } elseif (($key = array_search($countryCode, $countryMapByNumericCode, true)) !== false) { + return IsoCountries::$allCountries[$key]['name']; + } else { + if (strlen($countryCode) > 3) { + return null; + } + $fuzzyMatchKey = self::fuzzyMatch($countryMapByCode, $countryCode, self::SIGNIFICANT_CODE_MATCH); + + return IsoCountries::$allCountries[$fuzzyMatchKey]['name']; + } + } + + /** + * Get country code by country name + * @param string $country + * + * @return string|null + */ + public static function getCountryCodeByCountry($country) + { + if (empty($country)) { + return null; + } + $countryCodeMapByCountry = array_column(IsoCountries::$allCountries, "name"); + $countryMapByCode = array_column(IsoCountries::$allCountries, 'alpha2'); + $countryMapByNumericCode = array_column(IsoCountries::$allCountries, 'numeric'); + if (($index = array_search($country, $countryCodeMapByCountry, true)) !== false) { + return IsoCountries::$allCountries[$index]['alpha2']; + } elseif (($index = array_search($country, $countryCodeMapByCountry)) !== false) { + return $country; + } elseif (($index = array_search($country, $countryMapByNumericCode)) !== false) { + return IsoCountries::$allCountries[$index]['alpha2']; + } else { + $fuzzyCountryMatch = self::fuzzyMatch($countryCodeMapByCountry, $country, self::SIGNIFICANT_COUNTRY_MATCH); + if (!is_null($fuzzyCountryMatch)) { + return IsoCountries::$allCountries[$fuzzyCountryMatch]['alpha2']; + } else { + if (strlen($country) > 3) { + return null; + } + + $fuzzyCodeMatch = self::fuzzyMatch($countryMapByCode, $country, self::SIGNIFICANT_CODE_MATCH); + if (!is_null($fuzzyCodeMatch)) { + return IsoCountries::$allCountries[$fuzzyCodeMatch]['alpha2']; + } + + return null; + } + } + } + + /** + * Get all the country details returned as array + * Exemple: [ + * [name] => United States of America + * [numeric] => 840 + * [alpha2] => US + * [alpha3] => USA + * ] + * + * @param string $country + * + * @return array|null + */ + public static function getCountryInfo($country) + { + if (empty($country)) { + return null; + } + + $countryCodeMapByCountry = array_column(IsoCountries::$allCountries, "name"); + $countryMapByCode = array_column(IsoCountries::$allCountries, 'alpha2'); + $countryMapByNumericCode = array_column(IsoCountries::$allCountries, 'numeric'); + + if (($index = array_search($country, $countryCodeMapByCountry, true)) !== false) { + return IsoCountries::$allCountries[$index]; + } else { + if (($index = array_search($country, $countryCodeMapByCountry)) !== false) { + return IsoCountries::$allCountries[$index]; + } else { + if (($index = array_search($country, $countryMapByNumericCode)) !== false) { + return IsoCountries::$allCountries[$index]; + } else { + $fuzzyCountryMatch = self::fuzzyMatch($countryCodeMapByCountry, $country, self::SIGNIFICANT_COUNTRY_MATCH); + if (!is_null($fuzzyCountryMatch)) { + return IsoCountries::$allCountries[$fuzzyCountryMatch]; + } else { + if (strlen($country) > 3) { + return null; + } + + $fuzzyCodeMatch = self::fuzzyMatch($countryMapByCode, $country, self::SIGNIFICANT_CODE_MATCH); + if (!is_null($fuzzyCodeMatch)) { + return IsoCountries::$allCountries[$fuzzyCodeMatch]; + } + + return null; + } + } + } + } + } + + private static function fuzzyMatch($dict, $query, $significantMatch) + { + $rvalue = $rkey = null; + $matches = []; + $highScore = -1; + foreach ($dict as $key => $value) { + $score = self::fuzzyScore($value, $query); + if ($score > $significantMatch && $score > $highScore) { + $matches = []; + $highScore = $score; + $rvalue = $value; + $rkey = $key; + $matches[$rkey] = $rvalue; + } elseif ($score == $highScore) { + $matches[$key] = $value; + } + } + + if (count($matches) > 1) { + return null; + } + + return $rkey; + } + + private static function fuzzyScore($term, $query) + { + if (empty($term) || empty($query)) { + throw new ArgumentException("Strings must not be null"); + } + + $termLowerCase = strtolower($term); + $queryLowerCase = strtolower($query); + $score = 0; + $termIndex = 0; + $previousMatchingCharacterIndex = PHP_INT_MIN; + + for ($queryIndex = 0; $queryIndex < strlen($queryLowerCase); $queryIndex++) { + $queryChar = $queryLowerCase[$queryIndex]; + $termCharacterMatchFound = false; + for (; $termIndex < strlen($termLowerCase) && !$termCharacterMatchFound; $termIndex++) { + $termChar = $termLowerCase[$termIndex]; + if ($queryChar == $termChar) { + $score++; + if ($previousMatchingCharacterIndex + 1 == $termIndex) { + $score += 2; + } + $previousMatchingCharacterIndex = $termIndex; + $termCharacterMatchFound = true; + } + } + } + + return $score; + } + + public static function getNumericCodeByCountry($country) + { + $countryInfo = self::getCountryInfo($country); + + return !empty($countryInfo['numeric']) ? $countryInfo['numeric'] : null; + } +} \ No newline at end of file diff --git a/test/Integration/CountryUtilsTest.php b/test/Integration/CountryUtilsTest.php new file mode 100644 index 00000000..b3717a55 --- /dev/null +++ b/test/Integration/CountryUtilsTest.php @@ -0,0 +1,202 @@ +assertNotNull($result); + $this->assertEquals('IE', $result); + } + + public function testGetCountryCodeMisspelled() + { + $result = CountryUtils::getCountryCodeByCountry('Afganistan'); + $this->assertNotNull($result); + $this->assertEquals('AF', $result); + } + + public function testGetCountryCodeFromPartial() + { + $result = CountryUtils::getCountryCodeByCountry('Republic of Congo'); + $this->assertNotNull($result); + $this->assertEquals('CD', $result); + } + + public function testGetCountryCodeByExactCode() + { + $result = CountryUtils::getCountryCodeByCountry('IE'); + $this->assertNotNull($result); + $this->assertEquals('IE', $result); + } + + public function testGetCountryCodeByPartialCode() + { + $result = CountryUtils::getCountryCodeByCountry('USA'); + $this->assertNotNull($result); + $this->assertEquals('US', $result); + } + + public function testGetCountryCodeNullDoesNotError() + { + $result = CountryUtils::getCountryCodeByCountry(null); + $this->assertNull($result); + } + + public function testGetCountryCodeFakeCountry() + { + $result = CountryUtils::getCountryCodeByCountry('FakeCountry'); + $this->assertNull($result); + } + + public function testGetCountryCodeFakeCountry2() + { + $result = CountryUtils::getCountryCodeByCountry('Fakeistan'); + $this->assertNull($result); + } + + public function testGetCountryCodeFakeCountry3() + { + $result = CountryUtils::getCountryCodeByCountry('MyRussia'); + $this->assertNull($result); + } + + public function testGetCountryByCodeExact() + { + $result = CountryUtils::getCountryByCode('IE'); + $this->assertNotNull($result); + $this->assertEquals('Ireland', $result); + } + + public function testGetCountryByThreeDigitCode() + { + $result = CountryUtils::getCountryByCode('USA'); + $this->assertNotNull($result); + $this->assertEquals('United States of America', $result); + } + + public function testGetCountryByCodeNullDoesNotError() + { + $result = CountryUtils::getCountryByCode(null); + $this->assertNull($result); + } + + public function testCheckAddressCodeFromCountryExact() + { + $address = new Address(); + $address->country = "United States of America"; + $this->assertNotNull($address->countryCode); + $this->assertEquals('US', $address->countryCode); + } + + public function testCheckAddressCountryFromCodeExact() + { + $address = new Address(); + $address->countryCode = "US"; + $this->assertNotNull($address->country); + $this->assertEquals('United States of America', $address->country); + } + + public function testCheckAddressCodeFromCountryFuzzy() + { + $address = new Address(); + $address->country = "Afganistan"; + $this->assertNotNull($address->countryCode); + $this->assertEquals('AF', $address->countryCode); + } + + public function testCheckAddressCountryFromCodeFuzzy() + { + $address = new Address(); + $address->countryCode = "USA"; + $this->assertNotNull($address->country); + $this->assertEquals('United States of America', $address->country); + } + + public function testAddressIsCountryExactMatch() + { + $address = new Address(); + $address->country = "United States of America"; + $this->assertTrue($address->isCountry("US")); + } + + public function testAddressIsCountryExactMisMatch() + { + $address = new Address(); + $address->country = "United States of America"; + $this->assertFalse($address->isCountry("GB")); + } + + public function testAddressIsCountryFuzzyMatch() + { + $address = new Address(); + $address->country = "Afganistan"; + $this->assertTrue($address->isCountry("AF")); + } + + public function testAddressIsCountryFuzzyMisMatch() + { + $address = new Address(); + $address->country = "Afganistan"; + $this->assertFalse($address->isCountry("GB")); + } + + public function testCountryIsGB_NoStreetAddress1() + { + $address = new Address(); + $address->country = 'GB'; + $address->postalCode = 'E77 4Qj'; + + $this->assertNotNull($address->countryCode); + $this->assertTrue($address->isCountry('GB')); + + $card = new \GlobalPayments\Api\PaymentMethods\CreditCardData(); + $card->number = "4111111111111111"; + $card->expMonth = 12; + $card->expYear = 2025; + $card->cvn = "123"; + $card->cardHolderName = "Joe Smith"; + + $config = new GpEcomConfig(); + $config->merchantId = 'heartlandgpsandbox'; + $config->accountId = 'api'; + $config->sharedSecret = 'secret'; + $config->rebatePassword = 'rebate'; + $config->refundPassword = 'refund'; + + ServicesContainer::configureService($config); + + $response = $card->charge(10) + ->withCurrency('USD') + ->withAddress($address) + ->execute(); + + $this->assertNotNull($response); + $this->assertEquals('00', $response->responseCode); + } + + public function testGetNumericCodeByCountryCode() + { + $result = CountryUtils::getNumericCodeByCountry('US'); + $this->assertNotNull($result); + $this->assertEquals('840', $result); + } + + public function testGetNumericCodeByCountry() + { + $result = CountryUtils::getNumericCodeByCountry('United State of America'); + $this->assertNotNull($result); + $this->assertEquals('840', $result); + } + public function testGetNumericCodeByFakeCountry() + { + $result = CountryUtils::getNumericCodeByCountry('FakeCountry'); + $this->assertNull($result); + } +} \ No newline at end of file diff --git a/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php b/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php index 22bc2db6..b832c2ec 100644 --- a/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php +++ b/test/Integration/Gateways/GpApiConnector/CreditCardNotPresentTest.php @@ -4,6 +4,7 @@ namespace Gateways\GpApiConnector; use GlobalPayments\Api\Entities\Address; +use GlobalPayments\Api\Entities\CustomWebProxy; use GlobalPayments\Api\Entities\Enums\Environment; use GlobalPayments\Api\Entities\Enums\GpApi\Channels; use GlobalPayments\Api\Entities\Enums\StoredCredentialInitiator; @@ -911,11 +912,12 @@ public function setUpConfig() $config = new GpApiConfig(); $accessTokenInfo = new AccessTokenInfo(); //this is gpapistuff stuff - $config->setAppId('VuKlC2n1cr5LZ8fzLUQhA7UObVks6tFF'); - $config->setAppKey('NmGM0kg92z2gA7Og'); - $config->environment = Environment::TEST; + $config->setAppId('i872l4VgZRtSrykvSn8Lkah8RE1jihvT'); + $config->setAppKey( '9pArW2uWoA8enxKc'); $config->setAccessTokenInfo($accessTokenInfo); $config->setChannel(Channels::CardNotPresent); + $config->environment = Environment::TEST; +// $config->webProxy = new CustomWebProxy('127.0.0.1:8866'); return $config; } diff --git a/test/Integration/Gateways/RealexConnector/Certifications/SdkTest.php b/test/Integration/Gateways/RealexConnector/Certifications/SdkTest.php index 5b4ebfa5..e0456410 100644 --- a/test/Integration/Gateways/RealexConnector/Certifications/SdkTest.php +++ b/test/Integration/Gateways/RealexConnector/Certifications/SdkTest.php @@ -4349,7 +4349,7 @@ public function testAVS001a() // billing address $billingAddress = new Address(); - $billingAddress->StreetAddress1 = "Flat 123 House 456"; + $billingAddress->streetAddress1 = "Flat 123 House 456"; $billingAddress->postalCode = "E77 4QJ"; $billingAddress->country = "GB"; @@ -4390,7 +4390,7 @@ public function testAVS001b() // billing address $billingAddress = new Address(); - $billingAddress->StreetAddress1 = "Flat #123 House No. 456"; + $billingAddress->streetAddress1 = "Flat #123 House No. 456"; $billingAddress->postalCode = "E77 #4QJ"; $billingAddress->country = "GB"; @@ -4431,7 +4431,7 @@ public function testAVS001c() // billing address $billingAddress = new Address(); - $billingAddress->StreetAddress1 = "# Flat #123 House No. #456"; + $billingAddress->streetAddress1 = "# Flat #123 House No. #456"; $billingAddress->postalCode = "# E77 @~4 Q # J"; $billingAddress->country = "GB"; @@ -4511,7 +4511,7 @@ public function testAVS001e() // billing address $billingAddress = new Address(); - $billingAddress->StreetAddress1 = "Lorem ipsum dolor sit 1amet; consectetur adipiscing elit. Aenean ali2quam tellus in elit hendrerit; non 3porttE77 4QJitor lorem venenatis. Pellentesque dictum eu nunc ac fringilla. In vitae quam eu odio sollicitudin rhoncus. Praesent ullamcorper eros vitae consequat tempus. In gravida viverra iaculis. Morbi dignissim orci et ipsum accumsan"; + $billingAddress->streetAddress1 = "Lorem ipsum dolor sit 1amet; consectetur adipiscing elit. Aenean ali2quam tellus in elit hendrerit; non 3porttE77 4QJitor lorem venenatis. Pellentesque dictum eu nunc ac fringilla. In vitae quam eu odio sollicitudin rhoncus. Praesent ullamcorper eros vitae consequat tempus. In gravida viverra iaculis. Morbi dignissim orci et ipsum accumsan"; $billingAddress->postalCode = "Lorem ipsum dolo1r sit amet; consectetur adipiscing elit. Aenean aliquam tellus in elit hendrerit; non porttE77 4QJitor lorem venenatis. Pellentesque dictum eu2 nunc ac fringilla. In vitae quam eu 3odio sollicitudin rhoncus. Praesent ullamcorper eros vitae consequat tempus. In gravida viverra iaculis. Morbi dignissim orci et ipsum accumsan"; $billingAddress->country = "GB"; @@ -4552,7 +4552,7 @@ public function testAVS001f() // billing address $billingAddress = new Address(); - $billingAddress->StreetAddress1 = "ABCDEFGHIJ"; + $billingAddress->streetAddress1 = "ABCDEFGHIJ"; $billingAddress->postalCode = "ABCDEFGHIJ"; $billingAddress->country = "GB"; @@ -4593,7 +4593,7 @@ public function testAVS001g() // billing address $billingAddress = new Address(); - $billingAddress->StreetAddress1 = "Lorem ipsum dolor sit amet; consectetur adipiscing elit. Aenean aliquam tellus in elit hendrerit; non porttE77 4QJitor lorem venenatis. Pellentesque dictum eu nunc ac fringilla. In vitae quam eu odio sollicitudin rhoncus. Praesent ullamcorper eros vitae consequat tempus. In gravida viverra iaculis. Morbi dignissim orci et ipsum accumsan"; + $billingAddress->streetAddress1 = "Lorem ipsum dolor sit amet; consectetur adipiscing elit. Aenean aliquam tellus in elit hendrerit; non porttE77 4QJitor lorem venenatis. Pellentesque dictum eu nunc ac fringilla. In vitae quam eu odio sollicitudin rhoncus. Praesent ullamcorper eros vitae consequat tempus. In gravida viverra iaculis. Morbi dignissim orci et ipsum accumsan"; $billingAddress->postalCode = "Lorem ipsum dolor sit amet; consectetur adipiscing elit. Aenean aliquam tellus in elit hendrerit; non porttE77 4QJitor lorem venenatis. Pellentesque dictum eu nunc ac fringilla. In vitae quam eu odio sollicitudin rhoncus. Praesent ullamcorper eros vitae consequat tempus. In gravida viverra iaculis. Morbi dignissim orci et ipsum accumsan"; $billingAddress->country = "GB"; @@ -4634,7 +4634,7 @@ public function testAVS003a() // billing address $billingAddress = new Address(); - $billingAddress->StreetAddress1 = "Flat 123 House 456"; + $billingAddress->streetAddress1 = "Flat 123 House 456"; $billingAddress->postalCode = "E77 4QJ"; $billingAddress->country = "GB"; @@ -4675,7 +4675,7 @@ public function testAVS003b() // billing address $billingAddress = new Address(); - $billingAddress->StreetAddress1 = "Flat 123 House 456"; + $billingAddress->streetAddress1 = "Flat 123 House 456"; $billingAddress->postalCode = "E77 4QJ"; $billingAddress->country = "GB"; @@ -4716,7 +4716,7 @@ public function testAVS003c() // billing address $billingAddress = new Address(); - $billingAddress->StreetAddress1 = "Flat 123 House 456"; + $billingAddress->streetAddress1 = "Flat 123 House 456"; $billingAddress->postalCode = "E77 4QJ"; $billingAddress->country = "GB"; @@ -4757,7 +4757,8 @@ public function testAVS003d() // billing address $billingAddress = new Address(); - $billingAddress->StreetAddress1 = "Flat 123 House 456"; + + $billingAddress->streetAddress1 = "Flat 123 House 456"; $billingAddress->postalCode = "E77 4QJ"; $billingAddress->country = "GB"; @@ -4798,7 +4799,7 @@ public function testAVS003e() // billing address $billingAddress = new Address(); - $billingAddress->StreetAddress1 = "Flat 123 House 456"; + $billingAddress->streetAddress1 = "Flat 123 House 456"; $billingAddress->postalCode = "E77 4QJ"; $billingAddress->country = "GB"; @@ -4839,7 +4840,7 @@ public function testAVS003f() // billing address $billingAddress = new Address(); - $billingAddress->StreetAddress1 = "Flat 123 House 456"; + $billingAddress->streetAddress1 = "Flat 123 House 456"; $billingAddress->postalCode = "E77 4QJ"; $billingAddress->country = "GB"; diff --git a/test/Integration/Gateways/RealexConnector/HppTest.php b/test/Integration/Gateways/RealexConnector/HppTest.php index 8d0ca1dc..f11f199b 100644 --- a/test/Integration/Gateways/RealexConnector/HppTest.php +++ b/test/Integration/Gateways/RealexConnector/HppTest.php @@ -414,12 +414,16 @@ public function testFraudManagementRequest() // billing address $billingAddress = new Address(); - $billingAddress->postalCode = "50001|Flat 123"; + $billingAddress->streetAddress1 = 'Flat 123'; + $billingAddress->streetAddress2 = 'House 456'; + $billingAddress->postalCode = "50001"; $billingAddress->country = "US"; // shipping address $shippingAddress = new Address(); - $shippingAddress->postalCode = "654|123"; + $shippingAddress->streetAddress1 = 'Flat 456'; + $shippingAddress->streetAddress2 = 'House 123'; + $shippingAddress->postalCode = "WB3 A21"; $shippingAddress->country = "GB"; // data to be passed to the HPP along with transaction level settings diff --git a/test/Integration/Gateways/RealexConnector/RecurringTest.php b/test/Integration/Gateways/RealexConnector/RecurringTest.php index 357cc2e5..0fed5ccf 100644 --- a/test/Integration/Gateways/RealexConnector/RecurringTest.php +++ b/test/Integration/Gateways/RealexConnector/RecurringTest.php @@ -74,7 +74,7 @@ public function setup() $this->newCustomer->address->streetAddress3 = "The Cul-De-Sac"; $this->newCustomer->address->city = "Halifax"; $this->newCustomer->address->province = "West Yorkshire"; - $this->newCustomer->address->pstalCode = "W6 9HR"; + $this->newCustomer->address->postalCode = "W6 9HR"; $this->newCustomer->address->country = "United Kingdom"; $this->newCustomer->homePhone = "+35312345678"; $this->newCustomer->workPhone = "+3531987654321";