createSingleUseToken method

Future<TokenResult> createSingleUseToken(
  1. XCard card, {
  2. required int amount,
  3. bool shouldAuthenticate = true,
  4. String onBehalfOf = '',
  5. BillingDetails? billingDetails,
  6. Customer? customer,
  7. String? currency,
})

Creates a single-use token. 3DS authentication will be bundled into this method unless you set shouldAuthenticate as false.

@param card A credit card @param amount The amount you will eventually charge. This value is used to display to the user in the 3DS authentication view. @param shouldAuthenticate A flag indicating if 3DS authentication are required for this token @param onBehalfOf The onBehalfOf is sub account business id @param billingDetails Billing details of the card @param customer Customer object making the transaction @param currency Currency when requesting for 3DS authentication

Implementation

Future<TokenResult> createSingleUseToken(
  XCard card, {
  required int amount,
  bool shouldAuthenticate = true,
  String onBehalfOf = '',
  BillingDetails? billingDetails,
  Customer? customer,
  String? currency,
}) async {
  var params = <String, dynamic>{
    'publishedKey': publishedKey,
    'card': card.to(),
    'amount': amount,
    'shouldAuthenticate': shouldAuthenticate,
    'onBehalfOf': onBehalfOf,
  };

  if (billingDetails != null) {
    params['billingDetails'] = billingDetails.to();
  }

  if (customer != null) {
    params['customer'] = customer.to();
  }

  if (currency != null) {
    params['currency'] = currency;
  }

  try {
    var result = await _channel.invokeMethod('createSingleToken', params);
    return TokenResult(token: Token.from(result));
  } on PlatformException catch (e) {
    return TokenResult(
      errorCode: e.code,
      errorMessage: e.message ?? '',
    );
  }
}