### Console Application Integration Example Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/README.md Shows a basic setup for a console application to initialize the Omise Client and create a charge using a provided token ID. Includes basic output for the created charge. ```csharp class Program { static async Task Main() { var client = new Client(skey: "skey_test_..."); var charge = await client.Charges.Create(new CreateChargeRequest { Amount = 100000, Currency = "thb", Card = tokenId }); Console.WriteLine($"Charge created: {charge.Id}"); } } ``` -------------------------------- ### Example: Charge Operations Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Client.md Demonstrates how to get a specific charge resource and perform operations like refunds. ```csharp var chargeResource = client.Charge("ch_test_1234567890"); var refund = await chargeResource.Refunds.Create(new CreateRefundRequest { Amount = 50000 }); ``` -------------------------------- ### Example: Schedule Operations Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Client.md Shows how to get a schedule resource and retrieve its occurrences. ```csharp var scheduleResource = client.Schedule("sch_test_1234567890"); var schedule = await scheduleResource.Get(); var occurrences = await scheduleResource.Occurrences.GetList(); ``` -------------------------------- ### Example: Customer Operations Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Client.md Shows how to get a customer resource, retrieve customer details, and list associated cards. ```csharp var customerResource = client.Customer("cust_test_1234567890"); var customer = await customerResource.Get(); var cards = await customerResource.Cards.GetList(); ``` -------------------------------- ### Create Monthly Recurring Charge (Subscription) Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/ScheduleResource.md Example of setting up a monthly subscription charge. It specifies the recurrence every month, a start and end date, and the charge details including amount, currency, and customer ID. ```csharp var schedule = await client.Schedules.Create(new CreateScheduleRequest { Every = 1, Period = SchedulePeriod.Month, StartDate = DateTime.Now.AddDays(1), EndDate = DateTime.Now.AddYears(1), Charge = new ChargeScheduling { Amount = 100000, // 1000 THB Currency = "thb", Customer = customerId, Description = "Monthly subscription" } }); Console.WriteLine($"Monthly subscription created: {schedule.Id}"); ``` -------------------------------- ### Get Token Example Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/TokenResource.md Example of retrieving a token using its ID. Note that sensitive card data is not returned. ```csharp var token = await client.Tokens.Get("tokn_test_4xs8idev4xsugvfq9hf"); Console.WriteLine($"Card: {token.Card.Brand} ending in {token.Card.LastDigits}"); ``` -------------------------------- ### Credentials Constructor Examples Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Credentials.md Demonstrates initializing Credentials with both keys, only the secret key, or only the public key. ```csharp // Both keys var creds = new Credentials( pkey: "pkey_test_4xs8idev4xsugvfq9hf", skey: "skey_test_4xs8idev4xsugvfq9hf" ); // Secret key only var creds = new Credentials(skey: "skey_test_4xs8idev4xsugvfq9hf"); // Public key only (rare) var creds = new Credentials(pkey: "pkey_test_4xs8idev4xsugvfq9hf"); ``` -------------------------------- ### GetList Token Example Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/TokenResource.md Example of listing tokens with specified limit and offset. The output includes the token ID and card brand. ```csharp var tokens = await client.Tokens.GetList(limit: 20, offset: 0); foreach (var token in tokens.Data) { Console.WriteLine($"{token.Id}: {token.Card.Brand}"); } ``` -------------------------------- ### Complete Payment Flow (Auth + Capture) Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/ChargeResource.md This example demonstrates the complete payment flow, starting with creating an authorized charge without immediate capture, followed by capturing the authorized amount later. ```csharp // Create authorized charge (not captured immediately) var charge = await client.Charges.Create(new CreateChargeRequest { Amount = 100000, Currency = "thb", Card = tokenId, Capture = false // Create authorization only }); // Later: capture the authorized amount var captured = await client.Charges.Capture(charge.Id); ``` -------------------------------- ### Use Token for Customer Creation Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/TokenResource.md Example of creating a customer and associating a token with their account. ```csharp var token = await client.Tokens.Get("tokn_test_4xs8idev4xsugvfq9hf"); var customer = await client.Customers.Create(new CreateCustomerRequest { Email = "customer@example.com", Card = token.Id }); ``` -------------------------------- ### Client Usage Example Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/INDEX.md Demonstrates how to initialize the Omise client and create a charge using the Charges resource. ```APIDOC ## Client Usage Example ### Description This example shows how to instantiate the `Client` with your secret key and then use the `Charges` resource to create a new charge. ### Method POST ### Endpoint `/charges` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **request** (`CreateChargeRequest`) - Required - The details for creating a charge. ### Request Example ```csharp using Omise; using Omise.Models; using Omise.Resources; var client = new Client(skey: "skey_..."); var charge = await client.Charges.Create(new CreateChargeRequest { Amount = 1000, Currency = "THB", Description = "Test Charge" }); ``` ### Response #### Success Response (200) - **charge** (`Charge`) - The created charge object. #### Response Example ```json { "id": "chrg_...", "object": "charge", "amount": 1000, "currency": "THB", "description": "Test Charge", "status": "successful", "..." } ``` ``` -------------------------------- ### Listable Resource Example Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/README.md Demonstrates how to retrieve a list of items for a given resource, such as charges. ```APIDOC ## Listable Resource ### Description Retrieve a list of all items for a resource, with optional limit parameter. ### Method GetList ### Endpoint N/A (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters - **limit** (int) - Optional - The maximum number of items to return. #### Request Body None ### Request Example ```csharp var charges = await client.Charges.GetList(limit: 20); ``` ### Response #### Success Response (200) - A list of items for the resource. #### Response Example ```json [ { ... charge object ... }, { ... charge object ... } ] ``` ``` -------------------------------- ### Create Token Example Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/TokenResource.md Example of creating a payment token using card details. This method should only be used server-side with PCI-DSS compliance or via the Omise.js frontend library. ```csharp var token = await client.Tokens.Create(new CreateTokenRequest { Name = "John Doe", Number = "4242424242424242", ExpirationMonth = 12, ExpirationYear = 2025, SecurityCode = "123" }); Console.WriteLine($"Token created: {token.Id}"); ``` -------------------------------- ### Minimal Credentials Configuration Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Credentials.md Recommended setup using only the secret key, suitable for server-side operations. ```csharp var creds = new Credentials(skey: "skey_test_4xs8idev4xsugvfq9hf"); var client = new Client(creds); ``` -------------------------------- ### Install Omise NuGet Package Source: https://github.com/omise/omise-dotnet/blob/master/README.md Use the NuGet Package Manager to install the Omise library into your .NET project. ```bash > Install-Package omise ``` -------------------------------- ### Creatable Resource Example Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/README.md Demonstrates how to create a new item for a given resource, such as a charge. ```APIDOC ## Creatable Resource ### Description Create a new item for a resource with the provided request data. ### Method Create ### Endpoint N/A (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **Request Object** (object) - Required - The data for the new item. ### Request Example ```csharp var charge = await client.Charges.Create(new CreateChargeRequest { ... }); ``` ### Response #### Success Response (200) - The newly created item object. #### Response Example ```json { "id": "ch_...", "amount": 100000, ... } ``` ``` -------------------------------- ### Asynchronous API Call Example Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/README.md Demonstrates making an asynchronous API call using async/await, which is the standard pattern for all SDK operations. This example shows creating a charge. ```csharp var charge = await client.Charges.Create(request); ``` -------------------------------- ### HTTP Request Example Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/README.md An example of an HTTP POST request sent by the SDK to the Omise API, including headers. ```http POST /charges HTTP/1.1 Content-Type: application/json Authorization: Basic [base64(skey:)] ``` -------------------------------- ### ASP.NET Core Integration Example Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/README.md Demonstrates how to register the Omise Client as a singleton service and use it within a controller to create charges. Handles potential Omise API errors. ```csharp // Startup.cs services.AddSingleton(provider => { var config = provider.GetRequiredService(); return new Client(skey: config["Omise:SecretKey"]); }); // Controller usage public class PaymentController { private readonly Client _omise; public PaymentController(Client omise) => _omise = omise; [HttpPost("charge")] public async Task CreateCharge([FromBody] ChargeRequest req) { try { var charge = await _omise.Charges.Create(new CreateChargeRequest { Amount = req.Amount, Currency = req.Currency, Card = req.Token }); return Ok(charge); } catch (OmiseError ex) { return BadRequest(new { error = ex.Code, message = ex.Message }); } } } ``` -------------------------------- ### Searchable Resource Example Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/README.md Demonstrates how to perform a full-text search across items for a given resource, such as charges. ```APIDOC ## Searchable Resource ### Description Perform a full-text search across items for a resource. ### Method Search ### Endpoint N/A (SDK Method) ### Parameters #### Path Parameters None #### Query Parameters - **query** (string) - Required - The search query string. #### Request Body None ### Request Example ```csharp var results = await client.Charges.Search(query: "..."); ``` ### Response #### Success Response (200) - A list of items matching the search query. #### Response Example ```json [ { ... charge object ... }, { ... charge object ... } ] ``` ``` -------------------------------- ### Transfer to Default Recipient (Usage Example) Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/TransferResource.md A simplified example demonstrating how to create a transfer to a pre-configured default recipient. This is useful for common, recurring transfers. ```csharp var transfer = await client.Transfers.Create(new CreateTransferRequest { Amount = 500000 // 5000.00 in subunit }); Console.WriteLine($"Transfer ID: {transfer.Id}"); Console.WriteLine($"Status: {transfer.Status}"); // Likely "sent" or "pending" ``` -------------------------------- ### Example: Recipient Operations Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Client.md Demonstrates retrieving a specific recipient resource. ```csharp var recipientResource = client.Recipient("recp_test_1234567890"); var recipient = await recipientResource.Get(); ``` -------------------------------- ### Omise Namespace Usage Example Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/INDEX.md Demonstrates how to initialize the Omise client and create a charge using the Charges resource. Ensure you have the necessary using directives for Omise, Omise.Models, and Omise.Resources. ```csharp using Omise; using Omise.Models; using Omise.Resources; var client = new Client(skey: "skey_..."); var charge = await client.Charges.Create(new CreateChargeRequest { ... }); ``` -------------------------------- ### Manage Multiple Omise Accounts/Environments Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Credentials.md Example of creating and using separate Omise clients for test and production environments with different credentials. ```csharp // Test environment var testCreds = new Credentials(skey: "skey_test_..."); var testClient = new Client(testCreds, Environments.Staging); // Production environment var prodCreds = new Credentials(skey: "skey_live_..."); var prodClient = new Client(prodCreds, Environments.Production); // Use appropriate client based on environment var client = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Production" ? prodClient : testClient; ``` -------------------------------- ### Retrievable Resource Example Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/README.md Demonstrates how to retrieve a specific item by its ID for a given resource, such as a charge. ```APIDOC ## Retrievable Resource ### Description Retrieve a specific item by its unique identifier. ### Method Get ### Endpoint N/A (SDK Method) ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the item. #### Query Parameters None #### Request Body None ### Request Example ```csharp var charge = await client.Charges.Get("ch_..."); ``` ### Response #### Success Response (200) - The requested item object. #### Response Example ```json { "id": "ch_...", "amount": 100000, ... } ``` ``` -------------------------------- ### Partial Refund Example Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/ChargeResource.md Demonstrates how to perform a partial refund on a previously created charge. A full charge is created first, and then a portion of the amount is refunded. ```csharp // Create full charge var charge = await client.Charges.Create(new CreateChargeRequest { Amount = 100000, Currency = "thb", Card = tokenId }); // Refund partial amount var chargeResource = client.Charge(charge.Id); var refund = await chargeResource.Refunds.Create(new CreateRefundRequest { Amount = 25000 // Refund 25% of original charge }); ``` -------------------------------- ### Destroyable Resource Example Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/README.md Demonstrates how to delete an existing item by its ID for a given resource, such as a customer. ```APIDOC ## Destroyable Resource ### Description Delete an existing item identified by its ID. ### Method Destroy ### Endpoint N/A (SDK Method) ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the item to delete. #### Query Parameters None #### Request Body None ### Request Example ```csharp var deleted = await client.Customers.Destroy("cust_..."); ``` ### Response #### Success Response (200) - A boolean indicating if the deletion was successful. #### Response Example ```json true ``` ``` -------------------------------- ### Use Token for Charge Creation Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/TokenResource.md Example of creating a charge using a previously created token's ID. ```csharp var token = await client.Tokens.Get("tokn_test_4xs8idev4xsugvfq9hf"); var charge = await client.Charges.Create(new CreateChargeRequest { Amount = 100000, Currency = "thb", Card = token.Id }); ``` -------------------------------- ### Using Frontend Token for Charge Creation Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/TokenResource.md Example of how to use a token obtained from Omise.js on the frontend to create a charge server-side. ```csharp // C# (server-side) var charge = await client.Charges.Create(new CreateChargeRequest { Amount = 100000, Currency = "thb", Card = tokenFromFrontend // Use token from Omise.js }); ``` -------------------------------- ### Updatable Resource Example Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/README.md Demonstrates how to update an existing item by its ID for a given resource, such as a charge. ```APIDOC ## Updatable Resource ### Description Update an existing item identified by its ID with the provided request data. ### Method Update ### Endpoint N/A (SDK Method) ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the item to update. #### Query Parameters None #### Request Body - **Request Object** (object) - Required - The data to update the item with. ### Request Example ```csharp var charge = await client.Charges.Update("ch_...", new UpdateChargeRequest { ... }); ``` ### Response #### Success Response (200) - The updated item object. #### Response Example ```json { "id": "ch_...", "amount": 150000, ... } ``` ``` -------------------------------- ### Server-Side Token Creation (PCI-DSS Required) Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/TokenResource.md Example of server-side token creation. This is only recommended if you have valid PCI-DSS compliance. ```csharp // Only use this if you have PCI-DSS compliance var token = await client.Tokens.Create(new CreateTokenRequest { Name = "Jane Smith", Number = "4242424242424242", ExpirationMonth = 3, ExpirationYear = 2026, SecurityCode = "456" }); ``` -------------------------------- ### Create Charge with Token (Synchronous) Source: https://github.com/omise/omise-dotnet/blob/master/README.md Create a charge using a token. This example uses .Result, which can block the calling thread. ```csharp var token = GetToken(); var charge = Client.Charges.Create(new CreateChargeRequest { Amount = 200000 // 2,000.00 THB Currency = "thb", Card = token.Id }) .Result; Print("created charge: " + charge.Id); ``` -------------------------------- ### Create New Item using Create Method Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/README.md Example of creating a new item using the Create method. This requires a request object containing the necessary parameters for the item. ```csharp var charge = await client.Charges.Create(new CreateChargeRequest { ... }); ``` -------------------------------- ### List Items using GetList Method Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/README.md Example of retrieving a list of items using the GetList method, common for resources like charges. Specify a limit for the number of items to retrieve. ```csharp var charges = await client.Charges.GetList(limit: 20); ``` -------------------------------- ### Create a Charge with Token Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/README.md Example of creating a charge using a payment token obtained from Omise.js. Specify the amount, currency, and the token ID. ```csharp var charge = await client.Charges.Create(new CreateChargeRequest { Amount = 100000, Currency = "thb", Card = tokenId // Token from Omise.js }); ``` -------------------------------- ### Initialize Client with Custom Environment (Staging) Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/configuration.md Allows configuration for staging environments, useful for testing with test API keys before production deployment. ```csharp var client = new Client( skey: "skey_test_...", env: Environments.Staging // or Environments.Production ); ``` -------------------------------- ### Retrieve Specific Item by ID Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/README.md Demonstrates how to fetch a specific item by its unique identifier using the Get method. This is applicable to most retrievable resources. ```csharp var charge = await client.Charges.Get("ch_..."); ``` -------------------------------- ### Configure Omise Client with Dependency Injection Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/configuration.md Register the Omise IClient as a singleton service in your ASP.NET Core application's startup configuration. This example shows how to retrieve the secret key from application configuration. ```csharp // Startup.cs or Program.cs services.AddSingleton(provider => { var config = provider.GetRequiredService(); var skey = config["Omise:SecretKey"]; return new Client(skey: skey); }); // Usage in controller public class PaymentController { private readonly IClient _omiseClient; public PaymentController(Client omiseClient) { _omiseClient = omiseClient; } public async Task CreateCharge() { var charge = await _omiseClient.Charges.Create(new CreateChargeRequest { ... }); return Ok(charge); } } ``` -------------------------------- ### Initialize Client with Environment Variables Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/configuration.md Retrieve secret and public keys from environment variables to initialize the Omise client. Recommended for managing keys securely. ```csharp string skey = Environment.GetEnvironmentVariable("OMISE_SECRET_KEY"); string pkey = Environment.GetEnvironmentVariable("OMISE_PUBLIC_KEY"); var client = new Client(pkey: pkey, skey: skey); ``` -------------------------------- ### Initialize Client for Staging Environment Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/configuration.md Configures the client to use the staging environment for testing purposes. ```csharp var client = new Client(skey: "skey_test_...", env: Environments.Staging); ``` -------------------------------- ### Create Bi-Weekly Recurring Charge Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/ScheduleResource.md Example for creating a bi-weekly recurring charge. It sets the recurrence to every 2 weeks, defines the start and end dates, and specifies the charge amount, currency, customer, and a description. ```csharp var schedule = await client.Schedules.Create(new CreateScheduleRequest { Every = 2, Period = SchedulePeriod.Week, StartDate = DateTime.Now.AddDays(1), EndDate = DateTime.Now.AddMonths(12), Charge = new ChargeScheduling { Amount = 50000, Currency = "thb", Customer = customerId, Description = "Bi-weekly service charge" } }); ``` -------------------------------- ### Retrieve Token Details (Safe to Log) Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/TokenResource.md Example of retrieving token details, focusing on safe-to-log information like card brand and last digits. Sensitive data is not returned. ```csharp var token = await client.Tokens.Get("tokn_test_4xs8idev4xsugvfq9hf"); // These are safe to log/display Console.WriteLine($"Cardholder: {token.Card.Name}"); Console.WriteLine($"Brand: {token.Card.Brand}"); Console.WriteLine($"Last 4 digits: {token.Card.LastDigits}"); Console.WriteLine($"Expires: {token.Card.ExpirationMonth}/{token.Card.ExpirationYear}"); // Sensitive data (full card number, CVV) are NOT returned ``` -------------------------------- ### Get Token Request Signature Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/TokenResource.md Signature for the Get method in TokenResource, used to retrieve a previously created token by its ID. ```csharp public async Task Get(string tokenId) ``` -------------------------------- ### Initialize Client with Custom Environment Configuration Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/configuration.md Provides advanced configuration for custom API endpoints, suitable for specific deployment scenarios. ```csharp var customEnv = new CustomEnvironment(new Dictionary { { Endpoint.Api, "https://custom-api.example.com" }, { Endpoint.Vault, "https://custom-vault.example.com" } }); var client = new Client(skey: "skey_...", env: customEnv); ``` -------------------------------- ### Get Recipient Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/RecipientResource.md Retrieves a specific recipient by their ID. ```APIDOC ## Get Recipient ### Description Retrieves the details of a specific recipient using their unique identifier. ### Method GET ### Endpoint /recipients/{recipientId} ### Parameters #### Path Parameters - **recipientId** (string) - Required - The unique identifier of the recipient. ### Response #### Success Response (200) - **Recipient** (Recipient object) - The details of the requested recipient. #### Response Example (Response structure depends on Recipient object definition) ``` -------------------------------- ### Get Customer Details Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/CustomerResource.md Retrieves the details of a specific customer. ```APIDOC ## Get Customer Details ### Description Retrieves the details of a specific customer. ### Method GET ### Endpoint /customers/{customer_id} ### Parameters (No specific parameters mentioned for Get in the source) ### Request Example ```csharp var customerResource = client.Customer("cust_test_1234567890"); var customer = await customerResource.Get(); ``` ### Response #### Success Response (200) - **id** (string) - The customer's unique identifier. - **email** (string) - The customer's email address. - **description** (string) - A description for the customer. #### Response Example (Response structure not detailed in source beyond basic fields) ``` -------------------------------- ### Initialize Client for Production Environment Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/configuration.md The default environment used if no environment is specified. Ensures communication with the live Omise API. ```csharp var client = new Client(skey: "skey_...", env: Environments.Production); ``` -------------------------------- ### Initialize Client for Local Development Environment Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/configuration.md Enables local testing against development servers by configuring specific local endpoints. ```csharp var client = new Client(skey: "skey_...", env: Environments.LocalMachine); ``` -------------------------------- ### Get Customer Schedules Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/CustomerResource.md Retrieves a list of schedules associated with a specific customer. ```APIDOC ## Get Customer Schedules ### Description Retrieves a list of schedules associated with a specific customer. ### Method GET ### Endpoint /customers/{customer_id}/schedules ### Parameters (No specific parameters mentioned for GetList in the source) ### Request Example ```csharp var customerResource = client.Customer("cust_test_1234567890"); var schedules = await customerResource.Schedules.GetList(); ``` ### Response #### Success Response (200) - **data** (array) - A list of schedule objects. #### Response Example (Response structure not detailed in source) ``` -------------------------------- ### Get Charge Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/ChargeResource.md Retrieves the details of a specific charge using its unique ID. ```APIDOC ## Get Charge ### Description Retrieves the details of a specific charge using its unique ID. ### Method GET ### Endpoint /charges/{chargeId} ### Parameters #### Path Parameters - **chargeId** (string) - Yes - The charge ID (ch_...) ### Response #### Success Response (200) - **charge** (Charge) - The charge details. #### Response Example ```json { "id": "ch_test_4xs8idev4xsugvfq9hf", "object": "charge", "amount": 100000, "currency": "thb", "status": "successful", "description": "Order #12345", "card": { "id": "tokn_test_4xs8idev4xsugvfq9hf", "object": "card", "last_digits": "4242", "brand": "Visa" }, "created_at": "2023-10-27T10:00:00Z", "captured_at": "2023-10-27T10:05:00Z" } ``` ``` -------------------------------- ### Initialize Client with Both Public and Secret Keys Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/configuration.md Useful when both keys are needed server-side, such as for PCI-DSS token creation. ```csharp var client = new Client( pkey: "pkey_test_4xs8idev4xsugvfq9hf", skey: "skey_test_4xs8idev4xsugvfq9hf" ); ``` -------------------------------- ### Usage of ListOptions for Fetching Charges Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/configuration.md Demonstrates how to use ListOptions to paginate, filter by date, and sort the results when fetching a list of charges. ```csharp var charges = await client.Charges.GetList( offset: 0, limit: 20, from: DateTime.Now.AddDays(-30), to: DateTime.Now, order: Ordering.Desc ); ``` -------------------------------- ### Get Link Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/LinkResource.md Retrieves the details of a specific payment link using its unique ID. ```APIDOC ## Get Link ### Description Retrieve a specific payment link by ID. ### Method GET ### Endpoint /links/{linkId} ### Parameters #### Path Parameters - **linkId** (string) - Required - The link ID (link_...) ### Response #### Success Response (200) - **Link** (Link) - Link details. #### Response Example ```json { "PaymentUri": "https://payment.omise.co/links/link_test_xxxxxxxxx", "ChargesCount": 0 } ``` ``` -------------------------------- ### Get Recipient Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/RecipientResource.md Retrieves a specific recipient's details using their unique ID. ```APIDOC ## Get Recipient ### Description Retrieve a specific recipient by their unique identifier. ### Method GET (Implied by SDK method) ### Endpoint `/recipients/{recipientId}` (Implied by SDK method) ### Parameters #### Path Parameters - **recipientId** (string) - Yes - The recipient ID (recp_...) #### Query Parameters None #### Request Body None ### Request Example ```csharp var recipient = await client.Recipients.Get("recp_test_4xs8idev4xsugvfq9hf"); ``` ### Response #### Success Response (200) - **Recipient** (Recipient) - Recipient details. #### Response Example ```json { "id": "recp_test_4xs8idev4xsugvfq9hf", "name": "John Smith", "bank_account": { "brand": "bank", "number": "7777-777-777", "name": "John Smith" } } ``` ``` -------------------------------- ### Client Constructor with API Keys Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Client.md Initializes a new Omise client using public and/or secret API keys. The secret key is recommended for minimal initialization. An optional environment can be specified. ```csharp public Client(string pkey = null, string skey = null, IEnvironment env = null) ``` ```csharp // Minimal initialization with secret key only (recommended) var client = new Client(skey: "skey_test_4xs8idev4xsugvfq9hf"); ``` ```csharp // Full initialization with both keys and staging environment var client = new Client( pkey: "pkey_test_4xs8idev4xsugvfq9hf", skey: "skey_test_4xs8idev4xsugvfq9hf", env: Environments.Staging ); ``` -------------------------------- ### Full Credentials Configuration Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Credentials.md Initializes credentials using both public and secret keys, useful when both are available. ```csharp var creds = new Credentials( pkey: "pkey_test_4xs8idev4xsugvfq9hf", skey: "skey_test_4xs8idev4xsugvfq9hf" ); var client = new Client(creds); ``` -------------------------------- ### Initialize Client with Secret Key Only Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/configuration.md Recommended for minimizing public key exposure. Only the secret key is required for server-side operations. ```csharp var client = new Client(skey: "skey_test_4xs8idev4xsugvfq9hf"); ``` -------------------------------- ### Get Default API Version Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/configuration.md Retrieves the default API version used by the client, which is '2019-05-29'. ```csharp var client = new Client(skey: "skey_test_..."); Console.WriteLine(client.APIVersion); // "2019-05-29" ``` -------------------------------- ### Create Customer and Charge Source: https://github.com/omise/omise-dotnet/blob/master/README.md Create a customer with a card token, then create a charge associated with that customer. ```csharp var token = GetToken(); var customer = await Client.Customers.Create(new CreateCustomerRequest { Email = "customers_email@example.com", Description = "customer#1234", Card = token.Id }); Print("created customer: {0}", customer.Id); var charge = await Client.Charges.Create(new CreateChargeRequest { Customer = customer.Id, Amount = 200000, // 2,000.00 THB Currency = "thb" }); Print("created charge: {0}", charge.Id); ``` -------------------------------- ### TransferResource Methods Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/00_MANIFEST.txt The TransferResource includes methods for managing transfers, with properties for schedules and examples for recurring transfers. ```APIDOC ## TransferResource Methods ### Description The `TransferResource` is used for managing fund transfers. It provides methods to initiate and manage transfers, and includes properties related to scheduling transfers. The documentation offers several usage examples, including a specific example for setting up recurring transfers. ### Methods - **Create**: Initiates a new fund transfer. - **Get**: Retrieves details of a specific transfer. - **GetList**: Retrieves a list of transfers. - **Update**: Updates an existing transfer (if applicable). - **Cancel**: Cancels a pending transfer. - **Search**: Searches for transfers based on specified criteria. ``` -------------------------------- ### Client Constructor (API Keys) Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Client.md Initializes a new Omise client using public and secret API keys. This is the primary method for setting up API access. ```APIDOC ## Client Constructor (API Keys) ### Description Initializes a new Omise client with API credentials using public and secret keys. ### Method Constructor ### Signature `Client(string pkey = null, string skey = null, IEnvironment env = null)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Table | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | pkey | string | No | null | Public API key (pkey_...) from Omise dashboard | | skey | string | No | null | Secret API key (skey_...) from Omise dashboard | | env | IEnvironment | No | Environments.Production | Environment to connect to (Production, Staging, LocalMachine) | ### Throws `ArgumentException` if both pkey and skey are null or empty. ### Example ```csharp // Minimal initialization with secret key only (recommended) var client = new Client(skey: "skey_test_4xs8idev4xsugvfq9hf"); // Full initialization with both keys and staging environment var client = new Client( pkey: "pkey_test_4xs8idev4xsugvfq9hf", skey: "skey_test_4xs8idev4xsugvfq9hf", env: Environments.Staging ); ``` ``` -------------------------------- ### Get Customer Schedules Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/CustomerResource.md Retrieves a list of schedules associated with a specific customer. Requires the customer ID. ```csharp var customerResource = client.Customer("cust_test_1234567890"); var schedules = await customerResource.Schedules.GetList(); ``` -------------------------------- ### Handle Invalid Keys During Initialization Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Credentials.md Demonstrates how to catch an ArgumentException when initializing Credentials without providing any keys. ```csharp try { var creds = new Credentials(); // No keys provided } catch (ArgumentException ex) { Console.WriteLine(ex.Message); // "pkey and skey can't both be null" } ``` -------------------------------- ### DisputeResource Methods Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/00_MANIFEST.txt The DisputeResource allows for querying and managing disputes, with properties for different dispute statuses and usage examples. ```APIDOC ## DisputeResource Methods ### Description The `DisputeResource` provides functionality to manage and query disputes raised against charges. It allows retrieval of disputes based on their status (open, pending, closed) and offers methods for interacting with dispute records. The documentation includes usage examples and references for dispute statuses and common reasons. ### Properties - **OpenDisputes**: Access to open disputes. - **PendingDisputes**: Access to pending disputes. - **ClosedDisputes**: Access to closed disputes. ### Methods - **Get**: Retrieves a specific dispute by its ID. - **GetList**: Retrieves a list of disputes, with options for status-specific queries. - **Update**: Updates a dispute record (e.g., submitting evidence). - **Close**: Closes a dispute. ``` -------------------------------- ### Create Credentials with Both Keys Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/configuration.md Instantiates the Credentials class providing both public and secret keys. ```csharp // Both keys var credentials = new Credentials( pkey: "pkey_test_...", skey: "skey_test_..." ); ``` -------------------------------- ### Get Schedule Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/ScheduleResource.md Retrieve a specific schedule by its unique ID. This allows you to view the details of an existing recurring schedule. ```APIDOC ## Get Schedule ### Description Retrieve a specific schedule by ID. This allows you to view the details of an existing recurring schedule. ### Method GET ### Endpoint /schedules/{scheduleId} ### Parameters #### Path Parameters - **scheduleId** (string) - Yes - The schedule ID (sch_...) ### Response #### Success Response (200) - **schedule** (Schedule) - Schedule details. #### Response Example ```json { "id": "sch_test_4xs8idev4xsugvfq9hf", "status": "active", "next_occurrence_date": "YYYY-MM-DDTHH:MM:SSZ" } ``` ``` -------------------------------- ### Client Constructor with Credentials Object Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Client.md Initializes a new Omise client using a pre-configured Credentials object. This is an alternative to providing API keys directly during client instantiation. The target environment can also be specified. ```csharp public Client(Credentials credentials, IEnvironment env = null) ``` ```csharp var credentials = new Credentials(pkey: "pkey_...", skey: "skey_..."); var client = new Client(credentials, Environments.Production); ``` -------------------------------- ### Get Specific Schedule Resource Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Client.md Retrieves a specific schedule resource for detailed operations. Requires the schedule ID. ```csharp public ScheduleSpecificResource Schedule(string scheduleId) ``` -------------------------------- ### Create Customer with Card Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/CustomerResource.md Creates a new customer and associates a payment card with their account using a token ID. The card token is obtained from the frontend. ```csharp var customer = await client.Customers.Create(new CreateCustomerRequest { Email = "customer@example.com", Description = "Subscription customer", Card = tokenId // Token obtained from frontend }); ``` -------------------------------- ### Get Specific Recipient Resource Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Client.md Retrieves a specific recipient resource for detailed operations. Requires the recipient ID. ```csharp public RecipientSpecificResource Recipient(string recipientId) ``` -------------------------------- ### Initialize Omise Client with Public and Secret Keys Source: https://github.com/omise/omise-dotnet/blob/master/README.md Instantiate the Omise client by providing both your public and secret API keys. Ensure you have obtained these keys from the Opn Payments Dashboard. ```csharp using Omise; var client = new Client([YOUR_PUBLIC_KEY], [YOUR_SECRET_KEY]); ``` -------------------------------- ### Get Specific Customer Resource Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Client.md Retrieves a specific customer resource for detailed operations. Requires the customer ID. ```csharp public CustomerSpecificResource Customer(string customerId) ``` -------------------------------- ### Get Specific Charge Resource Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Client.md Retrieves a specific charge resource for detailed operations. Requires the charge ID. ```csharp public ChargeSpecificResource Charge(string chargeId) ``` -------------------------------- ### Client Initialization Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/README.md The main entry point for interacting with the Omise API. Initialization requires your secret key. ```APIDOC ## Client Initialization ### Description Initialize the Omise client with your secret key to authenticate API requests. ### Method Constructor ### Endpoint N/A (SDK Initialization) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```csharp var client = new Client(skey: "skey_test_..."); ``` ### Response N/A (Initialization) #### Success Response N/A #### Response Example N/A ``` -------------------------------- ### Get Customer Cards Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/CustomerResource.md Retrieves a list of saved payment cards for a specific customer. Requires the customer ID. ```csharp var customerResource = client.Customer("cust_test_1234567890"); var cards = await customerResource.Cards.GetList(); ``` -------------------------------- ### Get Transfer Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/TransferResource.md Retrieve a specific transfer by its ID. This is useful for checking the status or details of a previously initiated transfer. ```APIDOC ## GET /transfers/{transferId} ### Description Retrieve a specific transfer by ID. ### Method GET ### Endpoint /transfers/{transferId} ### Parameters #### Path Parameters - **transferId** (string) - Yes - The transfer ID (trsf_...) ### Response #### Success Response (200) - **Transfer** (Transfer) - Transfer details. #### Response Example ```json { "id": "trsf_test_xxxxxxxxxxxxxxxxx", "object": "transfer", "amount": 500000, "recipient": "recp_test_4xs8idev4xsugvfq9hf", "status": "sent", "created_at": "2023-01-01T12:00:00Z" } ``` ``` -------------------------------- ### Create a Schedule Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/README.md Creates a recurring payment schedule. Specify the frequency, start and end dates, and charge details. ```csharp var schedule = await client.Schedules.Create(new CreateScheduleRequest { Every = 1, Period = SchedulePeriod.Month, StartDate = DateTime.Now, EndDate = DateTime.Now.AddYears(1), Charge = new ChargeScheduling { Amount = 100000, Currency = "thb", Customer = customerId } }); ``` -------------------------------- ### Customer Metadata and Tagging Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/CustomerResource.md Creates a customer with initial metadata and demonstrates how to update the metadata later. Metadata can be used for custom tagging and segmentation. ```csharp var customer = await client.Customers.Create(new CreateCustomerRequest { Email = "customer@example.com", Card = tokenId, Metadata = new Dictionary { { "customer_segment", "premium" }, { "signup_campaign", "summer_2024" }, { "ltv", 150000 } } }); // Update metadata later await client.Customers.Update("cust_test_1234567890", new UpdateCustomerRequest { Metadata = new Dictionary { { "customer_segment", "vip" } } } ); ``` -------------------------------- ### LinkResource Methods Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/00_MANIFEST.txt The LinkResource provides methods for creating and managing payment links, with extensive usage examples for various scenarios. ```APIDOC ## LinkResource Methods ### Description The `LinkResource` is used to create and manage Omise Payment Links, which provide a simple way to accept payments without requiring complex integration. The documentation details how to create various types of links, including simple payment links, reusable links, and invoice links, along with examples for monitoring link performance and usage in fundraising scenarios. ### Methods - **Create**: Creates a new payment link. - **Get**: Retrieves a specific payment link by its ID. - **GetList**: Retrieves a list of payment links. - **Update**: Updates an existing payment link. ``` -------------------------------- ### Charge Creation with Passkey Authentication Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/ChargeResource.md This snippet shows how to create a charge using Passkey authentication. It also includes a check to verify if the charge was indeed authenticated by Passkey. ```csharp var charge = await client.Charges.Create(new CreateChargeRequest { Amount = 100000, Currency = "thb", Card = tokenId, Authentication = AuthFlow.Passkey }); // Check authentication method used if (charge.AuthenticatedBy == AuthFlow.Passkey) { Console.WriteLine("Payment authenticated with Passkey"); } ``` -------------------------------- ### Create a New Customer Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/CustomerResource.md Use this method to create a new customer profile. Provide email, description, and optionally a card token for initial payment information. ```csharp var customer = await client.Customers.Create(new CreateCustomerRequest { Email = "john.doe@example.com", Description = "customer#12345", Card = "tokn_test_4xs8idev4xsugvfq9hf" }); Console.WriteLine($"Created customer: {customer.Id}"); ``` -------------------------------- ### RecipientResource Methods Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/00_MANIFEST.txt The RecipientResource offers methods for managing recipients, including examples for individual and corporate accounts, and metadata usage. ```APIDOC ## RecipientResource Methods ### Description The `RecipientResource` allows for the management of recipient accounts, which are essential for processing transfers. It provides methods to create, retrieve, update, and delete recipient information, supporting both individual and corporate recipient types. Examples demonstrate how to use metadata effectively with recipients. ### Methods - **Create**: Creates a new recipient account. - **Get**: Retrieves a specific recipient by their ID. - **GetList**: Retrieves a list of recipients. - **Update**: Updates the details of an existing recipient. - **Destroy**: Deletes a recipient account. - **Search**: Searches for recipients based on specified criteria. ``` -------------------------------- ### Credentials Constructor Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Credentials.md Initializes API credentials using provided public and/or secret key strings. At least one key must be provided. ```csharp public Credentials(string? pkey = null, string? skey = null) ``` -------------------------------- ### Get a Specific Dispute Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/DisputeResource.md Retrieves the details of a single dispute using its unique ID. Ensure you have the correct dispute ID. ```csharp var dispute = await client.Disputes.Get("disp_test_4xs8idev4xsugvfq9hf"); Console.WriteLine($ ``` ```csharp var dispute = await client.Disputes.Get("disp_test_1234567890"); Console.WriteLine($"Dispute ID: {dispute.Id}"); Console.WriteLine($"Charge ID: {dispute.ChargeId}"); Console.WriteLine($"Amount: {dispute.Amount} {dispute.Currency}"); Console.WriteLine($"Status: {dispute.Status}"); Console.WriteLine($"Reason: {dispute.Reason}"); Console.WriteLine($"Created: {dispute.CreatedAt}"); ``` -------------------------------- ### Client Constructor (Credentials Object) Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Client.md Initializes a new Omise client using a pre-configured Credentials object, offering an alternative way to manage API authentication. ```APIDOC ## Client Constructor (Credentials Object) ### Description Initializes a new Omise client with pre-configured credentials. ### Method Constructor ### Signature `Client(Credentials credentials, IEnvironment env = null)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Table | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | credentials | Credentials | Yes | — | Pre-configured credentials object | | env | IEnvironment | No | Environments.Production | Environment to connect to | ### Throws `ArgumentNullException` if credentials is null. ### Example ```csharp var credentials = new Credentials(pkey: "pkey_...", skey: "skey_..."); var client = new Client(credentials, Environments.Production); ``` ``` -------------------------------- ### Validate Secret Key Format During Client Creation Source: https://github.com/omise/omise-dotnet/blob/master/_autodocs/api-reference/Credentials.md Illustrates a factory pattern for creating an Omise client, including validation of the secret key format before initializing Credentials. ```csharp public class OmiseClientFactory { private readonly ILogger _logger; private readonly IConfiguration _config; public OmiseClientFactory(ILogger logger, IConfiguration config) { _logger = logger; _config = config; } public Client CreateClient() { var skey = _config["Omise:SecretKey"] ?? throw new InvalidOperationException("Missing Omise:SecretKey configuration"); if (!skey.StartsWith("skey_")) { throw new ArgumentException("Invalid secret key format"); } var creds = new Credentials(skey: skey); _logger.LogInformation("Omise client created"); return new Client(creds, Environments.Production); } } ```