Created
October 24, 2023 08:38
-
-
Save rizkytegar/a8ad589453d6864fa9c250209087eeb8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
public class MidtransStatusFetcher { | |
public static void main(String[] args) { | |
try { | |
// URL transaksi yang ingin Anda cek statusnya | |
String transactionUrl = "https://api.sandbox.midtrans.com/v2/[ORDERID]/status"; | |
URL url = new URL(transactionUrl); | |
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | |
connection.setRequestMethod("GET"); | |
// Tambahkan header otorisasi sesuai kebutuhan | |
connection.setRequestProperty("Authorization", "Basic BASE64ENCODE"); | |
int responseCode = connection.getResponseCode(); | |
if (responseCode == HttpURLConnection.HTTP_OK) { | |
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); | |
String inputLine; | |
StringBuilder response = new StringBuilder(); | |
while ((inputLine = in.readLine()) != null) { | |
response.append(inputLine); | |
} | |
in.close(); | |
// Hasil respons dari Midtrans API | |
String responseText = response.toString(); | |
System.out.println("Response: " + responseText); | |
} else { | |
System.out.println("Gagal mengambil status transaksi. Kode respons: " + responseCode); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
contoh response