PHP code example of tangentopay / tangentopay-php
1. Go to this page and download the library: Download tangentopay/tangentopay-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tangentopay / tangentopay-php example snippets
use TangentoPay\ServiceClient;
use TangentoPay\MerchantClient;
// ── Storefront: create a Stripe checkout session ──────────────────────────────
$service = new ServiceClient(['serviceKey' => getenv('TANGENTOPAY_SERVICE_KEY')]);
$session = $service->checkout->create([
'products' => [['name' => 'Pro Plan', 'price' => 49.99, 'quantity' => 1]],
'currency_code' => 'USD',
'customer_email'=> '[email protected] ',
'return_url' => 'https://myshop.com/thank-you',
]);
// redirect your customer to $session->redirectUrl
// ── Or: hosted checkout — let the customer pick the payment method ────────────
// Returns a checkout.tangentopay.com URL showing the methods you've enabled
// (card, Google/Apple Pay, Alipay, WeChat, MTN MoMo, Orange Money).
$hosted = $service->checkout->createHosted([
'amount' => 5000,
'currency_code' => 'XAF',
'return_url' => 'https://myshop.com/thank-you',
'cancel_url' => 'https://myshop.com/cart',
]);
// redirect your customer to $hosted['checkout_url']
// ── Backend: manage payments with an API token ────────────────────────────────
$merchant = new MerchantClient(['apiToken' => getenv('TANGENTOPAY_API_TOKEN')]);
$payments = $merchant->payments->list(['perPage' => 20]);
$balance = $merchant->wallets->mainBalance();
$service = new ServiceClient([
'serviceKey' => getenv('TANGENTOPAY_SERVICE_KEY'),
// optional:
'baseUrl' => 'https://api.tangentopay.com/api/v1',
'timeoutS' => 30,
'maxRetries' => 3,
]);
$merchant = new MerchantClient(['apiToken' => getenv('TANGENTOPAY_API_TOKEN')]);
$client = new MerchantClient();
$client->auth->login(['email' => $email, 'password' => $password]);
$token = $client->auth->verifyOtp(['email' => $email, 'otp' => $otp]);
$merchant = new MerchantClient(['apiToken' => $token->accessToken]);
use TangentoPay\Exceptions\AuthenticationException;
try {
$payments = $merchant->payments->list();
} catch (AuthenticationException $e) {
$merchant->auth->login(['email' => $email, 'password' => $password]);
$token = $merchant->auth->verifyOtp(['email' => $email, 'otp' => $otp]);
$merchant->setToken($token->accessToken); // updates all resources in place
$payments = $merchant->payments->list(); // retry
}
$service = new ServiceClient(['serviceKey' => 'pk_test_<your_test_key>']);
var_dump($service->testMode); // bool(true)
$status = $merchant->providerStatus->get();
// or: $service->providerStatus->get()
// $status is an associative array keyed by provider slug:
// [
// 'mtn_momo' => ['slug' => 'mtn_momo', 'name' => 'MTN Mobile Money', 'status' => 'operational', ...],
// 'orange_money' => ['slug' => 'orange_money', 'name' => 'Orange Money', 'status' => 'degraded', ...],
// 'stripe' => ['slug' => 'stripe', 'name' => 'Stripe', 'status' => 'operational', ...],
// ]
if ($status['mtn_momo']['status'] === 'down') {
return response()->json([
'message' => 'MTN Mobile Money is currently unavailable. Try Orange Money or pay by card.',
], 503);
}
// ── Collect from a customer's MoMo ───────────────────────────────────────────
$topup = $service->topups->create([
'amount' => 5000, // XAF
'customer_phone' => '237XXXXXXXXX',
'external_ref' => 'ORDER-001',
'notify_url' => 'https://yourapp.com/webhooks/momo',
]);
// pending — wallet credited after Fapshi webhook confirms
// ── Disburse to a customer's MoMo ────────────────────────────────────────────
$withdrawal = $service->withdrawals->create([
'amount' => 4000, // XAF
'recipient_phone' => '237XXXXXXXXX',
'external_ref' => 'PAYOUT-001',
]);
// Step 1 — initiate
$initiation = $merchant->payouts->initiate([
'amount' => 50_000,
'currency_code' => 'XAF',
'recipient_type' => 'tangentopay_wallet',
'recipient_details' => ['wallet_address' => '[email protected] '],
'note' => 'Freelance payment',
]);
// Step 2 — confirm with payout PIN
$merchant->payouts->confirm($initiation->payoutRef, ['pin' => getenv('PAYOUT_PIN')]);
// Option A: use a saved card
$merchant->payouts->initiate([
'amount' => 100,
'currency_code' => 'USD',
'recipient_type' => 'virtual_card',
'recipient_details' => ['payout_method_id' => 'pm_...'],
]);
// Option B: one-time Stripe.js token (card never stored)
$merchant->payouts->initiate([
'amount' => 100,
'currency_code' => 'USD',
'recipient_type' => 'virtual_card',
'recipient_details' => ['stripe_token_id' => 'tok_...'],
]);
$batch = $merchant->payouts->bulk->initiate([
'csv_file' => fopen('payouts.csv', 'r'),
'default_recipient_type' => 'tangentopay_wallet',
]);
$merchant->payouts->bulk->confirm($batch->batchRef, ['pin' => getenv('PAYOUT_PIN')]);
// Via MoMo
$topup = $merchant->topups->create([
'amount' => 100_000, // XAF
'phone' => '237XXXXXXXXX',
'provider' => 'mtn_momo',
]);
// Via card (Stripe-hosted page)
$cardTopup = $merchant->topups->createCardTopup([
'amount' => 200,
'currency_code' => 'USD',
'return_url' => 'https://dashboard.yourapp.com/wallet',
]);
$methods = $merchant->services->listPaymentMethods($serviceId);
// [['slug' => 'mtn_momo', 'name' => 'MTN Mobile Money', 'enabled' => true, 'locked' => false, ...], ...]
// Disable Orange Money if provider is down
$status = $merchant->providerStatus->get();
if ($status['orange_money']['status'] === 'down') {
$merchant->services->setPaymentMethod($serviceId, 'orange_money', false);
}
// Replace entire set (card must always be
use TangentoPay\Exceptions\AuthenticationException; // 401
use TangentoPay\Exceptions\PermissionException; // 403
use TangentoPay\Exceptions\NotFoundException; // 404
use TangentoPay\Exceptions\ValidationException; // 422 — has ->errors array
use TangentoPay\Exceptions\RateLimitException; // 429 — has ->retryAfter seconds
use TangentoPay\Exceptions\ServerException; // 5xx
use TangentoPay\Exceptions\NetworkException; // connection-level failure
use TangentoPay\Exceptions\TangentoPayException; // base class
try {
$merchant->payouts->initiate([...]);
} catch (ValidationException $e) {
print_r($e->errors); // field-level validation messages
} catch (RateLimitException $e) {
echo "Retry after {$e->retryAfter}s";
} catch (TangentoPayException $e) {
throw $e;
}
use TangentoPay\Webhook;
use TangentoPay\Exceptions\WebhookSignatureException;
$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_TANGENTOPAY_SIGNATURE'] ?? '';
try {
$event = Webhook::constructEvent($payload, $signature, getenv('TANGENTOPAY_WEBHOOK_SECRET'));
} catch (WebhookSignatureException $e) {
http_response_code(400);
exit('Bad signature');
}
if ($event->event === 'transaction.payment_completed') {
fulfillOrder($event->payload);
}
http_response_code(200);
echo json_encode(['received' => true]);
bash
composer