### Install and Configure Xendit PHP SDK Source: https://context7.com/xendit/xendit-php/llms.txt This snippet shows how to install the Xendit PHP SDK using Composer and configure it with your Xendit API key. It requires the `xendit/xendit-php` package and sets the API key globally for subsequent requests. ```php getBalance($account_type, $currency, $at_timestamp, $for_user_id); print_r($result); } catch (Xendit\XenditSdkException $e) { echo 'Exception when calling BalanceApi->getBalance: ', $e->getMessage(), PHP_EOL; echo 'Full Error: ', json_encode($e->getFullError()), PHP_EOL; } ``` -------------------------------- ### Get All Refunds using Xendit API (PHP) Source: https://github.com/xendit/xendit-php/blob/master/docs/RefundApi.md Provides an example of how to fetch a list of all refunds using the `getAllRefunds` method. This method supports various filtering parameters such as `for_user_id`, `payment_request_id`, `invoice_id`, `payment_method_type`, `channel_code`, `limit`, `after_id`, and `before_id`. ```php getAllRefunds( $for_user_id, $payment_request_id, $invoice_id, $payment_method_type, $channel_code, $limit, $after_id, $before_id ); print_r($result); ``` -------------------------------- ### Import PaymentSimulation Class in PHP Source: https://github.com/xendit/xendit-php/blob/master/docs/PaymentRequest/PaymentSimulation.md This snippet shows how to import the PaymentSimulation class from the Xendit PHP SDK. It requires the Xendit PHP SDK to be installed. ```php use Xendit\PaymentRequest\PaymentSimulation; ``` -------------------------------- ### Initialize Refund Module in PHP Source: https://github.com/xendit/xendit-php/blob/master/docs/Refund/Refund.md This snippet demonstrates how to import and initialize the Refund module from the Xendit PHP SDK. It requires the Xendit SDK to be installed and configured. ```php use Xendit\Refund\Refund; ``` -------------------------------- ### ChannelPropertiesCardsInstallmentConfiguration Source: https://github.com/xendit/xendit-php/blob/master/docs/Invoice/ChannelPropertiesCardsInstallmentConfiguration.md Represents the configuration for pre-setting cards installment options for an invoice. It allows specifying whether full payment is permitted and defining the allowed installment terms. ```APIDOC ## ChannelPropertiesCardsInstallmentConfiguration ### Description An object to pre-set cards installment for a specific invoice. This configuration allows you to control whether full payment is allowed and to define specific terms for card installments. ### Method N/A (This is a data structure definition, not an API endpoint) ### Endpoint N/A ### Parameters #### Properties - **allow_full_payment** (bool) - Optional - Indicate whether full payment (without installment) is allowed. - **allowed_terms** (array) - Optional - An object to set what kind (from specific bank / specific tenor) of cards installments will be available on a specific invoice. This should be an array of ChannelPropertiesCardsInstallmentConfigurationAllowedTermsInner objects. ``` -------------------------------- ### GET /customers Source: https://github.com/xendit/xendit-php/blob/master/docs/CustomerApi.md Retrieve a list of customers, optionally filtered by reference ID. ```APIDOC ## GET /customers ### Description Retrieves a list of customers. You can filter customers by their reference ID. For detailed explanations, see this link: https://developers.xendit.co/api-reference/#get-customer ### Method GET ### Endpoint /customers ### Parameters #### Query Parameters - **reference_id** (string) - Optional - The reference ID to filter customers by. - **for_user_id** (string) - Optional - The sub-account user-id to filter by. ### Request Example ```php getCustomerByReferenceID($reference_id, $for_user_id); // This method name is hypothetical based on the table print_r($result); } catch (XenditXenditSdkException $e) { echo 'Exception when calling CustomerApi->getCustomerByReferenceID: ', $e->getMessage(), PHP_EOL; echo 'Full Error: ', json_encode($e->getFullError()), PHP_EOL; } ?> ``` ### Response #### Success Response (200) - **customers** (array) - An array of customer objects matching the criteria. #### Response Example ```json [ { "id": "cust-123", "name": "John Doe", "email": "john.doe@example.com", "mobile_number": "+6281234567890", "metadata": {}, "created_at": "2023-10-27T10:00:00Z", "updated_at": "2023-10-27T10:00:00Z" } ] ``` ``` -------------------------------- ### Initialize Xendit Transaction API Client (PHP) Source: https://github.com/xendit/xendit-php/blob/master/docs/TransactionApi.md This snippet shows how to set up the Xendit API key and instantiate the TransactionApi client in PHP. It requires the Xendit SDK to be installed via Composer. ```php getAllTransactions($for_user_id, $types, $statuses, $channel_categories, $reference_id, $product_id, $account_identifier, $amount, $currency, $created, $updated, $limit, $after_id, $before_id); print_r($result); } catch (\Xendit\XenditSdkException $e) { echo 'Exception when calling TransactionApi->getAllTransactions: ', $e->getMessage(), PHP_EOL; echo 'Full Error: ', json_encode($e->getFullError()), PHP_EOL; } ``` -------------------------------- ### Get Customer by ID using Xendit API (PHP) Source: https://github.com/xendit/xendit-php/blob/master/docs/CustomerApi.md This example demonstrates how to retrieve a customer by their ID using the Xendit PHP SDK. It requires the customer's ID and an optional for_user_id. The function returns a Customer object or throws an XenditSdkException on failure. ```php getCustomer($id, $for_user_id); print_r($result); } catch (XenditXenditSdkException $e) { echo 'Exception when calling CustomerApi->getCustomer: ', $e->getMessage(), PHP_EOL; echo 'Full Error: ', json_encode($e->getFullError()), PHP_EOL; } ``` -------------------------------- ### Create Payment Method for E-Wallet (PHP) Source: https://github.com/xendit/xendit-php/blob/master/docs/PaymentMethodApi.md Example demonstrating how to create an E-Wallet payment method using the `createPaymentMethod` function. It includes setting up user ID, payment method parameters, and handling potential SDK exceptions. ```php 'EWALLET', 'reusability' => 'MULTIPLE_USE', 'customer' => [ 'reference_id' => 'customer-123', 'type' => 'INDIVIDUAL', 'individual_detail' => [ 'given_names' => 'John', 'surname' => 'Doe' ] ], 'ewallet' => [ 'channel_code' => 'OVO', 'channel_properties' => [ 'success_return_url' => 'https://redirect.me/success', 'failure_return_url' => 'https://redirect.me/failure', 'cancel_return_url' => 'https://redirect.me/cancel' ] ], 'metadata' => [ 'sku' => 'example-1234' ] ]); // \Xendit\PaymentMethod\PaymentMethodParameters try { $result = $apiInstance->createPaymentMethod($for_user_id, $payment_method_parameters); print_r($result); } catch (\Xendit\XenditSdkException $e) { echo 'Exception when calling PaymentMethodApi->createPaymentMethod: ', $e->getMessage(), PHP_EOL; echo 'Full Error: ', json_encode($e->getFullError()), PHP_EOL; } ``` -------------------------------- ### Create Customer using Xendit PHP SDK Source: https://context7.com/xendit/xendit-php/llms.txt Creates a new customer record with personal, contact, and address information. Requires the Xendit SDK and API key. Input is customer details including reference ID, type, individual details, contact info, addresses, and metadata. Output is the created customer object or an error. ```php 'customer-123', 'type' => 'INDIVIDUAL', 'individual_detail' => [ 'given_names' => 'John', 'surname' => 'Doe', 'nationality' => 'ID', 'date_of_birth' => '1990-01-15', 'gender' => 'MALE' ], 'email' => 'john.doe@example.com', 'mobile_number' => '+628123456789', 'addresses' => [ [ 'country' => 'ID', 'street_line1' => 'Jl. Sudirman No. 123', 'city' => 'Jakarta', 'province_state' => 'DKI Jakarta', 'postal_code' => '12190' ] ], 'metadata' => [ 'internal_id' => 'user-abc-123' ] ]); try { $result = $apiInstance->createCustomer($idempotency_key, null, $customer_request); print_r($result); // Store customer ID: $result->getId() } catch (\Xendit\XenditSdkException $e) { echo 'Exception when calling CustomerApi->createCustomer: ', $e->getMessage(), PHP_EOL; echo 'Full Error: ', json_encode($e->getFullError()), PHP_EOL; } ?> ``` -------------------------------- ### Get a Specific Refund by ID using Xendit API (PHP) Source: https://github.com/xendit/xendit-php/blob/master/docs/RefundApi.md Shows how to retrieve details of a specific refund using the `getRefund` method. This requires the `refund_id`, an idempotency key, and an optional `for_user_id`. The example includes a try-catch block to handle potential SDK exceptions. ```php getRefund($refund_id, $idempotency_key, $for_user_id); print_r($result); } catch (XenditXenditSdkException $e) { echo 'Exception when calling RefundApi->getRefund: ', $e->getMessage(), PHP_EOL; echo 'Full Error: ', json_encode($e->getFullError()), PHP_EOL; } ``` -------------------------------- ### Get All Payment Requests - PHP Source: https://github.com/xendit/xendit-php/blob/master/docs/PaymentRequestApi.md Retrieves a list of payment requests based on specified parameters. Supports filtering by user ID, reference ID, payment request ID, customer ID, and pagination using limit, before_id, and after_id. Requires the Xendit SDK to be installed and configured with an API key. ```php getAllPaymentRequests($for_user_id, $reference_id, $id, $customer_id, $limit, $before_id, $after_id); print_r($result); } catch (\Xendit\XenditSdkException $e) { echo 'Exception when calling PaymentRequestApi->getAllPaymentRequests: ', $e->getMessage(), PHP_EOL; echo 'Full Error: ', json_encode($e->getFullError()), PHP_EOL; } ?> ``` -------------------------------- ### Initialize Xendit Balance API Client (PHP) Source: https://github.com/xendit/xendit-php/blob/master/docs/BalanceApi.md This snippet demonstrates how to configure the Xendit secret key and instantiate the BalanceApi client. It requires the Xendit PHP SDK to be installed via Composer. ```php getInvoices($for_user_id, $external_id, $statuses, $limit, $created_after, $created_before, $paid_after, $paid_before, $expired_after, $expired_before, $last_invoice, $client_types, $payment_channels, $on_demand_link, $recurring_payment_id); print_r($result); } catch (\Xendit\XenditSdkException $e) { echo 'Exception when calling InvoiceApi->getInvoices: ', $e->getMessage(), PHP_EOL; echo 'Full Error: ', json_encode($e->getFullError()), PHP_EOL; } ``` -------------------------------- ### Initialize Xendit PaymentRequestApi Client (PHP) Source: https://github.com/xendit/xendit-php/blob/master/docs/PaymentRequestApi.md This snippet shows how to configure the Xendit secret key and instantiate the PaymentRequestApi client. It requires the `xendit/xendit-php` package and the `vendor/autoload.php` file. ```php getAllRefunds($for_user_id, $payment_request_id, $invoice_id, $payment_method_type, $channel_code, $limit, $after_id, $before_id); print_r($result); } catch (XenditXenditSdkException $e) { echo 'Exception when calling RefundApi->getAllRefunds: ', $e->getMessage(), PHP_EOL; echo 'Full Error: ', json_encode($e->getFullError()), PHP_EOL; } ``` -------------------------------- ### Get All Transactions with Xendit PHP SDK Source: https://github.com/xendit/xendit-php/blob/master/docs/TransactionApi.md This snippet demonstrates how to retrieve all transactions using the Xendit PHP SDK. It requires the SDK to be installed and configured with an API key. The function accepts numerous parameters for filtering transactions by user ID, types, statuses, categories, reference ID, product ID, account identifier, amount, currency, creation/update dates, and pagination. It includes error handling for potential SDK exceptions. ```php new \Xendit\BalanceAndTransaction\DateRangeFilter()); // DateRangeFilter | Filter time of transaction by created date. If not specified will list all dates. $updated = array('key' => new \Xendit\BalanceAndTransaction\DateRangeFilter()); // DateRangeFilter | Filter time of transaction by updated date. If not specified will list all dates. $limit = 10; // float | number of items in the result per page. Another name for "results_per_page" $after_id = "'after_id_example'"; // string $before_id = "'before_id_example'"; // string try { $result = $apiInstance->getAllTransactions($for_user_id, $types, $statuses, $channel_categories, $reference_id, $product_id, $account_identifier, $amount, $currency, $created, $updated, $limit, $after_id, $before_id); print_r($result); } catch (\Xendit\XenditSdkException $e) { echo 'Exception when calling TransactionApi->getAllTransactions: ', $e->getMessage(), PHP_EOL; echo 'Full Error: ', json_encode($e->getFullError()), PHP_EOL; } ``` -------------------------------- ### Create Invoice using Xendit API (PHP) Source: https://github.com/xendit/xendit-php/blob/master/docs/InvoiceApi.md This example demonstrates how to create an invoice using the Xendit PHP SDK. It involves setting up the API client, defining invoice details in a `CreateInvoiceRequest` object, and calling the `createInvoice` method. Error handling for SDK exceptions is included. ```php 'test1234', 'description' => 'Test Invoice', 'amount' => 10000, 'invoice_duration' => 172800, 'currency' => 'IDR', 'reminder_time' => 1 ]); // \Xendit\Invoice\CreateInvoiceRequest $for_user_id = "62efe4c33e45694d63f585f0"; // string | Business ID of the sub-account merchant (XP feature) try { $result = $apiInstance->createInvoice($create_invoice_request, $for_user_id); print_r($result); } catch (Xendit\XenditSdkException $e) { echo 'Exception when calling InvoiceApi->createInvoice: ', $e->getMessage(), PHP_EOL; echo 'Full Error: ', json_encode($e->getFullError()), PHP_EOL; } ``` -------------------------------- ### Create Customer using Xendit API (PHP) Source: https://github.com/xendit/xendit-php/blob/master/docs/CustomerApi.md This example shows how to create a new customer using the Xendit PHP SDK. It requires an idempotency key, an optional for_user_id, and a CustomerRequest object. The function returns a Customer object or throws an XenditSdkException on failure. ```php createCustomer($idempotency_key, $for_user_id, $customer_request); print_r($result); } catch (XenditXenditSdkException $e) { echo 'Exception when calling CustomerApi->createCustomer: ', $e->getMessage(), PHP_EOL; echo 'Full Error: ', json_encode($e->getFullError()), PHP_EOL; } ``` -------------------------------- ### Customer Authentication and Initialization Source: https://github.com/xendit/xendit-php/blob/master/docs/CustomerApi.md Before using the Customer API, you need to configure your Xendit secret key and initiate the client instance. ```APIDOC ## Xendit Customer API Initialization ### Description Configure your Xendit secret key and instantiate the `CustomerApi` client to begin making API calls. ### Code Example ```php ``` ``` -------------------------------- ### Initialize Xendit Refund API Client (PHP) Source: https://github.com/xendit/xendit-php/blob/master/docs/RefundApi.md Initializes the Xendit Refund API client by setting the API key and creating an instance of the RefundApi class. This is a prerequisite for making any refund-related API calls. It requires the 'vendor/autoload.php' file and the Xendit configuration. ```php setExpiresAt(new DateTime('2025-12-31T23:59:59Z')); $patch->setSuggestedAmount(50000.00); ``` -------------------------------- ### ChannelPropertiesCardsInstallmentConfigurationAllowedTermsInner Source: https://github.com/xendit/xendit-php/blob/master/docs/Invoice/ChannelPropertiesCardsInstallmentConfigurationAllowedTermsInner.md Represents the allowed installment terms for a specific card issuer. ```APIDOC ## ChannelPropertiesCardsInstallmentConfigurationAllowedTermsInner ### Description Represents the allowed installment terms for a specific card issuer, including the issuer's identifier and the available tenors. ### Properties #### Request Body - **issuer** (string) - Required - The bank code of the installment provider / issuer. - **terms** (float[]) - Required - An array containing a list of installment tenors available to choose. ### Request Example ```json { "issuer": "BCA", "terms": [ 3, 6, 12 ] } ``` ### Response #### Success Response (200) - **issuer** (string) - The bank code of the installment provider / issuer. - **terms** (float[]) - An array containing a list of installment tenors available to choose. #### Response Example ```json { "issuer": "BCA", "terms": [ 3, 6, 12 ] } ``` ``` -------------------------------- ### GET /payment_methods Source: https://github.com/xendit/xendit-php/blob/master/docs/PaymentMethodApi.md Retrieves a list of all payment methods based on specified filters. ```APIDOC ## GET /payment_methods ### Description Retrieves a list of all payment methods based on specified filters. ### Method GET ### Endpoint /v1/payment_methods ### Parameters #### Query Parameters - **for_user_id** (string) - Optional - Filter by user ID. - **id** (string[]) - Optional - Filter by payment method IDs. - **type** (string[]) - Optional - Filter by payment method types (e.g., "VIRTUAL_ACCOUNT", "EWALLET"). - **status** (PaymentMethodStatus) - Optional - Filter by payment method status. - **reusability** (PaymentMethodReusability) - Optional - Filter by reusability status. - **customer_id** (string) - Optional - Filter by customer ID. - **reference_id** (string) - Optional - Filter by reference ID. - **after_id** (string) - Optional - Retrieve payment methods after a specific ID. - **before_id** (string) - Optional - Retrieve payment methods before a specific ID. - **limit** (int) - Optional - The maximum number of results to return. ### Request Example ```php getAllPaymentMethods($for_user_id, $id, $type, $status, $reusability, $customer_id, $reference_id, $after_id, $before_id, $limit); print_r($result); } catch (Xendit\XenditSdkException $e) { echo 'Exception when calling PaymentMethodApi->getAllPaymentMethods: ', $e->getMessage(), PHP_EOL; echo 'Full Error: ', json_encode($e->getFullError()), PHP_EOL; } ``` ### Response #### Success Response (200) - **payment_methods** (array) - An array of payment method objects. - **hasNext** (boolean) - Indicates if there are more results. #### Response Example ```json { "payment_methods": [ { "id": "pm-1fdaf346-dd2e-4b6c-b938-124c7167a822", "type": "VIRTUAL_ACCOUNT", "status": "ACTIVE", "reusability": "MULTIPLE_USE", "customer_id": "cust-abc", "reference_id": "ref-xyz", "created_at": "2023-01-01T10:00:00Z", "updated_at": "2023-01-01T10:05:00Z" } ], "hasNext": true } ``` ``` -------------------------------- ### Get All Payment Methods Source: https://github.com/xendit/xendit-php/blob/master/docs/PaymentMethodApi.md Retrieves a list of all payment methods, with options to filter the results. ```APIDOC ## GET /v2/payment_methods ### Description Retrieves all payment methods based on specified filters. ### Method GET ### Endpoint /v2/payment_methods ### Parameters #### Query Parameters - **limit** (integer) - Optional - The maximum number of payment methods to return. - **offset** (integer) - Optional - The number of payment methods to skip before returning results. - **customer_id** (string) - Optional - Filter payment methods by customer ID. - **type** (string) - Optional - Filter payment methods by type (e.g., 'EWALLET'). - **reusability** (string) - Optional - Filter payment methods by reusability (e.g., 'MULTIPLE_USE'). - **status** (string) - Optional - Filter payment methods by status (e.g., 'ACTIVE'). ### Response #### Success Response (200) - **data** (array) - An array of payment method objects. - Each payment method object contains details like `id`, `type`, `reusability`, `customer_id`, `status`, etc. #### Response Example ```json { "data": [ { "id": "pm_abc123xyz789", "type": "EWALLET", "reusability": "MULTIPLE_USE", "customer_id": "cust_12345", "created_at": "2023-10-27T10:00:00Z", "updated_at": "2023-10-27T10:00:00Z", "status": "ACTIVE" }, { "id": "pm_def456uvw012", "type": "CreditCard", "reusability": "ONE_TIME_USE", "customer_id": "cust_67890", "created_at": "2023-10-26T09:00:00Z", "updated_at": "2023-10-26T09:00:00Z", "status": "ACTIVE" } ], "has_more": true, "limit": 2, "offset": 0 } ``` ``` -------------------------------- ### Initialize Xendit Customer API Client (PHP) Source: https://github.com/xendit/xendit-php/blob/master/docs/CustomerApi.md This snippet demonstrates how to initialize the Xendit Customer API client in PHP. It requires setting the Xendit secret key and instantiating the CustomerApi class. Ensure the Xendit SDK is installed via Composer. ```php getCustomer($id, $for_user_id); print_r($result); } catch (XenditXenditSdkException $e) { echo 'Exception when calling CustomerApi->getCustomer: ', $e->getMessage(), PHP_EOL; echo 'Full Error: ', json_encode($e->getFullError()), PHP_EOL; } ?> ``` ### Response #### Success Response (200) - **customer** (object) - The customer object matching the provided ID. #### Response Example ```json { "id": "cust-123", "name": "John Doe", "email": "john.doe@example.com", "mobile_number": "+6281234567890", "metadata": {}, "created_at": "2023-10-27T10:00:00Z", "updated_at": "2023-10-27T10:00:00Z" } ``` ``` -------------------------------- ### Get Payment Method By ID Source: https://github.com/xendit/xendit-php/blob/master/docs/PaymentMethodApi.md Retrieves a specific payment method using its unique identifier. ```APIDOC ## GET /v2/payment_methods/{paymentMethodId} ### Description Retrieves a payment method by its unique ID. ### Method GET ### Endpoint /v2/payment_methods/{paymentMethodId} ### Parameters #### Path Parameters - **paymentMethodId** (string) - Required - The unique identifier of the payment method to retrieve. ### Response #### Success Response (200) - **id** (string) - Unique identifier for the payment method. - **type** (string) - The type of payment method. - **reusability** (string) - The reusability status of the payment method. - **customer_id** (string) - The ID of the customer associated with the payment method. - **created_at** (string) - Timestamp when the payment method was created. - **updated_at** (string) - Timestamp when the payment method was last updated. - **status** (string) - The current status of the payment method. - **payment_method_details** (object) - Details specific to the payment method type. #### Response Example ```json { "id": "pm_abc123xyz789", "type": "EWALLET", "reusability": "MULTIPLE_USE", "customer_id": "cust_12345", "created_at": "2023-10-27T10:00:00Z", "updated_at": "2023-10-27T10:00:00Z", "status": "ACTIVE", "payment_method_details": { "ewallet": { "channel_code": "OVO", "account_id": "ovo_user_id_123" } } } ``` ```