Skip to content

Make money parameter optional in buyer verification flows#281

Open
realmeylisdev wants to merge 1 commit intosquare:masterfrom
realmeylisdev:fix/optional-money-buyer-verification
Open

Make money parameter optional in buyer verification flows#281
realmeylisdev wants to merge 1 commit intosquare:masterfrom
realmeylisdev:fix/optional-money-buyer-verification

Conversation

@realmeylisdev
Copy link
Copy Markdown

Summary

Fixes #258

The money parameter in startBuyerVerificationFlow and startCardEntryFlowWithBuyerVerification is now optional (Money?). When buyerAction is "Store" (verifying a saved card on file rather than a charge), the native SDKs on both Android and iOS discard the money value entirely — requiring callers to construct a dummy Money object was unnecessary and non-intuitive.

Problem

Both native SDKs model BuyerAction as a discriminated union:

  • Android: BuyerAction.Store() vs BuyerAction.Charge(money)
  • iOS: [SQIPBuyerAction storeAction] vs [SQIPBuyerAction chargeActionWithMoney:money]

The Flutter plugin flattened this into String buyerAction + required Money money, losing the parameter-action relationship. This forced callers using the "Store" action to pass a meaningless dummy:

// Before: forced to pass dummy money for Store action
await InAppPayments.startBuyerVerificationFlow(
    buyerAction: "Store",
    money: Money((b) => b..amount = 0..currencyCode = 'USD'), // unused, but required
    ...
);

Reproducing steps

  1. Try calling startBuyerVerificationFlow with buyerAction: "Store" and omit money
  2. Before this fix: Compile error — money is required
  3. After this fix: Compiles and works correctly — money is optional

Changes

Layer File Change
Dart lib/in_app_payments.dart required Money moneyMoney? money; added debug assert that money is non-null for "Charge"; money serialized conditionally
Android CardEntryModule.java Null-guard moneyMap before getMoney() in both methods
iOS FSQIPCardEntry.m Nil-guard moneyMap before _getMoney: in both methods
Docs doc/reference.md Updated parameter tables for both methods

After this fix

// Store action — money omitted
await InAppPayments.startBuyerVerificationFlow(
    buyerAction: "Store",
    squareLocationId: locationId,
    contact: contact,
    paymentSourceId: cardOnFileId,
    onBuyerVerificationSuccess: _onSuccess,
    onBuyerVerificationFailure: _onFailure,
);

// Charge action — money still required (enforced by assert in debug mode)
await InAppPayments.startBuyerVerificationFlow(
    buyerAction: "Charge",
    money: Money((b) => b..amount = 100..currencyCode = 'USD'),
    squareLocationId: locationId,
    contact: contact,
    paymentSourceId: nonce,
    onBuyerVerificationSuccess: _onSuccess,
    onBuyerVerificationFailure: _onFailure,
);

Backwards compatibility

This is a non-breaking change. Existing callers passing money continue to compile and work unchanged.

Test plan

  • Call startBuyerVerificationFlow with buyerAction: "Store" and no money — should succeed on both Android and iOS
  • Call startBuyerVerificationFlow with buyerAction: "Charge" and valid money — should succeed as before
  • Call startBuyerVerificationFlow with buyerAction: "Charge" and no money in debug mode — should hit assert
  • Same verification for startCardEntryFlowWithBuyerVerification

The `money` parameter in `startBuyerVerificationFlow` and
`startCardEntryFlowWithBuyerVerification` is now optional. When
`buyerAction` is "Store" (verifying a saved card on file), the native
SDKs on both Android and iOS ignore the money value entirely, so
requiring callers to construct a dummy Money object was unnecessary.

Changes across all three layers:
- Dart: `required Money money` → `Money? money` with a debug assert
  that money is provided when buyerAction is "Charge"
- Android: null-guard moneyMap before calling getMoney()
- iOS: nil-guard moneyMap before calling _getMoney:
- Docs: updated reference.md parameter tables

This is a non-breaking change — existing callers passing money
continue to work unchanged.

Fixes square#258
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 12, 2026

CLA assistant check
All committers have signed the CLA.

@github-advanced-security
Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

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.

money parameter in startBuyerVerificationFlow must be optional

3 participants