Skip to content

Instantly share code, notes, and snippets.

@JaniKibichi
JaniKibichi / Utilities.java
Last active January 27, 2022 10:37
Function to Calculate the 1.5% ZawadiPay Discount
public class Utilities {
public Utilities(){}
public static void launchMpesa(String phoneNumber,Float amount){
//Calculate Discount
Double newDiscAmt=(1 - 0.015)*amount;
//Send Mpesa checkout with sendMpesaCheckout method defined elsewhere based on daraja API
//Metadata CAN BE the MerchantID to be returned to the callback
@JaniKibichi
JaniKibichi / db.php
Last active January 27, 2022 10:37
PHP DB Connector
<?php
include_once './util.php';
class DBConnector {
var $pdo;
function __construct(){
$dsn= "mysql:host=". Util::$SERVER_NAME . ";dbname=" . Util::$DB_NAME ."";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
@JaniKibichi
JaniKibichi / cloudbuild.yaml
Created April 7, 2021 11:48
Sample cloudbuild
steps:
# Build the container image
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/bboxxussd:$COMMIT_SHA', '.']
# Push the container image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/bboxxussd:$COMMIT_SHA']
# Deploy container image to Cloud Run
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: gcloud
enablePlugins(JavaAppPackaging)
name := "utility-ussd"
version := "1.0"
scalaVersion := "2.12.6"
lazy val AkkaVersion = "2.6.3"
lazy val AkkaHttpVersion = "10.1.11"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % AkkaVersion,
"com.typesafe.akka" %% "akka-stream" % AkkaVersion,
repos:
- repo: git://github.com/pecigonzalo/pre-commit-shfmt
rev: 9ee28e3f14556aa88dd5255f2e091d1d2f607bb7
hooks:
- id: shell-fmt
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v1.2.3
hooks:
- id: check-yaml
- repo: [email protected]:coyainsurance/pre-commit-scalafmt.git
sha: master
hooks:
- id: scalafmt
args: [ -p9090, -t ]
akka{
http{
server{
server-header = "UTILITY USSD API"
request-timeout = 30s
}
}
}
http {
object Main extends App with LazyLogging with Routes {
// SERVER SET UP
val httpServerFuture: Future[ServerBinding] = Http().bindAndHandle(routes, http.host, http.port)
httpServerFuture.onComplete {
case Success(binding: ServerBinding) =>
logger.info(s"Akka Server is up and bound to ${binding.localAddress}")
case Failure(exception) =>
logger.info(
package com.janikibichi.routes
import net.liftweb.json._
trait Routes extends LazyLogging with CORSHandler {
implicit val formats: DefaultFormats = DefaultFormats
def routes: server.Route = healthCheckRoutes
def healthCheckRoutes: server.Route = {
package com.janikibichi.routes.cors
import akka.http.scaladsl.model.HttpMethods._
import akka.http.scaladsl.model._
import akka.http.scaladsl.model.headers._
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server._
import scala.concurrent.duration._
trait CORSHandler{