Use Financial Transactions module Java API
- Former user (Deleted)
Owned by Former user (Deleted)
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; }