Unhandled Exception: Instance of 'StripeConfigException'

796 Views Asked by At

I want to intigrate stripe payment but i get this error I am using flutter_stripe: ^8.0.0+1

ERROR MESSAGES

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Instance of 'StripeConfigException' E/flutter (20428): #0 Stripe.publishableKey (package:flutter_stripe/src/stripe.dart:30:7) E/flutter (20428): #1 Stripe.applySettings (package:flutter_stripe/src/stripe.dart:104:25) E/flutter (20428): #2 Stripe._awaitForSettings (package:flutter_stripe/src/stripe.dart:624:25) E/flutter (20428): #3 Stripe.initPaymentSheet (package:flutter_stripe/src/stripe.dart:463:11) E/flutter (20428): #4 _stripeState.intpayment (package:ecommerce/payment_intigration/stripe.dart:42:23) E/flutter (20428): E/flutter (20428): I/flutter (20428): Instance of 'StripeConfigException'

CODE

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  Stripe.publishableKey = 'key';
  runApp( MaterialApp(
    home: MediaQuery(
      data: MediaQueryData(),
      child: stripe(),
    ),
  ),);
}

class stripe extends StatefulWidget {
  const stripe({Key? key}) : super(key: key);
  @override
  State<stripe> createState() => _stripeState();
}

class _stripeState extends State<stripe> {

  Future<void> intpayment(
      {required String email, required double amount})async{
    try{
      final response= await http.post(Uri.parse("https://api.stripe.com/v1/payment_intents")
          ,body:{
            "receipt_email": email,
            "amount": amount.toInt().toString(),
            "currency": "usd"

          },
          headers: {
            'Authorization': 'Bearer ' + 'secret key',
            'Content-Type': 'application/x-www-form-urlencoded'
          }
      );
      final jsonresponse=jsonDecode(response.body);
      print(jsonresponse.toString());
      Stripe.instance.initPaymentSheet(paymentSheetParameters: SetupPaymentSheetParameters(
        paymentIntentClientSecret: jsonresponse['paymentIntent'],
        merchantDisplayName: 'Grocery Flutter course',
        customerId: jsonresponse['customer'],
        customerEphemeralKeySecret: jsonresponse['ephemeralKey'],
      ));
      await Stripe.instance.presentPaymentSheet();
      print("payment successfull");
    }
    catch(e){
      if (e is StripeException) {
        print(e);
      }
      print(e);
    }
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Payment Demo'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            intpayment(email: "[email protected]", amount: 50.0);
          },
          child: Text("Pay20\$"),
        ),
      ),
    );
  }
}


`
0

There are 0 best solutions below