Skip to content

Instantly share code, notes, and snippets.

View hamza39460's full-sized avatar

Hamza Azam hamza39460

View GitHub Profile
@hamza39460
hamza39460 / Add Payment Details to Firestore
Created March 24, 2020 09:12
Add Payment Details to Firestore flutter
void addPaymentDetailsToFirestore() {
widget._db.collection("Users").document(widget.user.email).collection("Payments").add({
"currency":"USD",
'amount':'100',
});
}
@hamza39460
hamza39460 / Confirm Stripe Payment
Created March 20, 2020 23:23
Flutter Confirm payment
confirmPayment(String sec, PaymentMethod paymentMethod) {
StripePayment.confirmPaymentIntent(
PaymentIntent(clientSecret: sec, paymentMethodId: paymentMethod.id),
).then((val) {
addPaymentDetailsToFirestore(); //Function to add Payment details to firestore
final snackBar = SnackBar(content: Text('Payment Successfull'),);
Scaffold.of(context).showSnackBar(snackBar);
});
}
@hamza39460
hamza39460 / Alert Dialog for ask User's confirmation
Last active March 22, 2020 00:56
Flutter Alert Dialog for ask User's confirmation
confirmDialog(String clientSecret,PaymentMethod paymentMethod) {
var confirm = AlertDialog(
title: Text("Confirm Payement"),
content: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
"Make Payment",
@hamza39460
hamza39460 / Stripe create Payment Intent
Last active March 20, 2020 23:15
Payment Via Flutter
StripePayment.paymentRequestWithCardForm(CardFormPaymentRequest())
.then((paymentMethod) {
double amount=100*100.0; // multipliying with 100 to change $ to cents
INTENT.call(<String, dynamic>{'amount': amount,'currency':'usd'}).then((response) {
confirmDialog(response.data["client_secret"],paymentMethod); //function for confirmation for payment
});
});
@hamza39460
hamza39460 / Payment
Created March 20, 2020 23:05
Payment Via Flutter
StripePayment.paymentRequestWithCardForm(CardFormPaymentRequest())
.then((paymentMethod) {
setState(() {
_isLoading = true;
});
_paymentMethod = paymentMethod;
getAmount();
var result = INTENT.call(<String, dynamic>{'amount': _rem}).then((re) {
_currentSecret = re.data["client_secret"];
confirmDialog();
@hamza39460
hamza39460 / index.js
Last active March 20, 2020 22:50
Cloud functions/index.js for Stripe Payment With Flutter
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const firestore = admin.firestore();
const settings = { timestampInSnapshots: true };
firestore.settings(settings)
const stripe = require('stripe')('YOUR_SECRET_STRIPE_KEY');
exports.createPaymentIntent = functions.https.onCall((data, context) => {
return stripe.paymentIntents.create({