PHP code example of tcgunel / omnipay-odeal
1. Go to this page and download the library: Download tcgunel/omnipay-odeal 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/ */
tcgunel / omnipay-odeal example snippets
use Omnipay\Omnipay;
$gateway = Omnipay::create('Odeal');
$gateway->setClientId('your-client-id');
$gateway->setClientSecret('your-client-secret');
$gateway->setTestMode(true); // false for production
$gateway->setAgent('KOLAYSIPARIS'); // sent as the X-ODEAL-AGENT header
$gateway->setTokenUrl('https://proxy.test/auth/v1'); // override the token base URL
$gateway->setGatewayUrl('https://proxy.test/gw'); // override the gateway base URL
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$gateway->setLogger(new Logger('odeal', [new StreamHandler('php://stderr')]));
$gateway->setLogger(\Illuminate\Support\Facades\Log::channel('odeal'));
$gateway->setTokenCache($psr16Cache); // e.g. Laravel: cache()->store()
$response = $gateway->purchase([
'amount' => '25.00',
'transactionId' => 'ORDER-12345', // becomes externalId unless passed explicitly
'card' => [
'number' => '4026719999999999',
'expiryMonth' => '12',
'expiryYear' => '2030',
'cvv' => '123',
'firstName' => 'Test',
'lastName' => 'User',
],
'installment' => 1, // 1-12, 1 = single payment
'currency' => 'TRY', // optional, TRY is the default
'phone' => '5551234567', // 5XXXXXXXXX; 05xx / +90 5xx are normalised
'returnUrl' => 'https://shop.test/odeal/return', // receives Ödeal's server-to-server callback
'successRedirectUrl' => 'https://shop.test/order/ok',
'failureRedirectUrl' => 'https://shop.test/order/fail',
'buyerName' => 'Test User', // optional BuyerInfo fields
'buyerCity' => 'Istanbul',
'buyerMail' => '[email protected] ',
'buyerAddress' => 'Test Mah. 1. Sok.',
])->send();
if ($response->isRedirect()) {
// Show the self-contained 3D challenge page to the shopper.
echo $response->getHtmlContent();
// Save Ödeal's transaction id NOW: cancel/refund/status operate on it.
$transactionId = $response->getTransactionReference();
} else {
echo 'Payment could not be started: ' . $response->getMessage();
}
$response = $gateway->completePurchase([
'externalId' => 'ORDER-12345', // or 'id' => $transactionId
])->send();
if ($response->isSuccessful()) { // payment_status === COMPLETED
echo 'Paid. Auth code: ' . $response->getAuthCode();
} elseif ($response->isPending()) {
// still processing — poll again shortly
} else {
echo 'Payment status: ' . $response->getPaymentStatus();
}
$response = $gateway->purchaseNon3D([
'amount' => '25.00',
'card' => [/* ... */],
])->send();
// Or: $gateway->purchase([... 'secure' => false ...])
// Or set the gateway default: $gateway->setSecure(false);
if ($response->isSuccessful()) {
echo 'Paid. Transaction id: ' . $response->getTransactionReference();
} elseif ($response->getForce3DPayment()) {
// The issuer demands 3D for this card/amount: restart through purchase().
}
$response = $gateway->payByLink([
'amount' => '25.00',
'returnUrl' => 'https://shop.test/odeal/return',
])->send();
if ($response->isSuccessful()) {
redirect($response->getCheckout3DUrl());
}
$response = $gateway->void([
'id' => 123456789, // or 'externalId' => 'ORDER-12345'
])->send();
if ($response->isSuccessful()) {
echo 'Cancelled.';
}
$response = $gateway->refund([
'id' => 123456789, // or 'externalId' => 'ORDER-12345'
'amount' => '10.50',
'reason' => 'Musteri talebi', // optional
'reasonType' => 'REQUESTEDBYCUSTOMER', // DUPLICATE, FRAUDULENT, REQUESTEDBYCUSTOMER
])->send();
$response = $gateway->fetchTransaction(['externalId' => 'ORDER-12345'])->send();
$response->getStatus(); // COMPLETED, REFUND, ...
$response->getAmount(); // 25.00
$response->getRefundedAmount(); // 5.00
$response->getRefunds(); // refund history
$response->getCreatedDateFormatted();
try {
$gateway->fetchToken()->send();
} catch (\Omnipay\Common\Exception\InvalidResponseException $e) {
echo 'Credentials rejected: ' . $e->getMessage();
}