Skip to content
This repository has been archived by the owner on Jan 5, 2020. It is now read-only.

Firebase cloud functions for JustJava.

Notifications You must be signed in to change notification settings

MarkNjunge/JustJava-CloudFunctions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 

Repository files navigation

JustJava-CloudFunctions

Firebase cloud functions for JustJava.

Installation

  • Clone the repository
$ git clone https://github.com/MarkNjunge/JustJava-CloudFunctions just-java-cloud-functions
  • Install dependencies
$ cd just-java-cloud-functions/functions

$ yarn install
  • Link to a Firebase project, choosing not to overwrite existing files.
$ firebase init functions
module.exports = {
  apiKey: "api_key",
  safaricomConsumerKey: "safaricom_consumer_key",
  safaricomConsumerSecret: "safaricom_consumer_secret",
  basefunctionsUrl: "https://[region]-[project-name].cloudfunctions.net/payments/"
};

apiKey: A key of your chosing. It is used to verify requests.
safaricomConsumerKey, safaricomConsumerSecret: Get from Safaricom developer portal
basefunctionsUrl: The only accurate way to determine this is to first deploy, then check the url. MUST end with payments/.

Functions

[Firestore Trigger] notifyOnCompletedOrder

Notifies a user when their order is marked as completed.

[HTTP Trigger] /payments/mpesa/request

Makes an STK push request to M-Pesa's API.

{
  "amount": "1",
  "phone": "2547xxxxxxxx",
  "customerId": "customer_id",
  "orderId": "order_id",
}

[HTTP Trigger] /payments/mpesa/callback

Route for LNMO callback requests

Testing locally

To test messaging locally, you will need to set up admin credentials.

Testing HTTP endpoints

$ cd functions & yarn serve

Testing firestore triggers

$ cd functions & yarn shell

Sample command for a completed order

notifyOnCompletedOrder({ after: { status: "COMPLETED", fcmToken:"get_a_valid_token", date: "May 15, 2018 at 9:30:45 PM UTC+3", customerId: "customer_id"}}, { params: { orderId: "order_id" } })

Deploy

firebase deploy --only functions