diff --git a/composer.json b/composer.json index 62ee1cf..19442b1 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "payvision/payvision-sdk-php", "description": "Payvision PHP SDK", "type": "library", - "version": "5.0.0", + "version": "5.1.0", "license": "MIT", "require": { "php": "^7.2.5|^7.3", diff --git a/src/Domain/Checkouts/Service/Builder/Error.php b/src/Domain/Checkouts/Service/Builder/Error.php index 63f962f..b01b60a 100644 --- a/src/Domain/Checkouts/Service/Builder/Error.php +++ b/src/Domain/Checkouts/Service/Builder/Error.php @@ -42,6 +42,15 @@ public function setMessage(string $message): Error return $this->set('message', $message); } + /** + * @param string $detailedMessage + * @return Error + */ + public function setDetailedMessage(string $detailedMessage): Error + { + return $this->set('detailedMessage', $detailedMessage); + } + /** * @return ErrorObject */ @@ -49,7 +58,8 @@ protected function buildObject(): ErrorObject { return new ErrorObject( $this->get('code'), - $this->get('message') + $this->get('message'), + $this->get('detailedMessage') ); } } diff --git a/src/Domain/Checkouts/ValueObject/Error.php b/src/Domain/Checkouts/ValueObject/Error.php index 06e2057..2275fa5 100644 --- a/src/Domain/Checkouts/ValueObject/Error.php +++ b/src/Domain/Checkouts/ValueObject/Error.php @@ -23,18 +23,26 @@ class Error */ private $message; + /** + * @var string + */ + private $detailedMessage; + /** * Error constructor. * * @param int $code * @param string $message + * @param string $detailedMessage */ public function __construct( int $code, - string $message + string $message, + string $detailedMessage = null ) { $this->code = $code; $this->message = $message; + $this->detailedMessage = $detailedMessage; } /** @@ -52,4 +60,12 @@ public function getMessage(): string { return $this->message; } + + /** + * @return string|null + */ + public function getDetailedMessage(): ?string + { + return $this->detailedMessage; + } } diff --git a/src/Domain/Paymentlinks/Service/Builder/Error.php b/src/Domain/Paymentlinks/Service/Builder/Error.php index 11fc52b..45d575c 100644 --- a/src/Domain/Paymentlinks/Service/Builder/Error.php +++ b/src/Domain/Paymentlinks/Service/Builder/Error.php @@ -42,6 +42,15 @@ public function setMessage(string $message): Error return $this->set('message', $message); } + /** + * @param string $detailedMessage + * @return Error + */ + public function setDetailedMessage(string $detailedMessage): Error + { + return $this->set('detailedMessage', $detailedMessage); + } + /** * @return ErrorObject */ @@ -49,7 +58,8 @@ protected function buildObject(): ErrorObject { return new ErrorObject( $this->get('code'), - $this->get('message') + $this->get('message'), + $this->get('detailedMessage') ); } } diff --git a/src/Domain/Paymentlinks/Service/Builder/Link/ResponsePaymentError.php b/src/Domain/Paymentlinks/Service/Builder/Link/ResponsePaymentError.php index 1f44b93..1bbef08 100644 --- a/src/Domain/Paymentlinks/Service/Builder/Link/ResponsePaymentError.php +++ b/src/Domain/Paymentlinks/Service/Builder/Link/ResponsePaymentError.php @@ -42,6 +42,15 @@ public function setMessage(string $message): ResponsePaymentError return $this->set('message', $message); } + /** + * @param string $detailedMessage + * @return ResponsePaymentError + */ + public function setDetailedMessage(string $detailedMessage): ResponsePaymentError + { + return $this->set('detailedMessage', $detailedMessage); + } + /** * @return ResponsePaymentErrorObject */ @@ -49,7 +58,8 @@ protected function buildObject(): ResponsePaymentErrorObject { return new ResponsePaymentErrorObject( $this->get('code'), - $this->get('message') + $this->get('message'), + $this->get('detailedMessage') ); } } diff --git a/src/Domain/Paymentlinks/ValueObject/Error.php b/src/Domain/Paymentlinks/ValueObject/Error.php index 9f0fd2a..a47fb8d 100644 --- a/src/Domain/Paymentlinks/ValueObject/Error.php +++ b/src/Domain/Paymentlinks/ValueObject/Error.php @@ -23,18 +23,26 @@ class Error */ private $message; + /** + * @var string + */ + private $detailedMessage; + /** * Error constructor. * * @param int $code * @param string $message + * @param string $detailedMessage */ public function __construct( int $code, - string $message + string $message, + string $detailedMessage = null ) { $this->code = $code; $this->message = $message; + $this->detailedMessage = $detailedMessage; } /** @@ -52,4 +60,12 @@ public function getMessage(): string { return $this->message; } + + /** + * @return string|null + */ + public function getDetailedMessage(): ?string + { + return $this->detailedMessage; + } } diff --git a/src/Domain/Paymentlinks/ValueObject/Link/ResponsePaymentError.php b/src/Domain/Paymentlinks/ValueObject/Link/ResponsePaymentError.php index 98a0b6a..988a9d8 100644 --- a/src/Domain/Paymentlinks/ValueObject/Link/ResponsePaymentError.php +++ b/src/Domain/Paymentlinks/ValueObject/Link/ResponsePaymentError.php @@ -23,18 +23,26 @@ class ResponsePaymentError */ private $message; + /** + * @var string + */ + private $detailedMessage; + /** * ResponsePaymentError constructor. * * @param int $code * @param string $message + * @param string $detailedMessage */ public function __construct( int $code, - string $message + string $message, + string $detailedMessage = null ) { $this->code = $code; $this->message = $message; + $this->detailedMessage = $detailedMessage; } /** @@ -52,4 +60,12 @@ public function getMessage(): string { return $this->message; } + + /** + * @return string|null + */ + public function getDetailedMessage(): ?string + { + return $this->detailedMessage; + } } diff --git a/src/Domain/Payments/Service/Builder/Error.php b/src/Domain/Payments/Service/Builder/Error.php index 9d51601..f6edcf6 100644 --- a/src/Domain/Payments/Service/Builder/Error.php +++ b/src/Domain/Payments/Service/Builder/Error.php @@ -42,6 +42,15 @@ public function setMessage(string $message): Error return $this->set('message', $message); } + /** + * @param string $detailedMessage + * @return Error + */ + public function setDetailedMessage(string $detailedMessage): Error + { + return $this->set('detailedMessage', $detailedMessage); + } + /** * @return ErrorObject */ @@ -49,7 +58,8 @@ protected function buildObject(): ErrorObject { return new ErrorObject( $this->get('code'), - $this->get('message') + $this->get('message'), + $this->get('detailedMessage') ); } } diff --git a/src/Domain/Payments/ValueObject/Error.php b/src/Domain/Payments/ValueObject/Error.php index e40b2ed..bd7d297 100644 --- a/src/Domain/Payments/ValueObject/Error.php +++ b/src/Domain/Payments/ValueObject/Error.php @@ -23,18 +23,26 @@ class Error */ private $message; + /** + * @var string + */ + private $detailedMessage; + /** * Error constructor. * * @param int $code * @param string $message + * @param string $detailedMessage */ public function __construct( int $code, - string $message + string $message, + string $detailedMessage = null ) { $this->code = $code; $this->message = $message; + $this->detailedMessage = $detailedMessage; } /** @@ -52,4 +60,12 @@ public function getMessage(): string { return $this->message; } + + /** + * @return string|null + */ + public function getDetailedMessage(): ?string + { + return $this->detailedMessage; + } } diff --git a/src/Domain/Service/Helper/AfterpayErrorMessageHelper.php b/src/Domain/Service/Helper/AfterpayErrorMessageHelper.php new file mode 100644 index 0000000..502c06a --- /dev/null +++ b/src/Domain/Service/Helper/AfterpayErrorMessageHelper.php @@ -0,0 +1,85 @@ +[a-z]+\.[a-z.]+)/', $message, $matches)) { + return $matches['code']; + } + throw new AfterpayErrorException('Unable to handle Afterpay error code: ' . $message); + } +} diff --git a/src/Exception/AfterpayErrorException.php b/src/Exception/AfterpayErrorException.php new file mode 100644 index 0000000..be8f909 --- /dev/null +++ b/src/Exception/AfterpayErrorException.php @@ -0,0 +1,16 @@ + [ + 'field.billto.city.missing (De plaatsnaam van het factuuradres ontbreekt)', + [AfterpayErrorMessageHelper::BILLTO_CITY_MISSING], + ], + 'multiple error codes' => [ + 'field.billto.housenumber.missing (Het huisnummer van het factuuradres ontbreekt) | ' . + 'field.billto.housenumberaddition.missing (De huisnummertoevoeging van het factuuradres ontbreekt)', + [ + AfterpayErrorMessageHelper::BILLTO_HOUSENUMBER_MISSING, + AfterpayErrorMessageHelper::BILLTO_HOUSENUMBERADDITION_MISSING, + ], + ], + ]; + } + + /** + * @param string $message + * @param string $expected + * @throws AfterpayErrorException + * @dataProvider afterpayExtractMessageCodeExceptionProvider + */ + public function testExtractMessageCodesException(string $message, string $expected): void + { + $this->expectException(AfterpayErrorException::class); + try { + AfterpayErrorMessageHelper::extractMessageCodes($message); + } catch (Exception $exception) { + self::assertSame($expected, $exception->getMessage()); + throw $exception; + } + } + + public function afterpayExtractMessageCodeExceptionProvider(): array + { + return [ + 'Non parsable error code' => [ + 'housenumberaddition_missing', + 'Unable to handle Afterpay error code: housenumberaddition_missing', + ] + ]; + } +}