Skip to content

Examples

In this guide

Copy-ready snippets for a minimal checkout, a reusable operation callback, and post-payment status verification — plus a map of the sample app.

The repository includes a sample Android app in the app module. Use it as a reference for wiring UI state, callbacks, and SDK operations.

Runnable sample app

The app module is a full working example. Build and run it against SANDBOX to see every flow end-to-end before wiring your own UI.

Minimal Checkout

fun Activity.startDigetPayCheckout() {
    DigetPay.checkout(
        activity = this,
        request = CheckoutRequest(
            merchantOrderId = "ORDER-${System.currentTimeMillis()}",
            amount = 125.0,
            currency = "SAR",
            customerName = "Ahmed Ali",
            customerEmail = "ahmed@example.com",
            customerPhone = "+966501234567"
        ),
        callback = object : PaymentCallback {
            override fun onSuccess(result: PaymentResult) {
                // Persist result IDs and update the order.
            }

            override fun onFailure(error: PaymentError) {
                // Show a recoverable error message.
            }

            override fun onCancelled() {
                // Keep the order pending or let the user retry.
            }
        }
    )
}
void startDigetPayCheckout(Activity activity) {
    CheckoutRequest request = new CheckoutRequest(
        "ORDER-" + System.currentTimeMillis(),
        125.0,
        "SAR",
        "Ahmed Ali",
        "ahmed@example.com",
        "+966501234567",
        CheckoutRequest.DEFAULT_SUCCESS_URL,
        CheckoutRequest.DEFAULT_FAILURE_URL
    );

    DigetPay.checkout(activity, request, new PaymentCallback() {
        @Override
        public void onSuccess(PaymentResult result) {
            // Persist result IDs and update the order.
        }

        @Override
        public void onFailure(PaymentError error) {
            // Show a recoverable error message.
        }

        @Override
        public void onCancelled() {
            // Keep the order pending or let the user retry.
        }
    });
}

Reusable Operation Callback

private fun <T> operationCallback(
    onFailure: (PaymentError) -> Unit,
    onSuccess: (T) -> Unit
) = object : OperationCallback<T> {
    override fun onSuccess(result: T) = onSuccess(result)
    override fun onFailure(error: PaymentError) = onFailure(error)
}
import java.util.function.Consumer;

private static <T> OperationCallback<T> operationCallback(
    Consumer<PaymentError> onFailure,
    Consumer<T> onSuccess
) {
    return new OperationCallback<T>() {
        @Override
        public void onSuccess(T result) {
            onSuccess.accept(result);
        }

        @Override
        public void onFailure(PaymentError error) {
            onFailure.accept(error);
        }
    };
}

Check Status After Success

override fun onSuccess(result: PaymentResult) {
    DigetPay.getTransactionStatus(
        paymentId = result.sessionId,
        callback = operationCallback(
            onFailure = { error -> logPaymentError(error) },
            onSuccess = { status ->
                val finalStatus = status.paymentStatus ?: status.transactionStatus
                updateOrderStatus(result.orderId, finalStatus)
            }
        )
    )
}
@Override
public void onSuccess(PaymentResult result) {
    DigetPay.getTransactionStatus(
        result.getSessionId(),
        operationCallback(
            error -> logPaymentError(error),
            status -> {
                String finalStatus = status.getPaymentStatus() != null
                    ? status.getPaymentStatus()
                    : status.getTransactionStatus();
                updateOrderStatus(result.getOrderId(), finalStatus);
            }
        )
    );
}

Sample App Areas

Checkout screen
Hosted checkout integration.
SDK operations
Status, capture, void, and refund.
Recurring screen
Listing recurring records and charging a token.
Merchant views
Separating merchant backend state from SDK calls.

Next step

Ready for production? Review Error Handling and the go-live checklist before shipping.