<?php
/*
Template Name: Payment Page
*/
?>
<?php get_header(); ?>
<div class="container mx-auto p-8">
<div class="bg-white p-8 rounded-lg shadow-lg w-full md:w-1/2 mx-auto">
<h1 class="text-2xl font-bold mb-6 text-center">Payment Checkout</h1>
<form id="paymentForm" action="" method="POST">
<div class="mb-4">
<label for="name" class="block text-gray-700 text-sm font-bold mb-2">Name</label>
<input type="text" id="name" name="name" required class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
</div>
<div class="mb-6">
<label for="phone_number" class="block text-gray-700 text-sm font-bold mb-2">Phone Number</label>
<input type="tel" id="phone_number" name="phone_number" required class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
</div>
<div class="flex items-center justify-between">
<button type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline">
Pay Now
</button>
</div>
</form>
</div>
</div>
<?php
class SwahiliesPay {
private $api_key;
private $sandbox;
private $webhook_url;
public function __construct($api_key, $sandbox, $webhook_url) {
$this->api_key = $api_key;
$this->sandbox = $sandbox;
$this->webhook_url = $webhook_url;
}
public function make_payment($amount, $transaction_id, $phone_number, $description) {
$payload = json_encode(array(
'api' => 170,
'code' => 104,
'data' => array(
'api_key' => $this->api_key,
'order_id' => $transaction_id,
'amount' => $amount,
'username' => $description,
'is_live' => !$this->sandbox,
'phone_number' => $phone_number,
'webhook_url' => $this->webhook_url
)
));
$ch = curl_init('https://swahiliesapi.invict.site/Api');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));