### Configure Plugin Settings - PHP Source: https://context7.com/foojiayin/woocommerce-amego/llms.txt This snippet shows how to register and retrieve plugin settings using the WordPress Settings API. It includes the retrieval of the Invoice ID and App Key, which are essential for API authentication. Test credentials for development are also provided. ```php 測試帳號登入 ``` -------------------------------- ### Send Invoice API (PHP) Source: https://context7.com/foojiayin/woocommerce-amego/llms.txt This PHP code snippet demonstrates how to construct and send invoice data to the Amego API. It includes details on API endpoint, data structure, optional fields for different invoice types (B2C, B2B, mobile carrier, charity), and MD5 signature authentication using cURL. Dependencies include PHP's cURL extension and JSON encoding. ```php "1001", // WooCommerce order ID "BuyerIdentifier" => "0000000000", // Tax ID (0000000000 for individuals) "BuyerName" => "John Doe", // Customer name "BuyerAddress" => "123 Main St, Taipei", // Billing address "BuyerPhoneNumber" => "0912345678", // Phone number "BuyerEmailAddress" => "customer@example.com", // Email "ProductItem" => [ [ "Description" => "Product Name", "Quantity" => 2, "UnitPrice" => 150, "Amount" => 300, "Remark" => "", "TaxType" => "1" // 1 = Taxable ] ], "SalesAmount" => 300, "FreeTaxSalesAmount" => 0, "ZeroTaxSalesAmount" => 0, "TaxType" => "1", // Tax type: 1 = Taxable "TaxRate" => "0.05", // 5% tax rate "TaxAmount" => "0", // Tax amount (0 for B2C, calculated for B2B) "TotalAmount" => 300 // Total including tax ); // Optional fields based on invoice type: // For mobile carrier (3J0002) or certificate (CQ0001): $invoice_data["CarrierType"] = "3J0002"; $invoice_data["CarrierId1"] = "/ABC1234"; $invoice_data["CarrierId2"] = "/ABC1234"; // For charity donation: $invoice_data["NPOBAN"] = "25885"; // Charity organization code // For company invoice: $invoice_data["BuyerIdentifier"] = "12345678"; // Company tax ID $invoice_data["BuyerName"] = "Company Ltd"; $invoice_data["TaxAmount"] = 15; // 5% of SalesAmount $invoice_data["SalesAmount"] = 285; // Total minus tax // API signature calculation $nCurrent_Now_Time = time(); // Unix timestamp (10 digits) $sApi_Data = json_encode($invoice_data, JSON_UNESCAPED_UNICODE); $sSign = md5($sApi_Data . ((string) $nCurrent_Now_Time) . $app_key); // Send request $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $sUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array( 'invoice' => $invoice, // Merchant's unified business number 'data' => $sApi_Data, // JSON invoice data (URL encoded by http_build_query) 'time' => $nCurrent_Now_Time, 'sign' => $sSign, // MD5 signature ))); $sOutput = curl_exec($ch); curl_close($ch); ``` -------------------------------- ### Log API Data and Errors in PHP Source: https://context7.com/foojiayin/woocommerce-amego/llms.txt This PHP code snippet demonstrates how to log API request and response data, as well as capture and log PHP errors. Logs are directed to specific files within the 'logs/' directory for debugging purposes. ```php ``` -------------------------------- ### Register Test API Endpoint Handler (PHP) Source: https://context7.com/foojiayin/woocommerce-amego/llms.txt This PHP code snippet shows how to register a REST API endpoint within WordPress using `register_rest_route`. It defines a POST endpoint at `/amego/v1/test` that triggers the `amego_test_handler` function. The `permission_callback` is set to `__return_true`, allowing public access. It also defines a sample `$test_invoice_data` array for testing purposes. ```php 'POST', 'callback' => 'amego_test_handler', 'permission_callback' => '__return_true', )); // Test invoice payload (3 sample products, total $180) $test_invoice_data = array( "OrderId" => (string) time(), "BuyerIdentifier" => "0000000000", "BuyerName" => "Amego woocommerce", "BuyerAddress" => "address", "BuyerPhoneNumber" => "0123456789", "BuyerEmailAddress" => "invoice@gmail.com", "ProductItem" => [ ["Description" => "Product", "Quantity" => 2, "UnitPrice" => 30, "Amount" => 60, "Remark" => "", "TaxType" => "1"], ["Description" => "Product", "Quantity" => 2, "UnitPrice" => 30, "Amount" => 60, "Remark" => "", "TaxType" => "1"], ["Description" => "Product", "Quantity" => 2, "UnitPrice" => 30, "Amount" => 60, "Remark" => "", "TaxType" => "1"] ], "SalesAmount" => 180, "FreeTaxSalesAmount" => 0, "ZeroTaxSalesAmount" => 0, "TaxType" => "1", "TaxRate" => "0.05", "TaxAmount" => "0", "TotalAmount" => 180 ); ``` -------------------------------- ### Test API Endpoint Source: https://context7.com/foojiayin/woocommerce-amego/llms.txt This REST API endpoint allows for testing invoice submission without creating an actual WooCommerce order. It sends a synthetic test order to Amego using the configured credentials. ```APIDOC ## Test API Endpoint ### Description This endpoint provides a way to test the Amego invoice API by sending synthetic data without requiring a live WooCommerce order. It uses the plugin's configured credentials. ### Method POST ### Endpoint `https://your-domain.com/wp-json/amego/v1/test` ### Parameters #### Request Body This endpoint does not require a request body. ### Request Example ```bash curl -X POST \ -H "Content-Type: application/json" \ -d '' \ https://your-domain.com/wp-json/amego/v1/test ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the test invoice submission was successful. #### Response Example ```json { "success": true } ``` ### Notes - Test invoices can be viewed at: `https://invoice.amego.tw/login` > `測試帳號登入`. - The actual test invoice payload used by the handler includes sample products and a total of $180. ``` -------------------------------- ### Test Amego API Endpoint with cURL Source: https://github.com/foojiayin/woocommerce-amego/blob/main/README.md This command-line snippet demonstrates how to test the Amego API endpoint without making a purchase in WooCommerce. It sends a synthetic order to Amego for testing purposes. Ensure you replace 'your-domain.com' with your actual domain. ```bash curl -X POST -H "Content-Type: application/json" -d '' https://your-domain.com/wp-json/amego/v1/test ``` -------------------------------- ### Handle Checkout Invoice Type Selection - PHP Source: https://context7.com/foojiayin/woocommerce-amego/llms.txt This PHP snippet illustrates how the plugin adds custom fields to the WooCommerce checkout for invoice type selection. It defines the available invoice types, validation patterns for carrier IDs and tax IDs, and the order meta data stored after checkout. ```php '紙本發票', // Paper Invoice '3J0002' => '手機載具', // Mobile Carrier 'CQ0001' => '自然人憑證條碼', // Citizen Digital Certificate 'company' => '公司統一編號', // Company Tax ID 'charity' => '捐贈發票' // Charity Donation ); // Validation patterns used: // Mobile carrier: /^\/[A-Z0-9]{7}$/ Example: /ABC+123 // Certificate: /^[A-Z]{2}[0-9]{16}$/ Example: AB12345678901234 // Company Tax ID: /^[0-9]{8}$/ Example: 12345678 // Order meta stored after checkout: // - invoice_type: 'print', '3J0002', 'CQ0001', 'company', or 'charity' // - carrier_id: Mobile carrier or certificate barcode // - tax_id: Company unified business number // - billing_company: Company name // - npo_ban: Charity donation code ``` -------------------------------- ### Send Invoice API (Automatic on Payment Complete) Source: https://context7.com/foojiayin/woocommerce-amego/llms.txt This API endpoint is triggered automatically when a WooCommerce order payment is completed or its status changes to 'processing'. It constructs an invoice payload from order data and sends it to the Amego API, utilizing MD5 signature authentication. ```APIDOC ## Send Invoice API (Automatic on Payment Complete) ### Description This endpoint automatically sends an invoice to the Amego API when a WooCommerce order is paid or processed. It uses MD5 signature authentication and constructs the invoice payload from the order details. ### Method POST ### Endpoint `https://invoice-api.amego.tw/json/c0401` ### Parameters #### Request Body - **OrderId** (string) - Required - WooCommerce order ID. - **BuyerIdentifier** (string) - Required - Tax ID (use '0000000000' for individuals). - **BuyerName** (string) - Required - Customer name. - **BuyerAddress** (string) - Required - Billing address. - **BuyerPhoneNumber** (string) - Required - Phone number. - **BuyerEmailAddress** (string) - Required - Email address. - **ProductItem** (array) - Required - An array of product items, each with: - **Description** (string) - Product description. - **Quantity** (integer) - Product quantity. - **UnitPrice** (float) - Price per unit. - **Amount** (float) - Total amount for the item. - **Remark** (string) - Optional - Item remark. - **TaxType** (string) - Required - Tax type (e.g., '1' for taxable). - **SalesAmount** (float) - Required - Total taxable sales amount. - **FreeTaxSalesAmount** (float) - Required - Tax-free sales amount. - **ZeroTaxSalesAmount** (float) - Required - Zero-tax sales amount. - **TaxType** (string) - Required - Overall tax type (e.g., '1' for taxable). - **TaxRate** (string) - Required - Tax rate (e.g., '0.05' for 5%). - **TaxAmount** (float) - Required - Total tax amount (0 for B2C, calculated for B2B). - **TotalAmount** (float) - Required - Total amount including tax. - **CarrierType** (string) - Optional - Carrier type (e.g., '3J0002' for mobile). - **CarrierId1** (string) - Optional - Carrier ID 1 (used with CarrierType). - **CarrierId2** (string) - Optional - Carrier ID 2 (used with CarrierType). - **NPOBAN** (string) - Optional - Charity organization code (for donations). ### Request Example ```json { "OrderId": "1001", "BuyerIdentifier": "0000000000", "BuyerName": "John Doe", "BuyerAddress": "123 Main St, Taipei", "BuyerPhoneNumber": "0912345678", "BuyerEmailAddress": "customer@example.com", "ProductItem": [ { "Description": "Product Name", "Quantity": 2, "UnitPrice": 150, "Amount": 300, "Remark": "", "TaxType": "1" } ], "SalesAmount": 300, "FreeTaxSalesAmount": 0, "ZeroTaxSalesAmount": 0, "TaxType": "1", "TaxRate": "0.05", "TaxAmount": "0", "TotalAmount": 300 } ``` ### Response #### Success Response (200) - **status** (boolean) - Indicates if the invoice submission was successful. - **message** (string) - A message providing details about the response. #### Response Example ```json { "status": true, "message": "Invoice sent successfully." } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.