Java Library
Paga Collect Java library
The Paga Collect API allows anyone to initiate a payment request to a third party and automatically get notified when the payment request is fulfilled. This library makes it easier and faster for developers to integrate the API
1. Installation
Download the jar and install it in your project
If you are using a build process such as Maven or Gradle, follow the process below,
Step 1. Extract and add the downloaded package to ~/.m2 directory
- path ~/.m2/repository/com/pagatech/collect-lib/1.0.0/
Step 2. Add the dependency to your pom.xml or build.gradle file.
Maven
Go to your pom file and add the following to your pom.xml
Then add the Paga Business client dependency under your dependencies
<dependencies>
<dependency>
<groupId>com.pagatech</groupId>
<artifactId>collect-lib</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
Gradle
Add the Paga Collect library dependency under your dependencies
//include mavenLocal( ) under your repositories
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile(group: 'com.pagatech', name: 'collect-lib', version: '1.0.0')
}
2. Usage
Once installed to import the library
import <packageName>.Collect;
Initialize it, see sample code below:
Collect collect = new Collect.Builder()
.setApiKey(hash_key)
.setPrincipal(principal)
.setCredential(credentials)
.setTest(false)
.build();
<strong>Note</strong>
Test Server can be true or false. True means you calling PAGA test server while False means you are calling PAGA live Server.
Paga Collect API Operations
Now that you have created a collect object you easily call its operations
Request Payment
Register a new request for payment between a payer and a payee. Once a payment request is initiated successfully, the payer is notified by the platform (this can be suppressed) and can proceed to authorize/execute the payment. Once the payment is fulfilled, a notification is sent to the supplied callback URL. See the callback notification section for more details.
To make a payment request see sample code below:
PaymentRequestRequest.Payer payer = new PaymentRequestRequest.Payer();
payer.setName("John Doe");
payer.setPhoneNumber("07033333333");
payer.setBankId("3E94C4BC-6F9A-442F-8F1A-8214478D5D86");
PaymentRequestRequest.Payee payee = new PaymentRequestRequest.Payee();
payee.setName("Mary Doe");
payee.setAccountNumber("1111111111");
payee.setBankId("3E94C4BC-6F9A-442F-8F1A-8214478D5D86");
payee.setBankAccountNumber("000000000");
payee.setFinancialIdentificationNumber("02222843212");
List<String> paymentMethods = new ArrayList<>();
paymentMethods.add("BANK_TRANSFER");
paymentMethods.add("FUNDING_USSD");
PaymentRequestResponse paymentRequestResponse = collect.paymentRequest(PaymentRequestRequest.builder()
.referenceNumber("6020000011z10aab2")
.amount("200")
.currency("NGN")
.payer(payer)
.payee(payee)
.expiryDateTimeUTC("2021-06-30T00:00:00")
.isSuppressMessages(true)
.isAllowPartialPayments(true)
.payerCollectionFeeShare(0.5)
.payeeCollectionFeeShare(0.5)
.callBackUrl("http://localhost:9091/test-callback")
.paymentMethods(paymentMethods)
.build());
System.out.println(paymentRequestResponse.toString());
Register Persistent Payment Account
An operation for businesses to create Persistent Payment Account Numbers that can be assigned to their customers for payment collection.
To create a persistent payment account see the sample code below:
RegisterPersistentPaymentAccountResponse response = collect.registerPersistentPaymentAccount(
RegisterPersistentPaymentAccountRequest.builder()
.referenceNumber("test12345100zz0")
.phoneNumber("07033333333")
.accountName("John Doe")
.firstName("John")
.lastName("Doe")
.accountReference("012111111111")
.financialIdentificationNumber("22222222222")
.creditBankId("3E94C4BC-6F9A-442F-8F1A-8214478D5D86")
.creditBankAccountNumber("0000000000")
.callbackUrl("http://localhost:9091/test-callback")
.build());
System.out.println(response.toString());
Query Status
Query the current status of a submitted request
To check the status of a submitted request see the sample code below:
StatusResponse statusResponse = collect.getStatus(StatusRequest.builder()
.referenceNumber("6020000011z10aab2")
.build());
System.out.println(statusResponse.toString());
Query History
Get payment requests for a period between given start and end dates. The period window should not exceed 1 month.
See sample code below:
HistoryResponse historyResponse = collect.getHistory(HistoryRequest.builder()
.referenceNumber("6020000011z10aab2")
.startDateTimeUTC("2021-05-30T00:00:00")
.endDateTimeUTC("2021-06-10T00:00:00")
.build());
System.out.println(historyResponse.toString());
Get Banks
Retrieve a list of supported banks and their complementary unique ids on the bank. This is required for populating the payer (optional) and payee objects in the payment request model.
See usage sample code below:
BanksResponse banks = collect.getBanks(BanksRequest.builder()
.referenceNumber("test002")
.build());
System.out.println(banks.toString());
Payment Request Refund
This end-point can be used to either cancel or initiate a refund if we were unable to fulfill the request for one reason or the other.
See usage sample code below:
RefundPaymentResponse refundPaymentResponse = collect.refund(
RefundPaymentRequest.builder()
.referenceNumber("132131232")
.refundAmount("123")
.reason("no particular reason")
.build());
System.out.println(refundPaymentResponse.toString());
Delete Persistent Payment Account
This endpoint allows for deleting a persistent payment account.
See usage sample code below:
DeletePersistentPaymentAccountResponse deletePersistentPaymentAccountResponse = collect.deletePersistentPaymentAccount(
DeletePersistentPaymentAccountRequest.builder()
.referenceNumber("1223243244")
.accountIdentifier("13429424242")
.reason("Duplicate account")
.build());
System.out.println(deletePersistentPaymentAccountResponse.toString());
Get Persistent Payment Account
A method to query the properties associated with an existing persistent payment account.
See usage sample code below:
GetPersistentPaymentAccountResponse getPersistentPaymentAccountResponse = collect.getPersistentPaymentAccount(
GetPersistentPaymentAccountRequest.builder()
.referenceNumber("293030102302213")
.accountIdentifier("0798822314")
.build());
System.out.println(getPersistentPaymentAccountResponse.toString());
Update Persistent Payment Account
This endpoint allows for changing any of the account properties except the accountNumber (NUBAN) and the accounReference properties which cannot be changed.
See usage sample code below:
UpdatePersistentPaymentAccountResponse updatePersistentPaymentAccountResponse = collect.updatePersistentPaymentAccount(
UpdatePersistentPaymentAccountRequest.builder()
.referenceNumber("9238383939393839")
.accountIdentifier("0798822314")
.accountName("Joe Manchin")
.build());
System.out.println(updatePersistentPaymentAccountResponse.toString());
Updated almost 3 years ago