diff --git a/README.md b/README.md index b9ac5ed..467f18f 100644 --- a/README.md +++ b/README.md @@ -400,7 +400,7 @@ It works like this: for the payment. These details are not posted back to the merchant site. * JavaScript sends the authorisation details entered by the user to the data store using AJAX. -* Optioanlly, the data store JavaScript can provide anonymised versions of the data +* Optionally, the data store JavaScript can provide anonymised versions of the data entered, which can be posted back to the merchant site if required. * The merchant site then posts the authorisation or purchase transaction request to the remote gateway, using the `storageId` in place of credit card details. diff --git a/src/Message/AbstractCheckoutRequest.php b/src/Message/AbstractCheckoutRequest.php index 0147f85..1660638 100644 --- a/src/Message/AbstractCheckoutRequest.php +++ b/src/Message/AbstractCheckoutRequest.php @@ -164,6 +164,31 @@ public function getRiskConfigAlias() return $this->getParameter('riskConfigAlias'); } + /** + * Get the ISO 639-1 (two-letter) language code. + * This may need to be extracted from a longer supplied language code. + */ + protected function getLanguageCode() + { + $code = $this->getLanguage(); + + // If the language contains more than two characters, then *assume* it + // is a longer ISO code, e.g. "en-GB" or "de-DE" (RFC 5646). + // We could add further validation at this stage, but we'll leave that + // for a future Omnipay if we can get a language object in to stadardise + // the language handling. + + if (is_string($code)) { + if (strlen($code) > 2) { + $code = substr($code, 0, 2); + } + + $code = strtolower($code); + } + + return $code; + } + /** * Construct the request data to send. * @@ -173,7 +198,7 @@ public function getBaseData() { $data = array( 'customerId' => $this->getCustomerId(), - 'language' => $this->getLanguage(), + 'language' => $this->getLanguageCode(), 'shopId' => $this->getShopId(), );