Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Enable CCV and AVS Status in Magento 2 for Signifyd #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Helper/MonetraInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ public function refund($ttid, $amount)
}
}

public function transaction($ttid)
{
return $this->request('GET', 'transaction/' . $ttid);
}

public function request($credentials, $method, $path, $data = [])
{
$url = $this->origin . '/api/v2/' . $path;
Expand Down
22 changes: 22 additions & 0 deletions Model/ClientTicket.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ public function authorize(\Magento\Payment\Model\InfoInterface $payment, $amount
$transaction_id .= "-" . $response['token'];
}

$this->handleSignify($transaction_id, $payment);

$payment->setTransactionId($transaction_id);
$payment->setIsTransactionClosed(false);

Expand Down Expand Up @@ -270,6 +272,8 @@ public function capture(\Magento\Payment\Model\InfoInterface $payment, $amount)
$this->handleAuthResponse($response, $payment, $paymentToken);
}

$this->handleSignify($response['ttid'], $payment);

$payment->setTransactionId($response['ttid']);

return $this;
Expand Down Expand Up @@ -430,4 +434,22 @@ private static function getTTIDAndTokenFromTransactionId($transaction_id)
return [$ttid, $token];
}

private function handleSignify($transaction_id, $payment)
{
// Maping
$CcvStatusMap = ['GOOD' => 'M', 'BAD' => 'N', 'UNKNOWN' => 'M'];
$AvsStatusMap = ['GOOD' => 'Y', 'BAD' => 'N', 'STREET' => 'Z', 'ZIP' => 'A', 'UNKNOWN' => 'Y'];

// Get Transaction Details
$transaction = $this->monetraInterface->transaction($transaction_id);
$expDate = \DateTime::createFromFormat('my', $transaction['expdate'] ?? '0101');
$expDateMonth = $expDate->format('n') ?? date('n');
$expDateYear = $expDate->format('Y') ?? date('Y');

$payment->setCcCidStatus($CcvStatusMap[$transaction['cv'] ?? 'BAD']);
$payment->setCcAvsStatus($AvsStatusMap[$transaction['avs'] ?? 'BAD']);
$payment->setCcExpMonth($expDateMonth);
$payment->setCcExpYear($expDateYear);
}

}