API Reference

If you want to handle the withdrawal for the customer you call the approval API. This will initiate the transaction from the customer to your SPENN business account. After the approval is called it’s important to check the status of the transaction with the status API in the next section. It can take some seconds for the transaction to be verified. It’s important to not give the customer any money until the transaction is verified.

Description

Headers

  • Content-Type: The Content-Type header is set to application/json, indicating that the request body contains JSON data.
  • Authorization: The Authorization header is used with a bearer token for authentication. The actual token value should replace the placeholder Bearer eyJhbG...NrEQ41w.

Sample Response

import requests

def approve_withdrawal(withdraw_request_guid, token):
    # Endpoint URL
    url = "https://uat-businessapi.spenn.com/api/partner/transaction/withdraw/approval"

    # Headers with Content-Type and Authorization token
    headers = {
        'Content-Type': 'application/json',
        'Authorization': f'Bearer {token}'
    }

    # JSON body data
    data = {
        'withdrawRequestGuid': withdraw_request_guid
    }

    # Sending the POST request
    try:
        response = requests.post(url, headers=headers, json=data)
        # Return the response data (or handle it as needed)
        return response.json()
    except requests.RequestException as e:
        print(f"Error: {e}")

# Example usage
withdraw_request_guid = '3fa85f64-5717-4562-b3fc-2c963f66afa6'  # Replace with the actual withdraw request GUID
token = 'eyJhbG...NrEQ41w'  # Replace with your actual bearer token
approval_response = approve_withdrawal(withdraw_request_guid, token)
print(approval_response)

import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class WithdrawalApproval {

    public static void main(String[] args) {
        String withdrawRequestGuid = "3fa85f64-5717-4562-b3fc-2c963f66afa6"; // Replace with the actual withdraw request GUID
        String token = "eyJhbG...NrEQ41w"; // Replace with your actual bearer token
        String response = approveWithdrawal(withdrawRequestGuid, token);
        System.out.println(response);
    }

    private static String approveWithdrawal(String withdrawRequestGuid, String token) {
        try {
            // Endpoint URL
            URL url = new URL("https://uat-businessapi.spenn.com/api/partner/transaction/withdraw/approval");

            // Open a connection
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();

            // Set the request method and headers
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json; utf-8");
            connection.setRequestProperty("Authorization", "Bearer " + token);
            connection.setDoOutput(true);

            // JSON body data
            String jsonInputString = "{\"withdrawRequestGuid\": \"" + withdrawRequestGuid + "\"}";

            // Sending the request
            try (OutputStream os = connection.getOutputStream()) {
                byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
                os.write(input, 0, input.length);
            }

            // Reading the response
            StringBuilder response = new StringBuilder();
            try (java.io.BufferedReader br = new java.io.BufferedReader(
                    new java.io.InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
                String responseLine;
                while ((responseLine = br.readLine()) != null) {
                    response.append(responseLine.trim());
                }
            }

            // Disconnecting the connection
            connection.disconnect();

            // Return the response content
            return response.toString();

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

async function approveWithdrawal(withdrawRequestGuid, token) {
    // Endpoint URL
    const url = 'https://uat-businessapi.spenn.com/api/partner/transaction/withdraw/approval';

    // Setting up the request headers
    const headers = {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${token}`
    };

    // JSON body data
    const data = {
        'withdrawRequestGuid': withdrawRequestGuid
    };

    try {
        // Sending the POST request
        const response = await fetch(url, {
            method: 'POST',
            headers: headers,
            body: JSON.stringify(data) // Convert the JavaScript object to a JSON string
        });

        // Parsing the JSON response
        const responseData = await response.json();
        return responseData;
    } catch (error) {
        console.error('Error:', error);
    }
}

// Example usage
const withdrawRequestGuid = '3fa85f64-5717-4562-b3fc-2c963f66afa6'; // Replace with the actual withdraw request GUID
const token = 'eyJhbG...NrEQ41w'; // Replace with your actual bearer token

approveWithdrawal(withdrawRequestGuid, token)
    .then(responseData => console.log(responseData))
    .catch(error => console.error('Error in withdrawal approval:', error));

👍

Sample Response

{
    "$id": "1",
    "amount": 4.0,
    "partnerCustomerGuid": "b584e88d-16f9-4c8f-90b8-084d7d373bdc",
    "transactionGuid": "67735a6f-c7ac-4014-9d7d-d6953ea4bdb1",
    "transactionMessage": "Ref# 8tj8fp",
    "withdrawRequestGuid": "88479fac-a156-4055-90f9-97bac13661d2",
    "withdrawingCustomerGuid": "7587cdad-4cda-417d-af59-9c9ef165d3ff"
}