1. Go to this page and download the library: Download texhub/alif-pay 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/ */
texhub / alif-pay example snippets
use TexHub\AlifPay\AlifPay;
use TexHub\AlifPay\Enums\Environment;
use TexHub\AlifPay\Enums\Gate;
use TexHub\AlifPay\Requests\PaymentRequest;
$alif = AlifPay::make(
terminalId: 'YOUR_TERMINAL_ID',
terminalPassword: 'YOUR_TERMINAL_PASSWORD',
environment: Environment::Test, // Environment::Production when live
);
$response = $alif->payments()->initiate(
PaymentRequest::make('ORDER_123456', '100.50')
->gate(Gate::KortiMilli)
->callbackUrl('https://shop.tj/alif/callback')
->returnUrl('https://shop.tj/success')
->info('Оплата заказа №123456')
->phone('992900123456')
);
// Send the customer to the secure payment form:
header('Location: ' . $response->redirectUrl());
// All methods except Visa/Mastercard:
$alif->marketplace()->confirmDelivery(transactionId: '789013', amount: '300.00');
// Visa / Mastercard:
$alif->marketplace()->confirmVsaMcrDelivery(parentTransactionId: '789012');
// Status & cancellation:
$alif->marketplace()->checkStatus('MP_ORDER_123456');
$alif->marketplace()->cancel(transactionId: '789013', amount: '300.00');
use TexHub\AlifPay\Enums\PaymentStatus;
$callback = $alif->webhooks()->paymentCallback(file_get_contents('php://input'));
// Verify authenticity before trusting it (see note below):
if (! $alif->webhooks()->verifyPaymentCallback($callback)) {
http_response_code(400);
exit;
}
match ($callback->status) {
PaymentStatus::Ok => markOrderPaid($callback->orderId, $callback->amount),
PaymentStatus::Failed,
PaymentStatus::Canceled => markOrderFailed($callback->orderId),
default => null, // pending / to_approve
};
http_response_code(200);
echo 'OK';
$callback = $alif->webhooks()->tokenizationCallback(file_get_contents('php://input'));
if ($callback->isSuccessful()) {
saveToken($callback->orderId, $callback->token); // store for repeat charges
}
http_response_code(200);
$alif->webhooks()->verifyPaymentCallback($callback, dataToSign: $yourString);
// or the low-level check:
$alif->webhooks()->verifyToken($yourString, $callback->token);
use TexHub\AlifPay\Laravel\AlifPay;
use TexHub\AlifPay\Enums\Gate;
use TexHub\AlifPay\Requests\PaymentRequest;
$response = AlifPay::payments()->initiate(
PaymentRequest::make('ORDER_'.$order->id, $order->total)->gate(Gate::KortiMilli)
);
return redirect()->away($response->redirectUrl());
public function pay(\TexHub\AlifPay\AlifPay $alif) { /* ... */ }
use Illuminate\Http\Request;
use TexHub\AlifPay\Laravel\AlifPay;
use TexHub\AlifPay\Enums\PaymentStatus;
public function callback(Request $request)
{
$callback = AlifPay::webhooks()->paymentCallback($request->getContent());
if ($callback->status === PaymentStatus::Ok) {
Order::where('reference', $callback->orderId)->update(['status' => 'paid']);
}
return response('OK', 200);
}
use TexHub\AlifPay\AlifPay;
use TexHub\AlifPay\Config;
use TexHub\AlifPay\Tests\Support\FakeTransport;
$transport = (new FakeTransport())->willReturnJson([
'code' => 200, 'message' => 'Успешно', 'url' => 'https://web.alif.tj/abc',
]);
$alif = new AlifPay(new Config('id', 'secret'), $transport);
// ... assert on $transport->lastBody / lastHeaders / lastUrl