Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TokensAuthRequestBuilder #29

Merged
merged 1 commit into from
Sep 8, 2023
Merged
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver].

## Unreleased

### Added

- Property `TrInitiatorCode` in `TokensAuthRequestBuilder`

### Changed

- Mark property `token` as required for payment by token in `TokensAuthRequestBuilder`

## v1.6.0

### Added
Expand Down
30 changes: 26 additions & 4 deletions src/Requests/Payments/Tokens/TokensAuthRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ class TokensAuthRequestBuilder extends AbstractRequestBuilder
use PaymentRequestTrait, HasReceipt;

/**
* Required.
* Card tokens issued by the CloudPayments. You get it with the first successful payment.
*
* @var string|null
* @var string
*/
protected $token;
protected string $token;

/**
* Integer flag of the initiator of the transaction.
*
* Possible values:
* 0 - transaction initiated by the merchant based on previously saved credentials;
* 1 - transaction initiated by the cardholder (customer) based on previously saved credentials.
*
* @var int
*/
protected int $tr_initiator_code;

/**
* Required.
Expand All @@ -38,6 +49,16 @@ public function setToken(string $token): self
return $this;
}

/**
* Set the integer flag of the initiator of the transaction.
*/
public function setTransactionInitiatorCode(int $tr_initiator_code): self
{
$this->tr_initiator_code = $tr_initiator_code;

return $this;
}

/**
* {@inheritdoc}
*/
Expand All @@ -46,7 +67,8 @@ protected function getRequestPayload(): array
$this->json_data = \array_merge($this->json_data ?? [], $this->getReceiptData());

return \array_merge($this->getCommonPaymentParams(), [
'Token' => $this->token,
'Token' => $this->token,
'TrInitiatorCode' => $this->tr_initiator_code,
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ class TokensAuthRequestBuilderTest extends AbstractRequestBuilderTestCase

public function testToken(): void
{
$this->request_builder->setToken('some');
$this->request_builder->setToken('some')->setTransactionInitiatorCode(1);

$this->assertSame('{"Token":"some"}', $this->request_builder->buildRequest()->getBody()->getContents());
$this->assertSame('{"Token":"some","TrInitiatorCode":1}', $this->request_builder->buildRequest()->getBody()->getContents());
}

/**
* {@inheritdoc}
*/
protected function getRequestBuilder(): TokensAuthRequestBuilder
{
return new TokensAuthRequestBuilder;
return (new TokensAuthRequestBuilder)->setToken('some')->setTransactionInitiatorCode(1);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TokensChargeRequestBuilderTest extends TokensAuthRequestBuilderTest
*/
protected function getRequestBuilder(): TokensAuthRequestBuilder
{
return new TokensChargeRequestBuilder;
return (new TokensChargeRequestBuilder)->setToken('some')->setTransactionInitiatorCode(1);
}

/**
Expand Down