-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add transaction verification call to the workflow.
- Loading branch information
1 parent
d8f4eef
commit d4d257c
Showing
5 changed files
with
128 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Ampeco\OmnipayApcopay\Message; | ||
|
||
use Omnipay\Common\Message\ResponseInterface; | ||
|
||
class GetTransactionRequest extends AbstractRequest | ||
{ | ||
private const API_GET_TRANSACTION_ENDPOINT = '/MerchantTools/MerchantTools.svc/getTransactionsByORef'; | ||
|
||
public function getEndpoint(): string | ||
{ | ||
return self::API_GET_TRANSACTION_ENDPOINT; | ||
} | ||
|
||
protected function createResponse(array $data, int $statusCode): ResponseInterface | ||
{ | ||
return new GetTransactionResponse($this, $data, $statusCode, $this->getTrnType()); | ||
} | ||
|
||
public function getData(): array | ||
{ | ||
return [ | ||
'MerchID' => $this->getMerchantCode(), | ||
'MerchPass' => $this->getMerchantPassword(), | ||
'Oref' => $this->getReference(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Ampeco\OmnipayApcopay\Message; | ||
|
||
use Omnipay\Common\Message\AbstractResponse; | ||
use Omnipay\Common\Message\RequestInterface; | ||
|
||
class GetTransactionResponse extends AbstractResponse | ||
{ | ||
private const BANK_ACCEPT_YES = 'YES'; | ||
private const RESULT_OK = 'OK'; | ||
|
||
private ?string $transactionStatus; | ||
private ?string $transactionReference; | ||
|
||
public function __construct(RequestInterface $request, array $data, private int $code, private string $trnType) | ||
{ | ||
$this->transactionStatus = null; | ||
$this->transactionReference = null; | ||
|
||
parent::__construct($request, $data); | ||
$this->setTransactionData(); | ||
} | ||
|
||
public function isSuccessful() : bool | ||
{ | ||
return $this->code == 200 && isset($this->data['Result']) && $this->data['Result'] == self::RESULT_OK; | ||
} | ||
|
||
public function getTransactionStatus(): ?string | ||
{ | ||
return $this->transactionStatus; | ||
} | ||
|
||
public function getTransactionReference(): ?string | ||
{ | ||
return $this->transactionReference; | ||
} | ||
|
||
private function setTransactionData(): void | ||
{ | ||
if (!isset($this->data['Transactions']) || !is_array($this->data['Transactions'])) { | ||
return; | ||
} | ||
|
||
foreach ($this->data['Transactions'] as $transaction) { | ||
if (isset($transaction['TrnType']) && $transaction['TrnType'] === $this->trnType | ||
&& isset($transaction['BankAccept']) && $transaction['BankAccept'] === self::BANK_ACCEPT_YES | ||
) { | ||
$this->transactionStatus = $transaction['BankResponse'] ?? null; | ||
$this->transactionReference = $transaction['PSPID'] ?? null; | ||
} | ||
} | ||
} | ||
} |