### Installation Source: https://context7.com/itsazni/pakasir-sdk-php/llms.txt Install the Pakasir SDK PHP using Composer. ```APIDOC ## Installation Install the SDK via Composer. ```bash composer require itsazni/pakasir-sdk-php ``` ``` -------------------------------- ### Install Pakasir SDK PHP using Composer Source: https://github.com/itsazni/pakasir-sdk-php/blob/master/README.md This command installs the Pakasir SDK for PHP using Composer, the dependency manager for PHP. Ensure you have Composer installed globally. ```bash composer require itsazni/pakasir-sdk-php ``` -------------------------------- ### Handle and Verify Pakasir Webhook with API Source: https://github.com/itsazni/pakasir-sdk-php/blob/master/README.md This example demonstrates how to handle a Pakasir webhook request and simultaneously verify its authenticity using the Pakasir API. This provides an extra layer of security before processing the payment. ```php use ItsAzni\Pakasir\Pakasir; use ItsAzni\Pakasir\WebhookHandler; $pakasir = new Pakasir('your-slug', 'your-api-key'); $webhook = new WebhookHandler($pakasir); $body = file_get_contents('php://input'); $payment = $webhook->handleAndVerify($body); // Returns PaymentPayload if ($payment->isCompleted()) { processOrder($payment->order_id, $payment->amount); } ``` -------------------------------- ### Generate Pakasir Payment URLs Source: https://github.com/itsazni/pakasir-sdk-php/blob/master/README.md Provides examples of generating different types of payment URLs using the Pakasir SDK. This includes standard payment page URLs, URLs with a redirect, QRIS-only mode URLs, and direct PayPal payment URLs. ```php // Standard payment page URL $paymentUrl = $pakasir->getPaymentUrl('ORDER-001', 50000); // With redirect after payment $paymentUrl = $pakasir->getPaymentUrl('ORDER-001', 50000, 'https://yoursite.com/success'); // QRIS only mode $paymentUrl = $pakasir->getPaymentUrl('ORDER-001', 50000, null, true); // Direct PayPal URL $paypalUrl = $pakasir->getPaypalUrl('ORDER-001', 50000); ``` -------------------------------- ### Handle Pakasir SDK Exceptions in PHP Source: https://github.com/itsazni/pakasir-sdk-php/blob/master/README.md This snippet demonstrates how to gracefully handle exceptions thrown by the Pakasir SDK. It uses a try-catch block to capture PakasirException, allowing you to display a user-friendly error message if an operation fails. Ensure the Pakasir SDK is installed and configured correctly. ```php use ItsAzni\Pakasir\Exceptions\PakasirException; try { $payment = $pakasir->createPayment(PaymentMethod::QRIS, 'ORDER-001', 50000); } catch (PakasirException $e) { echo "Error: " . $e->getMessage(); } ``` -------------------------------- ### Handle Webhook Notifications Source: https://context7.com/itsazni/pakasir-sdk-php/llms.txt This section guides you on processing incoming webhook notifications from Pakasir, which are sent when a payment is completed. It includes parsing the payload and responding appropriately. ```APIDOC ## Handle Webhook Notifications Process incoming webhook notifications when Pakasir sends payment completion callbacks to your server. ### Method `POST` ### Endpoint Your configured webhook endpoint URL (e.g., `https://yoursite.com/webhook.php`) ### Parameters #### Request Body - The request body will contain a JSON payload with payment details sent by Pakasir. ### Request Example ```php handle($body); // Access webhook data echo "Order ID: " . $payment->order_id . "\n"; echo "Amount: " . $payment->amount . "\n"; echo "Status: " . $payment->status . "\n"; if ($payment->isCompleted()) { // Update order status in your database // updateOrderStatus($payment->order_id, 'paid'); } // Respond to Pakasir http_response_code(200); echo 'OK'; } catch (PakasirException $e) { http_response_code(400); echo 'Error: ' . $e->getMessage(); } ?> ``` ### Response #### Success Response (200) - A `200 OK` response indicates that the webhook was successfully received and processed. #### Error Response (400) - A `400 Bad Request` response with an error message indicates a problem processing the webhook. #### Response Example (Success) ``` OK ``` #### Response Example (Error) ``` Error: Invalid signature ``` ``` -------------------------------- ### Initialize Pakasir SDK and Create QRIS Payment Source: https://github.com/itsazni/pakasir-sdk-php/blob/master/README.md Demonstrates how to initialize the Pakasir SDK with your project slug and API key, then create a QRIS payment. It outputs the payment details such as payment number, total amount, and expiration time. ```php createPayment( method: PaymentMethod::QRIS, orderId: 'INV-2026-001', amount: 100000 ); echo "Payment Number: " . $payment->payment_number; echo "Total: Rp" . number_format($payment->total_payment); echo "Expires: " . $payment->expired_at; ``` -------------------------------- ### Initialize SDK Source: https://context7.com/itsazni/pakasir-sdk-php/llms.txt Initialize the Pakasir SDK with your project slug and API key. This instance is used for all subsequent API calls. ```APIDOC ## Initialize SDK Create a new Pakasir instance with your project slug and API key from the Pakasir dashboard. This instance is used for all subsequent API calls. ```php getSlug(); // Output: your-project-slug ``` ``` -------------------------------- ### Create Pakasir Payments with Different Methods and Options Source: https://github.com/itsazni/pakasir-sdk-php/blob/master/README.md Shows various ways to create payments using the Pakasir SDK, including using payment method enums or strings, and adding a redirect URL for post-payment redirection. This covers QRIS and Virtual Account payments. ```php use ItsAzni\Pakasir\PaymentMethod; // Using enum $payment = $pakasir->createPayment(PaymentMethod::QRIS, 'ORDER-001', 50000); // Using string $payment = $pakasir->createPayment('bni_va', 'ORDER-002', 100000); // With redirect URL $payment = $pakasir->createPayment( method: PaymentMethod::QRIS, orderId: 'ORDER-003', amount: 75000, redirect: 'https://yoursite.com/payment/success' ); ``` -------------------------------- ### Initialize Pakasir SDK in PHP Source: https://context7.com/itsazni/pakasir-sdk-php/llms.txt Initializes the Pakasir SDK with your project slug and API key. This instance is then used for all subsequent API calls. It requires the Composer autoloader and namespaces for Pakasir classes. ```php getSlug(); // Output: your-project-slug ``` -------------------------------- ### Create Pakasir Payments (QRIS, VA, PayPal) in PHP Source: https://context7.com/itsazni/pakasir-sdk-php/llms.txt Creates new payment transactions using the `createPayment()` method. Supports various payment methods like QRIS and Virtual Accounts (e.g., BNI, BRI) using enums or strings. An optional redirect URL can be provided for post-payment redirection. Error handling for `PakasirException` is included. ```php createPayment( method: PaymentMethod::QRIS, orderId: 'INV-2026-001', amount: 100000 ); echo "Payment Number: " . $payment->payment_number . "\n"; echo "Amount: Rp" . number_format($payment->amount) . "\n"; echo "Fee: Rp" . number_format($payment->fee) . "\n"; echo "Total: Rp" . number_format($payment->total_payment) . "\n"; echo "Status: " . $payment->status . "\n"; echo "Expires: " . $payment->expired_at . "\n"; echo "Payment URL: " . $payment->payment_url . "\n"; // Create BNI Virtual Account payment using string $vaPayment = $pakasir->createPayment('bni_va', 'INV-2026-002', 250000); echo "VA Number: " . $vaPayment->payment_number . "\n"; // Create payment with redirect URL after success $paymentWithRedirect = $pakasir->createPayment( method: PaymentMethod::BRI_VA, orderId: 'INV-2026-003', amount: 150000, redirect: 'https://yoursite.com/payment/success' ); echo "Redirect URL: " . $paymentWithRedirect->redirect_url . "\n"; } catch (PakasirException $e) { echo "Payment creation failed: " . $e->getMessage(); } ``` -------------------------------- ### Pakasir SDK PHP Error Handling (PHP) Source: https://context7.com/itsazni/pakasir-sdk-php/llms.txt Demonstrates how to handle exceptions thrown by the Pakasir SDK, specifically `PakasirException`. This includes catching initialization errors and API-related errors, allowing for specific error messages to be displayed or logged. It's crucial for robust payment processing. ```php getMessage(); // Output: Initialization error: Slug and API key are required } try { $pakasir = new Pakasir('your-slug', 'your-api-key'); // API errors (network, invalid response, etc.) $payment = $pakasir->createPayment(PaymentMethod::QRIS, 'ORDER-001', 50000); } catch (PakasirException $e) { // Handle specific error scenarios $message = $e->getMessage(); if (strpos($message, 'Invalid response') !== false) { echo "API returned unexpected response"; } elseif (strpos($message, 'Failed to create payment') !== false) { echo "Network or API error occurred"; } else { echo "Error: " . $message; } // Access previous exception for debugging $previous = $e->getPrevious(); if ($previous) { error_log('Original error: ' . $previous->getMessage()); } } ``` -------------------------------- ### Create Payment Source: https://context7.com/itsazni/pakasir-sdk-php/llms.txt Create a new payment transaction using the `createPayment()` method. Specify the payment method, your internal order ID, amount in Indonesian Rupiah, and an optional redirect URL. ```APIDOC ## Create Payment Create a new payment transaction using the `createPayment()` method. Specify the payment method, your internal order ID, amount in Indonesian Rupiah, and optional redirect URL. ```php createPayment( method: PaymentMethod::QRIS, orderId: 'INV-2026-001', amount: 100000 ); echo "Payment Number: " . $payment->payment_number . "\n"; echo "Amount: Rp" . number_format($payment->amount) . "\n"; echo "Fee: Rp" . number_format($payment->fee) . "\n"; echo "Total: Rp" . number_format($payment->total_payment) . "\n"; echo "Status: " . $payment->status . "\n"; echo "Expires: " . $payment->expired_at . "\n"; echo "Payment URL: " . $payment->payment_url . "\n"; // Create BNI Virtual Account payment using string $vaPayment = $pakasir->createPayment('bni_va', 'INV-2026-002', 250000); echo "VA Number: " . $vaPayment->payment_number . "\n"; // Create payment with redirect URL after success $paymentWithRedirect = $pakasir->createPayment( method: PaymentMethod::BRI_VA, orderId: 'INV-2026-003', amount: 150000, redirect: 'https://yoursite.com/payment/success' ); echo "Redirect URL: " . $paymentWithRedirect->redirect_url . "\n"; } catch (PakasirException $e) { echo "Payment creation failed: " . $e->getMessage(); } ``` ``` -------------------------------- ### Payment Methods Source: https://context7.com/itsazni/pakasir-sdk-php/llms.txt This section explains how to access and use payment method constants provided by the Pakasir SDK. It covers listing all supported methods and validating a given method. ```APIDOC ## Payment Methods Access available payment method constants using the `PaymentMethod` class. Validate and list all supported payment methods. ### Method `GET` (Implicit via SDK methods) ### Endpoint N/A (Class methods) ### Parameters N/A ### Request Example ```php createPayment(PaymentMethod::QRIS, 'ORDER-001', 50000); ?> ``` ### Response #### Success Response (200) - `PaymentMethod::all()` returns an array of strings, where each string is a supported payment method. - `PaymentMethod::isValid(string $method)` returns a boolean indicating if the provided method string is valid. #### Response Example (for `PaymentMethod::all()`) ``` Array ( [0] => qris [1] => bni_va [2] => bri_va // ... ) ``` ``` -------------------------------- ### Manage Payment Methods with Pakasir SDK (PHP) Source: https://context7.com/itsazni/pakasir-sdk-php/llms.txt Provides access to available payment method constants and utility functions for validation. Allows listing all supported methods and checking if a given method is valid. Used in conjunction with the Pakasir SDK for payment creation. ```php qris [1] => bni_va [2] => bri_va [3] => cimb_niaga_va [4] => sampoerna_va [5] => bnc_va [6] => maybank_va [7] => permata_va [8] => atm_bersama_va [9] => artha_graha_va [10] => paypal ) */ // Validate a payment method $userSelectedMethod = 'bni_va'; if (PaymentMethod::isValid($userSelectedMethod)) { echo "Valid payment method"; } else { echo "Invalid payment method"; } // Use in payment creation // Assuming $pakasir is an instance of ItsAzni\Pakasir\Pakasir // $pakasir->createPayment(PaymentMethod::QRIS, 'ORDER-001', 50000); // $pakasir->createPayment('bni_va', 'ORDER-002', 75000); // String also works ``` -------------------------------- ### Generate Payment URLs Source: https://context7.com/itsazni/pakasir-sdk-php/llms.txt This section details how to generate payment URLs for redirecting customers to the Pakasir payment interface. It supports standard payment pages, QRIS-only mode, and direct PayPal payments. ```APIDOC ## Generate Payment URLs Generate payment page URLs for redirecting customers to the Pakasir payment interface. Supports standard payment page, QRIS-only mode, and direct PayPal payment. ### Method `POST` (Implicit via SDK methods) ### Endpoint `/pay/{slug}/{amount}` `/paypal/{slug}/{amount}` ### Parameters #### Path Parameters - `slug` (string) - Required - Your Pakasir project slug. - `amount` (integer) - Required - The payment amount in the smallest currency unit (e.g., cents for USD, Rupiah for IDR). #### Query Parameters - `order_id` (string) - Required - Your unique order identifier. - `redirect` (string) - Optional - A URL to redirect the customer to after a successful payment. - `qris_only` (boolean) - Optional - If set to `true`, only the QRIS payment method will be shown. ### Request Example ```php getPaymentUrl('INV-2026-001', 100000); // Payment URL with redirect $paymentUrlWithRedirect = $pakasir->getPaymentUrl( 'INV-2026-001', 100000, 'https://yoursite.com/payment/success' ); // QRIS-only mode $qrisOnlyUrl = $pakasir->getPaymentUrl('INV-2026-001', 100000, null, true); // Direct PayPal payment URL $paypalUrl = $pakasir->getPaypalUrl('INV-2026-001', 100000); // Redirect customer // header('Location: ' . $paymentUrl); // exit; ?> ``` ### Response #### Success Response (200) - `paymentUrl` (string) - The generated URL for the payment page. #### Response Example ``` https://app.pakasir.com/pay/your-slug/100000?order_id=INV-2026-001 ``` #### Direct PayPal Response Example ``` https://app.pakasir.com/paypal/your-slug/100000?order_id=INV-2026-001 ``` ``` -------------------------------- ### Generate Payment URLs with Pakasir SDK (PHP) Source: https://context7.com/itsazni/pakasir-sdk-php/llms.txt Generates various payment page URLs for redirecting customers to the Pakasir payment interface. Supports standard, QRIS-only, and direct PayPal payments, with options for post-payment redirects. Requires Pakasir SDK and API credentials. ```php getPaymentUrl('INV-2026-001', 100000); echo $paymentUrl; // Output: https://app.pakasir.com/pay/your-slug/100000?order_id=INV-2026-001 // Payment URL with redirect after successful payment $paymentUrlWithRedirect = $pakasir->getPaymentUrl( 'INV-2026-001', 100000, 'https://yoursite.com/payment/success' ); echo $paymentUrlWithRedirect; // Output: https://app.pakasir.com/pay/your-slug/100000?order_id=INV-2026-001&redirect=https%3A%2F%2Fyoursite.com%2Fpayment%2Fsuccess // QRIS-only mode (hide other payment methods) $qrisOnlyUrl = $pakasir->getPaymentUrl('INV-2026-001', 100000, null, true); echo $qrisOnlyUrl; // Output: https://app.pakasir.com/pay/your-slug/100000?order_id=INV-2026-001&qris_only=1 // Direct PayPal payment URL (minimum Rp10,000) $paypalUrl = $pakasir->getPaypalUrl('INV-2026-001', 100000); echo $paypalUrl; // Output: https://app.pakasir.com/paypal/your-slug/100000?order_id=INV-2026-001 // Redirect customer to payment page header('Location: ' . $paymentUrl); exit; ``` -------------------------------- ### Handle and Verify Webhook with Pakasir API (PHP) Source: https://context7.com/itsazni/pakasir-sdk-php/llms.txt Securely handles incoming webhook data by parsing it and verifying the transaction status directly with the Pakasir API. This method ensures the authenticity of the payment notification and returns full transaction details. It requires the Pakasir SDK and expects raw webhook data as input. ```php handleAndVerify($body); // Verification ensures: // 1. Project slug matches your configured project // 2. Transaction exists and is authentic via API call if ($payment->isCompleted()) { // Safe to process - transaction verified with Pakasir $orderId = $payment->order_id; $amount = $payment->amount; $fee = $payment->fee; $totalPaid = $payment->total_payment; $method = $payment->payment_method; $completedAt = $payment->completed_at; // Process verified payment processVerifiedPayment($orderId, $amount); echo "Verified payment processed: {$orderId}"; } http_response_code(200); echo 'OK'; } catch (PakasirException $e) { // Handle verification failures error_log('Webhook verification failed: ' . $e->getMessage()); http_response_code(400); echo 'Verification failed'; } ``` -------------------------------- ### Handle Pakasir Webhook for Payment Completion Source: https://github.com/itsazni/pakasir-sdk-php/blob/master/README.md This PHP code shows how to handle incoming webhook requests from Pakasir to process payment completions. It uses the WebhookHandler to parse the request body and check if the payment was completed. ```php use ItsAzni\Pakasir\WebhookHandler; $webhook = new WebhookHandler(); // Get raw POST body $body = file_get_contents('php://input'); $payment = $webhook->handle($body); if ($payment->isCompleted()) { // Process the order processOrder($payment->order_id, $payment->amount); } http_response_code(200); echo 'OK'; ``` -------------------------------- ### Handle Webhook Notifications with Pakasir SDK (PHP) Source: https://context7.com/itsazni/pakasir-sdk-php/llms.txt Processes incoming webhook notifications from Pakasir for payment completion callbacks. Parses the payload, extracts payment details, and allows for conditional logic based on payment status. Includes error handling for invalid payloads. Requires Pakasir SDK. ```php handle($body); // Access webhook data echo "Order ID: " . $payment->order_id . "\n"; echo "Amount: " . $payment->amount . "\n"; echo "Project: " . $payment->project . "\n"; echo "Status: " . $payment->status . "\n"; echo "Payment Method: " . $payment->payment_method . "\n"; echo "Completed At: " . $payment->completed_at . "\n"; // Check status and process if ($payment->isCompleted()) { // Update order status in your database // updateOrderStatus($payment->order_id, 'paid'); // Send confirmation email // sendPaymentConfirmation($payment->order_id, $payment->amount); } // Convert to array if needed $data = $payment->toArray(); // Respond to Pakasir http_response_code(200); echo 'OK'; } catch (PakasirException $e) { http_response_code(400); echo 'Error: ' . $e->getMessage(); } ``` -------------------------------- ### Check Pakasir Payment Status in PHP Source: https://context7.com/itsazni/pakasir-sdk-php/llms.txt Retrieves detailed payment transaction information and status using the `detailPayment()` method. Includes helper methods like `isCompleted()`, `isPending()`, and `isCanceled()` to easily check the payment state. The full payment details can be accessed as an array using `toArray()`. ```php detailPayment('INV-2026-001', 100000); // Check payment status using helper methods if ($detail->isCompleted()) { echo "Payment completed at: " . $detail->completed_at . "\n"; echo "Payment method: " . $detail->payment_method . "\n"; // Process the order processOrder($detail->order_id); } elseif ($detail->isPending()) { echo "Waiting for payment...\n"; echo "Payment expires at: " . $detail->expired_at . "\n"; echo "Payment number: " . $detail->payment_number . "\n"; } elseif ($detail->isCanceled()) { echo "Payment was canceled\n"; } // Access all payment data print_r($detail->toArray()); /* Output: Array ( [project] => your-slug [order_id] => INV-2026-001 [amount] => 100000 [fee] => 1500 [status] => pending [total_payment] => 101500 [payment_method] => qris [payment_number] => 00020101021226... [payment_url] => https://app.pakasir.com/pay/your-slug/100000?order_id=INV-2026-001 [redirect_url] => [expired_at] => 2026-01-15 14:30:00 [completed_at] => ) */ } catch (PakasirException $e) { echo "Failed to get payment details: " . $e->getMessage(); } ``` -------------------------------- ### Check Payment Status Source: https://context7.com/itsazni/pakasir-sdk-php/llms.txt Retrieve payment transaction details and status using the `detailPayment()` method. Use helper methods to check the current payment state. ```APIDOC ## Check Payment Status Retrieve payment transaction details and status using the `detailPayment()` method. Use helper methods to check the current payment state. ```php detailPayment('INV-2026-001', 100000); // Check payment status using helper methods if ($detail->isCompleted()) { echo "Payment completed at: " . $detail->completed_at . "\n"; echo "Payment method: " . $detail->payment_method . "\n"; // Process the order processOrder($detail->order_id); } elseif ($detail->isPending()) { echo "Waiting for payment...\n"; echo "Payment expires at: " . $detail->expired_at . "\n"; echo "Payment number: " . $detail->payment_number . "\n"; } elseif ($detail->isCanceled()) { echo "Payment was canceled\n"; } // Access all payment data print_r($detail->toArray()); /* Output: Array ( [project] => your-slug [order_id] => INV-2026-001 [amount] => 100000 [fee] => 1500 [status] => pending [total_payment] => 101500 [payment_method] => qris [payment_number] => 00020101021226... [payment_url] => https://app.pakasir.com/pay/your-slug/100000?order_id=INV-2026-001 [redirect_url] => [expired_at] => 2026-01-15 14:30:00 [completed_at] => ) */ } catch (PakasirException $e) { echo "Failed to get payment details: " . $e->getMessage(); } ``` ``` -------------------------------- ### Check Pakasir Payment Status Source: https://github.com/itsazni/pakasir-sdk-php/blob/master/README.md This code snippet demonstrates how to retrieve the details of a payment using its order ID and amount, and then check its status (completed, pending, or canceled) using helper methods. ```php $detail = $pakasir->detailPayment('ORDER-001', 50000); if ($detail->isCompleted()) { echo "Payment completed at: " . $detail->completed_at; } elseif ($detail->isPending()) { echo "Waiting for payment..."; } elseif ($detail->isCanceled()) { echo "Payment was canceled"; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.