pay method
Perform the transaction using iOS/Android HyperPay SDK.
It's highly recommended to setup a listner using HyperPay webhooks, and perform the requird action after payment (e.g. issue receipt) on your server.
Implementation
Future<PaymentStatus> pay(CardInfo card) async {
try {
final result = await _channel.invokeMethod(
'start_payment_transaction',
{
'checkoutID': _checkoutID,
'brand': _checkoutSettings?.brand.name.toUpperCase(),
'card': card.toMap(),
},
);
log('$result', name: "HyperpayPlugin/platformResponse");
if (result == 'canceled') {
// Checkout session is still going on.
return PaymentStatus.init;
} else if (result == 'synchronous') {
final status = await paymentStatus(
_checkoutID,
headers: _checkoutSettings?.headers,
);
final String code = status['code'];
if (code.paymentStatus == PaymentStatus.rejected) {
throw HyperpayException(
"Rejected payment.", code, status['description']);
} else {
log('${code.paymentStatus}', name: "HyperpayPlugin/paymentStatus");
_clearSession();
_checkoutID = '';
return code.paymentStatus;
}
}
_clearSession();
_checkoutID = '';
return PaymentStatus.successful;
} catch (e) {
log('$e', name: "HyperpayPlugin/pay");
rethrow;
}
}