feat(webhooks): expose cancellationReason on the remaining cancel event DTOs - #60
Merged
Merged
Conversation
…nt DTOs fluent persists a subscription's cancellationReason downstream when a cancellation webhook ends it, but only SubscriptionCanceledForNonpayment exposed a top-level cancellationReason — so merchant_request / customer_request never flowed through. - SubscriptionCanceledImmediately and SubscriptionCanceledWithGracePeriod now carry a nullable ?string $cancellationReason, read straight from object['cancellationReason'] in fromWebhook() (null if absent). No hardcoded default (unlike the nonpayment DTO, which defaults to payment_failure) — reflects exactly what's in the payload. - Values are the existing Vatly\API\Types\CancellationReason constants. Tests assert the reason hydrates from the object (and is null when absent) at both the DTO and factory level. Docs (Webhooks.md) + CHANGELOG updated. 275 tests green; phpstan (level 5) and php-cs-fixer clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Consistency fix so every subscription cancellation reason flows through to
downstream consumers (fluent persists
cancellationReasonwhen a cancellationwebhook ends a subscription).
Today only
SubscriptionCanceledForNonpaymentexposes a top-levelcancellationReason. The other two cancel event DTOs don't, somerchant_request/customer_requestwere dropped. This adds the property toboth, matching the way the nonpayment DTO surfaces it.
Changes
SubscriptionCanceledImmediately— new nullable?string $cancellationReason(its
objectcarriescancellationReason: merchant_request).SubscriptionCanceledWithGracePeriod— new nullable?string $cancellationReason(
customer_requestfrom the portal, ormerchant_request).Both read the value straight from the delivery's
object['cancellationReason']in
fromWebhook(),nullif absent. Unlike the nonpayment DTO (which defaultsto
payment_failure), these reflect exactly what's in the payload with nohardcoded default. Valid values are the existing
Vatly\API\Types\CancellationReasonconstants (
payment_failure/merchant_request/customer_request).Tests
SubscriptionEventsTest: each DTO hydrates the reason fromobjectand isnullwhen absent.WebhookEventFactoryTest: the factory-built events carry the reason too.Docs (
Webhooks.md) andCHANGELOG.mdupdated.Verification
composer test→ 275 tests, 1370 assertions, OK.php -d memory_limit=1G vendor/bin/phpstan analyse src tests→ No errors (level 5).vendor/bin/php-cs-fixer fix --allow-risky=yes→ 0 files to fix.Over to you to merge once CI is green, then cut alpha.28.