### Java Example for Creating an Order Source: https://developer.viva.com/apis-for-payments/payment-api Shows a Java implementation for creating a payment order using the `HttpURLConnection` class. This example sends a POST request with the order payload. ```java import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; public class CreateOrder { public static void main(String[] args) { try { URL url = new URL("https://demo-api.vivapayments.com/resellers/v1/orders"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setDoOutput(true); String payload = "{\"amount\": 10.50, \"email\": \"customer@example.com\", \"phone\": \"+306912345678\", \"fullName\": \"Customer Name\", \"countryCode\": \"GR\", \"requestLang\": \"en-GR\", \"currencyCode\": \"978\", \"merchantTrns\": \"M12345\", \"customerTrns\": \"Order Description\"}"; try (OutputStream os = connection.getOutputStream()) { byte[] input = payload.getBytes(StandardCharsets.UTF_8); os.write(input, 0, input.length); } int responseCode = connection.getResponseCode(); System.out.println("Response Code: " + responseCode); // Read response // ... (implementation for reading response body) } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### cURL Example for Creating an Order Source: https://developer.viva.com/apis-for-payments/payment-api Demonstrates how to create an order using cURL. This example shows a POST request to the sandbox environment with a JSON payload. ```bash curl -X POST https://demo-api.vivapayments.com/resellers/v1/orders \ -H "Content-Type: application/json" \ -d '{ "amount": 10.50, "email": "customer@example.com", "phone": "+306912345678", "fullName": "Customer Name", "countryCode": "GR", "requestLang": "en-GR", "currencyCode": "978", "merchantTrns": "M12345", "customerTrns": "Order Description" }' ``` -------------------------------- ### Create Order Response Example (200 OK) Source: https://developer.viva.com/apis-for-payments/payment-api Example JSON response for a successful order creation (HTTP 200 OK). It includes order details and potential error codes if any. ```json { "OrderCode": 0, "ErrorCode": 0, "ErrorText": "string", "TimeStamp": "2026-01-20T20:24:55Z", "CorrelationId": "string", "EventId": 0, "Success": true } ``` -------------------------------- ### cURL Example for Linking a Bank Account Source: https://developer.viva.com/apis-for-payments/payment-api Demonstrates linking a bank account using cURL. This example sends a POST request to the sandbox environment with IBAN and optional details. ```bash curl -X POST https://demo.vivapayments.com/api/bankaccounts \ -H "Content-Type: application/json" \ -u "YOUR_API_KEY:YOUR_API_SECRET" \ -d '{ "iban": "GB74VPAY04136031593641", "friendlyName": "My UK Account", "beneficiaryName": "John Doe" }' ``` -------------------------------- ### Java Request Example for Cash Payments Source: https://developer.viva.com/apis-for-payments/payment-api Demonstrates how to initiate a cash payment request using Java. This example utilizes standard Java libraries for making HTTP requests. ```java import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; // ... inside a method ... String jsonInputString = "{\"phone\": \"string\", \"amount\": null, \"orderCode\": null, \"merchantId\": null, \"rfPaymentCode\": \"string\", \"countryCode\": \"string\", \"oneTimePassword\": \"string\", \"resellerSourceCode\": \"string\", \"tags\": null}"; URL url = new URL("https://api.vivapayments.com/resellers/v1/transactions/cashPayments"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/json"); con.setDoOutput(true); try(OutputStream os = con.getOutputStream()) { byte[] input = jsonInputString.getBytes("UTF-8"); os.write(input, 0, input.length); } int responseCode = con.getResponseCode(); System.out.println(responseCode); // ... read response ... ``` -------------------------------- ### Java Example for Linking a Bank Account Source: https://developer.viva.com/apis-for-payments/payment-api Provides a Java implementation for linking a bank account using `HttpURLConnection`. This example sends a POST request with the bank account details and Basic Authentication. ```java import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.Base64; public class LinkBankAccount { public static void main(String[] args) { try { URL url = new URL("https://demo.vivapayments.com/api/bankaccounts"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setDoOutput(true); String apiKey = "YOUR_API_KEY"; String apiSecret = "YOUR_API_SECRET"; String auth = "Basic " + Base64.getEncoder().encodeToString((apiKey + ":" + apiSecret).getBytes(StandardCharsets.UTF_8)); connection.setRequestProperty("Authorization", auth); String payload = "{\"iban\": \"GB74VPAY04136031593641\", \"friendlyName\": \"My UK Account\", \"beneficiaryName\": \"John Doe\"}"; try (OutputStream os = connection.getOutputStream()) { byte[] input = payload.getBytes(StandardCharsets.UTF_8); os.write(input, 0, input.length); } int responseCode = connection.getResponseCode(); System.out.println("Response Code: " + responseCode); // Read response // ... (implementation for reading response body) } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### Node.js Example for Creating an Order Source: https://developer.viva.com/apis-for-payments/payment-api Illustrates how to create an order using Node.js. This example uses the built-in 'https' module to make a POST request to the VIVA Payments API. ```javascript const https = require('https'); const orderData = JSON.stringify({ amount: 10.50, email: 'customer@example.com', phone: '+306912345678', fullName: 'Customer Name', countryCode: 'GR', requestLang: 'en-GR', currencyCode: '978', merchantTrns: 'M12345', customerTrns: 'Order Description' }); const options = { hostname: 'demo-api.vivapayments.com', port: 443, path: '/resellers/v1/orders', method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(orderData) } }; const req = https.request(options, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { console.log(JSON.parse(data)); }); }); req.on('error', (error) => { console.error(error); }); req.write(orderData); req.end(); ``` -------------------------------- ### Node.js Example for Linking a Bank Account Source: https://developer.viva.com/apis-for-payments/payment-api Shows a Node.js example for linking a bank account. This script uses the 'https' module to send a POST request with bank account details. ```javascript const https = require('https'); const auth = 'Basic ' + Buffer.from('YOUR_API_KEY:YOUR_API_SECRET').toString('base64'); const bankAccountData = JSON.stringify({ iban: 'GB74VPAY04136031593641', friendlyName: 'My UK Account', beneficiaryName: 'John Doe' }); const options = { hostname: 'demo.vivapayments.com', port: 443, path: '/api/bankaccounts', method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': auth, 'Content-Length': Buffer.byteLength(bankAccountData) } }; const req = https.request(options, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { console.log(JSON.parse(data)); }); }); req.on('error', (error) => { console.error(error); }); req.write(bankAccountData); req.end(); ``` -------------------------------- ### Retrieve Connected Account Information (Node.js) Source: https://developer.viva.com/apis-for-payments/payment-api Provides a Node.js example for fetching connected account details. It uses the 'axios' library to make the GET request, including the necessary OAuth2 authorization header. ```Node.js const axios = require('axios'); const accountId = 'YOUR_ACCOUNT_ID'; const token = 'YOUR_OAUTH2_TOKEN'; const apiUrl = `https://demo-api.vivapayments.com/platforms/v1/accounts/${accountId}`; axios.get(apiUrl, { headers: { 'Authorization': `Bearer ${token}`, 'Accept': 'application/json' } }) .then(response => { console.log(response.data); }) .catch(error => { console.error('Error fetching account info:', error.response ? error.response.data : error.message); }); ``` -------------------------------- ### Node.js Request Example for Cash Payments Source: https://developer.viva.com/apis-for-payments/payment-api Provides a Node.js example for making a cash payment request. It shows how to construct the request body and send it to the Viva Payments API. ```javascript const https = require('https'); const data = JSON.stringify({ phone: 'string', amount: null, orderCode: null, merchantId: null, rfPaymentCode: 'string', countryCode: 'string', oneTimePassword: 'string', resellerSourceCode: 'string', tags: null }); const options = { hostname: 'api.vivapayments.com', port: 443, path: '/resellers/v1/transactions/cashPayments', method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': data.length } }; const req = https.request(options, (res) => { let responseBody = ''; res.on('data', (chunk) => { responseBody += chunk; }); res.on('end', () => { console.log(JSON.parse(responseBody)); }); }); req.on('error', (error) => { console.error(error); }); req.write(data); req.end(); ``` -------------------------------- ### Retrieve Transactions by Query Parameters (GET Request) Source: https://developer.viva.com/apis-for-payments/payment-api Examples of retrieving transactions using various query parameters like date, clearance date, order code, or source code. These allow for flexible filtering of transaction data. ```http GET /api/transactions/?date=2018-08-27 GET /api/transactions/?clearancedate=2018-08-27 GET /api/transactions/?ordercode=175936509216 GET /api/transactions/?sourceCode=Default&date=2018-08-27 ``` -------------------------------- ### Create Order Payload Example Source: https://developer.viva.com/apis-for-payments/payment-api Example JSON payload for creating a new order. This includes customer details, transaction information, and payment-related settings. Ensure all required fields are populated correctly. ```json { "amount": 200, "email": "customer@example.com", "fullName": "Customer full name", "customerTrns": "Short description of items/services purchased to display to your customer", "phone": "7967813180", "requestLang": "en-GB", "sourceCode": "3891", "disableExactAmount": "false", "disableCash": "false", "disableWallet": "false", "allowRecurring": "false", "isPreAuth": "false", "maxInstallments": 1, "tipAmount": 0, "paymentTimeout": 1800, "expirationDate": "2021-12-01T08:00:00+00:00", "serviceId": 0, "merchantTrns": "Short description of items/services purchased by customer", "isCardVerification": false, "tags": [ "sample string 1", "sample string 2", "sample string 3" ] } ``` -------------------------------- ### Java Request Example for Bill Payments Source: https://developer.viva.com/apis-for-payments/payment-api Illustrates how to make a bill payment request using Java. This example uses standard Java libraries to construct and send the HTTP request. ```java import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; // ... inside a method ... String jsonInputString = "{\"vat\": \"string\", \"amount\": null, \"phone\": \"string\", \"date\": null, \"lastName\": \"string\", \"orderCode\": null, \"firstName\": \"string\", \"tags\": null, \"countryCode\": \"string\", \"merchantTrns\": \"string\", \"oneTimePassword\": \"string\", \"billId\": 0, \"resellerSourceCode\": \"string\"}"; URL url = new URL("https://api.vivapayments.com/resellers/v1/transactions/billPayments"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Content-Type", "application/json"); con.setDoOutput(true); try(OutputStream os = con.getOutputStream()) { byte[] input = jsonInputString.getBytes("UTF-8"); os.write(input, 0, input.length); } int responseCode = con.getResponseCode(); System.out.println(responseCode); // ... read response ... ``` -------------------------------- ### Node.js Request Example for Bill Payments Source: https://developer.viva.com/apis-for-payments/payment-api Provides a Node.js example for making a bill payment request. It shows how to format the request payload and send it to the relevant API endpoint. ```javascript const https = require('https'); const data = JSON.stringify({ vat: 'string', amount: null, phone: 'string', date: null, lastName: 'string', orderCode: null, firstName: 'string', tags: null, countryCode: 'string', merchantTrns: 'string', oneTimePassword: 'string', billId: 0, resellerSourceCode: 'string' }); const options = { hostname: 'api.vivapayments.com', port: 443, path: '/resellers/v1/transactions/billPayments', method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': data.length } }; const req = https.request(options, (res) => { let responseBody = ''; res.on('data', (chunk) => { responseBody += chunk; }); res.on('end', () => { console.log(JSON.parse(responseBody)); }); }); req.on('error', (error) => { console.error(error); }); req.write(data); req.end(); ``` -------------------------------- ### Retrieve Transactions by ID (GET Request) Source: https://developer.viva.com/apis-for-payments/payment-api Example of retrieving transaction details using a unique transaction ID. This endpoint requires the transaction ID as a path parameter. ```http GET /api/transactions/b1a3067c-321b-4ec6-bc9d-1778aef2a19d ``` -------------------------------- ### Example Payment Method Fees Configuration (Pay on Delivery) Source: https://developer.viva.com/apis-for-payments/payment-api Demonstrates how to configure additional service fees for specific payment methods, such as 'Pay on Delivery'. The fee is specified in the smallest currency unit. ```json { "paymentMethodFees": [ { "paymentMethodId": "35", "fee": 250 } ] } ``` -------------------------------- ### Retrieve Order - cURL Request Source: https://developer.viva.com/apis-for-payments/payment-api Example cURL command to retrieve information about a specific order using its order code. This demonstrates a GET request with Basic Authentication. ```bash curl --location -g 'https://demo.vivapayments.com/api/orders/{orderCode}?orderCode=null' \ --header 'Authorization: Basic TWVyY2hhbnRfSUQ6QVBJX0tleQ==' ``` -------------------------------- ### List Webhook Subscriptions (cURL) Source: https://developer.viva.com/apis-for-payments/payment-api Retrieves a list of all configured webhook subscriptions. This cURL example shows how to make a GET request to the subscriptions endpoint, requiring an Authorization header with a Bearer token. ```curl curl --location 'https://api.vivapayments.com/dataservices/v1/webhooks/subscriptions' \ --header 'Authorization: Bearer {Bearer_Token}' ``` -------------------------------- ### Retrieve Order - Node.js Request Source: https://developer.viva.com/apis-for-payments/payment-api Node.js code snippet for retrieving order details. This example uses the 'https' module to perform a GET request, passing the order code and authentication headers. ```javascript const https = require('https'); const orderCode = 'YOUR_ORDER_CODE'; // Replace with the actual order code const options = { hostname: 'demo.vivapayments.com', port: 443, path: `/api/orders/${orderCode}?orderCode=${orderCode}`, method: 'GET', headers: { 'Authorization': 'Basic TWVyY2hhbnRfSUQ6QVBJX0tleQ==' } }; const req = https.request(options, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { console.log(JSON.parse(data)); }); }); req.on('error', (e) => { console.error(`Error: ${e.message}`); }); req.end(); ``` -------------------------------- ### Retrieve Order - Java Request Source: https://developer.viva.com/apis-for-payments/payment-api Java code snippet for retrieving order details. This example uses Apache HttpClient to send a GET request to the API endpoint, including the order code and authentication. ```java import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; public class RetrieveOrder { public static void main(String[] args) throws Exception { String orderCode = "YOUR_ORDER_CODE"; // Replace with the actual order code String url = String.format("https://demo.vivapayments.com/api/orders/%s?orderCode=%s", orderCode, orderCode); HttpGet request = new HttpGet(url); request.setHeader("Authorization", "Basic TWVyY2hhbnRfSUQ6QVBJX0tleQ=="); try (CloseableHttpClient client = HttpClients.createDefault()) { org.apache.http.client.methods.CloseableHttpResponse response = client.execute(request); System.out.println(EntityUtils.toString(response.getEntity())); } } } ``` -------------------------------- ### Get Transaction Details using Node.js Source: https://developer.viva.com/apis-for-payments/payment-api This Node.js example demonstrates fetching transaction details via the Viva Payments API using the 'axios' library. It constructs the request URL and includes the Basic Authorization header. The function returns the transaction data as a JSON object. ```javascript const axios = require('axios'); async function getTransactionDetails(transactionId) { const merchantId = 'YOUR_MERCHANT_ID'; // Replace with your Merchant ID const apiKey = 'YOUR_API_KEY'; // Replace with your API Key const url = `https://demo.vivapayments.com/api/transactions/${transactionId}`; const authorization = Buffer.from(`${merchantId}:${apiKey}`).toString('base64'); try { const response = await axios.get(url, { headers: { 'Authorization': `Basic ${authorization}` } }); return response.data; } catch (error) { console.error('Error fetching transaction details:', error.response ? error.response.data : error.message); throw error; } } // Example usage: // getTransactionDetails('your_transaction_id') // .then(data => console.log(data)) // .catch(err => console.error(err)); ``` -------------------------------- ### Create Connected Account Response Sample Source: https://developer.viva.com/apis-for-payments/payment-api This JSON response is received after successfully creating a connected account. It includes the unique 'accountId' generated for the seller and an 'invitation' object containing the seller's email and the redirect URL for initiating the onboarding process. ```json { "accountId": "fa176a3b-a7e8-4f3d-abe6-5e65626f5994", "invitation": { "email": "user@example.com", "redirectUrl": "https://example.com/onboardingflow", "created": "2026-01-20T20:24:54.936Z" } } ``` -------------------------------- ### Create Connected Account - cURL Request Sample Source: https://developer.viva.com/apis-for-payments/payment-api This cURL command demonstrates how to create a connected account for a marketplace seller. It includes essential details like the seller's email, return URL, branding information, and optional payout configurations. This sample is useful for testing API integration from the command line. ```bash curl -X POST \ https://api.vivapayments.com/platforms/v1/accounts \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \ -d '{ "email": "user@example.com", "mobile": 6948740000, "legalName": "Consulting Detective", "tradeName": "Sherlock Holmes", "taxNumber": null, "returnUrl": "https://example.com/connected", "address": { "street": "Baker Street", "number": "221B", "city": "London", "postCode": "NW1", "countryCode": "GB", "secondLine": null }, "branding": { "partnerName": "Header/title summary", "primaryColor": null, "logoUrl": "https://example.com/company-logo" }, "payouts": { "statementDescriptor": "Weekly payouts", "dayOfWeek": 1, "dayOfMonth": null, "interval": 2, "amountThreshold": 1000, "disable": false, "bankAccount": { "iban": "NL04RABO6360804956", "friendlyName": "External account", "beneficiaryName": "Sherlock Holmes", "branchCode": null, "accountNumber": null, "countryCode": null } } }' ``` -------------------------------- ### Create Bank Transfer Fee Command (cURL) Source: https://developer.viva.com/apis-for-payments/payment-api This cURL example shows how to create a bank transfer fee command. It requires the bank account ID, amount, wallet ID, and instruction type. Optionally, it can specify if the transfer should be instant. The response includes the calculated fee and a bank command ID. ```bash curl --location 'https://demo-api.vivapayments.com/banktransfers/v1/bankaccounts/{bankAccountId}/fees' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer {Bearer_Token}' \ --data '{ "amount": 0, "walletId": 0, "isInstant": false, "instructionType": 1 }' ``` -------------------------------- ### Response Sample for Seller Account Details (JSON) Source: https://developer.viva.com/apis-for-payments/payment-api This JSON represents a sample response containing details of a seller's account, including IBAN, wallet ID, primary status, available balance, overdraft, and friendly name. ```json { "Iban": "GB73VPAY04002491883585", "WalletId": 91883585, "IsPrimary": true, "Amount": 2.16, "Available": -0.29, "Overdraft": 0, "FriendlyName": "Primary Account", "CurrencyCode": 826 } ``` -------------------------------- ### cURL Request Sample for Creating Orders Source: https://developer.viva.com/apis-for-payments/payment-api A cURL command example for creating an order. This shows the HTTP method, endpoint, headers, and JSON payload required for the request. ```bash # cURL command example for creating orders would go here. # This is a placeholder as the actual code was not provided in the input. ``` -------------------------------- ### Retrieve Connected Account Information (Java) Source: https://developer.viva.com/apis-for-payments/payment-api Java example for retrieving connected account details using the Apache HttpClient library. It demonstrates setting up the request, headers, and handling the response. ```Java import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; public class GetAccountInfo { public static void main(String[] args) { String accountId = "YOUR_ACCOUNT_ID"; String token = "YOUR_OAUTH2_TOKEN"; String apiUrl = String.format("https://demo-api.vivapayments.com/platforms/v1/accounts/%s", accountId); try (CloseableHttpClient httpClient = HttpClients.createDefault()) { HttpGet request = new HttpGet(apiUrl); request.addHeader("Authorization", "Bearer " + token); request.addHeader("Accept", "application/json"); try (CloseableHttpResponse response = httpClient.execute(request)) { System.out.println("Status Code: " + response.getStatusLine().getStatusCode()); String responseBody = EntityUtils.toString(response.getEntity()); System.out.println(responseBody); } } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### cURL Example for Transaction Export Source: https://developer.viva.com/apis-for-payments/payment-api Demonstrates how to initiate a transaction export using cURL. This command sends a POST request with the specified payload to the export endpoint. ```bash curl -X POST \ https://api.vivapayments.com/dataservices/v1/transactions/exports \ -H 'Content-Type: application/json' \ -d '{ "Id": "dac40e4b-0369-407e-b52b-a2172f408ffa", "Date": "2021-10-20", "FileType": "csv" }' ``` -------------------------------- ### Java Request Sample for Creating Orders Source: https://developer.viva.com/apis-for-payments/payment-api A Java code example for interacting with the Viva Payments API to create orders. This might involve using Java's built-in HTTP client or libraries like Apache HttpClient. ```java // Java code sample for creating orders would go here. // This is a placeholder as the actual code was not provided in the input. ``` -------------------------------- ### Checkout Order Request Sample (Java) Source: https://developer.viva.com/apis-for-payments/payment-api Java code example demonstrating how to make a POST request to the Viva Payments checkout orders API using Apache HttpClient. This includes setting up the request entity and headers. ```java import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; public class VivaPaymentsCheckout { public static void main(String[] args) throws Exception { CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost request = new HttpPost("https://demo-api.vivapayments.com/checkout/v2/orders/"); String jsonPayload = "{\"amount\": 1000, \"currencyCode\": \"EUR\", \"customer\": {\"email\": \"test@example.com\", \"phone\": \"1234567890\", \"fullName\": \"John Doe\"}, \"transfer\": {\"amount\": 1000, \"platformFee\": 10, \"connectedAccountId\": \"ac03972a-5ca5-43c5-b96f-c519ac843b7a\"}}"; StringEntity entity = new StringEntity(jsonPayload); request.setEntity(entity); request.setHeader("Content-Type", "application/json"); request.setHeader("Authorization", "Bearer YOUR_API_TOKEN"); try (CloseableHttpResponse response = httpClient.execute(request)) { System.out.println("Status code: " + response.getStatusLine().getStatusCode()); String responseBody = EntityUtils.toString(response.getEntity()); System.out.println("Response body: " + responseBody); } finally { httpClient.close(); } } } ``` -------------------------------- ### Get Transaction Details using PHP Source: https://developer.viva.com/apis-for-payments/payment-api This PHP code snippet shows how to fetch transaction details from the Viva Payments API. It utilizes cURL to make the GET request and includes the necessary Authorization header. The output is the JSON response from the API. ```php ``` -------------------------------- ### Get Transaction Details using Java Source: https://developer.viva.com/apis-for-payments/payment-api This Java code snippet illustrates how to retrieve transaction details using the Apache HttpClient library. It sets up the request with the necessary Authorization header and sends a GET request to the Viva Payments API. The response is parsed as a String. ```java import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import java.util.Base64; public class VivaPaymentsApiClient { private static final String BASE_URL = "https://demo.vivapayments.com/api/transactions/"; private String merchantId; private String apiKey; public VivaPaymentsApiClient(String merchantId, String apiKey) { this.merchantId = merchantId; this.apiKey = apiKey; } public String getTransactionDetails(String transactionId) throws Exception { String url = BASE_URL + transactionId; String auth = merchantId + ":" + apiKey; byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes(java.nio.charset.StandardCharsets.UTF_8)); String authHeaderValue = "Basic " + new String(encodedAuth); try (CloseableHttpClient client = HttpClients.createDefault()) { HttpGet request = new HttpGet(url); request.setHeader("Authorization", authHeaderValue); try (CloseableHttpResponse response = client.execute(request)) { if (response.getStatusLine().getStatusCode() == 200) { return EntityUtils.toString(response.getEntity()); } else { throw new Exception("API request failed with status code: " + response.getStatusLine().getStatusCode()); } } } } public static void main(String[] args) { // Example Usage: // String merchantId = "YOUR_MERCHANT_ID"; // String apiKey = "YOUR_API_KEY"; // String transactionId = "your_transaction_id"; // VivaPaymentsApiClient client = new VivaPaymentsApiClient(merchantId, apiKey); // try { // String transactionData = client.getTransactionDetails(transactionId); // System.out.println(transactionData); // } catch (Exception e) { // e.printStackTrace(); // } } } ``` -------------------------------- ### Java Example for Transaction Export Source: https://developer.viva.com/apis-for-payments/payment-api Demonstrates exporting transactions in Java using `HttpURLConnection`. This code snippet shows how to set up the request, send the JSON payload, and read the response. ```java import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; public class TransactionExport { public static void main(String[] args) { try { URL url = new URL("https://api.vivapayments.com/dataservices/v1/transactions/exports"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setDoOutput(true); String jsonPayload = "{\"Id\": \"dac40e4b-0369-407e-b52b-a2172f408ffa\", \"Date\": \"2021-10-20\", \"FileType\": \"csv\"}"; try (OutputStream os = connection.getOutputStream()) { byte[] input = jsonPayload.getBytes(StandardCharsets.UTF_8); os.write(input, 0, input.length); } int responseCode = connection.getResponseCode(); System.out.println("POST Response Code: " + responseCode); // Read response (optional) // ... } catch (Exception e) { e.printStackTrace(); } } } ``` -------------------------------- ### PHP Request Example for Cash Payments Source: https://developer.viva.com/apis-for-payments/payment-api Illustrates how to perform a cash payment request using PHP. This involves setting up the request payload and making a POST request to the API. ```php "string", "amount" => null, "orderCode" => null, "merchantId" => null, "rfPaymentCode" => "string", "countryCode" => "string", "oneTimePassword" => "string", "resellerSourceCode" => "string", "tags" => null ]; $options = [ 'http' => [ 'header' => "Content-type: application/json\r\n", 'method' => 'POST', 'content' => json_encode($data), ], ]; $context = stream_context_create($options); $result = file_get_contents('https://api.vivapayments.com/resellers/v1/transactions/cashPayments', false, $context); if ($result === FALSE) { /* Handle error */ } else { var_dump($result); } ?> ``` -------------------------------- ### Retrieve Account Transaction Details (GET Request) Source: https://developer.viva.com/apis-for-payments/account-api This snippet demonstrates how to retrieve details for a specific account transaction using a GET request. It requires the `AccountTransactionId` as a URI parameter and an `Authorization` header. The `PersonId` header is also required for access tokens. ```http GET /dataservices/v1/accounttransactions/91c94191-c4eb-44a6-a3f8-b07b7937921d HTTP/1.1 Host: api.viva.com Authorization: Bearer PersonId: 04a61c54-f26b-4026-b781-26f4684bbfec ``` -------------------------------- ### Retrieve Wallets using cURL Source: https://developer.viva.com/apis-for-payments/payment-api This cURL command demonstrates how to retrieve wallet information from the Viva Payments API. It uses a GET request and includes both Authorization and Content-Type headers. The request body contains sample wallet details, though for a GET request, the body is typically not used for filtering. ```curl curl --location --request GET 'https://demo.vivapayments.com/api/wallets' \ --header 'Authorization: Basic e01lcmNoYW50X0lEfTp7QVBJX0tleX0=' \ --header 'Content-Type: application/json' \ --data '{ "Iban": "GB73VPAY04002491881234", "WalletId": 91883585, "IsPrimary": true, "Amount": 2.16, "Available": -0.29, "Overdraft": 0, "FriendlyName": "Primary Account", "CurrencyCode": 826 }' ```