PHP SDK
Installation
Copy
composer require reevit/reevit-php
Quick Start
Copy
<?php
require_once 'vendor/autoload.php';
use Reevit\Reevit;
$client = new Reevit('pfk_live_xxx.secret');
// Create payment intent
$intent = $client->payments->createIntent([
'amount' => 5000,
'currency' => 'GHS',
'method' => 'mobile_money',
'country' => 'GH',
'customer_id' => 'cust_456',
'reference' => 'ORD-12345',
'metadata' => [
'order_id' => '12345',
],
]);
echo "Payment ID: {$intent['id']}, Status: {$intent['status']}\n";
Configuration
Copy
$client = new Reevit(
getenv('REEVIT_API_KEY'),
getenv('REEVIT_BASE_URL') ?: 'https://api.reevit.io'
);
Payments
Create Payment Intent
Copy
$intent = $client->payments->createIntent([
'amount' => 10000,
'currency' => 'GHS',
'method' => 'mobile_money',
'country' => 'GH',
'customer_id' => 'cust_123',
'reference' => 'ORD-2024-001',
'metadata' => [
'order_id' => 'ORD-2024-001',
],
]);
Get Payment
Copy
$payment = $client->payments->get('pay_abc123');
echo "Status: {$payment['status']}\n";
List Payments
Copy
$payments = $client->payments->list(['limit' => 50, 'offset' => 0]);
foreach ($payments as $payment) {
echo "{$payment['id']}: {$payment['status']}\n";
}
Refund Payment
Copy
// Full refund
$refund = $client->payments->refund('pay_abc123');
// Partial refund
$refund = $client->payments->refund('pay_abc123', [
'amount' => 2500,
'reason' => 'Customer requested',
]);
Connections
Create Connection
Copy
$connection = $client->connections->create([
'provider' => 'paystack',
'mode' => 'live',
'credentials' => [
'secret_key' => 'sk_live_xxx',
],
'labels' => ['nigeria', 'primary'],
'routing_hints' => [
'country_preference' => ['NG'],
'method_bias' => ['card' => 'high'],
],
]);
List Connections
Copy
$connections = $client->connections->list();
foreach ($connections as $conn) {
echo "{$conn->provider} ({$conn->mode}): {$conn->status}\n";
}
Webhook Verification
Copy
<?php
$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_REEVIT_SIGNATURE'] ?? '';
$webhookSecret = getenv('REEVIT_WEBHOOK_SECRET');
$expected = 'sha256=' . hash_hmac('sha256', $payload, $webhookSecret);
if (!hash_equals($expected, $signature)) {
http_response_code(401);
exit('Invalid signature');
}
$event = json_decode($payload, true);
switch ($event['type']) {
case 'payment.succeeded':
// Handle success
break;
}
http_response_code(200);
echo 'OK';
Laravel Webhook Handler
Copy
// routes/api.php
Route::post('/webhooks/reevit', [WebhookController::class, 'handle']);
// app/Http/Controllers/WebhookController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class WebhookController extends Controller
{
public function handle(Request $request)
{
$payload = $request->getContent();
$signature = $request->header('X-Reevit-Signature', '');
$secret = config('services.reevit.webhook_secret');
$expected = 'sha256=' . hash_hmac('sha256', $payload, $secret);
if (!hash_equals($expected, $signature)) {
return response()->json(['error' => 'Invalid signature'], 401);
}
$event = $request->all();
switch ($event['type']) {
case 'payment.succeeded':
$orderId = $event['data']['metadata']['order_id'] ?? null;
// Fulfill order
break;
}
return response()->json(['received' => true]);
}
}
Error Handling
Copy
try {
$payment = $client->payments->createIntent([
'amount' => 5000,
'currency' => 'GHS',
'method' => 'mobile_money',
'country' => 'GH',
]);
} catch (\Reevit\Exception\ApiException $e) {
echo "API Error: {$e->getMessage()}\n";
echo "Code: {$e->getCode()}\n";
echo "HTTP Status: {$e->getHttpStatus()}\n";
} catch (\Exception $e) {
echo "Error: {$e->getMessage()}\n";
}
Environment Variables
Copy
export REEVIT_API_KEY=pfk_live_xxx.secret
export REEVIT_ORG_ID=org_xxx
export REEVIT_WEBHOOK_SECRET=whsec_xxx
Supported Providers
| Provider | Countries | Methods |
|---|---|---|
| Paystack | NG, GH, ZA, KE | Card, Mobile Money, Bank |
| Flutterwave | NG, GH, KE, ZA+ | Card, Mobile Money, Bank |
| Hubtel | GH | Mobile Money |
| Stripe | Global | Card, Apple Pay, Google Pay |
| Monnify | NG | Bank Transfer, Card |
| M-Pesa | KE, TZ | Mobile Money |

