Skip to content

Commit

Permalink
Issue #5 support naive custom fields; bit of refactoring (renaming tr…
Browse files Browse the repository at this point in the history
…ait).
  • Loading branch information
judgej committed Jul 31, 2017
1 parent 3124903 commit 9fdc8b1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions src/AbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

namespace Omnipay\Wirecard\Message;
namespace Omnipay\Wirecard;

/**
* Manage common parameters shared betweem the gateway and the message levels.
* Manage common parameters shared between the gateway and the message levels.
* These cover authentication and other global parameters that apply to all
* gateways.
*/

use Omnipay\Common\Exception\InvalidRequestException;

trait ParametersTrait
trait CommonParametersTrait
{
/**
* The Customer ID is the merchant account ID string.
Expand Down
3 changes: 2 additions & 1 deletion src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
*/

use Omnipay\Common\Message\AbstractRequest as OmnipayAbstractRequest;
use Omnipay\Wirecard\CommonParametersTrait;
use Omnipay\Wirecard\Extend\ItemInterface;
use Omnipay\Common\ItemBag;

abstract class AbstractRequest extends OmnipayAbstractRequest
{
// Shared gateway/message properties.
use ParametersTrait;
use CommonParametersTrait;

// Access to the constants as lists.
use HasConstantListsTrait;
Expand Down
35 changes: 28 additions & 7 deletions src/Message/Checkout/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class AbstractRequest extends MessageAbstractRequest
const AUTO_DEPOSIT_YES = 'yes';
const AUTO_DEPOSIT_NO = 'no';

// The name of the custom field the transacton ID will go into.
// The name of the custom field the transaction ID will go into.
const CUSTOM_FIELD_NAME_TRANSACTION_ID = 'omnipay_transactionId';

/**
Expand Down Expand Up @@ -89,6 +89,23 @@ public function getRiskConfigAlias()
return $this->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.
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 9fdc8b1

Please sign in to comment.