Skip to content

Commit

Permalink
Perform the cardRerence fetch only for certain payment types.
Browse files Browse the repository at this point in the history
  • Loading branch information
judgej committed Mar 1, 2018
1 parent 7840b77 commit a741066
Showing 1 changed file with 52 additions and 43 deletions.
95 changes: 52 additions & 43 deletions src/Message/CompleteRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,49 +33,58 @@ public function sendData($data)
{
$this->validateNotificationData($data);

$gcResultPayment = !empty($data['gcResultPayment']) ? $data['gcResultPayment'] : null;
$success = ($gcResultPayment == Gateway::RESULT_PAYMENT_SUCCESS);

$transactionReference = !empty($data['gcReference']) ? $data['gcReference'] : null;
$pkn = !empty($data['gcPkn']) ? $data['gcPkn'] : null;

// Here, if we don't have the pkn details, then try to fetch them.
// 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 ($this->getCreateCard() && $success && empty($pkn) && !empty($transactionReference)) {
// Create a new gateway since we don't have access to the current
// gateway object from here.

$gateway = \Omnipay\Omnipay::create('GiroCheckout');
$gateway->initialize($this->getParameters());
$getCardRequest = $gateway->getCard([
'transactionReference' => $data['gcReference'],
]);
$response = $getCardRequest->send();

$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'];
}

if (! empty($cardData['cardnumber'])) {
$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'] . '/' . $cardData['expireyear'];
$paymentType = $this->getPaymentType();

// The cardReference may be available for a handlful of payment types.

if (
$paymentType === Gateway::PAYMENT_TYPE_CREDIT_CARD
|| $paymentType === Gateway::PAYMENT_TYPE_DIRECTDEBIT
) {
$gcResultPayment = !empty($data['gcResultPayment']) ? $data['gcResultPayment'] : null;
$success = ($gcResultPayment == Gateway::RESULT_PAYMENT_SUCCESS);

$transactionReference = !empty($data['gcReference']) ? $data['gcReference'] : null;
$pkn = !empty($data['gcPkn']) ? $data['gcPkn'] : null;

// Here, if we don't have the pkn details, then try to fetch them.
// 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 ($this->getCreateCard() && $success && empty($pkn) && !empty($transactionReference)) {
// Create a new gateway since we don't have access to the current
// gateway object from here.

$gateway = \Omnipay\Omnipay::create('GiroCheckout');
$gateway->initialize($this->getParameters());
$getCardRequest = $gateway->getCard([
'transactionReference' => $data['gcReference'],
]);
$response = $getCardRequest->send();

$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'];
}

if (! empty($cardData['cardnumber'])) {
$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'] . '/' . $cardData['expireyear'];
}
}
}

Expand Down

0 comments on commit a741066

Please sign in to comment.