Sample code for 30+ languages & platforms
Java Requires Chilkat v11.7.0+

Stripe: Identify the payment for a paid invoice

See more Stripe Examples

List the payments allocated to an invoice and identify a paid charge or PaymentIntent for refund.

Stripe documentation and cURL example

Chilkat Java Downloads

Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.HttpCurl;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

    public static void main(String[] args) {
        boolean success = false;

        // Requires an unlocked Chilkat bundle. See Global Unlock Sample.
        // Supply a restricted sandbox key from merchant-controlled configuration.
        String apiKey = "YOUR_STRIPE_TEST_KEY";

        HttpCurl curl = new HttpCurl();
        StringBuilder cmd = new StringBuilder();
        JsonObject json = new JsonObject();

        int replaced = 0;

        String invoiceId = "in_FROM_BILLING_RECORD";

        StringBuilder pageSuffix = new StringBuilder();
        boolean more = true;
        String cursor = "";
        while (more) {
            // curl -X GET "https://api.stripe.com/v1/invoice_payments?invoice={invoiceId}&limit=100" \
            //   -u "$STRIPE_API_KEY:" \
            //   -H "Stripe-Version: 2026-10-28.endive"
            cmd.setString("curl -X GET \"https://api.stripe.com/v1/invoice_payments?invoice=@ID@&limit=100@CURSOR@\"");
            cmd.append(" -u \"@KEY@:\"");
            cmd.append(" -H \"Stripe-Version: 2026-10-28.endive\"");
            replaced = cmd.replace("@CURSOR@", pageSuffix.getAsString());
            replaced = cmd.replace("@ID@", invoiceId);
            replaced = cmd.replace("@KEY@", apiKey);
            try {
                curl.doYourThing(cmd.getAsString());
            } catch (ChilkatException e) {
                System.out.println("No HTTP response. Chilkat failure code: " + curl.getFailReason());
                return;
            }

            try {
                curl.getResponseJson(json);
                success = true;
            } catch (ChilkatException e) {
                success = false;
            }
            if ((curl.getStatusCode() != 200) || (!success)) {
                System.out.println("Stripe HTTP " + curl.getStatusCode() + "  Request-Id: " + curl.getResponseHeaderField("Request-Id"));
                if (success) {
                    System.out.println(json.stringOf("error.message"));
                }

                return;
            }

            int i = 0;
            int count = json.sizeOfArray("data");
            while (i < count) {
                json.setI(i);
                System.out.println(json.stringOf("data[i].id") + " | " + json.stringOf("data[i].status") + " | " + json.stringOf("data[i].amount_paid") + " | " + json.stringOf("data[i].currency") + " | " + json.stringOf("data[i].payment.type"));
                if ("payment_intent".equals(json.stringOf("data[i].payment.type"))) {
                    System.out.println("  PaymentIntent: " + json.stringOf("data[i].payment.payment_intent"));
                }

                if ("charge".equals(json.stringOf("data[i].payment.type"))) {
                    System.out.println("  Charge: " + json.stringOf("data[i].payment.charge"));
                }

                i = i + 1;
            }

            more = json.boolOf("has_more");
            if (more) {
                String next = json.stringOf("data[i].id");
                if ((count < 1) || (("".equals(next)) || (next.equals(cursor)))) {
                    System.out.println("Invalid pagination cursor.");
                    return;
                }

                cursor = next;
                pageSuffix.setString("&starting_after=");
                pageSuffix.append(cursor);
            }
        }

        // Select the paid allocation belonging to the order before issuing its refund.
    }
}