import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
public class Main {
public static void main(String... args) throws IOException {
String email = "YOUR_EMAIL_HERE";
String token = "YOUR_TOKEN_HERE";
String projectCode = "YOUR_PROJECT_CODE_HERE";
long amount = 1000L; //minimum 10 rub!
JSONObject request = new JSONObject();
request.put("projectCode", projectCode);
request.put("description", "its easy, man!");
JSONObject amountObject = new JSONObject();
amountObject.put("amount", amount);
amountObject.put("currency", "RUB");
request.put("amount", amountObject);
URL url = new URL("https://api.capusta.space/v1/partner/payment"); // payment url
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestProperty("Authorization", "Bearer " + email + ":" + token);
try(OutputStream os = con.getOutputStream()) {
byte[] input = request.toString().getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
try(BufferedReader br = new BufferedReader(
new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) {
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println(response.toString());
}
con.disconnect();
}
}