我完全遵循了本教程:https://www.youtube.com/watch?v=JeyxolsJ3aE
我能够获得我的代码以使用Firebase身份验证创建新的带区客户,并且能够提交令牌并在带区中看到它。但是,将令牌发送到条带化之后,没有任何其他反应。令牌的详细信息应该显示在数据库中(但什么都没有显示。)。请帮助...
颤振代码:
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);
})))]);
}
}
然后,firebase函数的index.js文件如下所示(与说明相同):
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 });
}
});
请帮助。谢谢,Ev