Skip to content

Commit

Permalink
Accept longer RFC 5646 language codes as well as the required ISO 639-1.
Browse files Browse the repository at this point in the history
  • Loading branch information
judgej committed Jun 7, 2017
1 parent c96f28c commit 9978891
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 26 additions & 1 deletion src/Message/AbstractCheckoutRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -173,7 +198,7 @@ public function getBaseData()
{
$data = array(
'customerId' => $this->getCustomerId(),
'language' => $this->getLanguage(),
'language' => $this->getLanguageCode(),
'shopId' => $this->getShopId(),
);

Expand Down

0 comments on commit 9978891

Please sign in to comment.