createPaymentIntent method
ℹ️ Initiates the payment flow. Best practice is to wrap it with try/catch for any implementation error
Implementation
@override
Future<void> createPaymentIntent({
required List<PaymentIntent> paymentIntents,
}) async {
if (_posNamespaces.isEmpty) {
throw StateError('No chains set, call setTokens method first');
}
if (paymentIntents.isEmpty) {
throw StateError('No payment intents provided');
}
if (paymentIntents.length > 1) {
throw StateError('Currently 1 payment at a time is supported');
}
_reOwnCore!.logger.d('[$runtimeType] createPaymentIntent: $paymentIntents');
_pendingIntents
..clear()
..addAll(paymentIntents);
// throws if some payment intent is not valid
isValidPaymentIntents(_pendingIntents.first);
try {
_connectResponse = await reOwnSign!.connect(
optionalNamespaces: _posNamespaces,
);
final pairingUri = _connectResponse!.uri!;
onPosEvent.broadcast(QrReadyEvent(pairingUri));
// We await the response in case of failure processed in the catch block
// successful connection is handled in _onSessionConnect event handler
await _connectResponse!.session.future;
} catch (e, s) {
_errorHandling(e, s, ErrorStep.connection);
}
}