Skip to content

Commit

Permalink
Issue #6 fetch the cardReference during completion, if the user reque…
Browse files Browse the repository at this point in the history
…sts it.
  • Loading branch information
judgej committed Feb 28, 2018
1 parent 2ccac1e commit 3387e28
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 24 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,20 @@ $getCardResponse->getExpiryYear();
$getCardResponse->getExpiryMonth();
```

**Note:** The fetching of the card reference can be automated when completing
an authorisation, by setting the `createCard` parameter when completing:

```php
$completeRequest = $gateway->completeAuthorize([
'createCard' => true,
]);
$completeResponse = $completeRequest->send();

echo 'Card Ref: ' . $completeResponse->getCardReference();

// Card Ref: 6317fda4cce2192fecc51ba244a91a08
```

The `$cardReference` is then used for authorizing:

```php
Expand Down
18 changes: 18 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function getDefaultParameters()
'projectPassphrase' => '',
'language' => 'de',
'paymentPage' => true,
'createCard' => false,
'paymentType' => static::PAYMENT_TYPE_CREDIT_CARD,
];
}
Expand Down Expand Up @@ -162,6 +163,23 @@ public function setPaymentPage($value)
return $this->setParameter('paymentPage', $value);
}

/**
* @return mixed
*/
public function getCreateCard()
{
return $this->getParameter('createCard');
}

/**
* @param mixed $value A value that will later be cast to true/false
* @return $this
*/
public function setCreateCard($value)
{
return $this->setParameter('createCard', $value);
}

/**
* @param bool $assertValidation True to assert validation rules on the value
* @return string
Expand Down
22 changes: 22 additions & 0 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,23 @@ public function setPaymentType($value)
return $this->setParameter('paymentType', $value);
}

/**
* @return mixed
*/
public function getCreateCard()
{
return $this->getParameter('createCard');
}

/**
* @param mixed $value A value that will later be cast to true/false
* @return $this
*/
public function setCreateCard($value)
{
return $this->setParameter('createCard', $value);
}

/**
* Get the language string, in one of the supported formats.
* Returns an empty string if no valid format could be found.
Expand Down Expand Up @@ -343,6 +360,11 @@ public function responseHash($responseBody)
}

/**
* Retieve all parameters used as notification parameters,
* and in the correct order for hash validation. Additional
* parameters, some of which may be supplied by the merchant
* site, are ignored.
*
* @return array
*/
protected function getNotificationData()
Expand Down
17 changes: 0 additions & 17 deletions src/Message/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,23 +651,6 @@ public function setRecurring($value)
return $this->setParameter('recurring', $value);
}

/**
* @return mixed
*/
public function getCreateCard()
{
return $this->getParameter('createCard');
}

/**
* @param mixed $value A value that will later be cast to true/false
* @return $this
*/
public function setCreateCard($value)
{
return $this->setParameter('createCard', $value);
}

/**
* @return mixed
*/
Expand Down
20 changes: 13 additions & 7 deletions src/Message/CompleteRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public function sendData($data)
$pkn = !empty($data['gcPkn']) ? $data['gcPkn'] : null;

// Here, if we don't have the pkn details, then try to fetch them.
// It is disabled for now, as it fails the tests due to an invalid
// hash, through it does work in production. Perhaps tis can be
// turned on explicitly with the "createCard" option, until we can
// revisit the tests.
// These are the pseudo card details for saving and reusing.
// Basically, we want to suplement the data we have got, with data
// from an additional API call.
// The "createCard" parameter must be set to trigger this action.

if (false && $success && empty($pkn) && !empty($transactionReference)) {
if ($this->getCreateCard() && $success && empty($pkn) && !empty($transactionReference)) {
// Create a new gateway since we don't have access to the current
// gateway from here.
// gateway object from here.

$gateway = \Omnipay\Omnipay::create('GiroCheckout');
$gateway->initialize($this->getParameters());
Expand All @@ -59,6 +59,8 @@ public function sendData($data)
$cardData = $response->getData();

// Map card fields to fields that the Payment Page already uses.
// If the original authorisation request was issued without the
// "createCard" option set, then these details will not be availeble.

if (! empty($cardData['pkn'])) {
$data['gcPkn'] = $cardData['pkn'];
Expand All @@ -68,8 +70,12 @@ public function sendData($data)
$data['gcCardnumber'] = $cardData['cardnumber'];
}

// This endpoint returns the expiry date in two parts.
// The Payment Page APi returns the expiry date as one string.
// We will normalise the two parts to the format of the one string.

if (! empty($cardData['expireyear']) && ! empty($cardData['expiremonth'])) {
$data['gcCardExpDate'] = $cardData['expiremonth'] . '/' . $data['expireyear'];
$data['gcCardExpDate'] = $cardData['expiremonth'] . '/' . $cardData['expireyear'];
}
}

Expand Down

0 comments on commit 3387e28

Please sign in to comment.