Skip to content

Commit

Permalink
Fix bug, when cancel list is unset
Browse files Browse the repository at this point in the history
  • Loading branch information
vldmr-k committed Oct 16, 2022
1 parent 6d657df commit cef6f8c
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 5 deletions.
68 changes: 67 additions & 1 deletion spec/Mapper/Invoice/PaymentInfoMapperSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PhpSpec\ObjectBehavior;
use VldmrK\MonoAcquiring\Mapper\Invoice\PaymentInfoMapper;
use VldmrK\MonoAcquiring\Model\Invoice\CancelListItem;
use VldmrK\MonoAcquiring\Model\Invoice\InvoicePaymentInfo;

class PaymentInfoMapperSpec extends ObjectBehavior
Expand Down Expand Up @@ -37,14 +38,79 @@ class PaymentInfoMapperSpec extends ObjectBehavior
]
}';

private $jsonStringUnsetCancelList = '{
"maskedPan": "444403******1902",
"approvalCode": "662476",
"rrn": "060189181768",
"amount": 4200,
"ccy": 980,
"finalAmount": 4200,
"createdDate": "2019-08-24T14:15:22Z",
"terminal": "MI001088",
"paymentScheme": "full",
"paymentMethod": "pan",
"fee": 420,
"domesticCard": true,
"country": "804"
}';

function it_is_initializable()
{
$this->shouldHaveType(PaymentInfoMapper::class);
}

function it_json_to_object_unset_cancel_list() {
$this->jsonToObject($this->jsonStringUnsetCancelList)->shouldBeAnInstanceOf(InvoicePaymentInfo::class);

$paymentInfo = new InvoicePaymentInfo(
'444403******1902',
'662476',
'060189181768',
4200,
980,
4200,
'2019-08-24T14:15:22Z',
'MI001088',
'full',
'pan',
true,
"804",
420
);
$this->jsonToObject($this->jsonStringUnsetCancelList)->toArray()->shouldReturn($paymentInfo->toArray());
}

function it_json_to_object() {
$this->jsonToObject($this->jsonString)->shouldBeAnInstanceOf(InvoicePaymentInfo::class);

$this->jsonToObject($this->jsonString)->toArray()->shouldReturn(\json_decode($this->jsonString, true));
$paymentInfo = new InvoicePaymentInfo(
'444403******1902',
'662476',
'060189181768',
4200,
980,
4200,
'2019-08-24T14:15:22Z',
'MI001088',
'full',
'pan',
true,
"804",
420,
[
new CancelListItem(
'processing',
'2019-08-24T14:15:22Z',
'2019-08-24T14:15:22Z',
4200,
980,
'662476',
'060189181768',
'635ace02599849e981b2cd7a65f417fe'
)
]
);

$this->jsonToObject($this->jsonString)->toArray()->shouldReturn($paymentInfo->toArray());
}
}
60 changes: 59 additions & 1 deletion spec/Mapper/Invoice/StatusMapperSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
use PhpSpec\ObjectBehavior;
use VldmrK\MonoAcquiring\Mapper\Invoice\StatusMapper;
use VldmrK\MonoAcquiring\Mapper\MapperInterface;
use VldmrK\MonoAcquiring\Model\Invoice\CancelListItem;
use VldmrK\MonoAcquiring\Model\Invoice\InvoiceCancel;
use VldmrK\MonoAcquiring\Model\Invoice\InvoiceStatus;
use VldmrK\MonoAcquiring\Model\Statement;
use VldmrK\MonoAcquiring\Model\StatementCancelListItem;
use VldmrK\MonoAcquiring\Model\StatementItem;

class StatusMapperSpec extends ObjectBehavior
{
Expand Down Expand Up @@ -33,15 +38,68 @@ class StatusMapperSpec extends ObjectBehavior
]
}';

private $jsonStringUnsetCancelList = '{
"invoiceId": "p2_9ZgpZVsl3",
"status": "created",
"amount": 4200,
"ccy": 980,
"finalAmount": 4200,
"reference": "84d0070ee4e44667b31371d8f8813947",
"createdDate": "2019-08-24T14:15:22Z",
"modifiedDate": "2019-08-24T14:15:22Z",
"failureReason": "Неправильний CVV код"
}';

function it_is_initializable()
{
$this->shouldHaveType(StatusMapper::class);
$this->shouldImplement(MapperInterface::class);
}

function it_to_json_object_not_set_cancel_list() {

$status = new InvoiceStatus(
'p2_9ZgpZVsl3',
'created',
4200,
980,
4200,
'84d0070ee4e44667b31371d8f8813947',
'2019-08-24T14:15:22Z',
'2019-08-24T14:15:22Z',
'Неправильний CVV код'
);

$this->jsonToObject($this->jsonStringUnsetCancelList)->toArray()->shouldReturn($status->toArray());
}

function it_json_to_object() {
$this->jsonToObject($this->jsonString)->shouldBeAnInstanceOf(InvoiceStatus::class);

$this->jsonToObject($this->jsonString)->toArray()->shouldReturn(\json_decode($this->jsonString, true));
$status = new InvoiceStatus(
'p2_9ZgpZVsl3',
'created',
4200,
980,
4200,
'84d0070ee4e44667b31371d8f8813947',
'2019-08-24T14:15:22Z',
'2019-08-24T14:15:22Z',
'Неправильний CVV код',
[
new CancelListItem(
'processing',
'2019-08-24T14:15:22Z',
'2019-08-24T14:15:22Z',
4200,
980,
'662476',
'060189181768',
'635ace02599849e981b2cd7a65f417fe'
)
]
);

$this->jsonToObject($this->jsonString)->toArray()->shouldReturn($status->toArray());
}
}
42 changes: 42 additions & 0 deletions spec/Mapper/StatementMapperSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,53 @@ class StatementMapperSpec extends ObjectBehavior
]
}';

private $jsonStringUnsetCancelList = '
{
"list": [
{
"invoiceId": "2205175v4MfatvmUL2oR",
"status": "success",
"maskedPan": "444403******1902",
"date": "2019-08-24T14:15:22Z",
"paymentScheme": "bnpl_later_30",
"amount": 4200,
"profitAmount": 4100,
"ccy": 980,
"approvalCode": "662476",
"rrn": "060189181768",
"reference": "84d0070ee4e44667b31371d8f8813947"
}
]
}
';

function it_is_initializable()
{
$this->shouldHaveType(StatementMapper::class);
}

function it_to_json_object_not_set_cancel_list() {
$this->jsonToObject($this->jsonStringUnsetCancelList)->shouldBeAnInstanceOf(Statement::class);

$statement = new Statement([
new StatementItem(
'2205175v4MfatvmUL2oR',
'success',
'444403******1902',
'2019-08-24T14:15:22Z',
'bnpl_later_30',
4200,
4100,
980,
'662476',
'060189181768',
'84d0070ee4e44667b31371d8f8813947',
[]
)
]);
$this->jsonToObject($this->jsonStringUnsetCancelList)->toArray()->shouldReturn($statement->toArray());
}

function it_to_json_to_object() {
$this->jsonToObject($this->jsonString)->shouldBeAnInstanceOf(Statement::class);

Expand Down
2 changes: 1 addition & 1 deletion src/Mapper/Invoice/PaymentInfoMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function jsonToObject(string $jsonString): InvoicePaymentInfo
$item['rrn'],
$item['extRef']
);
}, $data['cancelList']);
}, $data['cancelList'] ?? []);

$output = new InvoicePaymentInfo(
$data['maskedPan'],
Expand Down
2 changes: 1 addition & 1 deletion src/Mapper/Invoice/StatusMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function jsonToObject(string $jsonString): InvoiceStatus
$item['rrn'],
$item['extRef']
);
}, $data['cancelList']);
}, $data['cancelList'] ?? []);

$output = new InvoiceStatus(
$data['invoiceId'],
Expand Down
2 changes: 1 addition & 1 deletion src/Mapper/StatementMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function jsonToObject(string $jsonString): Statement
$item['approvalCode'],
$item['rrn']
);
}, $item['cancelList']);
}, $item['cancelList'] ?? []);

$statement = new StatementItem(
$item['invoiceId'],
Expand Down

0 comments on commit cef6f8c

Please sign in to comment.