Add to your build.gradle:
dependencies {
implementation 'com.esite.zaincash:zaincash-sdk:0.0.1'
}Add to your application.properties or .yml:
zaincash:
msisdn:
secret:
merchant-id:
environment:
language: - Environment:
PRODUCTIONorSANDBOX - Language:
ENGLISHorARABIC
Use the PaymentRequest class:
PaymentRequest paymentRequest = new PaymentRequest(
your_amount,
your_service_type,
your_order_id,
"https://your-redirect-url.com"
);Notes:
-
Amount (IQD):
- Must be in Iraqi Dinar (IQD).
- If using USD, multiply by the exchange rate (e.g.,
10 USD * 1450 = 14500 IQD). - Must be greater than 1000 IQD.
-
Service Type:
Brief description (e.g.,"Book Purchase","Internet Subscription"). -
Order ID:
Used for internal tracking (e.g.,"Order12345").- Type: String
- Max Length: 512 characters
-
Redirect URL:
Publicly accessible endpoint to handle ZainCash response.
Inject ZainCashSDK and use:
private final ZainCashSDK zainCashSDK;
public void initializePayment() {
PaymentRequest paymentRequest = new PaymentRequest(
your_amount,
your_service_type,
your_order_id,
"https://your-redirect-url.com"
);
try {
// Redirect user to payment URL
String paymentResponse = zainCashSDK.initiatePayment(paymentRequest);
} catch (ZainCashException e) {
// Handle exception
}
}Extract the token from the redirect URL and check status:
private final ZainCashSDK zainCashSDK;
public void checkPaymentStatus(String token) {
try {
StatusResponse paymentStatusResponse = zainCashSDK.checkPaymentStatus(token);
} catch (ZainCashException e) {
// Handle exception
}
}public class StatusResponse {
private String success;
private String orderId;
private String id;
private Date iat;
private Date exp;
}For any issues, feel free to reach out.
Developed with ❤️ by @alsaadii98 at eSITE Information Technology.