Skip to main content
Migo Docs

Cancel an in-progress charge

stopTransaction aborts a charge that has not been authorized yet, while the SDK is waiting for the customer to tap the card.

:::danger Never cancel while the card is being read Do not call stopTransaction while the SDK is reading the card β€” that is, from the moment it fires onReadingCardData(). Interrupting the dialogue with the chip leaves the transaction in an indeterminate state: the reader may have moved on without your app knowing. Wait for the outcome and, if the charge needs undoing, use a reversal. :::

The safe window to cancel is between onPresentCardRequest() and onReadingCardData(). After the read, in USER_CONFIRMATION mode the way to not charge is to answer transactionConfirmation(sendTransactionAuthorization = false), not stopTransaction.

:::caution MIGO_PAY only stopTransaction is only implemented on MIGO_PAY. On MIGO_LINK_* integrations the call does nothing and no callback fires: the charge continues at the reader. There, the customer cancels from the reader's own flow. :::

:::info This is not a reversal To undo a charge that was already authorized, the method is different and so is the flow. See Reverse an authorized charge. :::

Aborting​

import com.migo.sdkmigo.domain.usecasesparams.StopTransactionParams

migoSDK.stopTransaction(StopTransactionParams(mActivity = this))

The SDK responds with onTransactionCancelled() and always with onGeneralException(STATE_TRANSACTION_CANCELLED_BY_USER, …). That second callback is the confirmation of the cancellation, not a failure β€” handle it apart from the other exceptions:

override fun onGeneralException(exception: GeneralMigoException?, message: String?) {
when (exception) {
GeneralMigoException.STATE_TRANSACTION_CANCELLED_BY_USER -> {
// Expected cancellation, not an error
}
else -> showError("Error: $message")
}
}

Once aborted, the charge cannot be resumed: start a new one if payment is still required.

When you can no longer abort​

stopTransaction stops applying the moment the processor authorizes. From onVoucherDataResponse with isTransactionApproved = true onward, the money has moved and the path is a reversal.

doTransaction()
β”‚
β”œβ”€ onPresentCardRequest βœ… stopTransaction is safe
β”œβ”€ onReadingCardData β›” NEVER cancel
β”œβ”€ onReturnCurrentTransactionInfo
β”‚ ↳ to not charge: transactionConfirmation(false)
└─ authorized ↳ to undo: reversal