Skip to content

Instantly share code, notes, and snippets.

View nukturnal's full-sized avatar

Alfred Rowe nukturnal

View GitHub Profile
@nukturnal
nukturnal / direct_pay_example.php
Created April 6, 2013 07:54
Code snippet shows how to perform an MPower DirectPay
<?php
require('mpower_php/mpower.php'); // Make sure the client library is relative to your path
MPower_Setup::setMasterKey("82403450-ee3a-4c57-9564-a8fbe30c5fb7");
MPower_Setup::setPublicKey("test_public_M6-fRS1RCnzlGqgeLaBF5vLLoKs");
MPower_Setup::setPrivateKey("test_private_jKxSn3ylcQdrQcuxAOFAbxvK5w4");
MPower_Setup::setMode("test");
MPower_Setup::setToken("7f6c81c1ea223674416e");
@nukturnal
nukturnal / rapgenius_cache_control_study.txt
Created March 9, 2013 14:46
Study on Rapgenious.com and their page caching.
curl -I rapgenius.com
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 09 Mar 2013 14:28:28 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 55913
Connection: keep-alive
Etag: "3cd63da6d49e1ec8fa84dc3ae13ff216"
X-Runtime: 1524
Set-Cookie: _rapgenius_session=BAh7BzoQX2NzcmZfdG9rZW4iMUxZRGZsbjhJdzZvS3NtTVlseE5iRnl6NnhUdzFiT245aVQwc0dzQ202S2M9Og9zZXNzaW9uX2lkIiUxZmEyOTQzZjU1NjI5NGVmZGQ2YjdmYjE2YmU1Y2Q1NA%3D%3D--c3f35e29399219a5990c3d864f9fa4b5682638f6; domain=.rapgenius.com; path=/; HttpOnly
direct_pay = MPower::DirectPay.new
if (direct_pay.credit_account("CUSTOMER_MPOWER_USERNAME_OR_PHONE",100))
puts direct_pay.description
puts direct_pay.response_text
puts direct_pay.transaction_id
else
puts direct_pay.description
puts direct_pay.response_text
end
MPowerDirectPay direct_pay = new MPowerDirectPay(apiSetupInstance);
if(direct_pay.creditAccount("MPOWER_CUSTOMER_USERNAME_OR_PHONENO",50)){
System.out.println("Status: "+direct_pay.getStatus());
System.out.println("Descripion: "+direct_pay.getDescription());
System.out.println("Transaction ID: "+direct_pay.getTransactionId());
}else{
System.out.println("Status: "+direct_pay.getStatus());
System.out.println("Response Message: "+direct_pay.getResponseText());
}
MPowerDirectPay direct_pay = new MPowerDirectPay (setup);
if(direct_pay.CreditAccount("MPOWER_CUSTOMER_USERNAME_OR_PHONENO",50)){
Console.WriteLine(direct_pay.Description);
Console.WriteLine(direct_pay.Status);
Console.WriteLine(direct_pay.ResponseText);
}else{
Console.WriteLine(direct_pay.ResponseText);
Console.WriteLine(direct_pay.Status);
}
<?php
$direct_pay = new MPower_DirectPay();
if ($direct_pay->creditAccount("MPOWER_CUSTOMER_USERNAME_OR_PHONENO",70.65)) {
print $direct_pay->description;
print $direct_pay->response_text;
print $direct_pay->transaction_id;
}else{
print $direct_pay->response_text;
}
<?php
// Onsite Payment Request requires the mpower customer account alias as the parameter
if ($invoice->create("MPOWER_CUSTOMER_USERNAME_OR_PHONENO")) {
echo $invoice->getStatus();
echo $invoice->response_text;
echo $invoice->getReceiptUrl();
} else {
echo $invoice->getStatus();
echo $invoice->response_text;
}
@nukturnal
nukturnal / my_api.rb
Created October 19, 2015 15:18 — forked from doitian/my_api.rb
Allow cors from any domain
class MyAPI < Grape::API
class CrossOriginResourceSharingPolicy < Grape::Middleware::Base
def append_cors_headers(headers)
headers['Access-Control-Allow-Origin'] = env['HTTP_ORIGIN'] || '*'
headers['Access-Control-Allow-Credentials'] = 'true'
headers['Access-Control-Max-Age'] = '180'
if env['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']
headers['Access-Control-Allow-Headers'] = env['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']
end
headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS'
@nukturnal
nukturnal / init_onsite_invoice.java
Created November 15, 2012 22:58
MPower Java initialise an onsite invoice
// If you wish to accept payments directly on your service
// Please note that the constructor requires a instance of both
// MPowerSetup & MPowerStore Classes respectively
MPowerOnsiteInvoice invoice = new MPowerOnsiteInvoice (setup, store);
@nukturnal
nukturnal / init_checkout_invoice.java
Created November 15, 2012 22:56
MPower Java initialise a checkout invoice
// If you intend to use a simpler approach by redirecting to the MPower checkout page
// Please note that the constructor requires a instance of both
// MPowerSetup & MPowerStore Classes respectively
MPowerCheckoutInvoice invoice = new MPowerCheckoutInvoice (setup, store);