From cef6f8c1aa5f6de114c6a6fa68fe122b1fbc7a7b Mon Sep 17 00:00:00 2001 From: Vladimir Konchakovsky Date: Sun, 16 Oct 2022 15:41:33 +0300 Subject: [PATCH] Fix bug, when cancel list is unset --- spec/Mapper/Invoice/PaymentInfoMapperSpec.php | 68 ++++++++++++++++++- spec/Mapper/Invoice/StatusMapperSpec.php | 60 +++++++++++++++- spec/Mapper/StatementMapperSpec.php | 42 ++++++++++++ src/Mapper/Invoice/PaymentInfoMapper.php | 2 +- src/Mapper/Invoice/StatusMapper.php | 2 +- src/Mapper/StatementMapper.php | 2 +- 6 files changed, 171 insertions(+), 5 deletions(-) diff --git a/spec/Mapper/Invoice/PaymentInfoMapperSpec.php b/spec/Mapper/Invoice/PaymentInfoMapperSpec.php index 9061abf..c0eb7bf 100644 --- a/spec/Mapper/Invoice/PaymentInfoMapperSpec.php +++ b/spec/Mapper/Invoice/PaymentInfoMapperSpec.php @@ -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 @@ -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()); } } diff --git a/spec/Mapper/Invoice/StatusMapperSpec.php b/spec/Mapper/Invoice/StatusMapperSpec.php index 635952e..f4a2eaa 100644 --- a/spec/Mapper/Invoice/StatusMapperSpec.php +++ b/spec/Mapper/Invoice/StatusMapperSpec.php @@ -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 { @@ -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()); } } diff --git a/spec/Mapper/StatementMapperSpec.php b/spec/Mapper/StatementMapperSpec.php index 58148cd..66f3904 100644 --- a/spec/Mapper/StatementMapperSpec.php +++ b/spec/Mapper/StatementMapperSpec.php @@ -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); diff --git a/src/Mapper/Invoice/PaymentInfoMapper.php b/src/Mapper/Invoice/PaymentInfoMapper.php index 06f883c..48b9828 100644 --- a/src/Mapper/Invoice/PaymentInfoMapper.php +++ b/src/Mapper/Invoice/PaymentInfoMapper.php @@ -27,7 +27,7 @@ public function jsonToObject(string $jsonString): InvoicePaymentInfo $item['rrn'], $item['extRef'] ); - }, $data['cancelList']); + }, $data['cancelList'] ?? []); $output = new InvoicePaymentInfo( $data['maskedPan'], diff --git a/src/Mapper/Invoice/StatusMapper.php b/src/Mapper/Invoice/StatusMapper.php index 79a7e7a..2d237d4 100644 --- a/src/Mapper/Invoice/StatusMapper.php +++ b/src/Mapper/Invoice/StatusMapper.php @@ -27,7 +27,7 @@ public function jsonToObject(string $jsonString): InvoiceStatus $item['rrn'], $item['extRef'] ); - }, $data['cancelList']); + }, $data['cancelList'] ?? []); $output = new InvoiceStatus( $data['invoiceId'], diff --git a/src/Mapper/StatementMapper.php b/src/Mapper/StatementMapper.php index 7f2e57d..cf8bc49 100644 --- a/src/Mapper/StatementMapper.php +++ b/src/Mapper/StatementMapper.php @@ -27,7 +27,7 @@ public function jsonToObject(string $jsonString): Statement $item['approvalCode'], $item['rrn'] ); - }, $item['cancelList']); + }, $item['cancelList'] ?? []); $statement = new StatementItem( $item['invoiceId'],