Use Financial Transactions module Java API

Create Financial Transactions

 

 Create Payment
Example
...
@EJB private CRMBOAccountReceivableBean accountReceivableBean;
@EJB private CRMBOPaymentBean paymentBean;
@EJB private CRMProcessFinTransactionBean finTransactionProcessBean;
@EJB private CRMBOFinancialTransactionTypeBean transactionTypeBean;
@EJB private CRMBOPaymentMethodBean paymentMethodBean;
@EJB private CRMBOPaymentPreferenceBean paymentPreferenceBean;
...
 
public CRMDOPayment createPayment(
									boolean post, 
									String accountNumber, 
									String typeName, 
									String methodName, 
									BigDecimal amount, 
									String paymentPreferenceName, 
									String cardReferenceNumber){
	
	CRMDOPayment payment = null;
 
	//Load related accounts receivable
	CRMDOAccountReceivable accountReceivable =  accountReceivableBean.loadByNumber(accountNumber);
 
	//Load payment type
	CRMDOFinancialTransactionType type=transactionTypeBean.loadByName(typeName, FinancialTransactionTypeClassification.PAYMENT);
 
	//Load payment method
	CRMDOPaymentMethod paymentMethod = paymentMethodBean.loadByName(methodName);
 
	//Load account payment preference
	CRMDOAccountPaymentPreference accountPaymentPreference = null;
	CRMDOPaymentGatewayCard paymentGateway	= null;
 
	if (payment.getPaymentMethod().getPaymentGatewaySetting().getProtocol().equals(PaymentGatewayProtocol.GENERIC))
	{
		CRMDOPaymentPreference paymentPreference = paymentPreferenceBean.loadByName(paymentPreferenceName);
		accountPaymentPreference = accountPaymentPreferenceBean.load(accountReceivable, paymentPreference);
	}
	else if (payment.getPaymentMethod().getPaymentGatewaySetting().getProtocol().equals(PaymentGatewayProtocol.STRIPE))
	{
		paymentGatewayCard	= paymentGatewayCardBean.loadByReferenceNumber(cardReferenceNumber);
	}
 
	//Construct payment
	CRMDOPayment payment = (CRMDOPayment)paymentBean.construct(financialAccount);
	payment.setType(financialTransactionType);
	payment.setPaymentMethod(paymentMethod);
	payment.setTotalAmount(amount);
	payment.setAccountPaymentPreference(accountPaymentPreference);
	payment.setPaymentGatewayCard(paymentGatewayCard);
 

	payment = paymentBean.roundTotalAmount(payment);		
	paymentBean.validateCheckDigitRules(payment);
	
	//payment will be saved as draft
	payment = (CRMDOPayment)paymentBean.validateAndSave(payment);
	
	if(post)
	{
		//post the payment
		payment = finTransactionProcessBean.postPayment(payment);
	}
 
	return payment;
}
 Create Payment to pay Bill
Example
...
@EJB private CRMBOAccountReceivableBean accountReceivableBean;
@EJB private CRMBOWalletBean walletBean;
@EJB private CRMBOPaymentBean paymentBean;
@EJB private CRMProcessFinTransactionBean finTransactionProcessBean;
@EJB private CRMBOFinancialTransactionTypeBean transactionTypeBean;
@EJB private CRMBOPaymentMethodBean paymentMethodBean;
@EJB private CRMBOPaymentPreferenceBean paymentPreferenceBean;
@EJB private CRMBOBillBean billBean;
@EJB private CRMBOBillItemBean billItemBean;
...
 
public CRMDOPayment createPayment(
									String accountNumber, 
									String walletNumber,
									String typeName, 
									String methodName, 
									String paymentPreferenceName, 
									String cardReferenceNumber,
									String billNumber){
	
	CRMDOPayment payment = null;
 
	//Load related accounts receivable
	CRMDOAccountReceivable accountReceivable =  null;
	if(accountNumber!null)
	{
		accountReceivableBean.loadByNumber(accountNumber);
	}
	else if if(walletNumber!null)
	{
		walletBean.loadByNumber(walletNumber);
 		accountReceivable = wallet.getAccountReceivable();
	}
 
	//Load payment type
	CRMDOFinancialTransactionType type=transactionTypeBean.loadByName(typeName, FinancialTransactionTypeClassification.PAYMENT);
 
	//Load payment method
	CRMDOPaymentMethod paymentMethod = paymentMethodBean.loadByName(methodName);
 
	//Load account payment preference
	CRMDOAccountPaymentPreference accountPaymentPreference = null;
	CRMDOPaymentGatewayCard paymentGateway	= null;
 
	if (payment.getPaymentMethod().getPaymentGatewaySetting().getProtocol().equals(PaymentGatewayProtocol.GENERIC))
	{
		CRMDOPaymentPreference paymentPreference = paymentPreferenceBean.loadByName(paymentPreferenceName);
		accountPaymentPreference = accountPaymentPreferenceBean.load(accountReceivable, paymentPreference);
	}
	else if (payment.getPaymentMethod().getPaymentGatewaySetting().getProtocol().equals(PaymentGatewayProtocol.STRIPE))
	{
		paymentGatewayCard	= paymentGatewayCardBean.loadByReferenceNumber(cardReferenceNumber);
	}
 
	//Construct payment
	CRMDOPayment payment = (CRMDOPayment)paymentBean.construct(financialAccount);
	payment.setType(financialTransactionType);
	payment.setPaymentMethod(paymentMethod);
	payment.setAccountPaymentPreference(accountPaymentPreference);
	payment.setPaymentGatewayCard(paymentGatewayCard);
 
	if(billNumber!=null)
	{
		CRMDOBill bill = billBean.loadByNumber(billNumber);
		bill = billBean.loadAdditionalInformation(bill);
		Set<CRMDOPaymentIntention> paymentIntentions = new HashSet<CRMDOPaymentIntention>();
		paymentIntentions = constructIntentionsForBill(payment, bill, paymentIntentions);
		payment.setPaymentIntentions(paymentIntentions);
		payment.setTotalAmount(billBean.getUnsettledAmount(bill));
	}
		
	paymentBean.validateCheckDigitRules(payment);
	
	//payment will be saved as draft
	payment = (CRMDOPayment)paymentBean.validateAndSave(payment);
	
	if(accountNumber!=null)
	{
		//payent will be allocated to account
		payment = finTransactionProcessBean.postPayment(payment, 
														new Boolean(false),
														new Boolean(true),
														null,
														numberSchemeBean.loadBySequence(SequenceNumber.PAYMENTS.toString(),new ArrayList<String>()),
														accountingPeriodBean.loadOpen(new ArrayList<String>()),
														new Boolean(false));
	}
	else if(walletNumber!=null)
	{
		//payment will be allocated to wallet
		payment = finTransactionProcessBean.postPayment(payment, 
														new Boolean(false),
														new Boolean(true),
														null,
														numberSchemeBean.loadBySequence(SequenceNumber.PAYMENTS.toString(),new ArrayList<String>()),
														accountingPeriodBean.loadOpen(new ArrayList<String>()),
														new Boolean(true));
	}
 
	return payment;
}
 
private Set<CRMDOPaymentIntention> constructIntentionsForBill(CRMDOPayment payment, CRMDOBill bill,Set<CRMDOPaymentIntention> paymentIntentions) throws Exception{
		ArrayList<String> associations = new ArrayList<String>();
		associations.add("invoice");
		ArrayList<CRMDO> billItems 	= billItemBean.load(bill,associations);
		
		if (billItems!=null && billItems.size() > 0)
		{
			for (int j=0;j<billItems.size();j++)
			{
				CRMDOBillItem billItem = (CRMDOBillItem)billItems.get(j);
				if (billItem.getInvoice()!=null)
				{
					CRMDOPaymentIntention paymentIntention=(CRMDOPaymentIntention)paymentIntentionBean.construct(payment);
					paymentIntention.setInvoice(billItem.getInvoice());
					paymentIntention.setBill(bill);
					paymentIntentions.add(paymentIntention);
				}
			}
			
		}
		return paymentIntentions;
}
 Create Payment to pay Invoice
Example
...
@EJB private CRMBOAccountReceivableBean accountReceivableBean;
@EJB private CRMBOWalletBean walletBean;
@EJB private CRMBOPaymentBean paymentBean;
@EJB private CRMProcessFinTransactionBean finTransactionProcessBean;
@EJB private CRMBOFinancialTransactionTypeBean transactionTypeBean;
@EJB private CRMBOPaymentMethodBean paymentMethodBean;
@EJB private CRMBOPaymentPreferenceBean paymentPreferenceBean;
@EJB private CRMBOInvoiceBean invoiceBean;	
...
 
public CRMDOPayment createPayment(
									String accountNumber, 
									String walletNumber,
									String typeName, 
									String methodName, 
									String paymentPreferenceName, 
									String cardReferenceNumber,
									String invoiceNumber){
	
	CRMDOPayment payment = null;
 
	//Load related accounts receivable
	CRMDOAccountReceivable accountReceivable =  null;
	if(accountNumber!null)
	{
		accountReceivableBean.loadByNumber(accountNumber);
	}
	else if if(walletNumber!null)
	{
		walletBean.loadByNumber(walletNumber);
 		accountReceivable = wallet.getAccountReceivable();
	}
 
	//Load payment type
	CRMDOFinancialTransactionType type=transactionTypeBean.loadByName(typeName, FinancialTransactionTypeClassification.PAYMENT);
 
	//Load payment method
	CRMDOPaymentMethod paymentMethod = paymentMethodBean.loadByName(methodName);
 
	//Load account payment preference
	CRMDOAccountPaymentPreference accountPaymentPreference = null;
	CRMDOPaymentGatewayCard paymentGateway	= null;
 
	if (payment.getPaymentMethod().getPaymentGatewaySetting().getProtocol().equals(PaymentGatewayProtocol.GENERIC))
	{
		CRMDOPaymentPreference paymentPreference = paymentPreferenceBean.loadByName(paymentPreferenceName);
		accountPaymentPreference = accountPaymentPreferenceBean.load(accountReceivable, paymentPreference);
	}
	else if (payment.getPaymentMethod().getPaymentGatewaySetting().getProtocol().equals(PaymentGatewayProtocol.STRIPE))
	{
		paymentGatewayCard	= paymentGatewayCardBean.loadByReferenceNumber(cardReferenceNumber);
	}
 
	//Construct payment
	CRMDOPayment payment = (CRMDOPayment)paymentBean.construct(financialAccount);
	payment.setType(financialTransactionType);
	payment.setPaymentMethod(paymentMethod);
	payment.setAccountPaymentPreference(accountPaymentPreference);
	payment.setPaymentGatewayCard(paymentGatewayCard);
 
	if(invoiceNumber!=null)
	{
		CRMDOInvoice invoice = invoice=invoiceBean.loadByNumber(invoiceNumber);
		CRMDOPaymentIntention paymentIntention = (CRMDOPaymentIntention)paymentIntentionBean.construct(payment);
		paymentIntention.setInvoice(invoice);
		Set<CRMDOPaymentIntention> paymentIntentions = new HashSet<CRMDOPaymentIntention>();
		paymentIntentions.add(paymentIntention);
		payment.setPaymentIntentions(paymentIntentions);
		payment.setTotalAmount(invoiceBean.getUnsettledAmount(invoice));
	}
		
	payment = paymentBean.roundTotalAmount(payment);
	
	//payment will be saved as draft
	payment = (CRMDOPayment)paymentBean.validateAndSave(payment);
	
	if(accountNumber!=null)
	{
		//payent will be allocated to account
		payment = finTransactionProcessBean.postPayment(payment, 
														new Boolean(false),
														new Boolean(true),
														null,
														numberSchemeBean.loadBySequence(SequenceNumber.PAYMENTS.toString(),new ArrayList<String>()),
														accountingPeriodBean.loadOpen(new ArrayList<String>()),
														new Boolean(false));
	}
	else if(walletNumber!=null)
	{
		//payment will be allocated to wallet
		payment = finTransactionProcessBean.postPayment(payment, 
														new Boolean(false),
														new Boolean(true),
														null,
														numberSchemeBean.loadBySequence(SequenceNumber.PAYMENTS.toString(),new ArrayList<String>()),
														accountingPeriodBean.loadOpen(new ArrayList<String>()),
														new Boolean(true));
	}
 
	return payment;
}
 
private Set<CRMDOPaymentIntention> constructIntentionsForBill(CRMDOPayment payment, CRMDOBill bill,Set<CRMDOPaymentIntention> paymentIntentions) throws Exception{
		ArrayList<String> associations = new ArrayList<String>();
		associations.add("invoice");
		ArrayList<CRMDO> billItems 	= billItemBean.load(bill,associations);
		
		if (billItems!=null && billItems.size() > 0)
		{
			for (int j=0;j<billItems.size();j++)
			{
				CRMDOBillItem billItem = (CRMDOBillItem)billItems.get(j);
				if (billItem.getInvoice()!=null)
				{
					CRMDOPaymentIntention paymentIntention=(CRMDOPaymentIntention)paymentIntentionBean.construct(payment);
					paymentIntention.setInvoice(billItem.getInvoice());
					paymentIntention.setBill(bill);
					paymentIntentions.add(paymentIntention);
				}
			}
			
		}
		return paymentIntentions;
}

Cancel Financial Transactions

 

 Cancel Payment
Example
...
@EJB private CRMBOPaymentBean paymentBean;
@EJB private CRMProcessFinTransactionBean finTransactionProcessBean;
...
 
public CRMDOPaymentCancellation cancelPayment(String paymentNumber, String canncellationTypeName){
	
	CRMDOPayment payment= paymentBean.loadByNumber(paymentNumber);
 
	//Load payment cancellation type
	CRMDOFinancialTransactionType type = transactionTypeBean.loadByName(canncellationTypeName, FinancialTransactionTypeClassification.PAYMENT_CANCEL);
	
	//construct payment cancellation
	CRMDOPaymentCancellation paymentCancelation=finTransactionProcessBean.constructPaymentCancellation(payment);
	paymentCancelation.setType(financialTransactionType);
 
	//cancel payment
	paymentCancelation=finTransactionProcessBean.cancelPayment(payment,paymentCancelation,true);	
		
	return payment;
}

Reject Financial Transactions

 

 Reject Payment
Example
...
@EJB private CRMBOPaymentBean paymentBean;
@EJB private CRMProcessFinTransactionBean finTransactionProcessBean;
...
 
public CRMDOPaymentCancellation cancelPayment(String paymentNumber, String rejectionReasonName){
	
	CRMDOPayment payment= paymentBean.loadByNumber(paymentNumber);
 
	//Load rejection reason
	CRMDOFinancialTransactionRejectionReason rejectionReason  = rejectionReasonBean.loadByName(rejectionReasonName);
 
	//Reject payment
	payment = finTransactionProcessBean.rejectPayment(payment, rejectionReason);
		
	return payment;
}