com.global.api.services.BillPayService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of globalpayments-sdk Show documentation
Show all versions of globalpayments-sdk Show documentation
API for processing payments through Global Payments
package com.global.api.services;
import java.math.BigDecimal;
import java.util.List;
import com.global.api.builders.BillingBuilder;
import com.global.api.entities.HostedPaymentData;
import com.global.api.entities.billing.Bill;
import com.global.api.entities.billing.BillingResponse;
import com.global.api.entities.billing.ConvenienceFeeResponse;
import com.global.api.entities.billing.LoadSecurePayResponse;
import com.global.api.entities.enums.BillingLoadType;
import com.global.api.entities.enums.TransactionType;
import com.global.api.entities.exceptions.ApiException;
import com.global.api.paymentMethods.IPaymentMethod;
public class BillPayService {
///
/// Returns the fee for the given payment method and amount
///
/// The payment method that will be used to make the
/// charge against
/// The total amount to be charged
/// The name of the registered configuration to
/// retrieve. This defaults to 'default'
///
public BigDecimal calculateConvenienceAmount(IPaymentMethod paymentMethod, BigDecimal amount) throws ApiException {
return calculateConvenienceAmount(paymentMethod, amount, "default");
}
public BigDecimal calculateConvenienceAmount(IPaymentMethod paymentMethod, BigDecimal amount, String configName)
throws ApiException {
BillingResponse response = new BillingBuilder(TransactionType.Fetch)
.withPaymentMethod(paymentMethod)
.withAmount(amount)
.execute(configName);
return ((ConvenienceFeeResponse) response).getConvenienceFee();
}
///
/// Loads one or more bills for a specific customer and returns an identifier that can be used by the customer to retrieve their bills
///
/// The payment data to be hosted
/// The name of the registered configuration to retrieve. This defaults to 'default'
///
public LoadSecurePayResponse loadHostedPayment(HostedPaymentData hostedPaymentData) throws ApiException {
return loadHostedPayment(hostedPaymentData, "default");
}
public LoadSecurePayResponse loadHostedPayment(HostedPaymentData hostedPaymentData, String configName)
throws ApiException {
BillingResponse response = new BillingBuilder(TransactionType.Create)
.withBillingLoadType(BillingLoadType.SECURE_PAYMENT)
.withHostedPaymentData(hostedPaymentData)
.execute(configName);
return ((LoadSecurePayResponse) response);
}
///
/// Loads one or more bills for one or many customers
///
/// The collection of bills to load
/// The name of the registered configuration to retrieve. This defaults to 'default'
public void loadBills(List bills) throws ApiException {
loadBills(bills, "default");
}
public void loadBills(List bills, String configName) throws ApiException {
int maxBillsPerUpload = 1000;
int billCount = bills.size();
int numberOfCalls = billCount < maxBillsPerUpload ? 1 : billCount / maxBillsPerUpload;
for (int i = 0; i < numberOfCalls; i++) {
// skipped bills from previous uploads
int fromIndex = i * maxBillsPerUpload;
// limit bills to `maxBillsPerUpload`
int toIndex = fromIndex + (billCount < maxBillsPerUpload ? billCount : maxBillsPerUpload);
List currentSetOfBills = bills.subList(fromIndex, toIndex);
new BillingBuilder(TransactionType.Create)
.withBillingLoadType(BillingLoadType.BILLS)
.withBills(currentSetOfBills)
.execute(configName);
}
}
///
/// Removes all bills that have been loaded and have not been committed
///
/// The name of the registered configuration to
/// retrieve. This defaults to 'default'
///
public BillingResponse clearBills() throws ApiException {
return clearBills("default");
}
public BillingResponse clearBills(String configName) throws ApiException {
return new BillingBuilder(TransactionType.Delete)
.withBillingLoadType(BillingLoadType.BILLS)
.clearPreloadedBills()
.execute(configName);
}
///
/// Commits all bills that have been preloaded
///
/// The name of the registered configuration to retrieve. This defaults to 'default'
///
public BillingResponse commitPreloadedBills() throws ApiException {
return commitPreloadedBills("default");
}
public BillingResponse commitPreloadedBills(String configName) throws ApiException {
return new BillingBuilder(TransactionType.Activate)
.withBillingLoadType(BillingLoadType.BILLS)
.commitPreloadedBills()
.execute(configName);
}
}