Skip to content

Commit

Permalink
Backend purchase and authorize using a cardReference (working).
Browse files Browse the repository at this point in the history
  • Loading branch information
judgej committed Apr 8, 2018
1 parent 264a406 commit 6131fa7
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 26 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ A separate gateway is used to do offline payments, initialized using the
same parameters as the redirect gateway, but like this:

```php
$gateway = Omnipay::create('Datatrans\Xml');
$xmlGateway = Omnipay::create('Datatrans\Xml');
```

If the `cardReference` was for a credit card, then the expiry date must be
Expand All @@ -259,21 +259,23 @@ $card = new \Omnipay\Common\CreditCard([
'number' => $cardReference,
]);

$response = $gateway->authorize([
//$response = $xmlGateway->purchase([
$response = $xmlGateway->authorize([
'card' => $card,
// Supply the card reference here if not in the $card object:
'cardReference' => $cardReference,
'amount' => '20.00',
'currency' => 'EUR',
'transactionId' => $transactionId,
// The original payment method
'paymentMethod' => Omnipay\Datatrans\Gateway::PAYMENT_PAYMENT_METHOD__VIS,
'paymentMethod' => \Omnipay\Datatrans\Gateway::PAYMENT_PAYMENT_METHOD_VIS,
])->send();
```

*Note: I have not seen offline authorization working yet.
I suspect it is a problem with the settings on my sandbox account,
but cannot yet be sure.*
For non-credit card payment methods, the `CreditCard` object is not needed since
there will be no expiry date. Just the previously saved `cardReference` is passed
in. The `cardReference` is a generic term used for a number of card and non-card
payment methods.

## Hidden Mode

Expand All @@ -292,19 +294,17 @@ It is not supported by this release of the driver drue to the PCI requirements i
* virtualCardno
* uppStartTarget
* uppReturnTarget
* uppTermsLink An external link to the merchant’s terms and conditions. Will be
* uppTermsLink An external link to the merchant’s terms and conditions
* uppDiscountAmount
* mode
* Customer name and address details
* Customer name and address details (this varies across payment methods)
* Basket details

### Functionality

* Additional parameters and results for different payment PAYMENT_METHOD_s
* Secure 3D support where applicable
* Capture of customer address when using PayPal
* Authorize and purchase on previous payments
* Authorize and purchase on card token (subscriptions)
* Support lightbox mode (iframe)
* Support inline mode (JavaScript)

6 changes: 5 additions & 1 deletion src/Interfaces/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
interface Constants
{
/**
* @var string reqtype parameter to indicate authorize only vs settle immediately
* @var string authorize only
*/
const REQTYPE_AUTHORIZE = 'NOA';

/**
* @var string authorize and settle immediately
*/
const REQTYPE_PURCHASE = 'CAA';

/**
Expand Down
14 changes: 13 additions & 1 deletion src/Message/AcceptNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@ class AcceptNotification extends AbstractNotification
use HasGatewayParameters;
use HasSignatureVerifier;

/**
* @var array the data sent from the gateway, parsed into a flat array.
*/
protected $data;

/**
* @return array
*/
public function getData()
{
return Helper::getRemoteData($this->httpRequest);
// Cache the data the first time we fetch it, as parsing the XML
// data can be intensive, and is called many times.

if ($this->data === null) {
$this->data = Helper::getRemoteData($this->httpRequest);
}

return $this->data;
}

/**
Expand Down
32 changes: 20 additions & 12 deletions src/Message/XmlAuthorizationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
*
* @package Omnipay\Datatrans\Message
*/

use Omnipay\Datatrans\Gateway;

class XmlAuthorizationRequest extends AbstractXmlRequest
{
/**
* @var array
*/
protected $optionalParameters = array(
'reqtype',
'uppCustomerIpAddress'
);

Expand All @@ -46,6 +48,11 @@ class XmlAuthorizationRequest extends AbstractXmlRequest
*/
protected $serviceVersion = 3;

/**
* Inidates authorize only.
*/
protected $requestType = Gateway::REQTYPE_AUTHORIZE;

/**
* This returns the data used for the "request" element of the XML request
* data. This is further wrapped with the merchant ID and transaction ID
Expand All @@ -55,13 +62,22 @@ class XmlAuthorizationRequest extends AbstractXmlRequest
*/
public function getData()
{
$this->validate('merchantId', 'transactionId', 'sign');
// The request type Determines whether the transaction is authorized
// only, or settled immediately.

$data = array(
'amount' => $this->getAmountInteger(),
'currency' => $this->getCurrency(),
'amount' => $this->getAmountInteger(),
'currency' => $this->getCurrency(),
'reqtype' => $this->getRequestType(),
);

// We probably need to filter out non-IPv4 addresses.
// That should actually be a core Omnipay fundion.

if ($this->getClientIp()) {
$data['uppCustomerIpAddress'] = $this->getClientIp();
}

// Some assumptions here.
// If the card object is supplied, and it has an expiry date set,
// then assume this is a card payment. Otherwise assume this is a
Expand All @@ -87,14 +103,6 @@ public function getData()
$data['pmethod'] = $this->getPaymentMethod();
}

foreach ($this->optionalParameters as $param) {
$value = $this->getParameter($param);

if ($value) {
$data[$param] = $value;
}
}

return $data;
}

Expand Down
13 changes: 13 additions & 0 deletions src/Message/XmlPurchaseRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Omnipay\Datatrans\Message;

use Omnipay\Datatrans\Gateway;

class XmlPurchaseRequest extends XmlAuthorizationRequest
{
/**
* Inidates authorize and settle.
*/
protected $requestType = Gateway::REQTYPE_PURCHASE;
}
5 changes: 3 additions & 2 deletions src/XmlGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use Omnipay\Datatrans\Message\TokenizeRequest;
use Omnipay\Datatrans\Message\XmlAuthorizationRequest;
use Omnipay\Datatrans\Message\XmlPurchaseRequest;
use Omnipay\Datatrans\Message\XmlSettlementRequest;
use Omnipay\Datatrans\Message\XmlSettlementCreditRequest;
use Omnipay\Datatrans\Message\XmlCancelRequest;
Expand All @@ -39,11 +40,11 @@ public function getName()

/**
* @param array $options
* @return XmlAuthorizationRequest
* @return XmlPurchaseRequest
*/
public function purchase(array $options = array())
{
return $this->authorize($options);
return $this->createRequest(XmlPurchaseRequest::class, $options);
}

/**
Expand Down

0 comments on commit 6131fa7

Please sign in to comment.