All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.midtrans.httpclient.TransactionApi Maven / Gradle / Ivy

Go to download

This is the Official Java API client/library for Midtrans Payment API. Visit https://midtrans.com. More information about the product and see documentation at http://docs.midtrans.com for more technical details. This library used java version 1.8

There is a newer version: 3.2.0
Show newest version
package com.midtrans.httpclient;

import com.midtrans.Config;
import com.midtrans.httpclient.error.MidtransError;
import org.json.JSONObject;

import java.util.Map;

import static com.midtrans.httpclient.CoreApi.API_VERSION2;


public class TransactionApi {

    public static JSONObject checkTransaction(String param, Config configOptions) throws MidtransError {
        return new JSONObject((String) APIHttpClient.request(
                APIHttpClient.GET, configOptions.getCoreApiURL() + API_VERSION2 + "/" + param + "/status",
                configOptions,
                null
        ));
    }

    public static JSONObject checkTransaction(String param) throws MidtransError {
        return checkTransaction(param, Config.getGlobalConfig());
    }

    public static JSONObject approveTransaction(String param, Config configOptions) throws MidtransError {
        return new JSONObject((String) APIHttpClient.request(
                APIHttpClient.POST, configOptions.getCoreApiURL() + API_VERSION2 + "/" + param + "/approve",
                configOptions,
                null
        ));
    }

    public static JSONObject approveTransaction(String param) throws MidtransError {
        return approveTransaction(param, Config.getGlobalConfig());
    }

    public static JSONObject denyTransaction(String param, Config configOptions) throws MidtransError {
        return new JSONObject((String) APIHttpClient.request(
                APIHttpClient.POST,
                configOptions.getCoreApiURL() + API_VERSION2 + "/" + param + "/deny",
                configOptions,
                null
        ));
    }

    public static JSONObject denyTransaction(String param) throws MidtransError {
        return denyTransaction(param, Config.getGlobalConfig());
    }

    public static JSONObject cancelTransaction(String param) throws MidtransError {
        return cancelTransaction(param, Config.getGlobalConfig());
    }

    public static JSONObject cancelTransaction(String param, Config configOptions) throws MidtransError {
        return new JSONObject((String) APIHttpClient.request(
                APIHttpClient.POST,
                configOptions.getCoreApiURL() + API_VERSION2 + "/" + param + "/cancel",
                configOptions,
                null
        ));
    }

    public static JSONObject expireTransaction(String param, Config configOptions) throws MidtransError {
        return new JSONObject((String) APIHttpClient.request(
                APIHttpClient.POST,
                configOptions.getCoreApiURL() + API_VERSION2 + "/" + param + "/expire",
                configOptions,
                null
        ));
    }

    public static JSONObject expireTransaction(String param) throws MidtransError {
        return expireTransaction(param, Config.getGlobalConfig());
    }

    public static JSONObject refundTransaction(String param, Map requestBody, Config configOptions) throws MidtransError {
        return new JSONObject((String) APIHttpClient.request(
                APIHttpClient.POST, configOptions.getCoreApiURL() + API_VERSION2 + "/" + param + "/refund",
                configOptions,
                requestBody
        ));
    }

    public static JSONObject refundTransaction(String param, Map requestBody) throws MidtransError {
        return refundTransaction(param, requestBody, Config.getGlobalConfig());
    }

    public static JSONObject directRefundTransaction(String param, Map requestBody, Config configOptions) throws MidtransError {
        return new JSONObject((String) APIHttpClient.request(
                APIHttpClient.POST,
                configOptions.getCoreApiURL() + API_VERSION2 + "/" + param + "/refund/online/direct",
                configOptions,
                requestBody
        ));
    }

    public static JSONObject directRefundTransaction(String param, Map requestBody) throws MidtransError {
        return directRefundTransaction(param, requestBody, Config.getGlobalConfig());
    }

    public static JSONObject captureTransaction(Map requestBody, Config configOptions) throws MidtransError {
        return new JSONObject((String) APIHttpClient.request(
                APIHttpClient.POST,
                configOptions.getCoreApiURL() + API_VERSION2 + "/" + "capture",
                configOptions,
                requestBody
        ));
    }

    public static JSONObject captureTransaction(Map requestBody) throws MidtransError {
        return captureTransaction(requestBody, Config.getGlobalConfig());
    }

    public static JSONObject getStatusB2b(String param, Config configOptions) throws MidtransError {
        return new JSONObject((String) APIHttpClient.request(
                APIHttpClient.GET,
                configOptions.getCoreApiURL() + API_VERSION2 + "/" + param + "/status/b2b",
                configOptions,
                null
        ));
    }

    public static JSONObject getStatusB2b(String param) throws MidtransError {
        return getStatusB2b(param, Config.getGlobalConfig());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy