Package com.akraml.satim.request
Class PaymentRequestBuilder
java.lang.Object
com.akraml.satim.request.PaymentRequestBuilder
Builder for payment registration requests.
Provides a fluent API for configuring payment parameters, mirroring the PHP library's chained method pattern.
Example usage:
api.registerPayment()
.amount(100000) // 1000 DZD in centimes
.returnUrl("https://example.com/success")
.failUrl("https://example.com/fail")
.description("Product purchase")
.language(Language.FRENCH)
.timeout(600)
.execute();
Required parameters:
amount(long)- Payment amount in centimesreturnUrl(String)- Callback URL after payment
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionPaymentRequestBuilder(@NotNull SatimAPI api) Creates a new PaymentRequestBuilder. -
Method Summary
Modifier and TypeMethodDescriptionamount(long amount) Sets the payment amount in centimes.Sets the currency code.description(@Nullable String description) Sets a description for the payment.@NotNull CompletableFuture<PaymentReply> execute()Validates and executes the payment registration request.Sets the fail URL for unsuccessful payments.Sets the language for the payment page.Sets the language for the payment page using a string code.orderNumber(long orderNumber) Sets a custom order number.@NotNull CompletableFuture<PaymentReply> register()Alias forexecute()to match PHP library naming.Sets the return URL for successful payments.timeout(int seconds) Sets the payment session timeout in seconds.userDefinedField(@NotNull String key, @NotNull String value) Adds a single user-defined field.userDefinedFields(@NotNull com.google.gson.JsonObject fields) Adds multiple user-defined fields.
-
Constructor Details
-
PaymentRequestBuilder
Creates a new PaymentRequestBuilder.- Parameters:
api- the SatimAPI instance to use for executing the request
-
-
Method Details
-
amount
Sets the payment amount in centimes.Example: For 1000.00 DZD, use
amount(100000)- Parameters:
amount- the amount in the smallest currency unit (centimes)- Returns:
- this builder for method chaining
- Throws:
IllegalArgumentException- if amount is not positive
-
returnUrl
Sets the return URL for successful payments.The customer will be redirected to this URL after completing payment.
- Parameters:
returnUrl- the success callback URL- Returns:
- this builder for method chaining
- Throws:
IllegalArgumentException- if returnUrl is null or empty
-
failUrl
Sets the fail URL for unsuccessful payments.If not set,
returnUrl(String)will be used for failures.- Parameters:
failUrl- the failure callback URL- Returns:
- this builder for method chaining
-
description
Sets a description for the payment.This may be displayed to the customer on the payment page.
- Parameters:
description- the payment description- Returns:
- this builder for method chaining
-
orderNumber
Sets a custom order number.If not set, a random 10-digit number will be generated.
- Parameters:
orderNumber- the custom order number (should be unique)- Returns:
- this builder for method chaining
-
language
Sets the language for the payment page.- Parameters:
language- the language enum value- Returns:
- this builder for method chaining
-
language
Sets the language for the payment page using a string code.- Parameters:
languageCode- the language code ("FR", "AR", or "EN")- Returns:
- this builder for method chaining
-
timeout
Sets the payment session timeout in seconds.Default is 600 seconds (10 minutes).
- Parameters:
seconds- the timeout in seconds- Returns:
- this builder for method chaining
- Throws:
IllegalArgumentException- if timeout is not positive
-
currency
Sets the currency code.Default is "012" (DZD - Algerian Dinar).
- Parameters:
currency- the ISO 4217 numeric currency code- Returns:
- this builder for method chaining
-
userDefinedField
public PaymentRequestBuilder userDefinedField(@NotNull @NotNull String key, @NotNull @NotNull String value) Adds a single user-defined field.These fields can store custom metadata with the payment.
- Parameters:
key- the field namevalue- the field value- Returns:
- this builder for method chaining
-
userDefinedFields
Adds multiple user-defined fields.- Parameters:
fields- a JsonObject containing field key-value pairs- Returns:
- this builder for method chaining
-
execute
Validates and executes the payment registration request.- Returns:
- a
CompletableFuturecontaining thePaymentReply - Throws:
IllegalStateException- if required parameters are missing
-
register
Alias forexecute()to match PHP library naming.- Returns:
- a
CompletableFuturecontaining thePaymentReply
-