Skip to content

feat(platform): let a payer cancel a pending payment step - #452

Open
WebCooper wants to merge 5 commits into
OpenNSW:mainfrom
WebCooper:feat/payment-plugin-resume
Open

WebCooper wants to merge 5 commits into
OpenNSW:mainfrom
WebCooper:feat/payment-plugin-resume

Conversation

@WebCooper

@WebCooper WebCooper commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A trader on a pending payment step can't go back to choosing a payment method, and the checkout they opened stays payable. This lets the PAYMENT plugin act when its step is resumed with the cancel command: it closes the step's own checkout and completes the step as cancelled, so the workflow can send the trader back to method selection.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Other (please describe):

Changes Made

Resume does not check who sent a command it passes through, so the step's PRE_RESUME authz must let only the system caller send submit, and only the payer's roles send cancel. The READMEs and the Resume comment say so.

Testing

  • I have tested this change locally
  • I have added tests that prove my fix is effective or that my feature works
  • I have tested edge cases
  • All existing tests pass

With GOWORK=off, on payment v0.6.0: go vet, go test ./... for the whole platform module, and golangci-lint pass, and go mod tidy changes nothing.

New tests in platform/tasktypes/payment_test.go cover: cancel closes the step's own checkout with its reference and token, the client's payload is ignored, submit and no command pass through without touching the checkout, a settled checkout is refused, a missing reference cancels nothing, and Resume reads the key Execute wrote. Breaking Resume so it always cancels, or so it takes payment_status from the client's payload, made its tests fail.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have checked that there are no merge conflicts

Related Issues

Related to #391

Additional Notes

payment/v0.6.0 is tagged on #430's merge commit (5471ef1), and platform/go.mod requires it, so this builds on released versions.

Next: OpenNSW/nsw-srilanka#1357 (draft) maps ErrPaymentSettled to 409 payment_settled in its step handler and documents the cancel command. Once this merges, it bumps core/platform to this PR's commit.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Payers can cancel a pending payment step and choose another payment method. Successful cancellation closes the checkout and marks the step as cancelled.
  • Documentation
    • Clarified how payment cancellation works and how to restrict authorization for payment commands.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The PAYMENT plugin now supports a cancel command. It uses the checkout reference stored by the step to cancel the checkout and complete the step with payment_status set to cancelled.

Changes: Payment step cancellation

Layer / File(s) Summary
Cancellation command and checkout reference
platform/go.mod, platform/payment/task_completer.go, platform/tasktypes/payment.go, platform/payment/README.md, platform/tasktypes/README.md
The payment dependencies are updated, and the payment package defines CancelCommand. Execute stores the checkout reference under a shared key. The documentation describes cancellation and command-based authorization.
Resume cancellation flow
platform/tasktypes/payment.go, platform/tasktypes/payment_test.go
Resume passes through other commands. For cancellation, it reads the stored reference, obtains a callback token, and calls CancelCheckoutSession. Tests cover successful cancellation, pass-through behavior, errors, invalid step data, and reference reuse.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant PaymentPlugin
  participant StepOutputData
  participant PaymentService
  PaymentPlugin->>StepOutputData: Read stored checkout reference
  PaymentPlugin->>PaymentPlugin: Obtain callback token
  PaymentPlugin->>PaymentService: CancelCheckoutSession with reference and token
  PaymentService-->>PaymentPlugin: Return cancellation result or error
Loading

Possibly related issues

  • OpenNSW/core issue 391 proposes the Resumer hook and checkout cancellation flow using the stored reference.

Possibly related PRs

  • OpenNSW/core#430: Adds the CancelCheckoutSession method called by the PAYMENT plugin.

Suggested labels: Type/New Feature

Suggested reviewers: lokewate, mushrafmim

Merge Risk: Minimal · up to 0f282 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat(platform): let a payer cancel a pending payment step" matches the main change. The PR adds a cancel command that lets the PAYMENT plugin close the step's checkout and complete the step…
Description check Passed The description follows the template. It has a Summary, a Type of Change with New feature checked, a Changes Made list, a Testing section with the boxes checked and test details, a Checklist, Related …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "feat(platform): let a payer cancel a pending payment step" matches the main change. The PR adds a cancel command that lets the PAYMENT plugin close the step's checkout and complete the step as cancelled. The title uses a short, specific conventional-commit form.

Full details: Description check

Explanation

The description follows the template. It has a Summary, a Type of Change with New feature checked, a Changes Made list, a Testing section with the boxes checked and test details, a Checklist, Related Issues, and Additional Notes. The PR links only to #391 under Related Issues, and the template's Closes/Fixes lines are replaced by that link. The Screenshots/Demo section is absent, which is acceptable for a backend change.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 51774b74-d63a-46dd-bc29-0da357cb48c6
Commits

Reviewing files that changed from the base of the PR and between 5471ef1 and 0f2825c.

Files ignored due to path filters: 1

  • platform/go.sum is excluded by !**/*.sum
Files selected for processing: 6

  • platform/go.mod
  • platform/payment/README.md
  • platform/payment/task_completer.go
  • platform/tasktypes/README.md
  • platform/tasktypes/payment.go
  • platform/tasktypes/payment_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@WebCooper WebCooper self-assigned this Dec 1, 2026
PaymentPlugin implements the taskflow Resumer. On the cancel command it closes
the step's own checkout through CancelCheckoutSession and completes the step
with payment_status "cancelled", dropping the client's payload. Any other
command, such as the webhook's submit, passes through unchanged.
Resume closes the step's own checkout on the cancel command and completes the
step as cancelled whatever the client sent. Other commands pass through, a
settled checkout is refused, and a step with no recorded reference cancels
nothing.
@WebCooper
WebCooper force-pushed the feat/payment-plugin-resume branch from 4f65d81 to 98402cc Compare December 1, 2026 09:45
PaymentPlugin.Resume calls payment.Service.CancelCheckoutSession (payment
v0.6.0) and implements plugins.Resumer, which core added in the same commit
range. Bump core to 5471ef1, the commit that holds both.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant