Skip to content

Instantly share code, notes, and snippets.

const functions = require("firebase-functions");
const stripe = require('stripe')(functions.config().stripe.key);
const admin = require("firebase-admin");
const axios = require('axios');
admin.initializeApp();
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
const functions = require("firebase-functions");
const stripe = require('stripe')(functions.config().stripe.testkey);
const admin = require("firebase-admin");
const axios = require('axios');
admin.initializeApp();
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const cors = require("cors")({ origin: true });
const axios = require('axios')
exports.payWithStripeAPI = functions.https.onRequest((request, response) => {
let secretKey;
let stripe;
export interface FireProductNormalized extends FireModel {
store_id: string;
user_id: string;
paused: boolean;
///provider source: eg. woocommerce
source?: string;
///Returns the description of the product.
description?: string;
/// For Algolia sorting
@threetwotwo
threetwotwo / story_page_view.dart
Last active April 7, 2020 04:30
Story Page View
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:nutes/core/models/story.dart';
import 'package:nutes/core/services/repository.dart';
import 'package:nutes/ui/screens/my_profile_screen.dart';
import 'package:nutes/ui/screens/profile_screen.dart';
import 'package:nutes/ui/shared/loading_indicator.dart';
import 'package:nutes/ui/widgets/story_view.dart';
class StoryPageView extends StatefulWidget {
@threetwotwo
threetwotwo / refresh_list_view.dart
Last active April 4, 2020 09:25
Refresh List View
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:agora/ui/shared/loading_indicator.dart';
class RefreshListView extends StatefulWidget {
final ScrollController controller;
final VoidCallback onRefresh;
final VoidCallback onLoadMore;
final Widget child;
@threetwotwo
threetwotwo / repo.dart
Created April 3, 2020 06:57
Nutes repo example
static Future getRecentSearches() => shared._firestore.getRecentSearches();
static Future deleteRecentSearch(String uid) =>
shared._firestore.deleteRecentSearch(uid);
static Future createRecentSearch(User user) =>
shared._firestore.createRecentSearch(user);
static Future<List<User>> searchUsers(String text) =>
shared._firestore.searchUsers(text);
@threetwotwo
threetwotwo / sendFCM.ts
Created April 3, 2020 06:47
Send FCM function
async function sendFCM(uid: string, payload: admin.messaging.DataMessagePayload) {
const message: admin.messaging.MessagingPayload = {
notification: {
title: payload.title,
body: payload.body,
clickAction: 'FLUTTER_NOTIFICATION_CLICK',
},
data: payload,
@threetwotwo
threetwotwo / fanOutPostWrite.ts
Last active February 5, 2021 10:20
Cloud function - fan out post write
export const fanOutPostWrite = functions.firestore
.document('users/{uid}/posts/{postId}')
.onWrite(async (change, context) => {
const postId = context.params.postId;
const uploader = context.params.uid;
const followerRefs = await firestore
.collection('users').doc(uploader)
.collection('followers').get();
@threetwotwo
threetwotwo / updatePostLikeCount.ts
Last active April 3, 2020 05:50
Cloud function - update post like count
export const updatePostLikeCount = functions.firestore
.document('posts/{postId}/likes/{uid}')
.onWrite((change, context) => {
const postId = context.params.postId;
let increment: number;
const publicPostRef = firestore.collection('posts').doc(postId);