createCustomCheckout method

Future<Map<String, dynamic>> createCustomCheckout({
  1. required int customPrice,
  2. required List<int> enabledVariants,
  3. String? buttonColor,
  4. String? discountCode,
  5. Map<String, dynamic>? customData,
  6. String? expiresAt,
  7. bool preview = false,
})

Implementation

Future<Map<String, dynamic>> createCustomCheckout({
  required int customPrice,
  required List<int> enabledVariants,
  String? buttonColor,
  String? discountCode,
  Map<String, dynamic>? customData,
  String? expiresAt,
  bool preview = false,
}) async {
  Options dioOptions = Options(
    headers: {
      "Authorization": "Bearer $apiKey",
      "Accept": "application/vnd.api+json",
      "Content-Type": "application/vnd.api+json",
    },
  );

  try {
    Response response = await dio.post(
      "https://api.lemonsqueezy.com/v1/checkouts",
      options: dioOptions,
      data: {
        "data": {
          "type": "checkouts",
          "attributes": {
            "custom_price": customPrice,
            "product_options": {"enabled_variants": enabledVariants},
            "checkout_options": {
              "button_color": buttonColor,
            },
            "checkout_data": {
              "discount_code": discountCode,
              "custom": customData,
            },
            "expires_at": expiresAt,
            "preview": preview
          }
        }
      },
    );

    return response.data;
  } catch (e) {
    return {'error': e.toString()};
  }
}