Repository navigation
ANS-24114 Align with PayPo API 3.1 - #15
Conversation
- send own refund identifier (referenceRefundId) with a refund request - expose the refunds list returned by the extended status response - throw ApiErrorException with the parsed error body for 4xx responses, keep ServiceUnavailable for 5xx and connection problems - read transactionUrl, settlementStatus and message from notifications - accept the documented message field in ConfirmResponse - allow setting an optional transaction id on CreateRequest
| return new self( | ||
| isset($refund['referenceRefundId']) ? (string) $refund['referenceRefundId'] : null, | ||
| (int) $refund['amount'], | ||
| (string) $refund['created'], |
There was a problem hiding this comment.
A refund without amount/created raises "Undefined array key" warnings and silently produces amount = 0 with created set to now.
There was a problem hiding this comment.
Fixed: an entry without amount/created now throws, surfaced as BadResponseException. Also refunds is now null when PayPo doesn't send the extended status response, so a disabled feature isn't confused with no refunds.
| * @param ErrorDetail[] $errors | ||
| */ | ||
| public function __construct( | ||
| public ?int $code, |
There was a problem hiding this comment.
typing it ?int with a hard cast turns a non-numeric API code such as "REFUND_TOO_HIGH" into 0, and contradicts Response::$code / ConfirmResponse::$code, which are strings
There was a problem hiding this comment.
Changed to ?string, consistent with Response::$code.
| { | ||
| private const HTTP_METHOD = 'POST'; | ||
| private const ENDPOINT = '/transactions'; | ||
| public const REFERENCE_REFUND_ID_MAX_LENGTH = 68; |
| public readonly ?string $message = null, | ||
| ) { | ||
| $this->transactionStatus = OrderStatusEnum::from($transactionStatus); | ||
| $this->settlementStatus = null === $settlementStatus ? null : SettlementStatusEnum::from($settlementStatus); |
There was a problem hiding this comment.
Switched to tryFrom; isSettlementNotify() now depends on the field being present, so an unknown status is still recognized as a settlement notify.
- refunds is null without the extended status response, [] when empty - refund entry without amount or created raises BadResponseException - keep ApiError code as string, consistent with Response code - remove unused REFERENCE_REFUND_ID_MAX_LENGTH - tryFrom for notify settlementStatus, settlement notify by field presence
Brings the library in line with the PayPo API 3.1 documentation.
Refunds
RefundRequestandOrder::refund()accept an optionalreferenceRefundId. PayPo does not return a refund identifier of its own, so this is the only way to match a refund later on.StatusResponseexposes therefundslist from the extended status response asRefund[], plusfindRefund()to look one up by identifier. The list is empty when PayPo has not enabled the extended response for given merchant.Refund::$referenceRefundIdis nullable, as refunds created outside of our system have none.Error handling
ApiErrorException, which carries the status code and the parsed error body:code,messageand per field validation errors. Until now every failure was reported asServiceUnavailable, so the reason of a rejected refund or a 409 on cancelling a completed transaction was lost.ServiceUnavailableis still thrown for 5xx responses and connection problems.ApiErrorExceptionextendsServiceUnavailablefor backward compatibility, so existingcatchblocks keep working. To be dropped in the next major release.Notifications
NotifyreadstransactionUrl,settlementStatusandmessage.isSettlementNotify()tells a settlement notification apart from a plain status or amount change.Notify::SIGNATURE_HEADERconstant.Other
ConfirmResponseaccepts the documentedmessagefield. It requiredstatusDescriptiononly, so deserializing a real response failed. Both fields are kept and filled.CreateRequest::setId()sets the optional transaction id.AC