PHP code example of yacoubalhaidari / telr-laravel
1. Go to this page and download the library: Download yacoubalhaidari/telr-laravel 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/ */
yacoubalhaidari / telr-laravel example snippets
use yacoubalhaidari\Telr\DTOs\Order\CustomerDTO;
$customer = CustomerDTO::fromContact(
fullName: $order->customer_name,
email: $order->customer_email,
phone: $order->customer_phone,
);
$response = Telr::createOrder(new CreateOrderDTO(
order: new OrderDetailsDTO(...),
return: new ReturnUrlsDTO(...),
customer: $customer,
));
use yacoubalhaidari\Telr\Facades\Telr;
use yacoubalhaidari\Telr\DTOs\Order\{CreateOrderDTO, OrderDetailsDTO, ReturnUrlsDTO};
use yacoubalhaidari\Telr\Enums\Currency;
$response = Telr::createOrder(new CreateOrderDTO(
order: new OrderDetailsDTO(
cartId: (string) $order->id,
amount: '150.00',
currency: Currency::AED,
description: 'Order #' . $order->id,
test: config('telr.test_mode'),
),
return: new ReturnUrlsDTO(
authorised: route('checkout.authorised'),
declined: route('checkout.declined'),
cancelled: route('checkout.cancelled'),
),
));
if ($response->success) {
return redirect($response->paymentUrl);
}
// $response->errorCode / $response->errorMessage
class ReconcileOrderPayment
{
public function __construct(private \App\Services\OrderPaymentReconciliation $payments) {}
public function handle(
\yacoubalhaidari\Telr\Events\TelrTransactionAuthorised|\yacoubalhaidari\Telr\Events\TelrTransactionDeclined $event,
): void
{
$this->payments->reconcile($event->transaction->cartId);
}
}
use yacoubalhaidari\Telr\Facades\Telr;
$xml = Telr::serviceApi()->transaction('011287290362');
$accounts = Telr::serviceApi()->accounts(); // JSON, unlike every other Service API endpoint