startCheckoutSDK method
Future<BlusaltCheckoutResultResponse?>
startCheckoutSDK({
- required String apiKey,
- bool isPayment = false,
- bool isDev = false,
- required double amount,
- required String currency,
- required String walletId,
- String? reference,
- Map<
String, dynamic> ? metadata, - String? primaryColorHex,
- String? companyEmail,
- Uint8List? companyLogo,
- IosConfig iosConfig = const IosConfig(),
override
Implementation
@override
Future<BlusaltCheckoutResultResponse?> startCheckoutSDK({
required String apiKey,
bool isPayment = false,
bool isDev = false,
required double amount,
required String currency,
required String walletId,
String? reference,
Map<String, dynamic>? metadata,
String? primaryColorHex,
String? companyEmail,
Uint8List? companyLogo,
IosConfig iosConfig = const IosConfig(),
}) async {
try {
if (amount < 0) {
return BlusaltCheckoutResultResponse(
blusaltCheckoutProcess: BlusaltCheckoutProcess.notImplemented,
message: "Amount must be greater than 0",
);
}
if (currency.isEmpty) {
return BlusaltCheckoutResultResponse(
blusaltCheckoutProcess: BlusaltCheckoutProcess.notImplemented,
message: "Currency must not be empty",
);
}
if (walletId.isEmpty) {
return BlusaltCheckoutResultResponse(
blusaltCheckoutProcess: BlusaltCheckoutProcess.notImplemented,
message: "Wallet Id must not be empty",
);
}
final result = await methodChannel.invokeMethod('startCheckoutSDK', {
'apiKey': apiKey,
'isPayment': isPayment,
'isDev': isDev,
'amount': amount,
'currency': currency,
'walletId': walletId,
'reference': reference,
'metadata': metadata,
'primaryColorHex': primaryColorHex,
'companyEmail': companyEmail,
'companyLogo': companyLogo,
'iOSAnimationType': iosConfig.iosPresentationStyle.name,
});
if (result != null) {
var response = result as Map<dynamic, dynamic>;
var paymentStatuses = BlusaltCheckoutResultType.values.where(
(element) => element.value == response['paymentStatus'].toString(),
);
return BlusaltCheckoutResultResponse(
blusaltCheckoutProcess: BlusaltCheckoutProcess.completed,
checkoutResultType: paymentStatuses.firstOrNull,
reference: response['reference'].toString(),
);
} else {
return BlusaltCheckoutResultResponse(
blusaltCheckoutProcess: BlusaltCheckoutProcess.notImplemented,
message: "Something went wrong",
);
}
} on PlatformException catch (exception) {
return BlusaltCheckoutResultResponse(
blusaltCheckoutProcess: BlusaltCheckoutProcess.notImplemented,
exception: exception,
message: exception.message,
code: exception.code,
);
} catch (e) {
return BlusaltCheckoutResultResponse(
blusaltCheckoutProcess: BlusaltCheckoutProcess.notImplemented,
message: e.toString(),
);
}
}