### Create Payment Sources with Omise Java Source: https://context7.com/omise/omise-java/llms.txt This snippet demonstrates how to create payment sources for different alternative payment methods such as mobile banking, installments, PromptPay, and TrueMoney Wallet using the Omise Java SDK. It also shows how to use a created source to initiate a charge and obtain a redirect URI for payment completion. Dependencies include the Omise Java SDK. Inputs are payment method type, amount, currency, and optional details like phone number or installment terms. Outputs include a Source object or a Charge object with an authorize URI. ```java import co.omise.models.Source; import co.omise.models.SourceType; import co.omise.models.Charge; import co.omise.requests.Request; // Create mobile banking source Request mobileBankingRequest = new Source.CreateRequestBuilder() .type(SourceType.MobileBankingKbank) .amount(100000) .currency("thb") .build(); Source mobileBankingSource = client.sendRequest(mobileBankingRequest); // Create installment payment source Request installmentRequest = new Source.CreateRequestBuilder() .type(SourceType.InstallmentBay) // Bangkok Bank installment .amount(500000) // 5,000 THB minimum for installments .currency("thb") .installmentTerm(6) // 6-month installment .zeroInterestInstallments(true) // Merchant absorbs interest .build(); Source installmentSource = client.sendRequest(installmentRequest); // Create PromptPay source Request promptPayRequest = new Source.CreateRequestBuilder() .type(SourceType.Promptpay) .amount(100000) .currency("thb") .build(); Source promptPaySource = client.sendRequest(promptPayRequest); // Create TrueMoney Wallet source Request trueMoneyRequest = new Source.CreateRequestBuilder() .type(SourceType.TrueMoneyWallet) .amount(100000) .currency("thb") .phoneNumber("0812345678") .build(); Source trueMoneySource = client.sendRequest(trueMoneyRequest); // Use source to create charge Request chargeWithSource = new Charge.CreateRequestBuilder() .amount(100000) .currency("thb") .source(mobileBankingSource.getId()) .returnUri("https://example.com/complete") .build(); Charge sourceCharge = client.sendRequest(chargeWithSource); // Redirect user to authorize_uri for payment completion System.out.println("Redirect to: " + sourceCharge.getAuthorizeUri()); ``` -------------------------------- ### Create Omise Charge with Card Token Source: https://github.com/omise/omise-java/blob/master/README.md Provides an example of creating a charge using a card token. This snippet illustrates how to set charge details like amount and currency, then submit the request to Omise. ```java Client client = new Client.Builder() .publicKey("pkey_test_123") .build(); Request request = new Charge.CreateRequestBuilder() .amount(100000) // 1,000 THB .currency("thb") .card("card_test_4xtsoy2nbfs7ujngyyq") .build(); Charge charge = client.sendRequest(request); System.out.println("created charge: " + charge.getId()); ``` -------------------------------- ### Create and Retrieve Omise Tokens Source: https://context7.com/omise/omise-java/llms.txt Illustrates the process of creating and retrieving tokens for secure credit card handling via the Token API. It emphasizes that token creation should ideally be done client-side in production environments. The example shows server-side token creation with card details and retrieving an existing token by its ID. ```java import co.omise.models.Token; import co.omise.models.Card; import co.omise.requests.Request; // Create a token (server-side - prefer client-side tokenization in production) Request createTokenRequest = new Token.CreateRequestBuilder() .card(new Card.Create() .name("Somchai Prasert") .number("4242424242424242") .expirationMonth(10) .expirationYear(2025) .city("Bangkok") .postalCode("10320") .securityCode("123") .email("customer@example.com") .phoneNumber("0812345678")) .build(); Token token = client.sendRequest(createTokenRequest); System.out.println("Token ID: " + token.getId()); // tokn_test_xxx System.out.println("Used: " + token.isUsed()); // false until charged System.out.println("Card Brand: " + token.getCard().getBrand()); System.out.println("Last Digits: " + token.getCard().getLastDigits()); // Retrieve existing token Request getTokenRequest = new Token.GetRequestBuilder("tokn_test_xxx").build(); Token existingToken = client.sendRequest(getTokenRequest); ``` -------------------------------- ### Manage Schedules with Omise Java SDK Source: https://context7.com/omise/omise-java/llms.txt Provides examples for retrieving, listing, and deleting schedules using the Omise Java SDK. It covers fetching a single schedule by ID, listing all schedules, filtering by customer, and listing schedule occurrences. Requires the Omise Java SDK and a client instance. ```java import co.omise.models.schedules.*; import co.omise.models.ScopedList; import co.omise.requests.Request; import java.time.LocalDate; // Assume 'client' is an initialized OmiseClient instance // Retrieve schedule Request getScheduleRequest = new Schedule.GetRequestBuilder("schd_test_xxx").build(); Schedule schedule = client.sendRequest(getScheduleRequest); // List all schedules Request> listSchedulesRequest = new Schedule.ListRequestBuilder().build(); ScopedList schedules = client.sendRequest(listSchedulesRequest); // List charge schedules Request> chargeSchedulesRequest = new Charge.ListSchedulesRequestBuilder().build(); ScopedList chargeSchedules = client.sendRequest(chargeSchedulesRequest); // List customer schedules Request> customerSchedulesRequest = new Schedule.CustomerScheduleListRequestBuilder("cust_test_xxx").build(); ScopedList customerSchedules = client.sendRequest(customerSchedulesRequest); // List schedule occurrences Request> occurrencesRequest = new Schedule.ListOccurrencesRequestBuilder("schd_test_xxx").build(); ScopedList occurrences = client.sendRequest(occurrencesRequest); // Delete/cancel schedule Request deleteScheduleRequest = new Schedule.DeleteRequestBuilder("schd_test_xxx").build(); Schedule deletedSchedule = client.sendRequest(deleteScheduleRequest); ``` -------------------------------- ### Schedule API Source: https://context7.com/omise/omise-java/llms.txt This section covers the creation, retrieval, listing, and deletion of recurring charges and transfers using the Omise Java SDK. It includes examples for monthly, weekly, and transfer schedules, as well as how to list schedules and their occurrences. ```APIDOC ## Schedule API ### Description This API allows you to create, manage, and retrieve recurring charges and transfers with flexible scheduling options. You can set up schedules for monthly, weekly, or bi-monthly occurrences, specify start and end dates, and associate them with customers or recipients. ### Method POST, GET, DELETE ### Endpoints - `/schedules` (POST to create, GET to list) - `/schedules/{schedule_id}` (GET to retrieve, DELETE to cancel) - `/charges/schedules` (GET to list charge schedules) - `/customers/{customer_id}/schedules` (GET to list schedules for a specific customer) - `/schedules/{schedule_id}/occurrences` (GET to list schedule occurrences) ### Parameters #### Path Parameters - **schedule_id** (string) - Required - The unique identifier of the schedule. - **customer_id** (string) - Required - The unique identifier of the customer. #### Query Parameters *For List Endpoints* - **limit** (integer) - Optional - The maximum number of items to return. - **offset** (integer) - Optional - The number of items to skip. #### Request Body (for creating schedules) - **period** (enum: `Month`, `Week`, `Year`) - Required - The period for the schedule recurrence. - **every** (integer) - Required - The frequency of the recurrence within the specified period. - **on** (object) - Required - Defines the specific day(s) for the recurrence. - **daysOfMonth** (array of integers) - Optional - For monthly/yearly schedules, specifies the day(s) of the month. - **weekdays** (enum: `Monday`, `Tuesday`, `Wednesday`, `Thursday`, `Friday`, `Saturday`, `Sunday`) - Optional - For weekly schedules, specifies the day(s) of the week. - **startDate** (date) - Required - The date when the schedule becomes active. - **endDate** (date) - Optional - The date when the schedule expires. - **charge** (object) - Optional - Parameters for creating a scheduled charge. - **customer** (string) - Required - The customer ID for the charge. - **amount** (integer) - Required - The charge amount in the smallest currency unit. - **description** (string) - Optional - A description for the charge. - **transfer** (object) - Optional - Parameters for creating a scheduled transfer. - **recipient** (string) - Required - The recipient ID for the transfer. - **amount** (integer) - Required - The transfer amount in the smallest currency unit. ### Request Example (Create Monthly Charge Schedule) ```java import co.omise.models.schedules.*; import co.omise.models.ScopedList; import co.omise.requests.Request; import java.time.LocalDate; Request monthlyScheduleRequest = new Schedule.CreateRequestBuilder() .every(1) .period(SchedulePeriod.Month) .on(new ScheduleOn.Params().daysOfMonth(1)) .startDate(LocalDate.of(2024, 1, 1)) .endDate(LocalDate.of(2024, 12, 31)) .charge(new ChargeSchedule.Params() .customer("cust_test_xxx") .amount(99900) .description("Monthly subscription")) .build(); Schedule monthlySchedule = client.sendRequest(monthlyScheduleRequest); ``` ### Response #### Success Response (200 OK) - **id** (string) - The unique identifier of the schedule. - **status** (string) - The current status of the schedule (e.g., `active`, `paused`, `deleted`). - **next_occurrences_on** (array of strings) - A list of upcoming occurrence dates. - **created_at** (timestamp) - The timestamp when the schedule was created. - **updated_at** (timestamp) - The timestamp when the schedule was last updated. #### Response Example (Schedule Object) ```json { "id": "schd_test_xxx", "status": "active", "next_occurrences_on": [ "2024-07-01T00:00:00Z", "2024-08-01T00:00:00Z" ], "created_at": "2024-01-01T10:00:00Z", "updated_at": "2024-01-01T10:00:00Z" } ``` ### Error Handling - **400 Bad Request**: Invalid request parameters. - **401 Unauthorized**: Authentication failed. - **404 Not Found**: The requested schedule or resource does not exist. - **500 Internal Server Error**: An error occurred on the server. ### Related Endpoints - **Retrieve Schedule**: Use `Schedule.GetRequestBuilder` to fetch a specific schedule by its ID. - **List Schedules**: Use `Schedule.ListRequestBuilder` to retrieve a list of all schedules. - **Delete Schedule**: Use `Schedule.DeleteRequestBuilder` to cancel a schedule. ``` -------------------------------- ### Create Recurring Schedules with Omise Java SDK Source: https://context7.com/omise/omise-java/llms.txt Demonstrates how to create monthly, weekly, and transfer schedules using the Omise Java SDK. It includes setting recurrence periods, specific dates or weekdays, start and end dates, and associated charge or transfer details. Requires the Omise Java SDK and a client instance. ```java import co.omise.models.schedules.*; import co.omise.models.ScopedList; import co.omise.requests.Request; import java.time.LocalDate; // Assume 'client' is an initialized OmiseClient instance // Create monthly charge schedule Request monthlyScheduleRequest = new Schedule.CreateRequestBuilder() .every(1) // Every 1 period .period(SchedulePeriod.Month) // Monthly .on(new ScheduleOn.Params().daysOfMonth(1)) // On the 1st of each month .startDate(LocalDate.of(2024, 1, 1)) .endDate(LocalDate.of(2024, 12, 31)) .charge(new ChargeSchedule.Params() .customer("cust_test_xxx") .amount(99900) // 999 THB .description("Monthly subscription")) .build(); Schedule monthlySchedule = client.sendRequest(monthlyScheduleRequest); System.out.println("Schedule ID: " + monthlySchedule.getId()); System.out.println("Status: " + monthlySchedule.getStatus()); System.out.println("Next Occurrences: " + monthlySchedule.getNextOccurrencesOn()); // Create weekly charge schedule Request weeklyScheduleRequest = new Schedule.CreateRequestBuilder() .every(1) .period(SchedulePeriod.Week) .on(new ScheduleOn.Params().weekdays(Weekdays.Monday)) // Every Monday .startDate(LocalDate.now()) .endDate(LocalDate.now().plusYears(1)) .charge(new ChargeSchedule.Params() .customer("cust_test_xxx") .amount(50000) .description("Weekly service fee")) .build(); Schedule weeklySchedule = client.sendRequest(weeklyScheduleRequest); // Create transfer schedule (auto-payout) Request transferScheduleRequest = new Schedule.CreateRequestBuilder() .every(1) .period(SchedulePeriod.Month) .on(new ScheduleOn.Params().daysOfMonth(15, 30)) // 15th and 30th .startDate(LocalDate.now()) .endDate(LocalDate.now().plusYears(2)) .transfer(new TransferSchedule.Params() .recipient("recp_test_xxx") .amount(100000)) .build(); Schedule transferSchedule = client.sendRequest(transferScheduleRequest); ``` -------------------------------- ### Interact with Omise Account API Source: https://context7.com/omise/omise-java/llms.txt Shows how to retrieve and update Omise account settings using the Account API. This includes fetching details like account ID, email, country, API version, and supported currencies. It also demonstrates updating webhook URIs and enabling zero-interest installments. ```java import co.omise.models.Account; import co.omise.requests.Request; // Retrieve account information Request getAccountRequest = new Account.GetRequestBuilder().build(); Account account = client.sendRequest(getAccountRequest); System.out.println("Account ID: " + account.getId()); System.out.println("Email: " + account.getEmail()); System.out.println("Country: " + account.getCountry()); System.out.println("API Version: " + account.getApiVersion()); System.out.println("Supported Currencies: " + account.getSupportedCurrencies()); // Update account settings Request updateRequest = new Account.UpdateRequestBuilder() .webhookUri("https://example.com/webhooks/omise") .zeroInterestInstallments(true) .build(); Account updatedAccount = client.sendRequest(updateRequest); ``` -------------------------------- ### Check Omise Account Balance Source: https://context7.com/omise/omise-java/llms.txt Provides an example of how to check the Omise account balance using the Balance API. It retrieves the currency, total balance (in the smallest currency unit), transferable funds, and funds held in reserve. ```java import co.omise.models.Balance; import co.omise.requests.Request; Request getBalanceRequest = new Balance.GetRequestBuilder().build(); Balance balance = client.sendRequest(getBalanceRequest); System.out.println("Currency: " + balance.getCurrency()); System.out.println("Total Balance: " + balance.getTotal()); // In smallest currency unit System.out.println("Transferable: " + balance.getTransferable()); // Available for transfer System.out.println("Reserve: " + balance.getReserve()); // Held in reserve ``` -------------------------------- ### Manage Payout Recipients with Omise Java SDK Source: https://context7.com/omise/omise-java/llms.txt This snippet illustrates how to manage transfer recipients (bank accounts for payouts) using the Omise Java SDK. It includes examples for creating individual and corporate recipients, updating recipient details, retrieving recipient information, listing all recipients, verifying recipients, and deleting recipients. Ensure the Omise client is properly initialized. ```java import co.omise.models.Recipient; import co.omise.models.RecipientType; import co.omise.models.BankAccount; import co.omise.models.ScopedList; import co.omise.requests.Request; // Create individual recipient Request createRecipientRequest = new Recipient.CreateRequestBuilder() .name("Somchai Prasert") .email("somchai@example.com") .type(RecipientType.Individual) .taxId("1234567890123") .bankAccount(new BankAccount.Params() .brand("kbank") // Bank code .number("1234567890") // Account number .name("SOMCHAI PRASERT")) // Account holder name .build(); Recipient recipient = client.sendRequest(createRecipientRequest); System.out.println("Recipient ID: " + recipient.getId()); System.out.println("Active: " + recipient.isActive()); System.out.println("Verified: " + recipient.isVerified()); // Create corporate recipient Request corporateRequest = new Recipient.CreateRequestBuilder() .name("Acme Corp Ltd.") .email("finance@acme.com") .type(RecipientType.Corporation) .taxId("0105556000001") .bankAccount(new BankAccount.Params() .brand("bbl") .number("9876543210") .name("ACME CORP LTD")) .build(); Recipient corporateRecipient = client.sendRequest(corporateRequest); // Update recipient Request updateRequest = new Recipient.UpdateRequestBuilder("recp_test_xxx") .email("newemail@example.com") .bankAccount(new BankAccount.Params() .brand("scb") .number("1111222233") .name("SOMCHAI PRASERT")) .build(); Recipient updatedRecipient = client.sendRequest(updateRequest); // Retrieve recipient Request getRequest = new Recipient.GetRequestBuilder("recp_test_xxx").build(); Recipient existingRecipient = client.sendRequest(getRequest); // List all recipients Request> listRequest = new Recipient.ListRequestBuilder().build(); ScopedList recipients = client.sendRequest(listRequest); // Verify recipient (trigger verification process) Request verifyRequest = new Recipient.VerifyRequestBuilder("recp_test_xxx").build(); Recipient verifiedRecipient = client.sendRequest(verifyRequest); // Delete recipient Request deleteRequest = new Recipient.DeleteRequestBuilder("recp_test_xxx").build(); Recipient deletedRecipient = client.sendRequest(deleteRequest); ``` -------------------------------- ### Initialize Omise Java Client Source: https://github.com/omise/omise-java/blob/master/README.md Demonstrates how to create an instance of the Omise Java Client using public and secret API keys. This client is essential for making authenticated requests to the Omise API. ```java Client client = new Client.Builder() .publicKey("pkey_test_123") .secretKey("skey_test_123") .build(); ``` -------------------------------- ### Search Resources (Java) Source: https://context7.com/omise/omise-java/llms.txt This code demonstrates how to search for various resources like charges using the Omise Java SDK. It covers basic search by query and advanced filtering with options for scope, specific filters, ordering, and pagination. The output includes total results and pagination details. ```java import co.omise.models.SearchResult; import co.omise.models.SearchScope; import co.omise.models.Charge; import co.omise.models.Ordering; import co.omise.requests.Request; // Search charges by query Request> searchRequest = new SearchResult.SearchRequestBuilder( new SearchResult.Options() .scope(SearchScope.Charge) .query("customer@example.com")) .build(); SearchResult searchResult = client.sendRequest(searchRequest); System.out.println("Total results: " + searchResult.getTotal()); System.out.println("Page: " + searchResult.getPage() + " of " + searchResult.getTotalPages()); // Search with filters Request> filteredSearch = new SearchResult.SearchRequestBuilder( new SearchResult.Options() .scope(SearchScope.Charge) .filter("captured", "true") .filter("currency", "thb") .order(Ordering.ReverseChronological) .page(1) .dataPerPage(50)) .build(); SearchResult filteredResult = client.sendRequest(filteredSearch); // Iterate through results for (Charge charge : filteredResult.getData()) { System.out.println("Found: " + charge.getId() + " - " + charge.getAmount()); } ``` -------------------------------- ### Create and Manage Charges with Omise Java SDK Source: https://context7.com/omise/omise-java/llms.txt This snippet demonstrates various ways to create and manage payment charges using the Omise Java SDK. It covers immediate capture, using saved cards, pre-authorization, 3D Secure authentication, metadata, capturing, reversing, retrieving, updating, and listing charges. Dependencies include the Omise Java SDK. Inputs are charge details like amount, currency, card token or customer ID, and optional parameters. Outputs include Charge objects or ScopedList of Charges. ```java import co.omise.models.Charge; import co.omise.models.ScopedList; import co.omise.models.AuthenticationType; import co.omise.models.AuthorizationType; import co.omise.requests.Request; import java.util.HashMap; import java.util.Map; // Create a charge with a token (immediate capture) Request createChargeRequest = new Charge.CreateRequestBuilder() .amount(100000) // 1,000 THB (in satangs) .currency("thb") .card("tokn_test_xxx") // Token from client-side .description("Order #12345") .returnUri("https://example.com/complete") // For 3DS redirect .build(); Charge charge = client.sendRequest(createChargeRequest); System.out.println("Charge ID: " + charge.getId()); System.out.println("Status: " + charge.getStatus()); System.out.println("Paid: " + charge.isPaid()); System.out.println("Authorize URI: " + charge.getAuthorizeUri()); // For 3DS // Create charge with customer's saved card Request customerChargeRequest = new Charge.CreateRequestBuilder() .amount(50000) .currency("thb") .customer("cust_test_xxx") .card("card_test_xxx") // Saved card ID .build(); Charge customerCharge = client.sendRequest(customerChargeRequest); // Create pre-authorized charge (authorize only, capture later) Request preAuthRequest = new Charge.CreateRequestBuilder() .amount(200000) .currency("thb") .card("tokn_test_xxx") .capture(false) // Don't capture immediately .authorizationType(AuthorizationType.PreAuth) .build(); Charge preAuthCharge = client.sendRequest(preAuthRequest); // Create charge with 3D Secure authentication Request secureChargeRequest = new Charge.CreateRequestBuilder() .amount(100000) .currency("thb") .card("tokn_test_xxx") .authentication(AuthenticationType.Threeds) .returnUri("https://example.com/3ds-complete") .build(); Charge secureCharge = client.sendRequest(secureChargeRequest); // Create charge with metadata Map metadata = new HashMap<>(); metadata.put("order_id", "ORD-12345"); metadata.put("customer_email", "customer@example.com"); Request chargeWithMetadata = new Charge.CreateRequestBuilder() .amount(100000) .currency("thb") .card("tokn_test_xxx") .metadata(metadata) .build(); // Capture a pre-authorized charge Request captureRequest = new Charge.CaptureRequestBuilder("chrg_test_xxx").build(); Charge capturedCharge = client.sendRequest(captureRequest); // Partial capture Request partialCaptureRequest = new Charge.CaptureRequestBuilder("chrg_test_xxx") .captureAmount(50000) // Capture only 500 THB of authorized amount .build(); Charge partiallyCaptured = client.sendRequest(partialCaptureRequest); // Reverse an uncaptured charge Request reverseRequest = new Charge.ReverseRequestBuilder("chrg_test_xxx").build(); Charge reversedCharge = client.sendRequest(reverseRequest); // Retrieve a charge Request getChargeRequest = new Charge.GetRequestBuilder("chrg_test_xxx").build(); Charge existingCharge = client.sendRequest(getChargeRequest); // Update charge description/metadata Request updateRequest = new Charge.UpdateRequestBuilder("chrg_test_xxx") .description("Updated description") .metadata("note", "VIP customer") .build(); Charge updatedCharge = client.sendRequest(updateRequest); // List all charges with pagination Request> listRequest = new Charge.ListRequestBuilder() .options(new ScopedList.Options().limit(20).offset(0)) .build(); ScopedList charges = client.sendRequest(listRequest); System.out.println("Total charges: " + charges.getTotal()); for (Charge c : charges.getData()) { System.out.println(" " + c.getId() + ": " + c.getAmount() + " " + c.getCurrency()); } ``` -------------------------------- ### Initialize Omise Java Client Source: https://context7.com/omise/omise-java/llms.txt Demonstrates how to initialize the Omise Client, the main entry point for API interactions. It requires public and secret API keys and is designed to be thread-safe, allowing a single instance to be shared across multiple threads. The client manages secure HTTP connections using TLS 1.2. ```java import co.omise.Client; import co.omise.ClientException; // Initialize client with API keys from Omise Dashboard Client client = new Client.Builder() .publicKey("pkey_test_123") // Public key for token creation .secretKey("skey_test_123") // Secret key for server-side operations .build(); // Client is thread-safe - share a single instance across threads ``` -------------------------------- ### Manage Customers with Omise Java Source: https://context7.com/omise/omise-java/llms.txt This snippet illustrates how to create, retrieve, update, and delete customer records using the Omise Java SDK. It covers attaching cards via tokens, setting default cards, and listing customers with pagination options. Dependencies include the Omise Java SDK. Inputs include customer details like email, description, card tokens, and metadata. Outputs are Customer objects or ScopedList of Customers. ```java import co.omise.models.Customer; import co.omise.models.Card; import co.omise.models.ScopedList; import co.omise.requests.Request; // Create a new customer Request createCustomerRequest = new Customer.CreateRequestBuilder() .email("john.doe@example.com") .description("John Doe (User ID: 12345)") .card("tokn_test_xxx") // Attach card via token .metadata("user_id", "12345") .build(); Customer customer = client.sendRequest(createCustomerRequest); System.out.println("Customer ID: " + customer.getId()); System.out.println("Default Card: " + customer.getDefaultCard()); // Retrieve customer Request getCustomerRequest = new Customer.GetRequestBuilder("cust_test_xxx").build(); Customer existingCustomer = client.sendRequest(getCustomerRequest); // Update customer information Request updateRequest = new Customer.UpdateRequestBuilder("cust_test_xxx") .email("john.smith@example.com") .description("Updated description") .defaultCard("card_test_yyy") // Change default card .build(); Customer updatedCustomer = client.sendRequest(updateRequest); // Attach new card to existing customer Request attachCardRequest = new Customer.UpdateRequestBuilder("cust_test_xxx") .card("tokn_test_newcard") // New card token .build(); Customer customerWithNewCard = client.sendRequest(attachCardRequest); // List all customers Request> listRequest = new Customer.ListRequestBuilder() .options(new ScopedList.Options().limit(50)) .build(); ScopedList customers = client.sendRequest(listRequest); // Delete customer Request deleteRequest = new Customer.DeleteRequestBuilder("cust_test_xxx").build(); Customer deletedCustomer = client.sendRequest(deleteRequest); ``` -------------------------------- ### Build Shadow JAR for Omise-Java Source: https://github.com/omise/omise-java/blob/master/README.md This command sequence outlines the process of building a shadowed JAR for the Omise-Java library. This is useful for resolving dependency conflicts by relocating JAR dependencies. The process involves cloning the repository and running the `shadowJar` Gradle task. ```sh $ git clone git://github.com/omise/omise-java $ cd omise-java $ gradle shadowJar :compileJava :processResources :classes :shadowJar BUILD SUCCESSFUL $ ls builds/libs omise-java-4.0.0-all.jar ``` -------------------------------- ### Create and Manage Payment Links with Omise Java API Source: https://context7.com/omise/omise-java/llms.txt This snippet demonstrates how to create single-use and multi-use payment links, retrieve existing links, list all links, list charges associated with a link, and delete a link using the Omise Java SDK. It requires the Omise Java SDK and a valid client instance. ```java import co.omise.models.Link; import co.omise.models.ScopedList; import co.omise.requests.Request; // Create single-use payment link Request singleUseLink = new Link.CreateRequestBuilder() .amount(150000) // 1,500 THB .currency("thb") .title("Invoice #12345") .description("Payment for consulting services") .multiple(false) // Single use only .build(); Link paymentLink = client.sendRequest(singleUseLink); System.out.println("Link ID: " + paymentLink.getId()); System.out.println("Payment URL: " + paymentLink.getPaymentUri()); System.out.println("Used: " + paymentLink.isUsed()); // Create multi-use payment link (donations, tips, etc.) Request multiUseLink = new Link.CreateRequestBuilder() .amount(100000) .currency("thb") .title("Donation Link") .description("Support our charity") .multiple(true) // Can be used multiple times .build(); Link donationLink = client.sendRequest(multiUseLink); // Retrieve link Request getLinkRequest = new Link.GetRequestBuilder("link_test_xxx").build(); Link existingLink = client.sendRequest(getLinkRequest); // List all links Request> listLinksRequest = new Link.ListRequestBuilder().build(); ScopedList links = client.sendRequest(listLinksRequest); // List charges created from a link Request> linkChargesRequest = new Link.ListChargesRequestBuilder("link_test_xxx").build(); ScopedList linkCharges = client.sendRequest(linkChargesRequest); // Delete link Request deleteLinkRequest = new Link.DeleteRequestBuilder("link_test_xxx").build(); Link deletedLink = client.sendRequest(deleteLinkRequest); ``` -------------------------------- ### Manage Fund Transfers with Omise Java SDK Source: https://context7.com/omise/omise-java/llms.txt This snippet demonstrates how to use the Omise Java SDK to manage fund transfers. It covers creating transfers to default or specific recipients, updating pending transfers, retrieving transfer details, listing all transfers, and deleting pending transfers. Ensure the Omise client is properly initialized before use. ```java import co.omise.models.Transfer; import co.omise.models.ScopedList; import co.omise.requests.Request; // Create transfer to default bank account Request createTransferRequest = new Transfer.CreateRequestBuilder() .amount(100000) // 1,000 THB .build(); Transfer transfer = client.sendRequest(createTransferRequest); System.out.println("Transfer ID: " + transfer.getId()); System.out.println("Amount: " + transfer.getAmount()); System.out.println("Fee: " + transfer.getFee()); System.out.println("Net: " + transfer.getNet()); System.out.println("Sendable: " + transfer.isSendable()); // Create transfer to specific recipient Request recipientTransferRequest = new Transfer.CreateRequestBuilder() .amount(50000) .recipient("recp_test_xxx") // Recipient ID .failFast(true) // Fail immediately if unable to transfer .metadata("reference", "PAYOUT-12345") .build(); Transfer recipientTransfer = client.sendRequest(recipientTransferRequest); // Update pending transfer Request updateRequest = new Transfer.UpdateRequestBuilder("trsf_test_xxx") .amount(75000) // Change amount before sent .build(); Transfer updatedTransfer = client.sendRequest(updateRequest); // Retrieve transfer Request getTransferRequest = new Transfer.GetRequestBuilder("trsf_test_xxx").build(); Transfer existingTransfer = client.sendRequest(getTransferRequest); // List all transfers Request> listRequest = new Transfer.ListRequestBuilder() .options(new ScopedList.Options().limit(50)) .build(); ScopedList transfers = client.sendRequest(listRequest); // Delete pending transfer Request deleteRequest = new Transfer.DeleteRequestBuilder("trsf_test_xxx").build(); Transfer deletedTransfer = client.sendRequest(deleteRequest); ``` -------------------------------- ### List and Retrieve Webhook Events (Java) Source: https://context7.com/omise/omise-java/llms.txt This snippet demonstrates how to list all webhook events and retrieve a specific event using the Omise Java SDK. It shows how to access event details and the associated data, such as a Charge object. Dependencies include Omise SDK models and request classes. ```java import co.omise.models.Event; import co.omise.models.ScopedList; import co.omise.models.Charge; import co.omise.requests.Request; // List all events Request> listEventsRequest = new Event.ListRequestBuilder() .options(new ScopedList.Options().limit(100)) .build(); ScopedList events = client.sendRequest(listEventsRequest); for (Event event : events.getData()) { System.out.println("Event: " + event.getId()); System.out.println(" Key: " + event.getKey()); // e.g., "charge.complete" System.out.println(" Created: " + event.getCreatedAt()); } // Retrieve specific event Request getEventRequest = new Event.GetRequestBuilder("evnt_test_xxx").build(); Event event = client.sendRequest(getEventRequest); // Access event data (the affected object) if (event.getData() instanceof Charge) { Charge charge = (Charge) event.getData(); System.out.println("Charge status: " + charge.getStatus()); } // List events for a specific charge Request> chargeEventsRequest = new Charge.ListEventsRequestBuilder("chrg_test_xxx").build(); ScopedList chargeEvents = client.sendRequest(chargeEventsRequest); ``` -------------------------------- ### Handle Payment Disputes with Omise Java API Source: https://context7.com/omise/omise-java/llms.txt This snippet shows how to list all, open, and pending disputes, retrieve a specific dispute, update a dispute with messages and metadata, accept a dispute, and create a dispute for testing purposes using the Omise Java SDK. It requires the Omise Java SDK and a valid client instance. ```java import co.omise.models.Dispute; import co.omise.models.DisputeStatus; import co.omise.models.ScopedList; import co.omise.requests.Request; // List all disputes Request> allDisputesRequest = new Dispute.ListRequestBuilder().build(); ScopedList disputes = client.sendRequest(allDisputesRequest); // List open disputes Request> openDisputesRequest = new Dispute.ListRequestBuilder() .status(DisputeStatus.Open) .build(); ScopedList openDisputes = client.sendRequest(openDisputesRequest); // List pending disputes Request> pendingDisputesRequest = new Dispute.ListRequestBuilder() .status(DisputeStatus.Pending) .build(); ScopedList pendingDisputes = client.sendRequest(pendingDisputesRequest); // Retrieve specific dispute Request getDisputeRequest = new Dispute.GetRequestBuilder("dspt_test_xxx").build(); Dispute dispute = client.sendRequest(getDisputeRequest); System.out.println("Dispute ID: " + dispute.getId()); System.out.println("Amount: " + dispute.getAmount()); System.out.println("Status: " + dispute.getStatus()); System.out.println("Reason: " + dispute.getReasonCode()); System.out.println("Charge: " + dispute.getCharge()); // Update dispute with evidence/message Request updateDisputeRequest = new Dispute.UpdateRequestBuilder("dspt_test_xxx") .message("Customer received the goods. Attached delivery confirmation.") .metadata("tracking_number", "TH123456789") .build(); Dispute updatedDispute = client.sendRequest(updateDisputeRequest); // Accept dispute (merchant accepts liability) Request acceptDisputeRequest = new Dispute.AcceptRequestBuilder("dspt_test_xxx").build(); Dispute acceptedDispute = client.sendRequest(acceptDisputeRequest); // Create dispute (for testing in test mode) Request createDisputeRequest = new Dispute.CreateDisputeRequestBuilder("chrg_test_xxx").build(); Dispute newDispute = client.sendRequest(createDisputeRequest); ``` -------------------------------- ### Handle API Errors (Java) Source: https://context7.com/omise/omise-java/llms.txt This Java snippet illustrates how to handle potential errors when interacting with the Omise API. It includes try-catch blocks for `ClientException`, `OmiseException`, and `IOException` to manage client configuration issues, API-specific errors, and network/serialization problems. It also shows how to check charge status and failure details. ```java import co.omise.Client; import co.omise.ClientException; import co.omise.models.OmiseException; import co.omise.models.Charge; import co.omise.requests.Request; import java.io.IOException; try { Client client = new Client.Builder() .publicKey("pkey_test_xxx") .secretKey("skey_test_xxx") .build(); Request request = new Charge.CreateRequestBuilder() .amount(100000) .currency("thb") .card("tokn_test_xxx") .build(); Charge charge = client.sendRequest(request); // Check charge status if (charge.isPaid()) { System.out.println("Payment successful: " + charge.getId()); } else if (charge.getAuthorizeUri() != null) { System.out.println("Redirect for 3DS: " + charge.getAuthorizeUri()); } else if (charge.getFailureCode() != null) { System.out.println("Payment failed: " + charge.getFailureCode()); System.out.println("Message: " + charge.getFailureMessage()); } } catch (ClientException e) { // Client configuration error (e.g., TLS not supported) System.err.println("Client error: " + e.getMessage()); } catch (OmiseException e) { // API error response from Omise System.err.println("API Error Code: " + e.getCode()); System.err.println("API Error Message: " + e.getMessage()); System.err.println("Location: " + e.getLocation()); } catch (IOException e) { // Network or serialization error System.err.println("IO Error: " + e.getMessage()); } ``` -------------------------------- ### Retrieve Omise Account Balance Source: https://github.com/omise/omise-java/blob/master/README.md Shows how to fetch the current account balance using the Omise Java SDK. It involves building a Balance request and sending it via the initialized client. ```java Request request = new Balance.GetRequestBuilder().build(); Balance balance = client.sendRequest(request); long total = balance.getTotal(); ``` -------------------------------- ### Process Refunds with Omise Java API Source: https://context7.com/omise/omise-java/llms.txt This snippet illustrates how to process refunds for charges using the Omise Java SDK. It covers creating full or partial refunds, including adding metadata, creating void refunds, listing refunds associated with a charge, retrieving a specific refund, and listing all refunds within an account. The Omise Java SDK is a key dependency. ```java import co.omise.models.Refund; import co.omise.models.ScopedList; import co.omise.requests.Request; // Create full refund Request fullRefundRequest = new Refund.CreateRequestBuilder("chrg_test_xxx") .amount(100000) // Full amount in smallest currency unit .build(); Refund fullRefund = client.sendRequest(fullRefundRequest); System.out.println("Refund ID: " + fullRefund.getId()); System.out.println("Amount: " + fullRefund.getAmount()); System.out.println("Status: " + fullRefund.getStatus()); // Create partial refund with metadata Request partialRefundRequest = new Refund.CreateRequestBuilder("chrg_test_xxx") .amount(50000) // Partial refund .metadata("reason", "Customer requested partial refund") .build(); Refund partialRefund = client.sendRequest(partialRefundRequest); // Create void refund (before settlement) Request voidRequest = new Refund.CreateRequestBuilder("chrg_test_xxx") .amount(100000) .isVoid(true) // Void instead of refund .build(); Refund voidedCharge = client.sendRequest(voidRequest); // List refunds for a charge Request> listRefundsRequest = new Refund.ListRequestBuilder("chrg_test_xxx").build(); ScopedList refunds = client.sendRequest(listRefundsRequest); // Retrieve specific refund Request getRefundRequest = new Refund.GetRequestBuilder("chrg_test_xxx", "rfnd_test_xxx").build(); Refund refund = client.sendRequest(getRefundRequest); // List all refunds across account Request> allRefundsRequest = new Refund.ListRefundsRequestBuilder().build(); ScopedList allRefunds = client.sendRequest(allRefundsRequest); ``` -------------------------------- ### Manage Customer Cards with Omise Java API Source: https://context7.com/omise/omise-java/llms.txt This snippet demonstrates how to manage customer cards using the Omise Java SDK. It covers listing all cards for a customer, retrieving a specific card, updating card details like expiration date and name, and deleting a card. Dependencies include the Omise Java SDK. ```java import co.omise.models.Card; import co.omise.models.ScopedList; import co.omise.requests.Request; import java.time.YearMonth; // List customer's cards Request> listCardsRequest = new Card.ListRequestBuilder("cust_test_xxx").build(); ScopedList cards = client.sendRequest(listCardsRequest); for (Card card : cards.getData()) { System.out.println("Card: " + card.getId()); System.out.println(" Brand: " + card.getBrand()); System.out.println(" Last 4: " + card.getLastDigits()); System.out.println(" Expires: " + card.getExpirationMonth() + "/" + card.getExpirationYear()); } // Retrieve specific card Request getCardRequest = new Card.GetRequestBuilder("cust_test_xxx", "card_test_xxx").build(); Card card = client.sendRequest(getCardRequest); // Update card details (expiration, name, etc.) Request updateRequest = new Card.UpdateRequestBuilder("cust_test_xxx", "card_test_xxx") .name("JOHN DOE") .expirationMonth(12) .expirationYear(2026) .city("Bangkok") .postalCode("10110") .build(); Card updatedCard = client.sendRequest(updateRequest); // Alternative: update using YearMonth Request updateWithYearMonth = new Card.UpdateRequestBuilder("cust_test_xxx", "card_test_xxx") .expiration(YearMonth.of(2026, 12)) .build(); // Delete card from customer Request deleteRequest = new Card.DeleteRequestBuilder("cust_test_xxx", "card_test_xxx").build(); Card deletedCard = client.sendRequest(deleteRequest); ``` -------------------------------- ### Add Omise-Java Dependency to Kotlin Gradle Source: https://github.com/omise/omise-java/blob/master/README.md This snippet demonstrates how to include the Omise-Java library in a Kotlin project using Gradle. It specifies the dependency for implementation and requires Java 8+. Users should be aware of security warnings for older versions. ```kotlin dependencies { implementation("co.omise:omise-java:4. +") } ``` -------------------------------- ### Add Omise-Java Dependency to Gradle Source: https://github.com/omise/omise-java/blob/master/README.md This snippet shows how to add the Omise-Java library as a dependency in a Gradle build file. It requires Java 8 or higher and is intended for Java server implementations. Ensure you are using a secure version of the library (3.1.1 or later). ```gradle dependencies { compile 'co.omise:omise-java:4.+' } ``` -------------------------------- ### Add Omise-Java Dependency to Maven Source: https://github.com/omise/omise-java/blob/master/README.md This snippet provides the XML configuration to add the Omise-Java library to a Maven project's pom.xml file. It specifies the group ID, artifact ID, and version. This library requires Java 8+ and users should avoid versions prior to 3.1.1 due to security vulnerabilities. ```xml co.omise omise-java 4.0.0 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.