If you do not want to handle the withdrawal for the customer after it has been validated, the withdrawal request needs to be rejected.

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 reject_withdrawal(withdraw_request_guid, token):
    # Endpoint URL
    url = "https://uat-businessapi.spenn.com/api/partner/transaction/withdraw/rejection"

    # 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
rejection_response = reject_withdrawal(withdraw_request_guid, token)
print(rejection_response)

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

public class WithdrawalRejection {

    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 = rejectWithdrawal(withdrawRequestGuid, token);
        System.out.println(response);
    }

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

            // 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 rejectWithdrawal(withdrawRequestGuid, token) {
    // Endpoint URL
    const url = 'https://uat-businessapi.spenn.com/api/partner/transaction/withdraw/rejection';

    // 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

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

👍

Sample Response

{
    "$id": "1",
    "withdrawRequestGuid": "5299a1aa-e604-40ef-9b14-e6ec23979091",
    "amount": 4.00,
    "fee": 0.50,
    "customerGuid": "7587cdad-4cda-417d-af59-9c9ef165d3ff", 
    "partnerCustomerGuid": "b584e88d-16f9-4c8f-90b8-084d7d373bdc", 
    "withdrawRequestShortCode": "ht9s85",
    "firstName": "SampleFirstName", 
    "middleName": "",
    "lastName": "SampleLastName",
    "phoneNumber": "+250783008884", 
    "withdrawRequestStatus": "InValidation", 
    "customerType": "string"
}