createToken method
Creates a token for card details.
Note this method is legacy and it is advised to use PaymentIntent.
Implementation
@override
Future<TokenData> createToken(CreateTokenParams params) async {
final response = await params.maybeWhen<Future<stripe_js.TokenResponse>>(
(type, name, address) => throw UnimplementedError(),
card: (params) {
return _stripe.createCardElementToken(
element! as stripe_js.CardPaymentElement,
stripe_js.CreateTokenCardData(
name: params.name,
addressLine1: params.address?.line1,
addressLine2: params.address?.line2,
addressCity: params.address?.city,
addressState: params.address?.state,
addressCountry: params.address?.country,
addressZip: params.address?.postalCode,
),
);
},
bankAccount: (params) {
return _stripe.createBankAccountToken(
stripe_js.CreateTokenBankAccountData(
country: params.country,
currency: params.currency,
accountHolderName: params.accountHolderName,
accountHolderType: params.accountHolderType?.toJs(),
routingNumber: params.routingNumber,
accountNumber: params.accountNumber,
),
);
},
pii: (params) {
return _stripe.createPIIToken(
stripe_js.CreateTokenPIIData(
personalIdNumber: params.personalId,
),
);
},
orElse: () {
throw UnimplementedError();
},
);
if (response.error != null) {
throw response.error!;
}
return response.token!.parse();
}