Attach a Source Attach a payment source to the customer record This lesson is available for PRO members or as a single course purchase. Sign-in and choose a plan below. *Enrollment provides full access to this course (and updates) for life. Or Signup for Unlimited PRO Access 📼 Login to Watch 👈 Payment Sources Stripe Elements Credit Card Form 👉 file_type_typescript sources.ts import * as functions from 'firebase-functions'; import { assert, assertUID, catchErrors } from './helpers'; import { stripe } from './config'; import { getOrCreateCustomer } from './customers'; /** Attaches a payment source to a stripe customer account. */ export const attachSource = async(uid: string, source: string) => { const customer = await getOrCreateCustomer(uid); const existingSource = customer.sources.data.filter(s => s.id === source).pop(); if (existingSource) { return existingSource; } else { await stripe.customers.createSource(customer.id, { source: source }); // update default return await stripe.customers.update(customer.id, { default_source: source }); } } /////// DEPLOYABLE FUNCTIONS //////// export const stripeAttachSource = functions.https.onCall( async (data, context) => { const uid = assertUID(context); const source = assert(data, 'source'); return catchErrors(attachSource(uid, source)); }); Chapters Intro 👶 1 Resources Helpful Resources for the Stripe Payments Course 👶 2 What is Stripe? How does Stripe Payments Work and why should you use it? 👶 3 Project Setup Get a basic backend project started with Stripe (NodeJS) & Firebase Cloud Functions. 👶 4 Stripe API Keys Explanation free What are Stripe API Keys used for and how do we configure them in Firebase? Unit Testing 🔬 5 Unit Testing - Why? free Unit testing strategy for Firebase Cloud Functions + Stripe 🔬 6 Testing Setup with Jest Configure Jest with Firebase Cloud Functions testing utilities. 🔬 7 First Unit Test Write a basic unit test to validate that Stripe & Firebase are initialized properly. Callable Firebase Cloud Functions ☎️ 8 Callable Cloud Functions? How callable Firebase Cloud Functions work ☎️ 9 Call a Function Call a callable function from your frontend code. ☎️ 10 Callable Functions Error Handing How to handler errors and validate data in a callable function Customers 🛍️ 11 Stripe Customers The importance of customers in Stripe 🛍️ 12 Get or Create a Customer Customer/User management between Stripe and Firebase. 🛍️ 13 Customer Unit Test Unit testing the customer creation logic. Payment Sources 💳 14 Payment Sources How tokens and payment sources work in Stripe 💳 15 Attach a Source Attach a payment source to the customer record 💳 16 Stripe Elements Credit Card Form Use Stripe Elements to attach a payment source from the frontend JS code Charges 💸 17 Charges How to charge a payment source 💸 18 Stripe Elements Charge Charge a card with Stripe Elements 💸 19 Testing Charges Using a mock credit card to test charges Subscriptions 💶 20 Subscriptions Introduction to subscriptions in Stripe 💶 21 Manage Subscriptions Create, retrieve, and cancel subscriptions in Stripe 💶 22 Subscriptions with Stripe Elements Use Stripe Elements to create a subscription in Stripe 💷 23 Webhooks Using webhooks to respond to Stripe events like recurring payments 💷 24 Coupons Applying coupons to subscriptions and/or orders Frontend file_type_ng_component_ts 25 Angular Angular integration for Stripe Payments