Marketplace
>
getUserPrimaryCard
rainbow

getUserPrimaryCard

v
0.0.2
Latest Version
Likes
0
4
Installations
0
2
Views
0
2

Overview

Get a user's default card-type payment method in Stripe.

Usage

### How this function works This HTTPS function will allow you to resolve the Stripe primary card of the current authenticated user, returning a payment method object according to Stripe docs. ### Requirements * You must have previous knowledge of **Firebase**. * You must have previous knowledge of **Firestore**. * You must have previous knowledge of **Stripe**. ### Function details This function resolves the Stripe customer from a Firestore collection, asuming the ID of each document is the Firebase user ID (i.e. `STRIPE_CUSTOMERS_COLLECTION_PATH/{uid}`), and the saved document is a Stripe customer object (See https://stripe.com/docs/api/customers/object). Once the customer is obtained, it is used to retrieve the default payment method configured for that customer in Stripe. Note that if the default payment method is not of type 'card', then this functions returns `undefined`. To install this function you need to enter the values of the following variables: * **STRIPE_SECRET_KEY**: Your Stripe secret API key. See [https://stripe.com/docs/keys](https://stripe.com/docs/keys). * **STRIPE_CUSTOMERS_COLLECTION_PATH**: The collection path where the Stripe customers are stored. Here is an example of how to call this function from your app with JavaScript: ```js // assuming `firebase` is an initialized Firebase app const getUserPrimaryCard = firebase.functions().httpsCallable('getUserPrimaryCard'); const paymentMethod = await getUserPrimaryCard(); if (!paymentMethod) { // The default payment method is not of type card return; } else { console.log(paymentMethod.card); // result.card is a Card object from Stripe } ``` ### Resources * [PaymentMethod object](https://stripe.com/docs/api/payment_methods/object) * [Card object](https://stripe.com/docs/api/cards/object)
Cost
FREE
Cost
Version
0.0.2
Language
JAVASCRIPT
Created At
Updated At
Workspace
rainbow
Tags
billing
stripe
card
© 2023 Function Store