### Convert Turkish Lira and Kuruş using PriceConverter in PHP Source: https://context7.com/furkanmeclis/paytr-link/llms.txt This PHP snippet demonstrates the use of the PriceConverter class to convert between Turkish Lira (TL) and kuruş (cents). It shows how to convert TL to kuruş for API requests and kuruş back to TL for display purposes, including examples of custom calculations. ```php use FurkanMeclis\PayTRLink\Support\PriceConverter; // Convert TL to kuruş (for API requests) $priceInTL = 1500.00; $priceInKurus = PriceConverter::toKurus($priceInTL); // Result: 150000 // Convert kuruş to TL (for display) $amountInKurus = 250050; $amountInTL = PriceConverter::fromKurus($amountInKurus); // Result: 2500.50 // Use in custom calculations $discountPercentage = 15; $originalPrice = 2000.00; $discountedPrice = $originalPrice * (1 - $discountPercentage / 100); $finalPriceInKurus = PriceConverter::toKurus($discountedPrice); // Display to user echo "Original: " . number_format($originalPrice, 2) . " TL\n"; echo "Discounted: " . number_format($discountedPrice, 2) . " TL\n"; echo "API Value: " . $finalPriceInKurus . " kuruş"; ``` -------------------------------- ### Create Product Payment Link with PayTR Laravel Source: https://context7.com/furkanmeclis/paytr-link/llms.txt Creates a product-type payment link using the PayTR Link Laravel package. It takes various parameters like name, price, currency, installments, and expiry date. The response includes the payment link URL and a unique link ID. It handles success and error responses from the API. ```php use FurkanMeclis\PayTRLink\Facades\PayTRLink; use FurkanMeclis\PayTRLink\Data\CreateLinkData; use FurkanMeclis\PayTRLink\Enums\CurrencyEnum; use FurkanMeclis\PayTRLink\Enums\LinkTypeEnum; // Create product link with installments $data = CreateLinkData::from([ 'name' => 'Premium Web Development Package', 'price' => 2500.00, // Amount in TL (automatically converted to kuruş) 'currency' => CurrencyEnum::TL, 'link_type' => LinkTypeEnum::Product, 'max_installment' => 12, 'min_count' => 1, 'lang' => 'tr', 'expiry_date' => '2025-12-31 23:59:59', 'description' => 'Professional web development services' ]); try { $response = PayTRLink::create($data); if ($response->isSuccess()) { $paymentLink = $response->link; // https://www.paytr.com/link/xxxxx $linkId = $response->id; // Store this ID for future operations return response()->json([ 'success' => true, 'payment_url' => $paymentLink, 'link_id' => $linkId ]); } else { return response()->json([ 'success' => false, 'message' => $response->message, 'errors' => $response->errors ], 400); } } catch (\Exception $e) { return response()->json(['error' => $e->getMessage()], 500); } ``` -------------------------------- ### Configure PayTR Credentials using .env and Spatie Laravel Settings in PHP Source: https://context7.com/furkanmeclis/paytr-link/llms.txt This snippet shows two methods for configuring PayTR credentials: using a .env file and using Spatie Laravel Settings for database storage. The database method takes precedence over .env, allowing for runtime configuration changes. Dependencies include the PayTRSettings class from the SDK. ```php // .env file configuration PAYTR_MERCHANT_ID=123456 PAYTR_MERCHANT_KEY=your_merchant_key_here PAYTR_MERCHANT_SALT=your_merchant_salt_here PAYTR_DEBUG_ON=1 PAYTR_TIMEOUT=30 // Using Spatie Laravel Settings for database storage use FurkanMeclis\PayTRLink\Settings\PayTRSettings; // Save settings to database $settings = app(PayTRSettings::class); $settings->merchant_id = '123456'; $settings->merchant_key = 'your_merchant_key_here'; $settings->merchant_salt = 'your_merchant_salt_here'; $settings->debug_on = true; $settings->save(); // Settings take precedence over .env configuration // This allows runtime configuration changes without redeploying ``` -------------------------------- ### Use PayTRLinkService via Dependency Injection in PHP Source: https://context7.com/furkanmeclis/paytr-link/llms.txt This snippet demonstrates how to inject and use the PayTRLinkService within a Laravel controller for creating payment links. It includes setting up link data, handling responses, and sending emails. Dependencies include the PayTRLinkService, CreateLinkData, CurrencyEnum, LinkTypeEnum, and SendEmailData. ```php use FurkanMeclis\PayTRLink\PayTRLinkService; use FurkanMeclis\PayTRLink\Data\CreateLinkData; use FurkanMeclis\PayTRLink\Enums\CurrencyEnum; use FurkanMeclis\PayTRLink\Enums\LinkTypeEnum; class PaymentController extends Controller { public function __construct( protected PayTRLinkService $paytrLink ) {} public function createInvoiceLink(Request $request) { $validated = $request->validate([ 'customer_name' => 'required|string', 'amount' => 'required|numeric|min:1', 'email' => 'required|email' ]); $linkData = CreateLinkData::from([ 'name' => "Invoice for {$validated['customer_name']}", 'price' => $validated['amount'], 'currency' => CurrencyEnum::TL, 'link_type' => LinkTypeEnum::Collection, 'email' => $validated['email'], 'max_installment' => 1, 'expiry_date' => now()->addDays(30)->format('Y-m-d H:i:s') ]); try { $response = $this->paytrLink->create($linkData); if ($response->isSuccess()) { // Send email automatically $this->paytrLink->sendEmail(FurkanMeclis\PayTRLink\Data\SendEmailData::from([ 'link_id' => $response->id, 'email' => $validated['email'] ])); return response()->json([ 'success' => true, 'link' => $response->link, 'link_id' => $response->id ]); } return response()->json([ 'success' => false, 'message' => $response->message ], 400); } catch (\Exception $e) { return response()->json(['error' => $e->getMessage()], 500); } } } ``` -------------------------------- ### Create Payment Links in Multiple Currencies with PayTRLink in PHP Source: https://context7.com/furkanmeclis/paytr-link/llms.txt This PHP snippet shows how to create payment links for different currencies (USD, EUR, GBP) using the PayTRLink facade. It utilizes the CreateLinkData object and specifies the desired currency using the CurrencyEnum. The resulting links and IDs are then stored in an associative array. ```php use FurkanMeclis\PayTRLink\Facades\PayTRLink; use FurkanMeclis\PayTRLink\Data\CreateLinkData; use FurkanMeclis\PayTRLink\Enums\CurrencyEnum; use FurkanMeclis\PayTRLink\Enums\LinkTypeEnum; // Create USD payment link $usdLink = PayTRLink::create(CreateLinkData::from([ 'name' => 'International Service Package', 'price' => 99.99, 'currency' => CurrencyEnum::USD, 'link_type' => LinkTypeEnum::Product, 'max_installment' => 1, 'lang' => 'en' ])); // Create EUR payment link $eurLink = PayTRLink::create(CreateLinkData::from([ 'name' => 'European Market Product', 'price' => 149.99, 'currency' => CurrencyEnum::EUR, 'link_type' => LinkTypeEnum::Product, 'max_installment' => 6, 'lang' => 'en' ])); // Create GBP payment link $gbpLink = PayTRLink::create(CreateLinkData::from([ 'name' => 'UK Premium Service', 'price' => 79.99, 'currency' => CurrencyEnum::GBP, 'link_type' => LinkTypeEnum::Product, 'max_installment' => 3, 'lang' => 'en' ])); // Store links with currency information $paymentLinks = [ 'usd' => ['link' => $usdLink->link, 'id' => $usdLink->id], 'eur' => ['link' => $eurLink->link, 'id' => $eurLink->id], 'gbp' => ['link' => $gbpLink->link, 'id' => $gbpLink->id] ]; ``` -------------------------------- ### Handle API Errors and Validation Failures in PHP Source: https://context7.com/furkanmeclis/paytr-link/llms.txt This snippet demonstrates how to handle API errors (PayTRRequestException) and validation failures (PayTRValidationException) when creating payment links using the PayTRLink facade. It logs errors and returns specific status messages based on the exception type. General exceptions are also caught for robust error management. ```php use FurkanMeclis\PayTRLink\Facades\PayTRLink; use FurkanMeclis\PayTRLink\Exceptions\PayTRRequestException; use FurkanMeclis\PayTRLink\Exceptions\PayTRValidationException; use FurkanMeclis\PayTRLink\Data\CreateLinkData; use FurkanMeclis\PayTRLink\Enums\CurrencyEnum; use FurkanMeclis\PayTRLink\Enums\LinkTypeEnum; public function createPaymentLink(array $orderData) { try { $data = CreateLinkData::from([ 'name' => $orderData['product_name'], 'price' => $orderData['amount'], 'currency' => CurrencyEnum::TL, 'link_type' => LinkTypeEnum::Product, 'max_installment' => 12 ]); $response = PayTRLink::create($data); if ($response->isSuccess()) { return [ 'status' => 'success', 'link' => $response->link, 'id' => $response->id ]; } return [ 'status' => 'error', 'message' => $response->message, 'errors' => $response->errors ]; } catch (PayTRRequestException $e) { // API communication error \Log::error('PayTR API request failed', [ 'message' => $e->getMessage(), 'response' => $e->response, 'order_data' => $orderData ]); return [ 'status' => 'api_error', 'message' => 'Payment gateway communication failed', 'details' => $e->response ]; } catch (PayTRValidationException $e) { // Data validation error \Log::error('PayTR validation failed', [ 'message' => $e->getMessage(), 'validation_errors' => $e->errors, 'order_data' => $orderData ]); return [ 'status' => 'validation_error', 'message' => 'Invalid payment data', 'errors' => $e->errors ]; } catch (\Exception $e) { // General error \Log::error('Unexpected payment error', [ 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); return [ 'status' => 'error', 'message' => 'An unexpected error occurred' ]; } } ``` -------------------------------- ### Send Payment Link via Email (PHP) Source: https://context7.com/furkanmeclis/paytr-link/llms.txt Sends a payment link to a customer's email address using PayTR's email service. It requires a `SendEmailData` object with the link ID and email address. After successful sending, it logs the notification to a database table. Dependencies include the PayTRLink facade and SendEmailData class. ```php use FurkanMeclis\PayTRLink\Facades\PayTRLink; use FurkanMeclis\PayTRLink\Data\SendEmailData; $emailData = SendEmailData::from([ 'link_id' => 'abc123xyz789', 'email' => 'customer@example.com' ]); $response = PayTRLink::sendEmail($emailData); if ($response->isSuccess()) { // Update notification log \DB::table('payment_notifications')->insert([ 'link_id' => 'abc123xyz789', 'notification_type' => 'email', 'recipient' => 'customer@example.com', 'status' => 'sent', 'sent_at' => now() ]); } ``` -------------------------------- ### Create Collection Payment Link with PayTR Laravel Source: https://context7.com/furkanmeclis/paytr-link/llms.txt Generates a collection-type payment link using the PayTR Link Laravel package. This link type is suitable for recurring payments or when customer email is required. It includes parameters like name, price, currency, and customer email. The created link and ID can be stored for further use. ```php use FurkanMeclis\PayTRLink\Facades\PayTRLink; use FurkanMeclis\PayTRLink\Data\CreateLinkData; use FurkanMeclis\PayTRLink\Enums\CurrencyEnum; use FurkanMeclis\PayTRLink\Enums\LinkTypeEnum; // Create collection link $data = CreateLinkData::from([ 'name' => 'Monthly Subscription Payment', 'price' => 99.99, 'currency' => CurrencyEnum::TL, 'link_type' => LinkTypeEnum::Collection, 'email' => 'customer@example.com', // Required for collection links 'max_installment' => 6, 'lang' => 'en' ]); $response = PayTRLink::create($data); if ($response->isSuccess()) { // Send link to customer $subscriptionLink = $response->link; $linkId = $response->id; // Store in database \DB::table('payment_links')->insert([ 'link_id' => $linkId, 'customer_email' => 'customer@example.com', 'amount' => 99.99, 'status' => 'pending', 'created_at' => now() ]); } ``` -------------------------------- ### Validate Payment Callback (PHP) Source: https://context7.com/furkanmeclis/paytr-link/llms.txt Validates incoming payment callback requests from PayTR to ensure authenticity and process payments. It uses the `PayTRLink::validateCallback` method with request data. If valid, it parses the `CallbackData` and updates the order status in the database, or logs payment failures. Dependencies include the Request object, PayTRLink facade, and CallbackData class. ```php use Illuminate\Http\Request; use FurkanMeclis\PayTRLink\Facades\PayTRLink; use FurkanMeclis\PayTRLink\Data\CallbackData; // Route: POST /paytr/callback public function handlePaymentCallback(Request $request) { // Validate callback authenticity if (!PayTRLink::validateCallback($request->all())) { \Log::warning('Invalid PayTR callback received', [ 'ip' => $request->ip(), 'data' => $request->all() ]); return response('Invalid hash', 400); } // Parse callback data $callback = CallbackData::from($request->all()); // Process based on payment status if ($callback->status === 'success') { // Payment successful - update order $order = \DB::table('orders') ->where('merchant_oid', $callback->merchant_oid) ->first(); if ($order) { \DB::table('orders') ->where('id', $order->id) ->update([ 'payment_status' => 'completed', 'callback_id' => $callback->callback_id, 'total_amount' => $callback->total_amount, 'payment_type' => $callback->payment_type, 'installment_count' => $callback->installment_count, 'paid_at' => now() ]); // Trigger order fulfillment event(new \App\Events\OrderPaid($order)); \Log::info('Payment completed', [ 'order_id' => $order->id, 'callback_id' => $callback->callback_id, 'amount' => $callback->total_amount ]); } return response('OK', 200); } else { // Payment failed \Log::error('Payment failed', [ 'merchant_oid' => $callback->merchant_oid, 'reason_code' => $callback->failed_reason_code, 'reason_msg' => $callback->failed_reason_msg ]); // Update order status \DB::table('orders') ->where('merchant_oid', $callback->merchant_oid) ->update([ 'payment_status' => 'failed', 'failure_reason' => $callback->failed_reason_msg ]); return response('OK', 200); } } ``` -------------------------------- ### Send Payment Link via SMS (PHP) Source: https://context7.com/furkanmeclis/paytr-link/llms.txt Sends a payment link to a customer's phone number using PayTR's SMS service. It requires a `SendSmsData` object containing the link ID and phone number. The function returns a success or failure response, with error logging for issues. Dependencies include the PayTRLink facade and SendSmsData class. ```php use FurkanMeclis\PayTRLink\Facades\PayTRLink; use FurkanMeclis\PayTRLink\Data\SendSmsData; $smsData = SendSmsData::from([ 'link_id' => 'abc123xyz789', 'phone' => '5551234567' // Turkish mobile format (without +90) ]); try { $response = PayTRLink::sendSms($smsData); if ($response->isSuccess()) { // Log SMS delivery \Log::info('Payment link SMS sent', [ 'link_id' => 'abc123xyz789', 'phone' => '5551234567', 'sent_at' => now() ]); return response()->json([ 'success' => true, 'message' => 'SMS sent successfully' ]); } else { return response()->json([ 'success' => false, 'message' => $response->message ], 400); } } catch (\FurkanMeclis\PayTRLink\Exceptions\PayTRRequestException $e) { \Log::error('SMS sending failed', [ 'error' => $e->getMessage(), 'response' => $e->response ]); return response()->json(['error' => 'Failed to send SMS'], 500); } ``` -------------------------------- ### Delete Payment Link with PayTR Laravel Source: https://context7.com/furkanmeclis/paytr-link/llms.txt Deletes a payment link from the PayTR system using the PayTR Link Laravel package. This prevents further payments on the specified link. It can be done using either a `DeleteLinkData` object or directly passing the link ID as a string. The response indicates success or failure, allowing for database updates. ```php use FurkanMeclis\PayTRLink\Facades\PayTRLink; use FurkanMeclis\PayTRLink\Data\DeleteLinkData; // Method 1: Using DeleteLinkData object $response = PayTRLink::delete(DeleteLinkData::from([ 'link_id' => 'abc123xyz789' ])); // Method 2: Using string directly (simpler) $response = PayTRLink::delete('abc123xyz789'); if ($response->isSuccess()) { // Update database status \DB::table('payment_links') ->where('link_id', 'abc123xyz789') ->update(['status' => 'deleted', 'deleted_at' => now()]); return response()->json([ 'success' => true, 'message' => 'Payment link successfully deleted' ]); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.