Firebase cloud functions for JustJava.
- 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
- Create a config.json file
/functions/config.json
. See config.sample.json
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/
.
Notifies a user when their order is marked as completed.
Makes an STK push request to M-Pesa's API.
{
"amount": "1",
"phone": "2547xxxxxxxx",
"customerId": "customer_id",
"orderId": "order_id",
}
Route for LNMO callback requests
To test messaging locally, you will need to set up admin credentials.
$ cd functions & yarn serve
$ 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" } })
firebase deploy --only functions