Skip to content

Commit

Permalink
fix toslapos after hash changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nuryagdym committed Nov 17, 2024
1 parent 0c2eb5b commit 1dba93c
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 58 deletions.
116 changes: 58 additions & 58 deletions src/DataMapper/RequestDataMapper/ToslaPosRequestDataMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ public function create3DEnrollmentCheckRequestData(AbstractPosAccount $posAccoun
{
$order = $this->preparePaymentOrder($order);

$requestData = [
'callbackUrl' => (string) $order['success_url'],
'orderId' => (string) $order['id'],
'amount' => $this->formatAmount($order['amount']),
'currency' => (int) $this->mapCurrency($order['currency']),
'installmentCount' => (int) $this->mapInstallment($order['installment']),
'rnd' => $this->crypt->generateRandomString(),
'timeSpan' => $order['time_span'],
];
$requestData = $this->getRequestAccountData($posAccount) + [
'callbackUrl' => (string) $order['success_url'],
'orderId' => (string) $order['id'],
'amount' => $this->formatAmount($order['amount']),
'currency' => (int) $this->mapCurrency($order['currency']),
'installmentCount' => (int) $this->mapInstallment($order['installment']),
'rnd' => $this->crypt->generateRandomString(),
'timeSpan' => $order['time_span'],
];

$requestData['hash'] = $this->crypt->createHash($posAccount, $requestData);

return $this->getRequestAccountData($posAccount) + $requestData;
return $requestData;
}

/**
Expand All @@ -71,22 +71,22 @@ public function createNonSecurePaymentRequestData(AbstractPosAccount $posAccount
{
$order = $this->preparePaymentOrder($order);

$requestData = [
'orderId' => (string) $order['id'],
'amount' => $this->formatAmount($order['amount']),
'currency' => (int) $this->mapCurrency($order['currency']),
'installmentCount' => (int) $this->mapInstallment($order['installment']),
'rnd' => $this->crypt->generateRandomString(),
'timeSpan' => $order['time_span'],
'cardHolderName' => $creditCard->getHolderName(),
'cardNo' => $creditCard->getNumber(),
'expireDate' => $creditCard->getExpirationDate('my'),
'cvv' => $creditCard->getCvv(),
];
$requestData = $this->getRequestAccountData($posAccount) + [
'orderId' => (string) $order['id'],
'amount' => $this->formatAmount($order['amount']),
'currency' => (int) $this->mapCurrency($order['currency']),
'installmentCount' => (int) $this->mapInstallment($order['installment']),
'rnd' => $this->crypt->generateRandomString(),
'timeSpan' => $order['time_span'],
'cardHolderName' => $creditCard->getHolderName(),
'cardNo' => $creditCard->getNumber(),
'expireDate' => $creditCard->getExpirationDate('my'),
'cvv' => $creditCard->getCvv(),
];

$requestData['hash'] = $this->crypt->createHash($posAccount, $requestData);

return $this->getRequestAccountData($posAccount) + $requestData;
return $requestData;
}

/**
Expand All @@ -96,16 +96,16 @@ public function createNonSecurePostAuthPaymentRequestData(AbstractPosAccount $po
{
$order = $this->preparePostPaymentOrder($order);

$requestData = [
'orderId' => (string) $order['id'],
'amount' => $this->formatAmount($order['amount']),
'rnd' => $this->crypt->generateRandomString(),
'timeSpan' => $order['time_span'],
];
$requestData = $this->getRequestAccountData($posAccount) + [
'orderId' => (string) $order['id'],
'amount' => $this->formatAmount($order['amount']),
'rnd' => $this->crypt->generateRandomString(),
'timeSpan' => $order['time_span'],
];

$requestData['hash'] = $this->crypt->createHash($posAccount, $requestData);

return $this->getRequestAccountData($posAccount) + $requestData;
return $requestData;
}

/**
Expand All @@ -115,15 +115,15 @@ public function createStatusRequestData(AbstractPosAccount $posAccount, array $o
{
$order = $this->prepareStatusOrder($order);

$requestData = [
'orderId' => (string) $order['id'],
'rnd' => $this->crypt->generateRandomString(),
'timeSpan' => $order['time_span'],
];
$requestData = $this->getRequestAccountData($posAccount) + [
'orderId' => (string) $order['id'],
'rnd' => $this->crypt->generateRandomString(),
'timeSpan' => $order['time_span'],
];

$requestData['hash'] = $this->crypt->createHash($posAccount, $requestData);

return $this->getRequestAccountData($posAccount) + $requestData;
return $requestData;
}

/**
Expand All @@ -133,15 +133,15 @@ public function createCancelRequestData(AbstractPosAccount $posAccount, array $o
{
$order = $this->prepareCancelOrder($order);

$requestData = [
'orderId' => (string) $order['id'],
'rnd' => $this->crypt->generateRandomString(),
'timeSpan' => $order['time_span'],
];
$requestData = $this->getRequestAccountData($posAccount) + [
'orderId' => (string) $order['id'],
'rnd' => $this->crypt->generateRandomString(),
'timeSpan' => $order['time_span'],
];

$requestData['hash'] = $this->crypt->createHash($posAccount, $requestData);

return $this->getRequestAccountData($posAccount) + $requestData;
return $requestData;
}

/**
Expand All @@ -151,16 +151,16 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o
{
$order = $this->prepareRefundOrder($order);

$requestData = [
'orderId' => (string) $order['id'],
'rnd' => $this->crypt->generateRandomString(),
'amount' => $this->formatAmount($order['amount']),
'timeSpan' => $order['time_span'],
];
$requestData = $this->getRequestAccountData($posAccount) + [
'orderId' => (string) $order['id'],
'rnd' => $this->crypt->generateRandomString(),
'amount' => $this->formatAmount($order['amount']),
'timeSpan' => $order['time_span'],
];

$requestData['hash'] = $this->crypt->createHash($posAccount, $requestData);

return $this->getRequestAccountData($posAccount) + $requestData;
return $requestData;
}

/**
Expand All @@ -169,18 +169,18 @@ public function createRefundRequestData(AbstractPosAccount $posAccount, array $o
public function createOrderHistoryRequestData(AbstractPosAccount $posAccount, array $order): array
{
$order = $this->prepareOrderHistoryOrder($order);
$requestData = [
'orderId' => (string) $order['id'],
'transactionDate' => $order['transaction_date']->format('Ymd'),
'page' => $order['page'],
'pageSize' => $order['page_size'],
'rnd' => $this->crypt->generateRandomString(),
'timeSpan' => $order['time_span'],
];
$requestData = $this->getRequestAccountData($posAccount) + [
'orderId' => (string) $order['id'],
'transactionDate' => $order['transaction_date']->format('Ymd'),
'page' => $order['page'],
'pageSize' => $order['page_size'],
'rnd' => $this->crypt->generateRandomString(),
'timeSpan' => $order['time_span'],
];

$requestData['hash'] = $this->crypt->createHash($posAccount, $requestData);

return $this->getRequestAccountData($posAccount) + $requestData;
return $requestData;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,15 @@ public function testMapInstallment($installment, $expected): void
*/
public function testCreateNonSecurePostAuthPaymentRequestData(array $order, array $expected): void
{
$requestDataWithoutHash = $expected;
unset($requestDataWithoutHash['hash']);

$this->crypt->expects(self::once())
->method('generateRandomString')
->willReturn($expected['rnd']);
$this->crypt->expects(self::once())
->method('createHash')
->with($this->account, $requestDataWithoutHash)
->willReturn($expected['hash']);

$actual = $this->requestDataMapper->createNonSecurePostAuthPaymentRequestData($this->account, $order);
Expand All @@ -125,11 +129,15 @@ public function testCreateNonSecurePostAuthPaymentRequestData(array $order, arra
*/
public function testCreate3DEnrollmentCheckRequestData(array $order, string $paymentModel, string $txType, array $expected): void
{
$requestDataWithoutHash = $expected;
unset($requestDataWithoutHash['hash']);

$this->crypt->expects(self::once())
->method('generateRandomString')
->willReturn($expected['rnd']);
$this->crypt->expects(self::once())
->method('createHash')
->with($this->account, $requestDataWithoutHash)
->willReturn($expected['hash']);

$actual = $this->requestDataMapper->create3DEnrollmentCheckRequestData($this->account, $order);
Expand All @@ -141,11 +149,15 @@ public function testCreate3DEnrollmentCheckRequestData(array $order, string $pay
*/
public function testCreateNonSecurePaymentRequestData(array $order, string $txType, array $expected): void
{
$requestDataWithoutHash = $expected;
unset($requestDataWithoutHash['hash']);

$this->crypt->expects(self::once())
->method('generateRandomString')
->willReturn($expected['rnd']);
$this->crypt->expects(self::once())
->method('createHash')
->with($this->account, $requestDataWithoutHash)
->willReturn($expected['hash']);

$actual = $this->requestDataMapper->createNonSecurePaymentRequestData($this->account, $order, $txType, $this->card);
Expand All @@ -157,11 +169,15 @@ public function testCreateNonSecurePaymentRequestData(array $order, string $txTy
*/
public function testCreateCancelRequestData(array $order, array $expected): void
{
$requestDataWithoutHash = $expected;
unset($requestDataWithoutHash['hash']);

$this->crypt->expects(self::once())
->method('generateRandomString')
->willReturn($expected['rnd']);
$this->crypt->expects(self::once())
->method('createHash')
->with($this->account, $requestDataWithoutHash)
->willReturn($expected['hash']);

$actual = $this->requestDataMapper->createCancelRequestData($this->account, $order);
Expand All @@ -174,11 +190,15 @@ public function testCreateCancelRequestData(array $order, array $expected): void
*/
public function testCreateOrderHistoryRequestData(array $order, array $expected): void
{
$requestDataWithoutHash = $expected;
unset($requestDataWithoutHash['hash']);

$this->crypt->expects(self::once())
->method('generateRandomString')
->willReturn($expected['rnd']);
$this->crypt->expects(self::once())
->method('createHash')
->with($this->account, $requestDataWithoutHash)
->willReturn($expected['hash']);

$actual = $this->requestDataMapper->createOrderHistoryRequestData($this->account, $order);
Expand Down Expand Up @@ -220,11 +240,15 @@ public function testGet3DFormData(array $order, string $txType, string $paymentM
*/
public function testCreateStatusRequestData(array $order, array $expected): void
{
$requestDataWithoutHash = $expected;
unset($requestDataWithoutHash['hash']);

$this->crypt->expects(self::once())
->method('generateRandomString')
->willReturn($expected['rnd']);
$this->crypt->expects(self::once())
->method('createHash')
->with($this->account, $requestDataWithoutHash)
->willReturn($expected['hash']);

$actualData = $this->requestDataMapper->createStatusRequestData($this->account, $order);
Expand All @@ -237,11 +261,15 @@ public function testCreateStatusRequestData(array $order, array $expected): void
*/
public function testCreateRefundRequestData(array $order, string $txType, array $expected): void
{
$requestDataWithoutHash = $expected;
unset($requestDataWithoutHash['hash']);

$this->crypt->expects(self::once())
->method('generateRandomString')
->willReturn($expected['rnd']);
$this->crypt->expects(self::once())
->method('createHash')
->with($this->account, $requestDataWithoutHash)
->willReturn($expected['hash']);

$actual = $this->requestDataMapper->createRefundRequestData($this->account, $order, $txType);
Expand Down

0 comments on commit 1dba93c

Please sign in to comment.