Ionic Shop Plus (with Firebase V3 support) | Documentation
The Ionic Shop Plus (with Firebase V3 support) is the complete solution to start your own eCommerce app or webshop today. It contains everything you need to sell your products immediately and receive payments on your account. It also comes with a complete Admin Management part that can be used by non-developers to manage the content of the app.
View a demo, preview it on your phone, read more about all the functionalities and download the template on the product page.
External Dependencies
The following external accounts are needed to work with this package as it is:
- An account for the database (firebase.com)
- An account to receive payments (stripe.com)
- An account on Mashape to consume the Stripe Payments API (mashape.com)
Getting started
Unzip the package in your workspace. You will find two folders:
- ionic-app
- admin
Setup 1: Payments
We first need to define a couple of constants in our app. If you are working with Angular/Ionic v1.x
, head over to ionic-app/www/js/app.js
and you'll see the following at the top:
// ---------------------------------------------------------------------------------------------------------
// !important settings
// Please fill in the following constants to get the project up and running
// You might need to create an account for some of the constants.
// Obtain your unique Mashape ID from here:
// https://market.mashape.com/noodlio/noodlio-pay-smooth-payments-with-stripe
var NOODLIO_PAY_API_URL = "https://noodlio-pay.p.mashape.com";
var NOODLIO_PAY_API_KEY = "<YOUR-UNIQUE-MASHAPE-ID>";
// Obtain your unique Stripe Account Id from here:
// https://www.noodl.io/pay/connect
// Please also connect your account on this address
// https://www.noodl.io/pay/connect/test
var STRIPE_ACCOUNT_ID = "<YOUR-UNIQUE-STRIPE-ID>";
// Define whether you are in development mode (TEST_MODE: true) or production mode (TEST_MODE: false)
var TEST_MODE = true;
The NOODLIO_PAY_API_URL
is basically the location of the server and is fixed (Do not change this!). The variable TEST_MODE
simply takes the values true
or false
and defines whether we are in test mode (development) or production (actually charging the user). Now let's define two constants:
Mashape
To consume the Stripe Payments API, we'll need to obtain our unique NOODLIO_PAY_API_KEY
. To do so, head over to Mashape and click on the right "Get your API Keys and Start Hacking" or press on "Sign up free".
After you are signed in, you'll find your unique API Key in the request example on the Stripe Payments API page:
curl -X POST --include 'https://noodlio-pay.p.mashape.com/charge/token' \
-H 'X-Mashape-Key: <YOUR-MASHAPE-API-KEY>' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Accept: application/json' \
... other values
Replace the NOODLIO_PAY_API_KEY
with this unique identifier.
Stripe Account
If you haven't already sign up for a Stripe Account. After that, you'll need to retrieve your unique Stripe Account ID (field: stripe_account
), which you can obtain on the following pages (Note: you'll need to visit both links once):
- For the production mode: https://www.noodl.io/pay/connect
- For the development mode: https://www.noodl.io/pay/connect/test
The Stripe Account ID looks something like acct_12abcDEF34GhIJ5K
. Replace the constant STRIPE_ACCOUNT_ID
wherever you have defined it.
That's it. Our payment server is configured and ready to receive payments.
Setup 2: Firebase
We use Firebase as a database to host your shopping items, i.e. the products that you are selling. These items are managed through an admin panel that is provided with this package in the folder admin
.
Add firebase to your app
- Head over to Firebase.com (sign/log in to the console panel) and Create a new project.
- Open the project, and in the section Overview press on Add firebase to your web app. Copy this html/script code.
- In both the
admin
andionic-app
folder, openindex.html
and replace the section "Firebase v3" (line 28
) with the code you just copied.
Copy/paste the Security Rules
To secure your app we will need to add Firebase security rules:
- Open the file
firebase_rules.txt
and copy the content - Go to your Firebase project, on the left click on Database and then select Rules.
- Paste (overwrite) all content with the content of
firebase_rules.txt
Enable password authentication
- To allow users to login, head over to Authentication in your project workspace and press on Sign in method.
- Enable E-mail and Password (minimum requirement!).
- The instructions for enabling social authentication will follow soon.
Setup 3: Admin panel
The admin panel allows you to manage the products you sell in the Ionic App. It also provides you with additional settings (such as fees, categories, etc.)
To enter the admin panel, you'll need a workspace that supports Angular v1.x. A good option is to use a Cloud IDE such as Cloud9:
- Head over to
www.c9.io
- Create an account or sign in
- In your dashboard, create a new workspace (select nodejs)
- Open this workspace
- Delete all the files in there (except for the folder .c9)
- Upload (drag and drop) all the files from this package to the workspace (drop the files at the folder )
- Open
index.html
and then press Run (green button in top)
Your admin panel should be served now on something like ``[name-workspace]-[username].c9users.io Note: if you are not active for two days, you will need to login to your workspace and press again the green button Run to activate the admin. This can be overcome by uploading all your files to a custom server or by managing it locally (
localhost` with `nodejs`).
Extending the Authorized Domains for oAuth redirect
If you are hosting the Admin panel on a foreign location (in the cloud), you will need to extend the authorized domains for oAuth redirects in Firebase. To do so:
- In your Firebase project, head to Authentication and press on tab Sign in methods.
- Scroll down to the section OAuth redirect domains
- Add the top field location of your admin panel. If you are hosting it on cloud9 then you would typically add:
https://[admin-workspace-name]-[your-username].c9users.io
Firebase Admin Rights
The instructions for this part are visually explained in the folder admin/img/examples
. Rune the admin at its root folder (index.html
) and follow steps 1-4 to define the administrator. The administrator manages the items that are displayed in the Ionic Shop.
Setup 4: Ionic V1 App
Now that we have prepared the back-end, it's time to setup and run the front-end. If you are familiar with Ionic Framework, then you know the structure of such apps. If you are new to Ionic, then you probably need to setup the dependencies. Here is how to get started with Ionic:
$ npm install -g cordova ionic
Usually you would follow up by typing something like ionic start myApp tabs
. This is not needed anymore since all the files are in the folder ionic-app
. To run the application, the only thing you need to do is:
$ cd ionic-app
$ ionic-serve
If you are working locally, you can then visit http://localhost:8100/
in your browser to
preview your application.
You can also unpack all the files in a cloud environment such as Cloud9 (see instructions above, they are similar).
IMPORTANT: when going through the Ionic Docs, make sure you are always in the V1 section!
Wrapping up
So far you have setup all the constants and variables. If everything went well, all should be working fine now. To proceed, you can now login to your admin panel and add items. These items will be immediately (after refreshing) shown in your Ionic App. You can try to make a test purchase in the Ionic App. You will see the payment immediately reflected on your Stripe Account. The orders will be also visible in both the admin management as the orders section of the app. Have fun earning money!
Questions?
If you have questions or remarks, please let me know by either typing a comment on this site, or by e-mailing me to: noodlio@seipel-ibisevic.com
Have fun!