postAction

suspend fun postAction(url: String, actionFields: Map<String, String>): Sep08PostActionResponse

Submits action fields to an action URL provided by the approval server.

When the approval server returns an Sep08PostTransactionResponse.ActionRequired response with actionMethod = "POST", the client must submit the required fields to the action URL. This method handles that POST request and parses the response.

The action URL may return either a "done" response (indicating the client should resubmit the original transaction) or a "next_url" response (indicating additional steps are needed).

Return

Sep08PostActionResponse indicating whether the action is complete or more steps are needed

Parameters

url

The action URL from the Sep08PostTransactionResponse.ActionRequired response

actionFields

Map of field names to values as required by the action URL

Throws

If the action URL returns a malformed response or an unexpected HTTP status code

Example:

// After receiving an ActionRequired response
val actionResponse = sep08.postAction(
url = actionRequired.actionUrl,
actionFields = mapOf(
"email_address" to "user@example.com",
"mobile_number" to "+1234567890"
)
)

when (actionResponse) {
is Sep08PostActionResponse.Done -> {
// Resubmit the original transaction to the approval server
val retryResponse = sep08.postTransaction(tx, approvalServer)
}
is Sep08PostActionResponse.NextUrl -> {
// Direct user to actionResponse.nextUrl
println("Next step: ${actionResponse.message}")
}
}