jonasbark / flutter_stripe_payment

[DISCONTINUED] A flutter plugin with stripe payment plugin integration
MIT License
308 stars 244 forks source link

I can't write numbers into CardFormPaymentRequest and Platform thrown ERROR when dismissed #234

Open PeterPaulez opened 3 years ago

PeterPaulez commented 3 years ago

Hello guys!

I have problems with CardFormPaymentRequest

I can show it, and create a paymentIntent, but I have to do it with COPY and PASTE, because I can't write numbers into the boxes.

Other problem is, if I click on cancel button, exceptios is thrown and I can't catch it, no matter where I put the try

import 'package:meta/meta.dart';
import 'package:stripe_app/models/stripeResponse.dart';
import 'package:stripe_payment/stripe_payment.dart';

class StripeService {
  StripeService._privateConstructor();
  static final StripeService _instance = StripeService._privateConstructor();
  factory StripeService() => _instance;

  String _paymentApiURL = 'https://api.stripe.com/v1/payment_intents';
  String _secretKey = 'sk_test_';
  String _publishableKey = 'pk_test_';

  void init() {
    StripePayment.setOptions(
      StripeOptions(
        publishableKey: _publishableKey,
        androidPayMode: 'test',
        merchantId: 'test',
      ),
    );
  }

  Future pagarTarjetaExistente({
    @required String amount,
    @required String currency,
    @required CreditCard card,
  }) async {}

  Future<StripeResponse> pagarNuevaTarjeta({
    @required String amount,
    @required String currency,
  }) async {
    try {
      final paymentMethod = await StripePayment.paymentRequestWithCardForm(
          CardFormPaymentRequest());
      // TODO: Crear paymentIntent
      return StripeResponse(ok: true);
    } catch (e) {
      return StripeResponse(
        ok: false,
        msg: e.toString(),
      );
    }
  }

  Future pagarAppleGooglePay({
    @required String amount,
    @required String currency,
  }) async {}

  Future _crearPaymentIntent({
    @required String amount,
    @required String currency,
  }) async {}

  Future _realizarPago({
    @required String amount,
    @required String currency,
    @required PaymentMethod paymentMethod,
  }) async {}
}
IconButton(
  onPressed: () async {
    final String amount =
        BlocProvider.of<PagarBloc>(context).state.dineroPagarString;
    final String currency =
        BlocProvider.of<PagarBloc>(context).state.moneda;
    final answer = await this.stripeService.pagarNuevaTarjeta(
          amount: amount,
          currency: currency,
        );

    if (answer.ok) {
      mostrarAlerta(
        context,
        'Tarjeta OK',
        'Todo se guardo correctamente en Stripe',
      );
    } else {
      mostrarAlerta(context, 'Algo salió mal', answer.msg);
    }
  },
  icon: Icon(Icons.add),
)
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:stripe_app/bloc/pagar/bloc.dart';
import 'package:stripe_app/pages/home.dart';
import 'package:stripe_app/pages/pagoCompleto.dart';
import 'package:stripe_app/services/stripe.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // Inicializamos StripeService
    new StripeService()..init();

    return MultiBlocProvider(
      providers: [
        BlocProvider(create: (_) => PagarBloc()),
      ],
      child: MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'Stripe App',
        initialRoute: 'home',
        routes: {
          'home': (_) => HomePage(),
          'pago_completo': (_) => PagoCompletoPage(),
        },
        theme: ThemeData.light().copyWith(
          primaryColor: Color(0xff284879),
          scaffoldBackgroundColor: Color(0xff21212A),
        ),
      ),
    );
  }
}
picaoao commented 3 years ago

seems to happen in iOS simulator. tested in an iPhone and it works

PeterPaulez commented 3 years ago

It happens the same in an iPhone.

wilpar commented 3 years ago

same issue

Yunus0or1 commented 3 years ago

Any update on this? Facing same issue.