### Composer Dependency Installation Source: https://github.com/souidev/laravel-clictopay/blob/master/CONTRIBUTING.md Command to install project dependencies using Composer. ```bash composer install ``` -------------------------------- ### Install Laravel ClicToPay Package via Composer Source: https://github.com/souidev/laravel-clictopay/blob/master/README.md This command installs the ClicToPay Laravel package using Composer. Ensure you have Composer installed and configured for your Laravel project. ```bash composer require Souidev/laravel-clictopay ``` -------------------------------- ### Set ClicToPay Environment Variables Source: https://github.com/souidev/laravel-clictopay/blob/master/README.md Example `.env` file entries for configuring the ClicToPay Laravel package. These variables hold your ClicToPay API credentials and other settings. Ensure these are set correctly for both test and production environments. ```dotenv CLICTOPAY_USERNAME=your_username CLICTOPAY_PASSWORD=your_password CLICTOPAY_TEST_MODE=true # or false CLICTOPAY_RETURN_URL=https://your-site.com/payment/success CLICTOPAY_FAIL_URL=https://your-site.com/payment/fail ``` -------------------------------- ### Refund Payment using ClicToPay in Laravel Source: https://context7.com/souidev/laravel-clictopay/llms.txt This example demonstrates how to process a full or partial refund for a completed payment via ClicToPay in Laravel. It validates the refund amount and records the refund in the database upon successful processing. The response is returned as JSON. ```php use Souidev\ClicToPayLaravel\Facades\ClicToPay; Route::post('/refund-payment/{orderId}', function(Request $request, $orderId) { $request->validate([ 'amount' => 'required|integer|min:1' ]); try { $result = ClicToPay::refundPayment([ 'orderId' => $orderId, 'amount' => $request->amount // Amount in millimes to refund ]); if ($result['errorCode'] === '0') { // Record refund in database Refund::create([ 'order_id' => $orderId, 'amount' => $request->amount, 'status' => 'completed', 'refunded_at' => now() ]); return response()->json([ 'success' => true, 'message' => 'Refund processed successfully', 'refund_amount' => $request->amount / 1000 . ' TND' ]); } return response()->json([ 'success' => false, 'error' => $result['errorMessage'] ], 400); } catch (Exception $e) { Log::error("Refund failed for order {$orderId}: " . $e->getMessage()); return response()->json(['error' => 'Refund processing failed'], 500); } }); ``` -------------------------------- ### Get Payment Status using ClicToPay in Laravel Source: https://context7.com/souidev/laravel-clictopay/llms.txt This code snippet illustrates how to retrieve the current status of a payment order using the ClicToPay facade in Laravel. It maps the returned status codes to human-readable states and returns the information as a JSON response. Ensure proper error handling for API communication. ```php use Souidev\ClicToPayLaravel\Facades\ClicToPay; Route::get('/payment-status/{orderId}', function($orderId) { try { $status = ClicToPay::getPaymentStatus([ 'orderId' => $orderId, 'language' => 'fr' // Optional: for localized error messages ]); // ErrorCode: 0 = success, non-zero = error if ($status['ErrorCode'] === '0') { // OrderStatus values: // 0 = Registered but not paid // 1 = Pre-authorized // 2 = Paid/Completed // 3 = Authorization cancelled // 4 = Transaction cancelled // 5 = Authorization on hold // 6 = Refunded $statusMap = [ 0 => 'pending', 1 => 'pre_authorized', 2 => 'completed', 3 => 'auth_cancelled', 4 => 'cancelled', 5 => 'on_hold', 6 => 'refunded' ]; return response()->json([ 'order_id' => $orderId, 'status' => $statusMap[$status['OrderStatus']] ?? 'unknown', 'status_code' => $status['OrderStatus'] ]); } return response()->json([ 'error' => $status['ErrorMessage'] ], 400); } catch (Exception $e) { Log::error("Status check failed for order {$orderId}: " . $e->getMessage()); return response()->json(['error' => 'Status check failed'], 500); } }); ``` -------------------------------- ### Get Extended Order Status with Laravel ClicToPay Source: https://context7.com/souidev/laravel-clictopay/llms.txt Retrieves comprehensive order information using the ClicToPay Laravel facade. This function takes an order ID and language as input and returns detailed order status, including amount, currency, transaction date, and card details. It handles success and error responses, logging any exceptions. ```php use Souidev\ClicToPayLaravel\Facades\ClicToPay; Route::get('/order-details/{orderId}', function($orderId) { try { $extendedStatus = ClicToPay::getExtendedOrderStatus([ 'orderId' => $orderId, 'language' => 'en' ]); if ($extendedStatus['ErrorCode'] === '0') { return response()->json([ 'order_id' => $orderId, 'order_number' => $extendedStatus['orderNumber'] ?? null, 'status' => $extendedStatus['orderStatus'], 'amount' => $extendedStatus['amount'], // in millimes 'amount_display' => ($extendedStatus['amount'] / 1000) . ' TND', 'currency' => $extendedStatus['currency'], 'transaction_date' => $extendedStatus['date'] ?? null, 'card_holder_name' => $extendedStatus['cardholderName'] ?? null, 'masked_pan' => $extendedStatus['Pan'] ?? null, // Masked card number 'ip_address' => $extendedStatus['ip'] ?? null, 'description' => $extendedStatus['orderDescription'] ?? null, 'merchant_order_params' => $extendedStatus['merchantOrderParams'] ?? [], 'action_code' => $extendedStatus['actionCode'] ?? null, 'action_code_description' => $extendedStatus['actionCodeDescription'] ?? null ]); } return response()->json([ 'error' => $extendedStatus['ErrorMessage'] ], 400); } catch (Exception $e) { Log::error("Extended status failed for order {$orderId}: " . $e->getMessage()); return response()->json(['error' => 'Unable to retrieve order details'], 500); } }); ``` -------------------------------- ### Get Extended ClicToPay Order Status in Laravel Source: https://github.com/souidev/laravel-clictopay/blob/master/README.md Fetches detailed information about a ClicToPay order status, providing more granular data than the basic status check. Requires `orderId` and optionally accepts `language`. The response includes `ErrorCode` and detailed order fields like `orderStatus`, `amount`, `currency`, and `date` if the `ErrorCode` is '0'. ```php try { $extendedStatus = ClicToPay::getExtendedOrderStatus([ 'orderId' => 'ORDER-12345', 'language' => 'fr' // Optional - for localized error messages ]); // Handle extended status information if ($extendedStatus['ErrorCode'] === '0') { // Access additional payment information $orderStatus = $extendedStatus['orderStatus']; $amount = $extendedStatus['amount']; $currency = $extendedStatus['currency']; $date = $extendedStatus['date']; // ... other available fields } } catch (Exception $e) { // Handle error } ``` -------------------------------- ### Composer Test Execution Source: https://github.com/souidev/laravel-clictopay/blob/master/CONTRIBUTING.md Command to run all project tests using Composer. ```bash composer test ``` -------------------------------- ### Composer Static Analysis Source: https://github.com/souidev/laravel-clictopay/blob/master/CONTRIBUTING.md Command to perform static code analysis using Composer. ```bash composer analyse ``` -------------------------------- ### Configure Laravel ClicToPay Settings Source: https://context7.com/souidev/laravel-clictopay/llms.txt Sets up ClicToPay integration by configuring environment variables and the service's configuration file. This includes merchant credentials, test mode toggle, return and failure URLs, and API base URLs for both test and production environments. The service automatically selects the correct API URL based on the `CLICTOPAY_TEST_MODE` setting. ```dotenv # .env configuration CLICTOPAY_USERNAME=your_merchant_username CLICTOPAY_PASSWORD=your_merchant_password CLICTOPAY_TEST_MODE=true CLICTOPAY_RETURN_URL=https://yoursite.com/payment/success CLICTOPAY_FAIL_URL=https://yoursite.com/payment/failed CLICTOPAY_API_BASE_URL=https://test.clictopay.com/payment/rest/ ``` ```php // config/clictopay.php (published via vendor:publish) env('CLICTOPAY_USERNAME'), 'password' => env('CLICTOPAY_PASSWORD'), 'test_mode' => env('CLICTOPAY_TEST_MODE', true), 'return_url' => env('CLICTOPAY_RETURN_URL'), 'fail_url' => env('CLICTOPAY_FAIL_URL'), 'api_base_url' => env('CLICTOPAY_API_BASE_URL', 'https://test.clictopay.com/payment/rest/'), ]; // Publish configuration file // php artisan vendor:publish --provider="Souidev\ClicToPayLaravel\ClicToPayLaravelServiceProvider" --tag="config" // Service automatically switches URLs based on test_mode: // test_mode=true: https://test.clictopay.com/payment/rest/ // test_mode=false: uses api_base_url value (production) ``` -------------------------------- ### Composer Test with Coverage Source: https://github.com/souidev/laravel-clictopay/blob/master/CONTRIBUTING.md Command to run tests and generate a code coverage report using Composer. ```bash composer test-coverage ``` -------------------------------- ### Composer Code Formatting Source: https://github.com/souidev/laravel-clictopay/blob/master/CONTRIBUTING.md Command to format code according to project standards using Composer. ```bash composer format ``` -------------------------------- ### Publish ClicToPay Configuration File Source: https://github.com/souidev/laravel-clictopay/blob/master/README.md This command publishes the ClicToPay configuration file to your Laravel project. After publishing, you will need to edit the `config/clictopay.php` file to set your ClicToPay credentials and settings. ```bash php artisan vendor:publish --provider="Souidev\ClicToPayLaravel\ClicToPayLaravelServiceProvider" --tag="config" ``` -------------------------------- ### Git Branching Command Source: https://github.com/souidev/laravel-clictopay/blob/master/CONTRIBUTING.md Command to create a new branch for feature development or bug fixes in Git. ```bash git checkout -b feature-name ``` -------------------------------- ### Register Pre-Authorization API Source: https://context7.com/souidev/laravel-clictopay/llms.txt This API endpoint allows you to register a pre-authorization for a payment. Funds are not captured immediately, which is useful for reservations or orders that will be fulfilled later. ```APIDOC ## POST /reserve ### Description Creates a payment authorization without immediately capturing funds. Useful for reservations or orders to be fulfilled later. ### Method POST ### Endpoint /reserve ### Parameters #### Request Body - **orderNumber** (string) - Required - Unique identifier for the pre-authorization. - **amount** (integer) - Required - The amount to pre-authorize in millimes. - **currency** (integer) - Required - The currency code (e.g., 788 for TND). - **returnUrl** (string) - Required - The URL to redirect to upon successful pre-authorization. - **failUrl** (string) - Required - The URL to redirect to upon pre-authorization failure. - **language** (string) - Optional - The language for the payment page ('fr', 'en', or 'ar'). Defaults to 'fr'. - **orderDescription** (string) - Optional - A description of the order. - **jsonParams** (string) - Optional - A JSON string containing additional parameters relevant to the reservation. ### Request Example ```json { "orderNumber": "PREAUTH-1678886400", "amount": 50000, "currency": 788, "returnUrl": "http://localhost/reservation/confirmed", "failUrl": "http://localhost/reservation/failed", "language": "en", "orderDescription": "Hotel Reservation - Room 205", "jsonParams": "{\"email\": \"guest@hotel.com\", \"checkInDate\": \"2024-12-25\", \"checkOutDate\": \"2024-12-28\"}" } ``` ### Response #### Success Response (200) - **orderId** (string) - The unique ID of the pre-authorized order. - **formUrl** (string) - The URL to redirect the customer to for authorization. #### Response Example ```json { "orderId": "p1q2r3s4t5u6v7w8", "formUrl": "https://clictopay.com/auth/p1q2r3s4t5u6v7w8" } ``` ``` -------------------------------- ### Register Payment with ClicToPay - Laravel Source: https://context7.com/souidev/laravel-clictopay/llms.txt Registers a new payment order with ClicToPay and returns a redirect URL for the customer to complete the payment. It requires order details, amount, currency, return/fail URLs, language, and optional JSON parameters. The function handles potential exceptions during the registration process. ```php use Souidev\ClicToPayLaravel\Facades\ClicToPay; Route::post('/checkout', function(Request $request) { try { $paymentDetails = ClicToPay::registerPayment([ 'orderNumber' => 'ORDER-' . uniqid(), 'amount' => 15000, // Amount in millimes (15.000 TND = 15000 millimes) 'currency' => 788, // TND currency code 'returnUrl' => route('payment.success'), 'failUrl' => route('payment.failed'), 'language' => 'fr', // fr, en, or ar 'pageView' => 'DESKTOP', // or MOBILE 'orderDescription' => 'Purchase of Premium Subscription', 'expirationDate' => now()->addHours(24)->toIso8601String(), 'jsonParams' => json_encode([ 'email' => 'customer@example.com', 'orderNumber' => '1234567890', 'customerName' => 'John Doe' ]) ]); // Response contains: orderId, formUrl if (isset($paymentDetails['formUrl'])) { return redirect()->away($paymentDetails['formUrl']); } throw new Exception('Payment registration failed'); } catch (Exception $e) { Log::error('Payment registration error: ' . $e->getMessage()); return back()->with('error', 'Unable to process payment. Please try again.'); } }); ``` -------------------------------- ### Register Pre-Authorization with ClicToPay - Laravel Source: https://context7.com/souidev/laravel-clictopay/llms.txt Creates a payment pre-authorization without immediate fund capture, suitable for reservations. It requires similar details to payment registration, including order number, amount, currency, return/fail URLs, and language. The order ID is stored in the session for later use in confirmation. ```php use Souidev\ClicToPayLaravel\Facades\ClicToPay; Route::post('/reserve', function(Request $request) { try { $preAuthDetails = ClicToPay::registerPreAuth([ 'orderNumber' => 'PREAUTH-' . time(), 'amount' => 50000, // 50.000 TND in millimes 'currency' => 788, 'returnUrl' => route('reservation.confirmed'), 'failUrl' => route('reservation.failed'), 'language' => 'en', 'orderDescription' => 'Hotel Reservation - Room 205', 'jsonParams' => json_encode([ 'email' => 'guest@hotel.com', 'checkInDate' => '2024-12-25', 'checkOutDate' => '2024-12-28' ]) ]); // Store orderId for later confirmation session(['preauth_order_id' => $preAuthDetails['orderId']]); return redirect()->away($preAuthDetails['formUrl']); } catch (Exception $e) { Log::error('Pre-authorization error: ' . $e->getMessage()); return back()->withErrors(['error' => $e->getMessage()]); } }); ``` -------------------------------- ### Confirm Payment API Source: https://context7.com/souidev/laravel-clictopay/llms.txt This API endpoint is used to capture funds from a previously authorized pre-authorization transaction. The amount captured must match or be less than the pre-authorized amount. ```APIDOC ## POST /capture-payment/{orderId} ### Description Captures funds from a previously authorized pre-authorization transaction. ### Method POST ### Endpoint /capture-payment/{orderId} ### Parameters #### Path Parameters - **orderId** (string) - Required - The ID of the pre-authorized order to confirm. #### Request Body - **amount** (integer) - Required - The amount to capture in millimes. Must be less than or equal to the pre-authorized amount. ### Request Example ```json { "amount": 50000 } ``` ### Response #### Success Response (200) - **errorCode** (string) - '0' indicates success. - **errorMessage** (string) - A message indicating the result of the operation. #### Response Example ```json { "errorCode": "0", "errorMessage": "Payment captured successfully" } ``` #### Error Response (400) - **success** (boolean) - False. - **error** (string) - Description of the error. #### Error Response Example ```json { "success": false, "error": "Invalid amount for capture" } ``` ``` -------------------------------- ### Register Payment API Source: https://context7.com/souidev/laravel-clictopay/llms.txt This API endpoint allows you to register a new payment order with ClicToPay. It returns a redirect URL to the ClicToPay payment page where the customer can complete their transaction. ```APIDOC ## POST /checkout ### Description Creates a new payment order and returns a redirect URL to the ClicToPay payment page. ### Method POST ### Endpoint /checkout ### Parameters #### Request Body - **orderNumber** (string) - Required - Unique identifier for the order. - **amount** (integer) - Required - The payment amount in millimes (e.g., 15000 for 15.000 TND). - **currency** (integer) - Required - The currency code (e.g., 788 for TND). - **returnUrl** (string) - Required - The URL to redirect to upon successful payment. - **failUrl** (string) - Required - The URL to redirect to upon payment failure. - **language** (string) - Optional - The language for the payment page ('fr', 'en', or 'ar'). Defaults to 'fr'. - **pageView** (string) - Optional - The view for the payment page ('DESKTOP' or 'MOBILE'). Defaults to 'DESKTOP'. - **orderDescription** (string) - Optional - A description of the order. - **expirationDate** (string) - Optional - The expiration date/time for the payment order in ISO8601 format. - **jsonParams** (string) - Optional - A JSON string containing additional parameters like customer email and name. ### Request Example ```json { "orderNumber": "ORDER-65c8f7e4a4d9f", "amount": 15000, "currency": 788, "returnUrl": "http://localhost/payment/success", "failUrl": "http://localhost/payment/failed", "language": "fr", "pageView": "DESKTOP", "orderDescription": "Purchase of Premium Subscription", "expirationDate": "2024-03-15T10:00:00+01:00", "jsonParams": "{\"email\": \"customer@example.com\", \"orderNumber\": \"1234567890\", \"customerName\": \"John Doe\"}" } ``` ### Response #### Success Response (200) - **orderId** (string) - The unique ID of the registered order. - **formUrl** (string) - The URL to redirect the customer to for payment. #### Response Example ```json { "orderId": "a1b2c3d4e5f67890", "formUrl": "https://clictopay.com/pay/a1b2c3d4e5f67890" } ``` ``` -------------------------------- ### Handle ClicToPay Payment Success Callback in Laravel Source: https://context7.com/souidev/laravel-clictopay/llms.txt Implements a callback handler for successful payment notifications from ClicToPay. This route verifies the payment status using `ClicToPay::getPaymentStatus` and updates the order status in the database if the payment is confirmed. It also sends an order confirmation email and redirects the user to a success or failure view based on the outcome. Error handling is included for potential issues during verification or processing. ```php use Souidev\ClicToPayLaravel\Facades\ClicToPay; Route::get('/payment/success', function(Request $request) { $orderId = $request->query('orderId'); if (!$orderId) { return redirect()->route('home')->with('error', 'Invalid payment response'); } try { // Verify payment status with ClicToPay $status = ClicToPay::getPaymentStatus(['orderId' => $orderId]); if ($status['ErrorCode'] === '0' && $status['OrderStatus'] === 2) { // Payment successful - update order $order = Order::where('clictopay_order_id', $orderId)->first(); if ($order && $order->status !== 'paid') { $order->update([ 'status' => 'paid', 'paid_at' => now(), 'payment_details' => json_encode($status) ]); // Send confirmation email Mail::to($order->customer_email) ->send(new OrderConfirmationMail($order)); return view('payment.success', ['order' => $order]); } } // Payment not completed Log::warning("Payment verification failed for order {$orderId}", $status); return redirect()->route('payment.failed') ->with('error', 'Payment could not be verified'); } catch (Exception $e) { Log::error("Payment success handler error: " . $e->getMessage()); return redirect()->route('home') ->with('error', 'An error occurred while processing your payment'); } })->name('payment.success'); ``` -------------------------------- ### Configure ClicToPay Credentials in Laravel Source: https://github.com/souidev/laravel-clictopay/blob/master/README.md Configuration for the ClicToPay package in Laravel. It is recommended to use environment variables for sensitive credentials like username, password, and API URLs. The `test_mode` setting controls whether to use the test or production API endpoint. ```php // config/clictopay.php return [ 'username' => env('CLICTOPAY_USERNAME'), 'password' => env('CLICTOPAY_PASSWORD'), 'test_mode' => env('CLICTOPAY_TEST_MODE', true), 'return_url' => env('CLICTOPAY_RETURN_URL'), 'fail_url' => env('CLICTOPAY_FAIL_URL'), 'api_base_url' => env('CLICTOPAY_API_BASE_URL', '[https://test.clictopay.com/payment/rest/](https://test.clictopay.com/payment/rest/)'), // Default test URL ]; ``` -------------------------------- ### Register a Payment with ClicToPay API in Laravel Source: https://github.com/souidev/laravel-clictopay/blob/master/README.md Registers a new payment transaction with the ClicToPay API using the ClicToPay facade. It requires essential parameters like order number, amount, and currency, and accepts optional parameters for customization. The response contains a `formUrl` to redirect the user for payment. ```php use Souidev\ClicToPayLaravel\Facades\ClicToPay; try { // Register a payment with optional parameters $paymentDetails = ClicToPay::registerPayment([ // Required parameters 'orderNumber' => 'ORDER-12345', 'amount' => 10000, // in cents 'currency' => 788, // Currency code (788 for TND) // Optional parameters 'language' => 'fr', // fr, en, ar 'pageView' => 'DESKTOP', // DESKTOP or MOBILE 'orderDescription' => 'Payment for order #12345', 'expirationDate' => '2024-12-31T23:59:59', // ISO 8601 'jsonParams' => json_encode([ 'email' => 'customer@example.com', // Required if merchant notifications are enabled 'orderNumber' => '1234567890', // Your internal order reference // Add any additional parameters needed for bank processing ]) ]); // Redirect user to ClicToPay payment page return redirect()->away($paymentDetails['formUrl']); } catch (Exception $e) { return back()->with('error', $e->getMessage()); } ``` -------------------------------- ### Confirm Pre-Authorized Payment with ClicToPay - Laravel Source: https://context7.com/souidev/laravel-clictopay/llms.txt Captures funds from a previously authorized pre-authorization transaction. This function requires the order ID and the amount to be captured, which must match or be less than the pre-authorized amount. It returns a JSON response indicating success or failure. ```php use Souidev\ClicToPayLaravel\Facades\ClicToPay; Route::post('/capture-payment/{orderId}', function($orderId) { try { $result = ClicToPay::confirmPayment([ 'orderId' => $orderId, 'amount' => 50000 // Must match or be less than pre-auth amount ]); // Check response if ($result['errorCode'] === '0') { // Payment captured successfully Order::where('clictopay_order_id', $orderId) ->update(['status' => 'paid', 'captured_at' => now()]); return response()->json([ 'success' => true, 'message' => 'Payment captured successfully' ]); } return response()->json([ 'success' => false, 'error' => $result['errorMessage'] ], 400); } catch (Exception $e) { Log::error("Payment confirmation failed for order {$orderId}: " . $e->getMessage()); return response()->json(['error' => 'Payment capture failed'], 500); } }); ``` -------------------------------- ### Cancel Payment using ClicToPay in Laravel Source: https://context7.com/souidev/laravel-clictopay/llms.txt This snippet shows how to cancel an existing payment or pre-authorization using the ClicToPay facade in Laravel. It handles success and error responses, updating the order status in the database upon successful cancellation. Ensure the ClicToPay facade is correctly configured. ```php use Souidev\ClicToPayLaravel\Facades\ClicToPay; Route::post('/cancel-payment/{orderId}', function($orderId) { try { $result = ClicToPay::cancelPayment([ 'orderId' => $orderId ]); if ($result['errorCode'] === '0') { Order::where('clictopay_order_id', $orderId) ->update(['status' => 'cancelled', 'cancelled_at' => now()]); return redirect()->route('orders.index') ->with('success', 'Payment cancelled successfully'); } throw new Exception($result['errorMessage'] ?? 'Cancellation failed'); } catch (Exception $e) { Log::error("Cancellation failed for order {$orderId}: " . $e->getMessage()); return back()->with('error', 'Unable to cancel payment: ' . $e->getMessage()); } }); ``` -------------------------------- ### Check ClicToPay Payment Status in Laravel Source: https://github.com/souidev/laravel-clictopay/blob/master/README.md Retrieves the current status of a payment transaction from the ClicToPay API. Requires the `orderId` and optionally accepts a `language` parameter for localized error messages. The response includes an `ErrorCode` and `OrderStatus` to indicate the payment's state. ```php try { $status = ClicToPay::getPaymentStatus([ 'orderId' => 'ORDER-12345', 'language' => 'fr' // Optional - for localized error messages ]); // Handle the response if ($status['ErrorCode'] === '0') { // No system error // Process the payment status $orderStatus = $status['OrderStatus']; // Possible values in $orderStatus: // - 0: Order registered but not paid // - 1: Order pre-authorized // - 2: Order paid // - 3: Authorization canceled // - 4: Transaction canceled // - 5: Authorization on hold // - 6: Refund } } catch (Exception $e) { // Handle error } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.