Java SDK for integrating with the Fapshi Payment API.
- π οΈ Dependabot: Automatically checks for dependency updates via
.github/dependabot.yml - π€ Renovate: Alternative to Dependabot for custom and bulk PRs (configurable via
renovate.json)
- Generate payment links
- Direct mobile money payments (MTN, Orange)
- Check transaction status
- Handle webhook notifications
- Java 21+
- Maven
Add the following to your Maven pom.xml to use the latest release from JitPack:
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<dependency>
<groupId>com.github.iinsys</groupId>
<artifactId>fapshi-java-sdk</artifactId>
<version>v1.0.0</version>
</dependency>import com.fapshi.sdk.FapshiConfig;
import com.fapshi.sdk.FapshiClient;
FapshiConfig config = new FapshiConfig(
"YOUR_API_KEY",
"YOUR_API_USER",
"https://api.fapshi.com"
);
FapshiClient client = new FapshiClient(config);import com.fapshi.sdk.model.PaymentLinkRequest;
import com.fapshi.sdk.model.PaymentLinkResponse;
import com.fapshi.sdk.service.PaymentService;
PaymentService paymentService = new PaymentService(client);
PaymentLinkRequest request = new PaymentLinkRequest();
request.setAmount(1000);
request.setCurrency("XAF");
request.setDescription("Order #1234");
request.setCustomerName("John Doe");
request.setCustomerEmail("john@example.com");
request.setCustomerPhone("2376XXXXXXX");
request.setCallbackUrl("https://yourdomain.com/payment-callback");
PaymentLinkResponse response = paymentService.generatePaymentLink(request);
System.out.println("Payment Link: " + response.getLink());import com.fapshi.sdk.model.DirectPaymentRequest;
import com.fapshi.sdk.model.DirectPaymentResponse;
DirectPaymentRequest directRequest = new DirectPaymentRequest();
directRequest.setAmount(1000); // required
directRequest.setPhone("237670000000"); // required
DirectPaymentResponse directResponse = paymentService.initiateDirectPayment(directRequest);
System.out.println("Direct Payment Status: " + directResponse.getStatus());DirectPaymentRequest directRequest = new DirectPaymentRequest();
directRequest.setAmount(2000); // required
directRequest.setPhone("237690000000"); // required
directRequest.setName("Jane Smith"); // optional
directRequest.setEmail("jane@example.com"); // optional
directRequest.setMedium("mobile money"); // optional
directRequest.setUserId("user-123"); // optional
directRequest.setExternalId("order-5678"); // optional
directRequest.setMessage("Order #5678 payment"); // optional
DirectPaymentResponse directResponse = paymentService.initiateDirectPayment(directRequest);
System.out.println("Direct Payment Status: " + directResponse.getStatus());The response will now include all fields as per the Fapshi API documentation:
import com.fapshi.sdk.model.TransactionStatusResponse;
String transactionId = "txn_abc123";
TransactionStatusResponse status = paymentService.getTransactionStatus(transactionId);
System.out.println("Transaction Status: " + status.getStatus());
System.out.println("Transaction ID: " + status.getTransId());
System.out.println("Amount: " + status.getAmount());
System.out.println("Medium: " + status.getMedium());
System.out.println("Payer Name: " + status.getPayerName());
// ... print other fields as needed| Field | Type | Description |
|---|---|---|
| transId | String | Transaction ID |
| status | String | Payment status (CREATED, PENDING, etc.) |
| medium | String | Payment medium (mobile money, orange money) |
| serviceName | String | Name of the service |
| amount | int | Payment amount |
| revenue | int | Revenue |
| payerName | String | Name of the payer |
| String | Payer's email | |
| redirectUrl | String | Redirect URL |
| externalId | String | External order/transaction ID |
| userId | String | Your system's user ID |
| webhook | String | Webhook URL |
| financialTransId | String | Financial transaction ID |
| dateInitiated | String | Date initiated |
| dateConfirmed | String | Date confirmed |
The webhook payload will match the transaction status response structure above. Example controller:
import org.springframework.web.bind.annotation.*;
import com.fapshi.sdk.model.WebhookNotification;
@RestController
@RequestMapping("/fapshi")
public class FapshiWebhookController {
@PostMapping("/webhook")
public void handleWebhook(@RequestBody WebhookNotification notification) {
// Access all fields from notification, e.g.:
System.out.println("Webhook Status: " + notification.getStatus());
System.out.println("Webhook Transaction ID: " + notification.getTransId());
// ... handle other fields as needed
}
}All SDK methods throw FapshiApiException on API or network errors. Use try/catch to handle errors gracefully.
try {
// call SDK method
} catch (FapshiApiException e) {
// handle error
}We welcome contributions! Please see docs/CONTRIBUTING.md for guidelines before submitting issues or pull requests.
See LICENSE.
