Search code examples
flutterstripe-paymentsflutter-web

IntegrationError: Client-only Checkout does not support prices with `custom_unit_amount` in `items[0]` || Flutter web stripe error


I am working on a stripe payment gateway where the user will click on the checkout button it will redirect to the stripe payment website. There is no documentation for stripe flutter web so, I was using this stripe documentation where prebuilt checkout is already built in for HTML, React & next.js.

In the docs, it is shown to use prod_id like this

line_items: [
  {
    // Provide the exact Price ID (for example, pr_1234) of the product you want to sell
    price: '{{PRICE_ID}}',
    quantity: 1,
  },
],

so, I declared the same like this in flutter

Future<String> createCheckout() async {
final auth = 'Basic ' + base64Encode(utf8.encode('$secretKey:'));
final body = {
  'payment_method_types': ['card'],
  'line_items': [
    {
      'price': PriceId,
      'quantity': 1,
    }
  ],
  'mode': 'payment',
  'success_url': 'http://localhost:8080/#/success',
  'cancel_url': 'http://localhost:8080/#/cancel',
};

Here is my const PriceId = 'price_1Ls00LIUBJ387UG0xxxxxx'; which I have declared my constants.dart file

And this is how I made called the function when the user presses the checkout button

    void redirectToCheckout(BuildContext _) async {
  final stripe = Stripe(apiKey);
  stripe.redirectToCheckout(CheckoutOptions(
    lineItems: [
      LineItem(price: PriceId, quantity: 1),
    ],
    mode: 'payment',
    successUrl: 'http://localhost:8080/#/success',
    cancelUrl: 'http://localhost:8080/#/cancel',
  ));
}

After clicking on the button this warning comes up on the console

enter image description here


Solution

  • As noted on the docs for this deprecated integration pattern, many newer Checkout features are only available when using the client & server integration or payment links.

    You will need to either use a server to create your sessions or set up payment links to redirect your customers if you don't have a server backend you can use.