Last active
July 23, 2017 13:49
-
-
Save crushcafeteria/698d4e371e3f684b2fb0d6f73b95cf83 to your computer and use it in GitHub Desktop.
Escrow API example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Collect relevant data from your backend systems | |
$transaction = [ | |
'telephone' => '0700123456', | |
'action' => 'BUY', | |
'product_name' => 'Nike Shoes', | |
'price' => 5000, | |
'description' => 'Hello World!', | |
]; | |
# Base64_encode your telephone | |
$transaction['telephone'] = base64_encode($transaction['telephone']); | |
?> | |
<!-- You can use a FORM to make a POST request --> | |
<form method="https://blackpay.co.ke/escrow/api" action="POST"> | |
<input type="hidden" name="action" value="<?=$transaction['action']?>"> | |
<input type="hidden" name="telephone" value="<?=$transaction['telephone']?>"> | |
<input type="hidden" name="product_name" value="<?=$transaction['product_name']?>"> | |
<input type="hidden" name="price" value="<?=$transaction['price']?>"> | |
<input type="hidden" name="description" value="<?=$transaction['description']?>"> | |
<button type="submit" name="Buy Nike Shoes"> | |
</form> | |
<?php | |
# OR A SERVER-SIDE IMPLEMENTATION IN YOUR FAVORITE LANGUAGE | |
# KEEP IN MIND YOU WILL BE REDIRECTED | |
# Build your query string | |
$qs = 'action=' . $transaction['action'] . | |
'&product_name=' . urlencode($transaction['product_name']) . # Encode this value | |
'&price=' . $transaction['price'] . | |
'&telephone=' . $transaction['telephone'] . | |
'&description=' . urlencode($transaction['description']); # Encode this value | |
$url = 'http://blackpay.dev/escrow/api?' . $qs; | |
# Final URL looks like this:- | |
# https://blackpay.co.ke/escrow/api?action=BUY&product_name=Nike+Shoes&price=5000&telephone=MDcwMDEyMzQ1Ng==&description=Hello+World%21 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment