PHP code example of ahmedibrahimyassindev / tamara-php-sdk
1. Go to this page and download the library: Download ahmedibrahimyassindev/tamara-php-sdk 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/ */
ahmedibrahimyassindev / tamara-php-sdk example snippets
use TamaraPhpSdk\Contracts\TamaraOrderableInterface;
use TamaraPhpSdk\Traits\TamaraOrderableTrait;
class Order extends \Illuminate\Database\Eloquent\Model implements TamaraOrderableInterface
{
use TamaraOrderableTrait;
public function getTamaraAmount(): float
{
return (float) $this->total_amount;
}
}
use TamaraPhpSdk\TamaraService;
// Create service from environment variables
$service = TamaraService::fromEnv();
// Or instantiate manually with credentials
// $client = new \TamaraPhpSdk\TamaraClient($merchantToken, $notificationToken, $sandbox = true);
// $service = new TamaraService($client);
$checkoutUrl = $service->initiateCheckout(
$order,
'https://yourdomain.com/payment/success',
'https://yourdomain.com/payment/failure',
'https://yourdomain.com/payment/cancel'
);
// Redirect user to Tamara
header("Location: {$checkoutUrl}");
exit;
// Authorise order
$service->authoriseOrder($tamaraOrderId);
// Get order details
$orderData = $service->getOrder($tamaraOrderId);
// Capture payment (provide shipping information service->cancelOrder($tamaraOrderId);
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.