Package com.akraml.satim
Class SatimAPI
java.lang.Object
com.akraml.satim.SatimAPI
Main entry point for interacting with the SATIM Payment API.
This class provides methods for:
- Registering new payment orders
- Confirming payment status
- Checking order status
- Processing refunds
- Reversing payments
Example usage:
SatimHttpClient client = new ApacheHttpClient(
"username", "password", "terminalId"
);
SatimAPI api = new SatimAPI(client);
// Register a payment
api.registerPayment()
.amount(100000)
.returnUrl("https://example.com/callback")
.execute()
.thenAccept(reply -> {
System.out.println("Payment URL: " + reply.getPaymentUrl());
});
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSatimAPI(@NotNull SatimHttpClient httpClient) Creates a new SatimAPI instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the HTTP client and releases resources.@NotNull CompletableFuture<OrderConfirmationReply> Alias forconfirmPayment(String)to match PHP library naming.@NotNull CompletableFuture<OrderConfirmationReply> confirmPayment(@NotNull String orderId) Confirms a payment order.@NotNull CompletableFuture<PaymentReply> executeRegisterPayment(@NotNull com.google.gson.JsonObject params) Executes a payment registration request.@NotNull SatimHttpClientRetrieves the current instance of HTTP client that's used by this API instance.@NotNull CompletableFuture<OrderStatusReply> getPaymentStatus(@NotNull String orderId) Gets the current status of a payment order.@NotNull CompletableFuture<RefundReply> Alias forrefundPayment(String)to match PHP library naming.@NotNull CompletableFuture<RefundReply> refundPayment(@NotNull String orderId) Requests a full refund for a completed payment.@NotNull CompletableFuture<RefundReply> refundPayment(@NotNull String orderId, long amount) Requests a partial or full refund for a completed payment.@NotNull PaymentRequestBuilderCreates a new payment request builder.@NotNull CompletableFuture<RefundReply> Alias forreversePayment(String).@NotNull CompletableFuture<RefundReply> reversePayment(@NotNull String orderId) Reverses (cancels) a payment that hasn't been deposited yet.@NotNull CompletableFuture<OrderStatusReply> Alias forgetPaymentStatus(String)to match PHP library naming.
-
Constructor Details
-
SatimAPI
Creates a new SatimAPI instance.- Parameters:
httpClient- aSatimHttpClientthat implements the HTTP behavior for communicating with the API
-
-
Method Details
-
getHttpClient
Retrieves the current instance of HTTP client that's used by this API instance.- Returns:
- the HTTP client
-
registerPayment
Creates a new payment request builder.Use the builder to configure the payment parameters before executing.
Example:
api.registerPayment() .amount(100000) .returnUrl("https://example.com/success") .failUrl("https://example.com/fail") .description("Product purchase") .execute();- Returns:
- a new
PaymentRequestBuilderinstance
-
executeRegisterPayment
@NotNull public @NotNull CompletableFuture<PaymentReply> executeRegisterPayment(@NotNull @NotNull com.google.gson.JsonObject params) Executes a payment registration request.This method is called internally by
PaymentRequestBuilder.execute().- Parameters:
params- the request parameters built by PaymentRequestBuilder- Returns:
- a
CompletableFuturecontaining thePaymentReply
-
confirmPayment
@NotNull public @NotNull CompletableFuture<OrderConfirmationReply> confirmPayment(@NotNull @NotNull String orderId) Confirms a payment order.This should be called when the customer returns from the payment page to verify and complete the transaction.
Example:
api.confirmPayment(orderId) .thenAccept(reply -> { if (reply.isSuccessful()) { System.out.println("Payment confirmed: " + reply.getApprovalCode()); } else { System.out.println("Payment failed: " + reply.getErrorMessage()); } });- Parameters:
orderId- the order ID returned from payment registration- Returns:
- a
CompletableFuturecontaining theOrderConfirmationReply
-
confirm
@NotNull public @NotNull CompletableFuture<OrderConfirmationReply> confirm(@NotNull @NotNull String orderId) Alias forconfirmPayment(String)to match PHP library naming.- Parameters:
orderId- the order ID- Returns:
- a
CompletableFuturecontaining theOrderConfirmationReply
-
getPaymentStatus
@NotNull public @NotNull CompletableFuture<OrderStatusReply> getPaymentStatus(@NotNull @NotNull String orderId) Gets the current status of a payment order.Example:
api.getPaymentStatus(orderId) .thenAccept(reply -> { System.out.println("Status: " + reply.getOrderStatus()); if (reply.isDeposited()) { System.out.println("Payment completed!"); } });- Parameters:
orderId- the order ID returned from payment registration- Returns:
- a
CompletableFuturecontaining theOrderStatusReply
-
status
@NotNull public @NotNull CompletableFuture<OrderStatusReply> status(@NotNull @NotNull String orderId) Alias forgetPaymentStatus(String)to match PHP library naming.- Parameters:
orderId- the order ID- Returns:
- a
CompletableFuturecontaining theOrderStatusReply
-
refundPayment
@NotNull public @NotNull CompletableFuture<RefundReply> refundPayment(@NotNull @NotNull String orderId) Requests a full refund for a completed payment.Example:
api.refundPayment(orderId) .thenAccept(reply -> { if (reply.isSuccessful()) { System.out.println("Refund processed successfully"); } });- Parameters:
orderId- the order ID of the payment to refund- Returns:
- a
CompletableFuturecontaining theRefundReply
-
refundPayment
@NotNull public @NotNull CompletableFuture<RefundReply> refundPayment(@NotNull @NotNull String orderId, long amount) Requests a partial or full refund for a completed payment.Example:
// Refund 500 DZD (50000 centimes) api.refundPayment(orderId, 50000) .thenAccept(reply -> { if (reply.isSuccessful()) { System.out.println("Partial refund processed"); } });- Parameters:
orderId- the order ID of the payment to refundamount- the amount to refund in centimes (0 for full refund)- Returns:
- a
CompletableFuturecontaining theRefundReply
-
refund
Alias forrefundPayment(String)to match PHP library naming.- Parameters:
orderId- the order ID- Returns:
- a
CompletableFuturecontaining theRefundReply
-
reversePayment
@NotNull public @NotNull CompletableFuture<RefundReply> reversePayment(@NotNull @NotNull String orderId) Reverses (cancels) a payment that hasn't been deposited yet.Use this for payments that are still in APPROVED status. For deposited payments, use
refundPayment(String)instead.Example:
api.reversePayment(orderId) .thenAccept(reply -> { if (reply.isSuccessful()) { System.out.println("Payment reversed"); } });- Parameters:
orderId- the order ID of the payment to reverse- Returns:
- a
CompletableFuturecontaining theRefundReply
-
reverse
Alias forreversePayment(String).- Parameters:
orderId- the order ID- Returns:
- a
CompletableFuturecontaining theRefundReply
-
close
Closes the HTTP client and releases resources.Call this when you're done using the API.
- Throws:
Exception
-