createCheckout method
- required String amount,
- required String currency,
- required String countryCode,
- required String customerId,
- String? orderNumber,
- String? completePaymentURL,
- String? errorPaymentURL,
- String? merchantReferenceId,
- List<
String> ? paymentMethods, - bool useCardholdersPreferredCurrency = true,
- String languageCode = 'en',
Used for generating a new checkout object.
The required parameters are amount
, currency
, countryCode
, and
customerId
-
amount
has to be passed as aString
. -
currency
of the country, has to be passed as aString
. -
countryCode
from where the payment is being processed, has to be passed as aString
. -
customerId
of the customer, has to be passed as aString
.
The optional parameters are:
-
orderNumber
that you may want to associate with this checkout, maybe helpful while generating invoice for the order. -
completePaymentURL
the URL where you want to redirect the user after completion of a successful transaction. -
errorPaymentURL
the URL where you want to redirect the user after completion of a failed transaction. -
merchantReferenceId
to be associated with the checkout. -
paymentMethods
that should be accepted, more information here. -
useCardholdersPreferredCurrency
whether to accept the card holder's preferred currency. By default, it's set totrue
. -
languageCode
By default, it's set toen
(English).
Implementation
Future<Checkout?> createCheckout({
required String amount,
required String currency,
required String countryCode,
required String customerId,
String? orderNumber,
String? completePaymentURL,
String? errorPaymentURL,
String? merchantReferenceId,
List<String>? paymentMethods,
bool useCardholdersPreferredCurrency = true,
String languageCode = 'en',
}) async {
Checkout? checkoutDetails;
var method = "post";
var checkoutEndpoint = '/v1/checkout';
final checkoutURL = Uri.parse(baseURL + checkoutEndpoint);
var data = jsonEncode({
"amount": amount,
"complete_payment_url": completePaymentURL,
"country": countryCode,
"currency": currency,
"error_payment_url": errorPaymentURL,
"merchant_reference_id": merchantReferenceId,
"cardholder_preferred_currency": useCardholdersPreferredCurrency,
"language": languageCode,
"metadata": {
"merchant_defined": true,
"sales_order": orderNumber,
},
"payment_method_types_include": paymentMethods,
"customer": customerId,
});
final headers = _generateHeader(
method: method,
endpoint: checkoutEndpoint,
body: data,
);
try {
var response = await http.post(
checkoutURL,
headers: headers,
body: data,
);
if (response.statusCode == 200) {
dev.log('SUCCESSFULLY CHECKOUT');
checkoutDetails = Checkout.fromJson(jsonDecode(response.body));
} else {
dev.log(response.statusCode.toString());
}
} catch (e) {
dev.log('Failed to generate the checkout');
}
return checkoutDetails;
}