FlyPay Widget

The FlyPay Widget integrates with FlyPay using a WebView component. This handles the communication between FlyPay and the SDK. Once completed, the WebView component returns the `FlyPayOrderId`.

FlyPay View

iOS

How to use the FlyPayWidget

1. Overview

This section provides a step-by-step guide on how to initialize and use the FlyPayWidget SwiftUI view in your application. The widget facilitates the payment using FlyPay services.

The following sample code demonstrates the definition of the FlyPayWidget:

FlyPayWidget(
    flyPayToken: (@escaping (String) -> Void) -> Void,
    completion: (Result<ChargeResponse, FlyPayError>) -> Void)

The following sample code demonstrates how you can use the widget in your application:

struct FlyPayExampleView: View {
    @StateObject private var viewModel = FlyPayExampleVM()
    var body: some View {
        FlyPayWidget { onFlyPayButtonTap in
            // Example: Initiate Wallet Transaction to retrieve the wallet token
            viewModel.initializeWalletCharge(completion: onFlyPayButtonTap)
        } completion: { result in
            switch result {
            case .success(let chargeResponse): // Handle success
            case .failure(let error): // Handle error
            }
        }
    }
}

2. Parameter definitions

This subsection describes the parameters required by the FlyPayWidget SwiftUI view. It provides information on the purpose of each parameter and its significance in configuring the behavior of the FlyPayWidget.

FlyPayWidget

NameDefinitionTypeMandatory/Optional
flyPayTokenA callback to obtain the wallet token asynchronously(@escaping (String) -> Void) -> VoidMandatory
completionResult callback with the FlyPayOrderId if successful, or error if not.(Result<ChargeResponse, FlyPayError>) -> VoidMandatory

3. Callback Explanation

Token Callback

The flyPayToken callback obtains the wallet token asynchronously. It receives a callback function (@escaping (String) -> Void) -> Void as a parameter, which you must invoke with the wallet token once it is obtained.

Completion Callback

The completion callback is invoked after the payment operation is completed. It receives a Result<ChargeResponse, FlyPayError> where ChargeResponse contains the FlyPayOrderId if the payment is successful. The callback handles the outcome of the payment operation.

Android

How to use the FlyPayWidget

1. Overview

This section provides a step-by-step guide on how to initialize and use the FlyPayWidget composable in your application. The widget facilitates the payment using FlyPay services.

The following sample code demonstrates the definition of the FlyPayWidget:

fun FlyPayWidget(
    modifier: Modifier,
    token: (onTokenReceived: (String) -> Unit) -> Unit,
    completion: (Result<String>) -> Unit
) {...}

The following sample code demonstrates how you can use the widget in your application:

// Initialize the FlyPayWidget
FlyPayWidget(
    modifier = Modifier
        .fillMaxWidth()
        .padding(16.dp), // optional
    token = { callback ->
        // Obtain Wallet Token asynchronously using the callback
        // Example: Initiate Wallet Transaction to retrieve the wallet token
        val walletToken = // ... retrieve the token
        callback(walletToken)
    }
) { result ->
    // Handle the result of the payment operation
    result.onSuccess { flyPayOrderId ->
        // Handle success - Update UI or perform actions
        Log.d("FlyPayWidget", "Payment successful. Order ID: $flyPayOrderId")
    }.onFailure { exception ->
        // Handle failure - Show error message or take appropriate action
        Log.e("FlyPayWidget", "Payment failed. Error: ${exception.message}")
    }
}

2. Parameter definitions

This subsection describes the various parameters required by the FlyPayWidget composable. It provides information on the purpose of each parameter and its significance in configuring the behavior of the FlyPayWidget.

FlyPayWidget

NameDefinitionTypeMandatory/Optional
modifierCompose modifier for container modificationsandroidx.compose.ui.ModifierOptional
tokenA callback to obtain the wallet token asynchronously(onTokenReceived: (String) -> Unit) -> UnitMandatory
completionResult callback with the FlyPayOrderId if successful, or error if not.(Result<ChargeResponse>) -> UnitMandatory

3. Callback Explanation

Token Callback

The token callback obtains the wallet token asynchronously. It receives a callback function (onTokenReceived: (String) -> Unit) as a parameter, which you must invoke with the wallet token once it is obtained.

Completion Callback

The completion callback is invoked after the payment operation is completed. It receives a Result<String> where String represents the FlyPayOrderId if the payment is successful. The callback handles the outcome of the payment operation.