(226) 377-3114

Ionic + Angular + Firebase + Stripe Connect

How to use Firebase cloud functions as a backend for Stripe Connect in an Angular Project.

Step #1: Add cloud functions to your project with firebase init

$ firebase init

Then select Firebase functions.

Step #2: Install the Stripe Package

Move into the newly created functions directory and install the stripe package.

$ cd functions
$ npm install --save stripe

Step #3: Modify functions/src/index.ts

Adding the stripe import and creating our first function.

import * as cors from 'cors';
const corsHandler = cors({origin: true}); //make more secure in production
const stripe = require('stripe')('sk_test_YOUR_KEY_HERE');
export const createExpressAccount = functions.https.onRequest(async (request, response) => {

  corsHandler(request, response, async () => {

    const account = await stripe.accounts.create({
      type: 'express',
    });
    response.send(account);

  });

});

Step #4: Deploy to Firebase Hosting

$ firebase deploy --only functions

Step #5: Send a GET request to the newly created endpoint

You'll see the endpoint after uploading the function in the console. It's also accessible in the Firebase console.

 

createStripeAccount(){
    console.log('sending request for account creation');
    this.http.get('https://YOUR-APP-HERE.cloudfunctions.net/createExpressAccount')
	.toPromise().then(result=>{
      console.log(result);
	  //do something with result
    }).catch(error =>{
      console.log(error);
    });
  }

Let's work together.

Get in Touch
Copyright © ConvertLion.
Lets Connect!