From 9fdc8b1cb45de3e6027f963344e02ad8cd21229a Mon Sep 17 00:00:00 2001 From: Jason Judge Date: Mon, 31 Jul 2017 13:00:14 +0100 Subject: [PATCH] Issue #5 support naive custom fields; bit of refactoring (renaming trait). --- README.md | 4 +-- src/AbstractGateway.php | 3 +- ...ersTrait.php => CommonParametersTrait.php} | 6 ++-- src/Message/AbstractRequest.php | 3 +- src/Message/Checkout/AbstractRequest.php | 35 +++++++++++++++---- 5 files changed, 36 insertions(+), 15 deletions(-) rename src/{Message/ParametersTrait.php => CommonParametersTrait.php} (96%) diff --git a/README.md b/README.md index e029b26..01db3f3 100644 --- a/README.md +++ b/README.md @@ -640,9 +640,9 @@ instructions, which may or may not involve a 3D Secure redirect. A transaction on the gateway is uniquely identified *within an account* by a numeric seven-digit value. The order number will be generated on the creation of a transaction, -or it can be generated in advance if that helps the merchant site processes. +or it can be generated in advance if that helps the merchant site workflow. -To generate, i.e. reservce in advance, an order number, use this method: +To generate, i.e. reserve in advance, an order number, use this method: ```php $response = $gateway->createOrderNumber()->send(); diff --git a/src/AbstractGateway.php b/src/AbstractGateway.php index 79d8284..347a639 100644 --- a/src/AbstractGateway.php +++ b/src/AbstractGateway.php @@ -8,12 +8,11 @@ use Omnipay\Common\AbstractGateway as OmnipayAbstractGateway; use Omnipay\Common\Exception\InvalidRequestException; -use Omnipay\Wirecard\Message\ParametersTrait; abstract class AbstractGateway extends OmnipayAbstractGateway { // Shared gateway/message properties. - use ParametersTrait; + use CommonParametersTrait; /** * diff --git a/src/Message/ParametersTrait.php b/src/CommonParametersTrait.php similarity index 96% rename from src/Message/ParametersTrait.php rename to src/CommonParametersTrait.php index 11ccfd4..ea9cafc 100644 --- a/src/Message/ParametersTrait.php +++ b/src/CommonParametersTrait.php @@ -1,16 +1,16 @@ getParameter('riskConfigAlias'); } + /** + * Set all custom parameters. + * There are no checks on the validity or format of the custom parameter + * names or values here. Just use as needed. + * + * @param array $value All custom parameters as key/value pairs. + */ + public function setCustomParameters(array $value) + { + return $this->setParameter('customParameters', $value); + } + + public function getCustomParameters() + { + return $this->getParameter('customParameters'); + } + /** * Get the ISO 639-1 (two-letter) language code. * This may need to be extracted from a longer supplied language code. @@ -241,17 +258,21 @@ public function getBaseData() $data['riskConfigAlias'] = $this->getRiskConfigAlias(); } - // TODO: Custom fields (probably a collection of names and values). - // It looks like custom fields are the only reliable way to tie back - // the back-channel notifications to the transaction in storage. - // We may need to create a predefined custom field for the - // transactionId, so the notification handler knows where to find it. - + // It looks like custom fields are the only reliable way to tie + // the notifications in the back-channel to the transaction in storage. // Put the transaction ID into a custom field. + if ($this->getTransactionId()) { $data[static::CUSTOM_FIELD_NAME_TRANSACTION_ID] = $this->getTransactionId(); } + // Additional custom parameters have been provided. + if ($customParameters = $this->getCustomParameters()) { + foreach($customParameters as $name => $value) { + $data[$name] = $value; + } + } + return $data; } }