tradePay function
Future<void>
tradePay({
- String? paymentUrl,
- void success(
- TradePayResult result
- void fail(
- TradePayResult result
- void complete(
- TradePayResult result
Initiates a payment transaction using Hylid's trade pay system.
This function opens the Hylid payment interface for the user to complete a payment transaction. The payment flow is handled by the Hylid Bridge, and callbacks are invoked based on the payment result.
Example:
await tradePay(
paymentUrl: 'https://payment-gateway.com/pay?order=12345',
success: (TradePayResult result) {
print('Payment successful: ${result.resultCode?.toDart}');
},
fail: (TradePayResult result) {
print('Payment failed: ${result.resultCode?.toDart}');
},
complete: (TradePayResult result) {
print('Payment flow completed');
},
);
Parameters:
paymentUrl: The payment URL provided by your backend server.success: Called when the payment completes successfully.fail: Called when the payment fails.complete: Called when the payment flow completes (success or fail).
Implementation
Future<void> tradePay({
String? paymentUrl,
void Function(TradePayResult result)? success,
void Function(TradePayResult result)? fail,
void Function(TradePayResult result)? complete,
}) async {
// Ensure the Hylid Bridge script is loaded before calling
await scriptLoader.ensureInitialized();
final tradePayParameters = _TradePayParameters(
paymentUrl: paymentUrl?.toJS,
success: success?.toJS,
fail: fail?.toJS,
complete: complete?.toJS,
);
_executeTradePayment(tradePayParameters);
}