Skip to content

Commit

Permalink
Refactor GetToken Request & Response classes
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinDamyanovAmpeco committed Jan 11, 2024
1 parent 20d7a0a commit e868902
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ampeco/omnipay-cardcom",
"description": "Omnipay plugin for Cardcom payment gateway",
"version": "1.0.0",
"version": "1.1.0",
"type": "library",
"license": "MIT",
"autoload": {
Expand Down
6 changes: 3 additions & 3 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public function getCreateCardAmount(): int
return 1;
}

public function getToken(array $requestData)
public function getToken(array $options = [])
{
return $this->createRequest(GetTokenRequest::class, $requestData)->send();
return $this->createRequest(GetTokenRequest::class, $options);
}

public function authorize(array $options = [])
Expand All @@ -96,7 +96,7 @@ public function void(array $options = [])
return $this->createRequest(VoidRequest::class, $options);
}

public function fetchTransaction(array $options = [])
public function query(array $options = [])
{
return $this->createRequest(FetchTransactionRequest::class, $options);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Message/GetTokenRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public function getData()
return [
'TerminalNumber' => $this->gateway->getTerminalId(),
'ApiName' => $this->gateway->getApiName(),
'LowProfileId' => $this->getGateway()->getLowProfileId(),
'LowProfileId' => $this->getTransactionReference(),
];
}

protected function createResponse($data, $statusCode)
{
return $this->response = new GetTokenResponse($this, $data, $statusCode, $this->gateway->getUserId());
return $this->response = new GetTokenResponse($this, $data, $statusCode);
}

}
32 changes: 25 additions & 7 deletions src/Message/GetTokenResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

class GetTokenResponse extends Response implements NotificationInterface
{
public function __construct(AbstractRequest $request, $data, int $statusCode, int $userId)
public function __construct(AbstractRequest $request, $data, int $statusCode)
{
parent::__construct($request, $data, $statusCode);
$this->data = json_decode($data, true);
$this->userId = $userId;
}
/**
* @inheritDoc
Expand Down Expand Up @@ -53,15 +52,34 @@ public function isForTokenization(): bool
return @$this->data['Operation'] == 'CreateTokenOnly';
}

public function getUserId()
{
return $this->userId;
}

/**
* @inheritDoc
*/
public function getTransactionStatus()
{
}

public function getCardReference(): ?string
{
return $this->isSuccessful() ? $this->getToken() : null;
}

public function getPaymentMethod(): object
{
$result = new \stdClass();

$result->imageUrl = '';
$result->last4 = $this->getCardNumber();
$result->cardType = $this->getCardType();

$result->expirationMonth = $this->getCardData()['CardMonth'];
$result->expirationYear = $this->getCardData()['CardYear'];

return $result;
}

public function getUserId()
{
return $this->userId;
}
}

0 comments on commit e868902

Please sign in to comment.