I followed this tutorial exactly: https://www.youtube.com/watch?v=JeyxolsJ3aE
I was able to get my code to create a new stripe customer with Firebase authentication and I am able to submit a token and see it in stripe. However, after the token is sent to stripe, nothing else happens. The details of the token are supposed to appear in the database (but nothing shows up..).Please help...
Flutter code:
import 'package:flutter/material.dart';
import 'package:stripe_payment/stripe_payment.dart';
import 'package:flutter/cupertino.dart';
PaymentMethod paymentMethod;
final CreditCard testCard = CreditCard(
number: '4242424242424242',
expMonth: 12,
expYear: 21,
);
class donationPage extends StatefulWidget {
@override
donationPageState createState() =>donationPageState();
}
class donationPageState extends State<donationPage> {
@override
initState() {
super.initState();
StripePayment.setOptions(
StripeOptions(publishableKey: "mykey", merchantId: "Test", androidPayMode: 'test'));
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: ListView(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 4.0, right:2, left: 2),
height: 60,
width: 120,
child: ButtonTheme(
child: RaisedButton(
color: Colors.teal,
child: Text('\$100'),
onPressed: () async {
await StripePayment.createTokenWithCard(testCard);
})))]);
}
}
Then, the firebase function index.js file looks like this (same as instructions):
const functions = require("firebase-functions");
const { allowedNodeEnvironmentFlags } = require("process");
const admin = require("firebase-admin");
const stripe = require("stripe")(functions.config().stripe.secret, {
apiVersion: "2020-03-02",
});
exports.createStripeCustomer = functions.auth.user().onCreate(async (user) => {
const customer = await stripe.customers.create({ email: user.email });
const intent = await stripe.setupIntents.create({
customer: customer.id,
});
await admin.firestore().collection("stripe_customers").doc(user.uid).set({
customer_id: customer.id,
setup_secret: intent.client_secret,
});
return;
});
exports.addPaymentMethodDetails = functions.firestore
.document("/stripe_customers/{userId}/payment_methods/{pushId}")
.onCreate(async (snap, context) => {
try {
const paymentMethodId = snap.data().id;
const paymentMethod = await stripe.paymentMethods.retrieve(
paymentMethodId
);
await snap.ref.set(paymentMethod);
// Create a new SetupIntent so the customer can add a new method next time.
const intent = await stripe.setupIntents.create({
customer: paymentMethod.customer,
});
await snap.ref.parent.parent.set(
{
setup_secret: intent.client_secret,
},
{ merge: true }
);
return;
} catch (error) {
await snap.ref.set({ error: userFacingMessage(error) }, { merge: true });
await reportError(error, { user: context.params.userId });
}
});
Please Help. Thanks, Ev