Skip to content

Instantly share code, notes, and snippets.

@crushcafeteria
Last active June 3, 2016 11:13
Show Gist options
  • Save crushcafeteria/8bd4aab2ea5a919393b9 to your computer and use it in GitHub Desktop.
Save crushcafeteria/8bd4aab2ea5a919393b9 to your computer and use it in GitHub Desktop.
BlackPay Express Hookup
<?php
# Generate a sample the payload structure
$payload = array(
'store_id' => '10',
'cart_id' => '#234-14-222-KY', # May be an invoice number
'cart_items' => array(
array(
'id' => 'SKU-123-145',
'name' => 'Sony Playstation 2',
'qty' => 1,
'price' => 12000
),
array(
'id' => 'SKU-123-456',
'name' => 'Plastic Chair',
'qty' => 2,
'price' => 500
),
),
'grand_total' => 800,
'success_url' => 'https://www.example.com/transaction/success',
'cancel_url' => 'https://www.example.com/transaction/cancelled',
'failed_url' => 'https://www.example.com/transaction/failed',
'logo' => 'https://www.example.com/assets/biz-logo.png',
'customer_email' => '[email protected]',
'customer_telephone' => '+254700123456', # We will send the customer an SMS receipt if this field exists
);
# Encode payload for sending to BlackPay express
$payload = base64_encode(json_encode($payload));
?>
<!--Send your request with an normal POST payload-->
<form method="POST" action="[ENTER BLACKPAY EXPRESS ENDPOINT]">
<input type="hidden" name="store_id" value="[ENTER STORE ID]">
<input type="hidden" name="cart_id" value="[CART UNIQUE ID]">
<input type="hidden" name="cart_items" value="<?php echo $cartItems?>"> <!-- $cartItems string here -->
<input type="hidden" name="grand_total" value="[GRAND TOTAL]">
<input type="hidden" name="success_url" value="[LINK TO REDIRECT ON SUCCESS]">
<input type="hidden" name="failed_url" value="[LINK TO REDIRECT ON FAIL]">
<input type="hidden" name="cancel_url" value="[LINK TO REDIRECT ON CANCEL]">
<input type="hidden" name="customer_email" value="[CUSTOMER EMAIL]">
<button type="submit" class="btn btn-success btn-lg btn-block">Pay with M-PESA</button>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment