Skip to content

Add refund_standalone function with tests#31

Open
chen-gloria wants to merge 2 commits intofatzebra:mainfrom
chen-gloria:add-refund-standalone-function-support
Open

Add refund_standalone function with tests#31
chen-gloria wants to merge 2 commits intofatzebra:mainfrom
chen-gloria:add-refund-standalone-function-support

Conversation

@chen-gloria
Copy link
Copy Markdown

@chen-gloria chen-gloria commented Mar 24, 2026

📝 Description

Implements a new standalone refund functionality for the FatZebra PHP Gateway library that allows merchants to process refunds directly to a card token without requiring an original transaction ID.

Jira ticket: N/A

Details of change

  • Implements refund_standalone($amount, $reference, $card_token, $extra = null) method in the Gateway class
  • Enables refund processing directly to tokenized cards (e.g., Apple Pay, Google Pay, stored cards)
  • Validates all required parameters: amount (positive value), reference (non-empty), and card token (non-empty)
  • Supports optional extra parameters for metadata and fraud information
  • Follows existing code patterns and PSR-4 autoloading conventions
  • Includes comprehensive PHPDoc documentation
  • Adds 3 unit test cases with mocked responses (valid refund, invalid token, extra parameters)

Change Rollback Plan

  • Remove the refund_standalone() method from src/Gateway.php (lines 366-395)
  • Remove the 3 test methods from test/GatewayTest.php (test_refund_standalone, test_refund_standalone_invalid_token, test_refund_standalone_with_extra)
  • Revert composer.json and composer.lock to remove PHPUnit dev dependency

🧨 Risk assessment

Name: New method behavior or API incompatibility
Severity: Minor
Likelihood: Unlikely
Impact: 🟢 Low

Severity justification:

  • This is a new method addition with no changes to existing APIs, so there's minimal risk of breaking existing functionality
  • The implementation closely mirrors the existing refund() method pattern

Likelihood justification:

  • Thorough parameter validation is in place
  • Unit tests cover valid and invalid scenarios
  • No external dependencies were added to the main codebase

Risk mitigation:

  • Parameter validation matches existing refund method patterns
  • Tests verify both success and failure paths
  • Change is isolated to new method only; no modifications to existing methods

Change Checklist

The following must be reviewed and signed off by the creator of the PR. To sign off review and check each

🔑 Security

  • Security of any environment is not reduced by this change.
  • All existing security controls remain in place or have been replaced with equal or stronger controls.

Testing of Changes

  • Testing results have been verified as complete and covering all aspects of the change.
  • Evidence of testing attached
  • Security scans are passing
  • No package vulnerabilities introduced

🔎 Quality assurance

  • Reviewed this PR myself
  • Automated tests are required and included
  • Security controls have been reviewed
  • Changes are Blue-Green friendly

- Implements standalone refund functionality without requiring original transaction ID
- Supports refunding to a card token directly
- Includes comprehensive validation for all parameters
- Adds 3 test cases covering valid refunds, invalid tokens, and extra parameters
- Follows existing code patterns and documentation standards
@snyk-io-au
Copy link
Copy Markdown

snyk-io-au bot commented Mar 24, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@chen-gloria
Copy link
Copy Markdown
Author

Hi @amasses,

I've submitted this PR to add standalone refund functionality to the PHP library.
This feature enables refunds directly to card tokens, which is useful for digital wallet scenarios.

All tests are passing (3/3), and the implementation follows existing code patterns.

Looking forward to your feedback! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant