PHP code example of voxyfy / anadolupay

1. Go to this page and download the library: Download voxyfy/anadolupay 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/ */

    

voxyfy / anadolupay example snippets




namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Voxyfy\AnadoluPay\DTO\CreatePaymentData;
use Voxyfy\AnadoluPay\Facades\AnadoluPay;

class PaymentController extends Controller
{
    public function pay(Request $request)
    {
        $data = new CreatePaymentData(
            amount: 100.00,
            currency: 'TRY',
            orderId: 'SIPARIS-123',
            customer: [
                'name' => 'Ahmet Yilmaz',
                'email' => '[email protected]',
                'phone' => '+905551112233',
                'card' => [
                    'cardHolderName' => 'Ahmet Yilmaz',
                    'cardNumber' => '5528790000000008',
                    'expireYear' => '2030',
                    'expireMonth' => '12',
                    'cvc' => '123',
                ],
            ],
            successUrl: 'https://example.com/success',
            failUrl: 'https://example.com/fail',
        );

        $response = AnadoluPay::driver('iyzico')->createPayment($data);

        $threeDsHtml = $response->raw['threeDSHtmlContent'] ?? null;

        return response()->json([
            'threeDSHtmlContent' => $threeDsHtml,
        ]);
    }
}

$response = AnadoluPay::driver('iyzico')->createPayment($data);

$html = base64_decode($response->raw['threeDSHtmlContent']);

return response($html);



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Voxyfy\AnadoluPay\DTO\VerifyPaymentData;
use Voxyfy\AnadoluPay\Facades\AnadoluPay;

class IyzicoCallbackController extends Controller
{
    public function handle(Request $request)
    {
        $result = AnadoluPay::driver('iyzico')->verify(new VerifyPaymentData(
            payload: $request->all(),
            headers: $request->headers->all(),
            rawBody: $request->getContent(),
        ));

        return response()->json([
            'success' => $result->success,
            'status' => $result->status,
            'paymentId' => $result->paymentId,
        ]);
    }
}
bash
php artisan vendor:publish --tag="anadolupay-config"