/** * Tries to create payment against review invoice. Here, instead of using the billing process to * generate a review invoice we are creating a review invoice with the help of saveLegacyInvoice * call. */ @Test public void testPayReviewInvoice() { // creating new user UserWS user = buildUser(PRANCING_PONY_ACCOUNT_TYPE); user.setId(api.createUser(user)); ItemTypeWS itemType = buildItemType(); itemType.setId(api.createItemCategory(itemType)); ItemDTOEx item = buildItem(itemType.getId(), api.getCallerCompanyId()); item.setId(api.createItem(item)); InvoiceWS invoice = buildInvoice(user.getId(), item.getId()); invoice.setIsReview(Integer.valueOf(1)); invoice.setId(api.saveLegacyInvoice(invoice)); // check if invoice is a review invoice System.out.println("Invoice is review : " + invoice.getIsReview()); assertEquals("Invoice is a review invoice", Integer.valueOf(1), invoice.getIsReview()); try { // pay for a review invoice api.payInvoice(invoice.getId()); fail("We should not be able to issue a payment against review invoice"); } catch (SessionInternalError e) { System.out.println(e.getMessage()); } // clean up api.deleteInvoice(invoice.getId()); api.deleteItem(item.getId()); api.deleteItemCategory(itemType.getId()); api.deleteUser(user.getId()); }
public void testDelete() { try { JbillingAPI api = JbillingAPIFactory.getAPI(); Integer invoiceId = new Integer(1); assertNotNull(api.getInvoiceWS(invoiceId)); api.deleteInvoice(invoiceId); try { api.getInvoiceWS(invoiceId); fail("Invoice should not have been deleted"); } catch (Exception e) { // ok } // try to delete an invoice that is not mine try { api.deleteInvoice(new Integer(75)); fail("Not my invoice. It should not have been deleted"); } catch (Exception e) { // ok } } catch (Exception e) { e.printStackTrace(); fail("Exception caught:" + e); } }
public PaymentWS createPaymentWS(Integer userId, Date date, String note) throws Exception { JbillingAPI api = JbillingAPIFactory.getAPI(); PaymentWS payment = new PaymentWS(); payment.setAmount(new BigDecimal("15.00")); payment.setIsRefund(new Integer(0)); payment.setMethodId(Constants.PAYMENT_METHOD_CHEQUE); payment.setPaymentDate(date); payment.setCreateDatetime(date); payment.setResultId(Constants.RESULT_ENTERED); payment.setCurrencyId(new Integer(1)); payment.setUserId(userId); payment.setPaymentNotes(note); payment.setPaymentPeriod(new Integer(1)); PaymentInformationWS cheque = com.sapienter.jbilling.server.user.WSTest.createCheque("ws bank", "2232-2323-2323", date); payment.getPaymentInstruments().add(cheque); System.out.println("Applying payment"); Integer ret = api.applyPayment(payment, new Integer(35)); System.out.println("Created payemnt " + ret); assertNotNull("Didn't get the payment id", ret); payment.setId(ret); return payment; }
@AfterClass protected void tearDown() { // TODO: should we be able to (soft) delete payment method type if all customers are soft // deleted??? api.deletePaymentMethodType(CC_PAYMENT_TYPE); api.deletePaymentMethodType(ACH_PAYMENT_TYPE); api.deletePaymentMethodType(CHEQUE_PAYMENT_TYPE); }
public void testCreateInvoiceFromOrder() throws Exception { JbillingAPI api = JbillingAPIFactory.getAPI(); final Integer USER_ID = 10730; // user has no orders // setup orders OrderWS order = new OrderWS(); order.setUserId(USER_ID); order.setBillingTypeId(Constants.ORDER_BILLING_PRE_PAID); order.setPeriod(1); // once order.setCurrencyId(1); order.setActiveSince(new Date()); OrderLineWS line = new OrderLineWS(); line.setTypeId(Constants.ORDER_LINE_TYPE_ITEM); line.setDescription("Order line"); line.setItemId(1); line.setQuantity(1); line.setPrice(new BigDecimal("10.00")); line.setAmount(new BigDecimal("10.00")); order.setOrderLines(new OrderLineWS[] {line}); // create orders Integer orderId1 = api.createOrder(order); Integer orderId2 = api.createOrder(order); // generate invoice using first order Integer invoiceId = api.createInvoiceFromOrder(orderId1, null); assertNotNull("Order 1 created", orderId1); assertNotNull("Order 2 created", orderId2); assertNotNull("Invoice created", invoiceId); Integer[] invoiceIds = api.getLastInvoices(USER_ID, 2); assertEquals("Only 1 invoice was generated", 1, invoiceIds.length); InvoiceWS invoice = api.getInvoiceWS(invoiceId); assertEquals("Invoice total is $10.00", new BigDecimal("10.00"), invoice.getTotalAsDecimal()); assertEquals("Only 1 order invoiced", 1, invoice.getOrders().length); assertEquals("Invoice generated from 1st order", orderId1, invoice.getOrders()[0]); // add second order to invoice Integer invoiceId2 = api.createInvoiceFromOrder(orderId2, invoiceId); assertEquals("Order added to the same invoice", invoiceId, invoiceId2); invoiceIds = api.getLastInvoices(USER_ID, 2); assertEquals("Still only 1 invoice generated", 1, invoiceIds.length); invoice = api.getInvoiceWS(invoiceId); assertEquals("Invoice total is $20.00", new BigDecimal("20.00"), invoice.getTotalAsDecimal()); assertEquals("2 orders invoiced", 2, invoice.getOrders().length); // cleanup api.deleteInvoice(invoiceId); api.deleteOrder(orderId1); api.deleteOrder(orderId2); }
public void testGetPaperInvoicePDF() throws Exception { final Integer USER_ID = 2; // user has invoices JbillingAPI api = JbillingAPIFactory.getAPI(); Integer[] invoiceIds = api.getLastInvoices(USER_ID, 1); assertEquals("Invoice found for user", 1, invoiceIds.length); byte[] pdf = api.getPaperInvoicePDF(invoiceIds[0]); assertTrue("PDF invoice bytes returned", pdf.length > 0); }
public void testCreateInvoiceSecurity() { try { JbillingAPI api = JbillingAPIFactory.getAPI(); try { api.createInvoice(13, false); fail("User 13 belongs to entity 2"); } catch (Exception e) { } } catch (Exception e) { e.printStackTrace(); fail("Exception caught:" + e); } }
private Integer getOrCreateOrderChangeStatusApply(JbillingAPI api) { OrderChangeStatusWS[] statuses = api.getOrderChangeStatusesForCompany(); for (OrderChangeStatusWS status : statuses) { if (status.getApplyToOrder().equals(ApplyToOrder.YES)) { return status.getId(); } } // there is no APPLY status in db so create one OrderChangeStatusWS apply = new OrderChangeStatusWS(); String status1Name = "APPLY: " + System.currentTimeMillis(); OrderChangeStatusWS status1 = new OrderChangeStatusWS(); status1.setApplyToOrder(ApplyToOrder.YES); status1.setDeleted(0); status1.setOrder(1); status1.addDescription( new InternationalDescriptionWS(Constants.LANGUAGE_ENGLISH_ID, status1Name)); return api.createOrderChangeStatus(apply); }
private Integer getOrCreateSuspendedStatus(JbillingAPI api) { List<AgeingWS> steps = Arrays.asList(api.getAgeingConfiguration(LANGUAGE_ID)); for (AgeingWS step : steps) { if (step.getSuspended().booleanValue()) { return step.getStatusId(); } } AgeingWS suspendStep = new AgeingWS(); suspendStep.setSuspended(Boolean.TRUE); suspendStep.setDays(Integer.valueOf(180)); suspendStep.setStatusStr("Ageing Step 180"); suspendStep.setFailedLoginMessage("You are suspended"); suspendStep.setWelcomeMessage("Welcome"); steps.add(suspendStep); api.saveAgeingConfiguration(steps.toArray(new AgeingWS[steps.size()]), LANGUAGE_ID); return getOrCreateOrderChangeStatusApply(api); }
@BeforeClass protected void setUp() throws Exception { api = JbillingAPIFactory.getAPI(); mordorApi = JbillingAPIFactory.getAPI("apiClientMordor"); CURRENCY_USD = Constants.PRIMARY_CURRENCY_ID; CURRENCY_AUD = Integer.valueOf(11); LANGUAGE_ID = Constants.LANGUAGE_ENGLISH_ID; PRANCING_PONY_ACCOUNT_TYPE = Integer.valueOf(1); MORDOR_ACCOUNT_TYPE = Integer.valueOf(2); PAYMENT_PERIOD = Integer.valueOf(1); ORDER_PERIOD_ONCE = Integer.valueOf(1); ORDER_CHANGE_STATUS_APPLY = getOrCreateOrderChangeStatusApply(api); STATUS_SUSPENDED = getOrCreateSuspendedStatus(api); CC_PAYMENT_TYPE = api.createPaymentMethodType(PaymentMethodHelper.buildCCTemplateMethod(api)); ACH_PAYMENT_TYPE = api.createPaymentMethodType(PaymentMethodHelper.buildACHTemplateMethod(api)); CHEQUE_PAYMENT_TYPE = api.createPaymentMethodType(PaymentMethodHelper.buildChequeTemplateMethod(api)); }
/** * Test for BlacklistUserStatusTask. When a user's status moves to suspended or higher, the user * and all their information is added to the blacklist. */ @Test(enabled = false) public void testBlacklistUserStatus() { UserWS user = buildUser( PRANCING_PONY_ACCOUNT_TYPE, "BlackListFirst", "BlackListSecond", "4916347258194745"); user.setId(api.createUser(user)); // expected filter response messages String[] messages = new String[3]; messages[0] = "User id is blacklisted."; messages[1] = "Name is blacklisted."; messages[2] = "Credit card number is blacklisted."; // TODO: for now we do not test for these three // messages[3] = "Address is blacklisted."; // messages[4] = "IP address is blacklisted."; // messages[5] = "Phone number is blacklisted."; // check that a user isn't blacklisted user = api.getUserWS(user.getId()); // CXF returns null if (user.getBlacklistMatches() != null) { assertTrue("User shouldn't be blacklisted yet", user.getBlacklistMatches().length == 0); } // change their status to suspended user.setStatusId(STATUS_SUSPENDED); user.setPassword(null); api.updateUser(user); // check all their records are now blacklisted user = api.getUserWS(user.getId()); assertEquals( "User records should be blacklisted.", Arrays.toString(messages), Arrays.toString(user.getBlacklistMatches())); // cleanup api.deleteUser(user.getId()); }
public void testGetUserInvoicesByDate() { try { final Integer USER_ID = 2; // user has some invoices JbillingAPI api = JbillingAPIFactory.getAPI(); // invoice dates: 2006-07-26 // select the week Integer[] result = api.getUserInvoicesByDate(USER_ID, "2006-07-23", "2006-07-29"); // note: invoice 1 gets deleted assertEquals("Number of invoices returned", 3, result.length); assertEquals("Invoice id 4", 4, result[0].intValue()); assertEquals("Invoice id 3", 3, result[1].intValue()); assertEquals("Invoice id 2", 2, result[2].intValue()); // test since date inclusive result = api.getUserInvoicesByDate(USER_ID, "2006-07-26", "2006-07-29"); assertEquals("Number of invoices returned", 3, result.length); assertEquals("Invoice id 4", 4, result[0].intValue()); assertEquals("Invoice id 3", 3, result[1].intValue()); assertEquals("Invoice id 2", 2, result[2].intValue()); // test until date inclusive result = api.getUserInvoicesByDate(USER_ID, "2006-07-23", "2006-07-26"); assertEquals("Number of invoices returned", 3, result.length); assertEquals("Invoice id 4", 4, result[0].intValue()); assertEquals("Invoice id 3", 3, result[1].intValue()); assertEquals("Invoice id 2", 2, result[2].intValue()); // test date with no invoices result = api.getUserInvoicesByDate(USER_ID, "2005-07-23", "2005-07-29"); // Note: CXF returns null for empty array if (result != null) { assertEquals("Number of invoices returned", 0, result.length); } } catch (Exception e) { e.printStackTrace(); fail("Exception caught:" + e); } }
/** Testing the saveLegacyPayment API call */ @Test public void testSaveLegacyPayment() { // setup UserWS user = buildUser(PRANCING_PONY_ACCOUNT_TYPE); user.setId(api.createUser(user)); PaymentWS payment = new PaymentWS(); payment.setAmount(new BigDecimal("15.00")); payment.setIsRefund(new Integer(0)); payment.setMethodId(Constants.PAYMENT_METHOD_CREDIT); payment.setPaymentDate(Calendar.getInstance().getTime()); payment.setResultId(Constants.RESULT_ENTERED); payment.setCurrencyId(CURRENCY_USD); payment.setUserId(user.getId()); payment.setPaymentNotes("Notes"); payment.setPaymentPeriod(PAYMENT_PERIOD); Integer paymentId = api.saveLegacyPayment(payment); assertNotNull("Payment should be saved", paymentId); PaymentWS retPayment = api.getPayment(paymentId); assertNotNull(retPayment); assertEquals(retPayment.getAmountAsDecimal(), payment.getAmountAsDecimal()); assertEquals(retPayment.getIsRefund(), payment.getIsRefund()); assertEquals(retPayment.getMethodId(), payment.getMethodId()); assertEquals(retPayment.getResultId(), payment.getResultId()); assertEquals(retPayment.getCurrencyId(), payment.getCurrencyId()); assertEquals(retPayment.getUserId(), payment.getUserId()); assertEquals( retPayment.getPaymentNotes(), payment.getPaymentNotes() + " This payment is migrated from legacy system."); assertEquals(retPayment.getPaymentPeriod(), payment.getPaymentPeriod()); // cleanup api.deletePayment(retPayment.getId()); api.deleteUser(user.getId()); }
@Test public void testNewGetPaymentsApiMethods() throws Exception { JbillingAPI api = JbillingAPIFactory.getAPI(); // Create a user with balance $1.00 UserWS user = com.sapienter.jbilling.server.user.WSTest.createUser(true, null, null); List<PaymentWS> payments = new ArrayList<PaymentWS>(); for (int i = 0; i < 5; i++) { payments.add( createPaymentWS( user.getUserId(), new DateTime().plusMonths(i).toDate(), String.valueOf(i))); } // get two latest payments except the latest one. Integer[] paymentsId = api.getLastPaymentsPage(user.getUserId(), 2, 1); assertEquals(2, paymentsId.length); assertEquals("3", api.getPayment(paymentsId[0]).getPaymentNotes()); assertEquals("2", api.getPayment(paymentsId[1]).getPaymentNotes()); // get the payments between next month and four months from now. Integer[] paymentsId2 = api.getPaymentsByDate( user.getUserId(), new DateTime().plusDays(1).toDate(), new DateTime().plusMonths(3).plusDays(1).toDate()); assertEquals(3, paymentsId2.length); assertEquals("3", api.getPayment(paymentsId2[0]).getPaymentNotes()); assertEquals("2", api.getPayment(paymentsId2[1]).getPaymentNotes()); assertEquals("1", api.getPayment(paymentsId2[2]).getPaymentNotes()); // Delete orders for (PaymentWS payment : payments) { api.deletePayment(payment.getId()); } // Delete user api.deleteUser(user.getUserId()); }
public void testGetTotalAsDecimal() { List<Integer> invoiceIds = new ArrayList<Integer>(); List<Integer> orderIds = new ArrayList<Integer>(); JbillingAPI api = null; try { final Integer USER_ID = 10730; // user has no orders api = JbillingAPIFactory.getAPI(); // test BigDecimal behavior assertFalse(new BigDecimal("1.1").equals(new BigDecimal("1.10"))); assertTrue(new BigDecimal("1.1").compareTo(new BigDecimal("1.10")) == 0); // with items 2 and 3 10% discount should apply orderIds.add( api.createOrder( com.sapienter.jbilling.server.order.WSTest.createMockOrder( USER_ID, 3, new BigDecimal("0.32")))); orderIds.add( api.createOrder( com.sapienter.jbilling.server.order.WSTest.createMockOrder( USER_ID, 3, new BigDecimal("0.32")))); invoiceIds.addAll(Arrays.asList(api.createInvoice(USER_ID, false))); assertEquals(1, invoiceIds.size()); InvoiceWS invoice = api.getInvoiceWS(invoiceIds.get(0)); assertEquals("1.7300000000", invoice.getTotal()); assertEquals(new BigDecimal("1.730"), invoice.getTotalAsDecimal()); } catch (Exception e) { e.printStackTrace(); fail("Exception caught:" + e); } finally { try { for (Integer integer : invoiceIds) { api.deleteInvoice(integer); } System.out.println("Successfully deleted invoices: " + invoiceIds.size()); for (Integer integer : orderIds) { api.deleteOrder(integer); } System.out.println("Successfully deleted orders: " + orderIds.size()); } catch (Exception ignore) { } } }
public static UserWS createUser( boolean goodCC, Integer parentId, Integer currencyId, boolean doCreate) throws JbillingAPIException, IOException { JbillingAPI api = JbillingAPIFactory.getAPI(); /* * Create - This passes the password validation routine. */ UserWS newUser = new UserWS(); newUser.setUserId(0); // it is validated newUser.setUserName("testUserName-" + Calendar.getInstance().getTimeInMillis()); newUser.setPassword("As$fasdf1"); newUser.setLanguageId(Integer.valueOf(1)); newUser.setMainRoleId(Integer.valueOf(5)); newUser.setAccountTypeId(Integer.valueOf(1)); newUser.setParentId(parentId); // this parent exists newUser.setStatusId(UserDTOEx.STATUS_ACTIVE); newUser.setCurrencyId(currencyId); newUser.setCreditLimit("1"); newUser.setInvoiceChild(new Boolean(false)); MetaFieldValueWS metaField1 = new MetaFieldValueWS(); metaField1.setFieldName("partner.prompt.fee"); metaField1.setValue("serial-from-ws"); MetaFieldValueWS metaField2 = new MetaFieldValueWS(); metaField2.setFieldName("ccf.payment_processor"); metaField2.setValue("FAKE_2"); // the plug-in parameter of the processor MetaFieldValueWS metaField3 = new MetaFieldValueWS(); metaField3.setFieldName("contact.email"); metaField3.setValue(newUser.getUserName() + "@shire.com"); metaField3.setGroupId(1); MetaFieldValueWS metaField4 = new MetaFieldValueWS(); metaField4.setFieldName("contact.first.name"); metaField4.setValue("FrodoRecharge"); metaField4.setGroupId(1); MetaFieldValueWS metaField5 = new MetaFieldValueWS(); metaField5.setFieldName("contact.last.name"); metaField5.setValue("BagginsRecharge"); metaField5.setGroupId(1); newUser.setMetaFields( new MetaFieldValueWS[] {metaField1, metaField2, metaField3, metaField4, metaField5}); // valid credit card must have a future expiry date to be valid for payment processing Calendar expiry = Calendar.getInstance(); expiry.set(Calendar.YEAR, expiry.get(Calendar.YEAR) + 1); // add a credit card PaymentInformationWS cc = createCreditCard( "Frodo Rech Baggins", goodCC ? "4929974024420784" : "4111111111111111", expiry.getTime()); newUser.getPaymentInstruments().add(cc); if (doCreate) { System.out.println("Creating user ..."); Integer userId = api.createUser(newUser); newUser = api.getUserWS(userId); } return newUser; }
public void testCreateInvoice() { try { final Integer USER_ID = 10730; // user has no orders JbillingAPI api = JbillingAPIFactory.getAPI(); // setup order OrderWS order = new OrderWS(); order.setUserId(USER_ID); order.setBillingTypeId(Constants.ORDER_BILLING_PRE_PAID); order.setPeriod(1); // once order.setCurrencyId(1); order.setActiveSince(new Date()); OrderLineWS line = new OrderLineWS(); line.setTypeId(Constants.ORDER_LINE_TYPE_ITEM); line.setDescription("Order line"); line.setItemId(1); line.setQuantity(1); line.setPrice(new BigDecimal("10.00")); line.setAmount(new BigDecimal("10.00")); order.setOrderLines(new OrderLineWS[] {line}); /* * Test invoicing of one-time and recurring orders */ // create 1st order Integer orderId1 = api.createOrder(order); // create 2nd order line.setPrice(new BigDecimal("20.00")); line.setAmount(new BigDecimal("20.00")); Integer orderId2 = api.createOrder(order); // create invoice Integer[] invoices = api.createInvoice(USER_ID, false); assertEquals("Number of invoices returned", 1, invoices.length); InvoiceWS invoice = api.getInvoiceWS(invoices[0]); assertNull("Invoice is not delegated.", invoice.getDelegatedInvoiceId()); assertEquals( "Invoice does not have a carried balance.", BigDecimal.ZERO, invoice.getCarriedBalanceAsDecimal()); Integer[] invoicedOrderIds = invoice.getOrders(); assertEquals("Number of orders invoiced", 2, invoicedOrderIds.length); Arrays.sort(invoicedOrderIds); assertEquals("Order 1 invoiced", orderId1, invoicedOrderIds[0]); assertEquals("Order 2 invoiced", orderId2, invoicedOrderIds[1]); assertEquals("Total is 30.0", new BigDecimal("30.00"), invoice.getTotalAsDecimal()); // clean up api.deleteInvoice(invoices[0]); api.deleteOrder(orderId1); api.deleteOrder(orderId2); /* * Test only recurring order can generate invoice. */ // one-time order line.setPrice(new BigDecimal("2.00")); line.setAmount(new BigDecimal("2.00")); orderId1 = api.createOrder(order); // try to create invoice, but none should be returned invoices = api.createInvoice(USER_ID, true); // Note: CXF returns null for empty array if (invoices != null) { assertEquals("Number of invoices returned", 0, invoices.length); } // recurring order order.setPeriod(2); // monthly line.setPrice(new BigDecimal("3.00")); line.setAmount(new BigDecimal("3.00")); orderId2 = api.createOrder(order); // create invoice invoices = api.createInvoice(USER_ID, true); assertEquals("Number of invoices returned", 1, invoices.length); invoice = api.getInvoiceWS(invoices[0]); invoicedOrderIds = invoice.getOrders(); assertEquals("Number of orders invoiced", 2, invoicedOrderIds.length); Arrays.sort(invoicedOrderIds); assertEquals("Order 1 invoiced", orderId1, invoicedOrderIds[0]); assertEquals("Order 2 invoiced", orderId2, invoicedOrderIds[1]); assertEquals("Total is 5.0", new BigDecimal("5.00"), invoice.getTotalAsDecimal()); // clean up api.deleteInvoice(invoices[0]); api.deleteOrder(orderId1); api.deleteOrder(orderId2); } catch (Exception e) { e.printStackTrace(); fail("Exception caught:" + e); } }
public void testGet() { try { JbillingAPI api = JbillingAPIFactory.getAPI(); // get // try getting one that doesn't belong to us try { System.out.println("Getting invalid invoice"); api.getInvoiceWS(75); fail("Invoice 75 belongs to entity 2"); } catch (Exception e) { } System.out.println("Getting invoice"); InvoiceWS retInvoice = api.getInvoiceWS(15); assertNotNull("invoice not returned", retInvoice); assertEquals("invoice id", retInvoice.getId(), new Integer(15)); System.out.println("Got = " + retInvoice); // latest // first, from a guy that is not mine try { api.getLatestInvoice(13); fail("User 13 belongs to entity 2"); } catch (Exception e) { } System.out.println("Getting latest invoice"); retInvoice = api.getLatestInvoice(2); assertNotNull("invoice not returned", retInvoice); assertEquals("invoice's user id", retInvoice.getUserId(), new Integer(2)); System.out.println("Got = " + retInvoice); Integer lastInvoice = retInvoice.getId(); // List of last // first, from a guy that is not mine try { api.getLastInvoices(13, 5); fail("User 13 belongs to entity 2"); } catch (Exception e) { } System.out.println("Getting last 5 invoices"); Integer invoices[] = api.getLastInvoices(2, 5); assertNotNull("invoice not returned", invoices); retInvoice = api.getInvoiceWS(invoices[0]); assertEquals("invoice's user id", new Integer(2), retInvoice.getUserId()); System.out.println("Got = " + invoices.length + " invoices"); for (int f = 0; f < invoices.length; f++) { System.out.println(" Invoice " + (f + 1) + invoices[f]); } // now I want just the two latest System.out.println("Getting last 2 invoices"); invoices = api.getLastInvoices(2, 2); assertNotNull("invoice not returned", invoices); retInvoice = api.getInvoiceWS(invoices[0]); assertEquals("invoice's user id", new Integer(2), retInvoice.getUserId()); assertEquals("invoice's has to be latest", lastInvoice, retInvoice.getId()); assertEquals("there should be only 2", 2, invoices.length); // get some by date System.out.println("Getting by date (empty)"); Integer invoices2[] = api.getInvoicesByDate("2000-01-01", "2005-01-01"); // CXF returns null instead of empty arrays // assertNotNull("invoice not returned", invoices2); if (invoices2 != null) { assertTrue("array not empty", invoices2.length == 0); } System.out.println("Getting by date"); invoices2 = api.getInvoicesByDate("2006-01-01", "2007-01-01"); assertNotNull("invoice not returned", invoices2); assertFalse("array not empty", invoices2.length == 0); System.out.println("Got array " + invoices2.length + " getting " + invoices2[0]); retInvoice = api.getInvoiceWS(invoices2[0]); assertNotNull("invoice not there", retInvoice); System.out.println("Got invoice " + retInvoice); System.out.println("Done!"); } catch (Exception e) { e.printStackTrace(); fail("Exception caught:" + e); } }
/** Tests failed and successful payment for ACH */ @Test public void testAchFakePayments() { UserWS user = buildUser(PRANCING_PONY_ACCOUNT_TYPE); // remove payment instruments and add only ACH payment instrument user.getPaymentInstruments().clear(); user.getPaymentInstruments() .add( PaymentMethodHelper.createACH( ACH_PAYMENT_TYPE, "Frodo Baggins", "Shire Financial Bank", "123456789", "123456789", PRANCING_PONY_ACCOUNT_TYPE)); System.out.println("Creating user with ACH record and no CC..."); user.setId(api.createUser(user)); // get ach PaymentInformationWS ach = user.getPaymentInstruments().get(0); System.out.println("Testing ACH payment with even amount (should pass)"); PaymentWS payment = new PaymentWS(); payment.setAmount(new BigDecimal("15.00")); payment.setIsRefund(new Integer(0)); payment.setMethodId(Constants.PAYMENT_METHOD_ACH); payment.setPaymentDate(Calendar.getInstance().getTime()); payment.setResultId(Constants.RESULT_ENTERED); payment.setCurrencyId(CURRENCY_USD); payment.setUserId(user.getId()); payment.setPaymentNotes("Notes"); payment.setPaymentPeriod(PAYMENT_PERIOD); payment.getPaymentInstruments().add(ach); PaymentAuthorizationDTOEx resultOne = api.processPayment(payment, null); assertEquals( "ACH payment with even amount should pass", Constants.RESULT_OK, api.getPayment(resultOne.getPaymentId()).getResultId()); System.out.println("Testing ACH payment with odd amount (should fail)"); payment = new PaymentWS(); payment.setAmount(new BigDecimal("15.01")); payment.setIsRefund(new Integer(0)); payment.setMethodId(Constants.PAYMENT_METHOD_ACH); payment.setPaymentDate(Calendar.getInstance().getTime()); payment.setResultId(Constants.RESULT_ENTERED); payment.setCurrencyId(CURRENCY_USD); payment.setUserId(user.getId()); payment.setPaymentNotes("Notes"); payment.setPaymentPeriod(PAYMENT_PERIOD); payment.getPaymentInstruments().add(ach); PaymentAuthorizationDTOEx resultTwo = api.processPayment(payment, null); assertEquals( "ACH payment with odd amount should fail", Constants.RESULT_FAIL, api.getPayment(resultTwo.getPaymentId()).getResultId()); // cleanup api.deletePayment(resultTwo.getPaymentId()); api.deletePayment(resultOne.getPaymentId()); api.deleteUser(user.getId()); }
/** Tests processPayment API call. */ @Test public void testProcessPayment() { // setup UserWS user = buildUser(PRANCING_PONY_ACCOUNT_TYPE, "4111111111111111"); user.setId(api.createUser(user)); ItemTypeWS itemType = buildItemType(); itemType.setId(api.createItemCategory(itemType)); ItemDTOEx item = buildItem(itemType.getId(), api.getCallerCompanyId()); item.setId(api.createItem(item)); // first, create two unpaid invoices OrderWS order = buildOrder(user.getId(), Arrays.asList(item.getId()), new BigDecimal("10.00")); Integer invoiceId1 = api.createOrderAndInvoice( order, OrderChangeBL.buildFromOrder(order, ORDER_CHANGE_STATUS_APPLY)); Integer invoiceId2 = api.createOrderAndInvoice( order, OrderChangeBL.buildFromOrder(order, ORDER_CHANGE_STATUS_APPLY)); // create the payment PaymentWS payment = new PaymentWS(); payment.setAmount(new BigDecimal("5.00")); payment.setIsRefund(new Integer(0)); payment.setMethodId(Constants.PAYMENT_METHOD_VISA); payment.setPaymentDate(Calendar.getInstance().getTime()); payment.setCurrencyId(CURRENCY_USD); payment.setUserId(user.getId()); // try a credit card number that fails // note that creating a payment with a NEW credit card will save it and associate // it with the user who made the payment. Calendar cal = Calendar.getInstance(); cal.add(Calendar.YEAR, 5); PaymentInformationWS cc = PaymentMethodHelper.createCreditCard( CC_PAYMENT_TYPE, "Frodo Baggins", "4111111111111111", cal.getTime()); cc.setPaymentMethodId(Constants.PAYMENT_METHOD_VISA); payment.getPaymentInstruments().add(cc); System.out.println("processing payment."); PaymentAuthorizationDTOEx authInfo = api.processPayment(payment, null); // check payment failed assertNotNull("Payment result not null", authInfo); assertFalse( "Payment Authorization result should be FAILED", authInfo.getResult().booleanValue()); // check payment has zero balance PaymentWS lastPayment = api.getLatestPayment(user.getId()); assertNotNull("payment can not be null", lastPayment); assertNotNull("auth in payment can not be null", lastPayment.getAuthorizationId()); assertEquals("correct payment amount", new BigDecimal("5"), lastPayment.getAmountAsDecimal()); assertEquals("correct payment balance", BigDecimal.ZERO, lastPayment.getBalanceAsDecimal()); // check invoices still have balance InvoiceWS invoice1 = api.getInvoiceWS(invoiceId1); assertEquals("correct invoice balance", new BigDecimal("10.0"), invoice1.getBalanceAsDecimal()); InvoiceWS invoice2 = api.getInvoiceWS(invoiceId1); assertEquals("correct invoice balance", new BigDecimal("10.0"), invoice2.getBalanceAsDecimal()); // do it again, but using the credit card on file // which is also 4111111111111111 payment.getPaymentInstruments().clear(); System.out.println("processing payment."); authInfo = api.processPayment(payment, null); // check payment has zero balance PaymentWS lastPayment2 = api.getLatestPayment(user.getId()); assertNotNull("payment can not be null", lastPayment2); assertNotNull("auth in payment can not be null", lastPayment2.getAuthorizationId()); assertEquals("correct payment amount", new BigDecimal("5"), lastPayment2.getAmountAsDecimal()); assertEquals("correct payment balance", BigDecimal.ZERO, lastPayment2.getBalanceAsDecimal()); assertFalse("Payment is not the same as preiouvs", lastPayment2.getId() == lastPayment.getId()); // check invoices still have balance invoice1 = api.getInvoiceWS(invoiceId1); assertEquals("correct invoice balance", new BigDecimal("10"), invoice1.getBalanceAsDecimal()); invoice2 = api.getInvoiceWS(invoiceId1); assertEquals("correct invoice balance", new BigDecimal("10"), invoice2.getBalanceAsDecimal()); // do a successful payment of $5 cc = PaymentMethodHelper.createCreditCard( CC_PAYMENT_TYPE, "Frodo Baggins", "4111111111111152", cal.getTime()); cc.setPaymentMethodId(Constants.PAYMENT_METHOD_VISA); payment.getPaymentInstruments().add(cc); System.out.println("processing payment."); authInfo = api.processPayment(payment, null); // check payment successful assertNotNull("Payment result not null", authInfo); assertNotNull("Auth id not null", authInfo.getId()); assertTrue("Payment Authorization result should be OK", authInfo.getResult().booleanValue()); // check payment was made lastPayment = api.getLatestPayment(user.getId()); assertNotNull("payment can not be null", lastPayment); assertNotNull("auth in payment can not be null", lastPayment.getAuthorizationId()); assertEquals("payment ids match", lastPayment.getId(), authInfo.getPaymentId().intValue()); assertEquals("correct payment amount", new BigDecimal("5"), lastPayment.getAmountAsDecimal()); assertEquals("correct payment balance", BigDecimal.ZERO, lastPayment.getBalanceAsDecimal()); // check invoice 1 was partially paid (balance 5) invoice1 = api.getInvoiceWS(invoiceId1); assertEquals("correct invoice balance", new BigDecimal("5.0"), invoice1.getBalanceAsDecimal()); // check invoice 2 wan't paid at all invoice2 = api.getInvoiceWS(invoiceId2); assertEquals("correct invoice balance", new BigDecimal("10.0"), invoice2.getBalanceAsDecimal()); // another payment for $10, this time with the user's credit card // update the credit card to the one that is good user = api.getUserWS(user.getId()); com.sapienter.jbilling.server.user.WSTest.updateMetaField( user.getPaymentInstruments().iterator().next().getMetaFields(), PaymentMethodHelper.CC_MF_NUMBER, "4111111111111152"); api.updateUser(user); // process a payment without an attached credit card // should try and use the user's saved credit card payment.getPaymentInstruments().clear(); payment.setAmount(new BigDecimal("10.00")); System.out.println("processing payment."); authInfo = api.processPayment(payment, null); // check payment successful assertNotNull("Payment result not null", authInfo); assertTrue("Payment Authorization result should be OK", authInfo.getResult().booleanValue()); // check payment was made lastPayment = api.getLatestPayment(user.getId()); assertNotNull("payment can not be null", lastPayment); assertNotNull("auth in payment can not be null", lastPayment.getAuthorizationId()); assertEquals("correct payment amount", new BigDecimal("10"), lastPayment.getAmountAsDecimal()); assertEquals("correct payment balance", BigDecimal.ZERO, lastPayment.getBalanceAsDecimal()); // check invoice 1 is fully paid (balance 0) invoice1 = api.getInvoiceWS(invoiceId1); assertEquals("correct invoice balance", BigDecimal.ZERO, invoice1.getBalanceAsDecimal()); // check invoice 2 was partially paid (balance 5) invoice2 = api.getInvoiceWS(invoiceId2); assertEquals("correct invoice balance", new BigDecimal("5"), invoice2.getBalanceAsDecimal()); // another payment for $10 payment.getPaymentInstruments().add(cc); payment.setAmount(new BigDecimal("10.00")); System.out.println("processing payment."); authInfo = api.processPayment(payment, null); // check payment successful assertNotNull("Payment result not null", authInfo); assertTrue("Payment Authorization result should be OK", authInfo.getResult().booleanValue()); // check payment was made lastPayment = api.getLatestPayment(user.getId()); assertNotNull("payment can not be null", lastPayment); assertNotNull("auth in payment can not be null", lastPayment.getAuthorizationId()); assertEquals("correct payment amount", new BigDecimal("10"), lastPayment.getAmountAsDecimal()); assertEquals( "correct payment balance", new BigDecimal("5"), lastPayment.getBalanceAsDecimal()); // check invoice 1 balance is unchanged invoice1 = api.getInvoiceWS(invoiceId1); assertEquals("correct invoice balance", BigDecimal.ZERO, invoice1.getBalanceAsDecimal()); // check invoice 2 is fully paid (balance 0) invoice2 = api.getInvoiceWS(invoiceId2); assertEquals("correct invoice balance", BigDecimal.ZERO, invoice2.getBalanceAsDecimal()); // cleanup System.out.println("Deleting invoices and orders."); api.deleteInvoice(invoice1.getId()); api.deleteInvoice(invoice2.getId()); api.deleteOrder(invoice1.getOrders()[0]); api.deleteOrder(invoice2.getOrders()[0]); api.deleteItem(item.getId()); api.deleteItemCategory(itemType.getId()); api.deleteUser(user.getId()); }
/** Test payInvoice(invoice) API call. */ @Test public void testPayInvoice() { // setup UserWS user = buildUser(PRANCING_PONY_ACCOUNT_TYPE); user.setId(api.createUser(user)); ItemTypeWS itemType = buildItemType(); itemType.setId(api.createItemCategory(itemType)); ItemDTOEx item = buildItem(itemType.getId(), api.getCallerCompanyId()); item.setId(api.createItem(item)); // testing System.out.println("Getting an invoice paid, and validating the payment."); OrderWS order = buildOrder(user.getId(), Arrays.asList(item.getId()), new BigDecimal("3.45")); Integer invoiceId = api.createOrderAndInvoice( order, OrderChangeBL.buildFromOrder(order, ORDER_CHANGE_STATUS_APPLY)); Integer orderId = api.getInvoiceWS(invoiceId).getOrders()[0]; PaymentAuthorizationDTOEx auth = api.payInvoice(invoiceId); assertNotNull("auth can not be null", auth); PaymentWS payment = api.getLatestPayment(user.getId()); assertNotNull("payment can not be null", payment); assertNotNull("auth in payment can not be null", payment.getAuthorizationId()); // cleanup api.deletePayment(auth.getPaymentId()); api.deleteInvoice(invoiceId); api.deleteOrder(orderId); api.deleteItem(item.getId()); api.deleteItemCategory(itemType.getId()); api.deleteUser(user.getId()); }
/** Removing pre-authorization when the CC number is changed. */ @Test public void testRemoveOnCCChange() { UserWS user = buildUser(PRANCING_PONY_ACCOUNT_TYPE); user.setId(api.createUser(user)); ItemTypeWS itemType = buildItemType(); itemType.setId(api.createItemCategory(itemType)); ItemDTOEx item = buildItem(itemType.getId(), api.getCallerCompanyId()); item.setId(api.createItem(item)); // put a pre-auth record on this user OrderWS order = buildOrder(user.getId(), Arrays.asList(item.getId()), new BigDecimal("3.45")); PaymentAuthorizationDTOEx auth = api.createOrderPreAuthorize( order, OrderChangeBL.buildFromOrder(order, ORDER_CHANGE_STATUS_APPLY)); Integer orderId = api.getLatestOrder(user.getId()).getId(); PaymentWS preAuthPayment = api.getPayment(auth.getPaymentId()); assertThat(preAuthPayment, is(not(nullValue()))); assertThat(preAuthPayment.getIsPreauth(), is(1)); assertThat(preAuthPayment.getDeleted(), is(0)); // NOT deleted // update the user's credit card, this should remove the old card // and delete any associated pre-authorizations DateTimeFormatter format = DateTimeFormat.forPattern(Constants.CC_DATE_FORMAT); user = api.getUserWS(user.getId()); com.sapienter.jbilling.server.user.WSTest.updateMetaField( user.getPaymentInstruments().iterator().next().getMetaFields(), PaymentMethodHelper.CC_MF_EXPIRY_DATE, format.print(new DateMidnight().plusYears(4).withDayOfMonth(1).toDate().getTime())); api.updateUser(user); System.out.println("User instruments are: " + user.getPaymentInstruments()); // validate that the pre-auth payment is no longer available preAuthPayment = api.getPayment(auth.getPaymentId()); assertThat(preAuthPayment, is(not(nullValue()))); assertThat(preAuthPayment.getIsPreauth(), is(1)); assertThat(preAuthPayment.getDeleted(), is(1)); // is now deleted // cleanup api.deleteOrder(orderId); api.deleteItem(item.getId()); api.deleteItemCategory(itemType.getId()); api.deleteUser(user.getId()); }
/** * Test for: CreditCardFilter.For now it uses a value already in DB for the blacklisted cc number. * In prepare-test db the cc number 5555555555554444 is blacklisted. */ @Test public void testBlacklistCreditCardFilter() { UserWS user = buildUser(PRANCING_PONY_ACCOUNT_TYPE, "5555555555554444"); user.setId(api.createUser(user)); ItemTypeWS itemType = buildItemType(); itemType.setId(api.createItemCategory(itemType)); ItemDTOEx item = buildItem(itemType.getId(), api.getCallerCompanyId()); item.setId(api.createItem(item)); InvoiceWS invoice = buildInvoice(user.getId(), item.getId()); invoice.setId(api.saveLegacyInvoice(invoice)); // get invoice id invoice = api.getLatestInvoice(user.getId()); assertNotNull("Couldn't get last invoice", invoice); Integer invoiceId = invoice.getId(); assertNotNull("Invoice id was null", invoiceId); // try paying the invoice System.out.println("Trying to pay invoice for blacklisted user ..."); PaymentAuthorizationDTOEx authInfo = api.payInvoice(invoiceId); assertNotNull("Payment result empty", authInfo); // check that it was failed by the test blacklist filter assertFalse( "Payment wasn't failed for user: "******"Processor response", "Credit card number is blacklisted.", authInfo.getResponseMessage()); // cleanup api.deleteInvoice(invoiceId); api.deleteItem(item.getId()); api.deleteItemCategory(itemType.getId()); api.deleteUser(user.getId()); }
@Test public void test001CreateCustomerWithAitMetaFields_DefaultDate() throws Exception { System.out.println("#test001CreateCustomerWithAitMetaFields_DefaultDate"); JbillingAPI api = JbillingAPIFactory.getAPI(); Integer userId = null; try { UserWS newUser = createUser(); System.out.println("Setting Ait fields values for date:" + CommonConstants.EPOCH_DATE); MetaFieldValueWS metaField1 = new MetaFieldValueWS(); metaField1.setFieldName("partner.prompt.fee"); metaField1.setValue("serial-from-ws"); MetaFieldValueWS metaField2 = new MetaFieldValueWS(); metaField2.setFieldName("ccf.payment_processor"); metaField2.setValue("FAKE_2"); // the plug-in parameter of the processor String email = newUser.getUserName() + "@shire.com"; String firstName = "Frodo"; String lastName = "Baggins"; MetaFieldValueWS metaField3 = new MetaFieldValueWS(); metaField3.setFieldName("contact.email"); metaField3.setValue(email); metaField3.setGroupId(1); MetaFieldValueWS metaField4 = new MetaFieldValueWS(); metaField4.setFieldName("contact.first.name"); metaField4.setValue(firstName); metaField4.setGroupId(1); MetaFieldValueWS metaField5 = new MetaFieldValueWS(); metaField5.setFieldName("contact.last.name"); metaField5.setValue(lastName); metaField5.setGroupId(1); newUser.setMetaFields( new MetaFieldValueWS[] {metaField1, metaField2, metaField3, metaField4, metaField5}); System.out.println("Setting default date as the only date of timeline"); ArrayList<Date> timelineDates = new ArrayList<Date>(0); timelineDates.add(CommonConstants.EPOCH_DATE); newUser.getTimelineDatesMap().put(new Integer(1), timelineDates); System.out.println("Creating user ..."); userId = api.createUser(newUser); newUser.setUserId(userId); System.out.println("Getting created user"); UserWS ret = api.getUserWS(newUser.getUserId()); ArrayList<MetaFieldValueWS> aitMetaFields = ret.getAccountInfoTypeFieldsMap().get(new Integer(1)).get(CommonConstants.EPOCH_DATE); // check that timeline contains default date if (!ret.getAccountInfoTypeFieldsMap() .get(new Integer(1)) .containsKey(CommonConstants.EPOCH_DATE)) { fail("Default date: " + CommonConstants.EPOCH_DATE + " should be present in timeline"); } // Total no of ait meta fields returned should be 18, no of meta fields for ait = 1, only 3 // has values assertEquals(3, aitMetaFields.size()); // ait meta fields should be 11. Customer Specific: 8 (2 has value). Ait meta field for // effective date: 18 (3 has values) assertEquals(5, ret.getMetaFields().length); // assert that email, first name and last name has same values for (MetaFieldValueWS ws : aitMetaFields) { if (ws.getFieldName().equals("contact.email")) { assertEquals("Email should be same", email, ws.getValue()); } else if (ws.getFieldName().equals("contact.first.name")) { assertEquals("First name should be same", firstName, ws.getValue()); } else if (ws.getFieldName().equals("contact.last.name")) { assertEquals("Last name should be same", lastName, ws.getValue()); } } } catch (Exception e) { e.printStackTrace(); fail("Exception caught:" + e); } finally { System.out.println("Deleting created user"); if (userId != null) api.deleteUser(userId); } }
/** * Tests that when a past due invoice is processed it will generate a new invoice for the current * period that contains all previously un-paid balances as the carried balance. * * <p>Invoices that have been carried still show the original balance for reporting/paper-trail * purposes, but will not be re-processed by the system as part of the normal billing process. * * @throws Exception */ public void testCreateWithCarryOver() throws Exception { final Integer USER_ID = 10743; // user has one past-due invoice to be carried forward final Integer OVERDUE_INVOICE_ID = 70; // holds a $20 balance JbillingAPI api = JbillingAPIFactory.getAPI(); // new order witha single line item OrderWS order = new OrderWS(); order.setUserId(USER_ID); order.setBillingTypeId(Constants.ORDER_BILLING_PRE_PAID); order.setPeriod(1); // once order.setCurrencyId(1); order.setActiveSince(new Date()); OrderLineWS line = new OrderLineWS(); line.setTypeId(Constants.ORDER_LINE_TYPE_ITEM); line.setDescription("Order line"); line.setItemId(1); line.setQuantity(1); line.setPrice(new BigDecimal("10.00")); line.setAmount(new BigDecimal("10.00")); order.setOrderLines(new OrderLineWS[] {line}); // create order Integer orderId = api.createOrder(order); // create invoice Integer invoiceId = api.createInvoice(USER_ID, false)[0]; // validate that the overdue invoice has been carried forward to the newly created invoice InvoiceWS overdue = api.getInvoiceWS(OVERDUE_INVOICE_ID); assertEquals( "Status updated to 'unpaid and carried'", Constants.INVOICE_STATUS_UNPAID_AND_CARRIED, overdue.getStatusId()); assertEquals("Carried invoice will not be re-processed", 0, overdue.getToProcess().intValue()); assertEquals( "Overdue invoice holds original balance", new BigDecimal("20.00"), overdue.getBalanceAsDecimal()); assertEquals( "Overdue invoice delegated to the newly created invoice", invoiceId, overdue.getDelegatedInvoiceId()); // validate that the newly created invoice contains the carried balance InvoiceWS invoice = api.getInvoiceWS(invoiceId); assertEquals( "New invoice balance is equal to the current period charges", new BigDecimal("10.00"), invoice.getBalanceAsDecimal()); assertEquals( "New invoice holds the carried balance equal to the old invoice balance", overdue.getBalanceAsDecimal(), invoice.getCarriedBalanceAsDecimal()); assertEquals( "New invoice total is equal to the current charges plus the carried total", new BigDecimal("30.00"), invoice.getTotalAsDecimal()); }
/** Tests payment apply and retrieve. */ @Test public void testApplyGet() { // setup UserWS mordorUser = buildUser(MORDOR_ACCOUNT_TYPE); mordorUser.setId(mordorApi.createUser(mordorUser)); UserWS user = buildUser(PRANCING_PONY_ACCOUNT_TYPE); user.setId(api.createUser(user)); ItemTypeWS itemType = buildItemType(); itemType.setId(api.createItemCategory(itemType)); ItemDTOEx item = buildItem(itemType.getId(), api.getCallerCompanyId()); item.setId(api.createItem(item)); InvoiceWS invoice = buildInvoice(user.getId(), item.getId()); invoice.setId(api.saveLegacyInvoice(invoice)); // testing PaymentWS payment = new PaymentWS(); payment.setAmount(new BigDecimal("15.00")); payment.setIsRefund(new Integer(0)); payment.setMethodId(Constants.PAYMENT_METHOD_CHEQUE); payment.setPaymentDate(Calendar.getInstance().getTime()); payment.setResultId(Constants.RESULT_ENTERED); payment.setCurrencyId(CURRENCY_USD); payment.setUserId(user.getId()); payment.setPaymentNotes("Notes"); payment.setPaymentPeriod(PAYMENT_PERIOD); PaymentInformationWS cheque = PaymentMethodHelper.createCheque( CHEQUE_PAYMENT_TYPE, "ws bank", "2232-2323-2323", Calendar.getInstance().getTime()); payment.getPaymentInstruments().add(cheque); System.out.println("Applying payment"); Integer paymentId = api.applyPayment(payment, invoice.getId()); System.out.println("Created payemnt " + paymentId); assertNotNull("Didn't get the payment id", paymentId); // get // verify the created payment System.out.println("Getting created payment"); PaymentWS retPayment = api.getPayment(paymentId); assertNotNull("didn't get payment ", retPayment); assertEquals("created payment result", retPayment.getResultId(), payment.getResultId()); System.out.println("Instruments are: " + retPayment.getPaymentInstruments()); assertEquals( "created payment cheque ", getMetaField( retPayment.getPaymentInstruments().iterator().next().getMetaFields(), PaymentMethodHelper.CHEQUE_MF_NUMBER) .getStringValue(), getMetaField( payment.getPaymentInstruments().iterator().next().getMetaFields(), PaymentMethodHelper.CHEQUE_MF_NUMBER) .getStringValue()); assertEquals("created payment user ", retPayment.getUserId(), payment.getUserId()); assertEquals("notes", retPayment.getPaymentNotes(), payment.getPaymentNotes()); assertEquals("period", retPayment.getPaymentPeriod(), payment.getPaymentPeriod()); System.out.println("Validated created payment and paid invoice"); assertNotNull("payment not related to invoice", retPayment.getInvoiceIds()); assertTrue("payment not related to invoice", retPayment.getInvoiceIds().length == 1); assertEquals("payment not related to invoice", retPayment.getInvoiceIds()[0], invoice.getId()); InvoiceWS retInvoice = api.getInvoiceWS(retPayment.getInvoiceIds()[0]); assertNotNull("New invoice not present", retInvoice); assertEquals( "Balance of invoice should be total of order", BigDecimal.ZERO, retInvoice.getBalanceAsDecimal()); assertEquals( "Total of invoice should be total of order", new BigDecimal("15"), retInvoice.getTotalAsDecimal()); assertEquals("New invoice not paid", retInvoice.getToProcess(), new Integer(0)); assertNotNull("invoice not related to payment", retInvoice.getPayments()); assertTrue("invoice not related to payment", retInvoice.getPayments().length == 1); assertEquals( "invoice not related to payment", retInvoice.getPayments()[0].intValue(), retPayment.getId()); // get latest // verify the created payment System.out.println("Getting latest"); retPayment = api.getLatestPayment(user.getId()); assertNotNull("didn't get payment ", retPayment); assertEquals("latest id", paymentId.intValue(), retPayment.getId()); assertEquals("created payment result", retPayment.getResultId(), payment.getResultId()); assertEquals( "created payment cheque ", getMetaField( retPayment.getPaymentInstruments().iterator().next().getMetaFields(), PaymentMethodHelper.CHEQUE_MF_NUMBER) .getStringValue(), getMetaField( payment.getPaymentInstruments().iterator().next().getMetaFields(), PaymentMethodHelper.CHEQUE_MF_NUMBER) .getStringValue()); assertEquals("created payment user ", retPayment.getUserId(), payment.getUserId()); try { System.out.println("Getting latest - invalid"); api.getLatestPayment(mordorUser.getId()); fail("User belongs to entity Mordor"); } catch (Exception e) { } // get last System.out.println("Getting last"); Integer retPayments[] = api.getLastPayments(user.getId(), Integer.valueOf(2)); assertNotNull("didn't get payment ", retPayments); // fetch the payment retPayment = api.getPayment(retPayments[0]); assertEquals("created payment result", retPayment.getResultId(), payment.getResultId()); assertEquals( "created payment cheque ", getMetaField( retPayment.getPaymentInstruments().iterator().next().getMetaFields(), PaymentMethodHelper.CHEQUE_MF_NUMBER) .getStringValue(), getMetaField( payment.getPaymentInstruments().iterator().next().getMetaFields(), PaymentMethodHelper.CHEQUE_MF_NUMBER) .getStringValue()); assertEquals("created payment user ", retPayment.getUserId(), payment.getUserId()); assertTrue("No more than two records", retPayments.length <= 2); try { System.out.println("Getting last - invalid"); api.getLastPayments(mordorUser.getId(), Integer.valueOf(2)); fail("User belongs to entity Mordor"); } catch (Exception e) { } // cleanup api.deletePayment(paymentId); api.deleteInvoice(invoice.getId()); api.deleteUser(user.getId()); mordorApi.deleteUser(mordorUser.getId()); }
@Test public void test003CreateCustomerWithAitMetaFields_UpdateTodaysFields() throws Exception { System.out.println("#test003CreateCustomerWithAitMetaFields_UpdateTodaysFields"); JbillingAPI api = JbillingAPIFactory.getAPI(); Integer userId = null; try { UserWS newUser = createUser(); System.out.println("Setting Ait fields values for date:" + CommonConstants.EPOCH_DATE); MetaFieldValueWS metaField1 = new MetaFieldValueWS(); metaField1.setFieldName("partner.prompt.fee"); metaField1.setValue("serial-from-ws"); MetaFieldValueWS metaField2 = new MetaFieldValueWS(); metaField2.setFieldName("ccf.payment_processor"); metaField2.setValue("FAKE_2"); // the plug-in parameter of the processor MetaFieldValueWS metaField3 = new MetaFieldValueWS(); metaField3.setFieldName("contact.email"); metaField3.setValue("*****@*****.**"); metaField3.setGroupId(1); newUser.setMetaFields(new MetaFieldValueWS[] {metaField1, metaField2, metaField3}); Date today = new DateTime().toDateMidnight().toDate(); System.out.println("Setting default date and todays date on timeline"); ArrayList<Date> timelineDates = new ArrayList<Date>(0); timelineDates.add(CommonConstants.EPOCH_DATE); timelineDates.add(today); newUser.getTimelineDatesMap().put(new Integer(1), timelineDates); System.out.println("Creating user ..."); userId = api.createUser(newUser); newUser.setUserId(userId); System.out.println("Getting created user"); UserWS ret = api.getUserWS(newUser.getUserId()); // Update todays ait meta field value for the created users metaField3 = new MetaFieldValueWS(); metaField3.setFieldName("contact.email"); metaField3.setValue("*****@*****.**"); metaField3.setGroupId(1); ret.setMetaFields(new MetaFieldValueWS[] {metaField1, metaField2, metaField3}); ret.getEffectiveDateMap().put(1, today); api.updateUser(ret); // get updated user ret = api.getUserWS(newUser.getUserId()); // check that timeline contains default date and today's date if (!ret.getAccountInfoTypeFieldsMap() .get(new Integer(1)) .containsKey(CommonConstants.EPOCH_DATE)) { fail("Default date: " + CommonConstants.EPOCH_DATE + " should be present in timeline"); } if (!ret.getAccountInfoTypeFieldsMap().get(new Integer(1)).containsKey(today)) { fail("Default date: " + today + " should be present in timeline"); } // verify meta fields for default date ArrayList<MetaFieldValueWS> aitMetaFields = ret.getAccountInfoTypeFieldsMap().get(new Integer(1)).get(CommonConstants.EPOCH_DATE); // Total no of ait meta fields returned should be 1, no of meta fields for ait 1 is 18, but // only // one has a value assertEquals(1, aitMetaFields.size()); // assert that email, first name and last name has same values for (MetaFieldValueWS ws : aitMetaFields) { if (ws.getFieldName().equals("contact.email")) { assertEquals("Email should be same", "*****@*****.**", ws.getValue()); } } // verify meta fields for todays date aitMetaFields = ret.getAccountInfoTypeFieldsMap().get(new Integer(1)).get(today); // Total no of ait meta fields returned should be 1, no of meta fields for ait 1 is 18, but // only // one has a value assertEquals(1, aitMetaFields.size()); // assert that email, first name and last name has same values for (MetaFieldValueWS ws : aitMetaFields) { if (ws.getFieldName().equals("contact.email")) { assertEquals("Email should be same", "*****@*****.**", ws.getValue()); } } } catch (Exception e) { e.printStackTrace(); fail("Exception caught:" + e); } finally { // Change System.out.println("Deleting created user"); if (userId != null) api.deleteUser(userId); } }
/** Tests the PaymentRouterCurrencyTask. */ @Test public void testPaymentRouterCurrencyTask() { // prepare UserWS userUSD = buildUser(PRANCING_PONY_ACCOUNT_TYPE); userUSD.setCurrencyId(CURRENCY_USD); userUSD.setId(api.createUser(userUSD)); UserWS userAUD = buildUser(PRANCING_PONY_ACCOUNT_TYPE); userAUD.setCurrencyId(CURRENCY_AUD); userAUD.setId(api.createUser(userAUD)); ItemTypeWS itemType = buildItemType(); itemType.setId(api.createItemCategory(itemType)); ItemDTOEx item = buildItem(itemType.getId(), api.getCallerCompanyId()); item.setId(api.createItem(item)); // testing OrderWS order = buildOrder(userUSD.getId(), Arrays.asList(item.getId()), new BigDecimal("10")); order.setCurrencyId(userUSD.getCurrencyId()); // create the order and invoice it System.out.println("Creating and invoicing order ..."); Integer invoiceIdUSD = api.createOrderAndInvoice( order, OrderChangeBL.buildFromOrder(order, ORDER_CHANGE_STATUS_APPLY)); Integer orderIdUSD = api.getLastOrders(userUSD.getId(), 1)[0]; // try paying the invoice in USD System.out.println("Making payment in USD..."); PaymentAuthorizationDTOEx authInfo = api.payInvoice(invoiceIdUSD); assertTrue("USD Payment should be successful", authInfo.getResult().booleanValue()); assertEquals( "Should be processed by 'first_fake_processor'", authInfo.getProcessor(), "first_fake_processor"); // create a new order in AUD and invoice it order.setUserId(userAUD.getId()); order.setCurrencyId(userAUD.getCurrencyId()); System.out.println("Creating and invoicing order ..."); Integer invoiceIdAUD = api.createOrderAndInvoice( order, OrderChangeBL.buildFromOrder(order, ORDER_CHANGE_STATUS_APPLY)); Integer orderIdAUD = api.getLastOrders(userAUD.getId(), 1)[0]; // try paying the invoice in AUD System.out.println("Making payment in AUD..."); authInfo = api.payInvoice(invoiceIdAUD); assertTrue("AUD Payment should be successful", authInfo.getResult().booleanValue()); assertEquals( "Should be processed by 'second_fake_processor'", authInfo.getProcessor(), "second_fake_processor"); // remove invoices and orders System.out.println("Deleting invoices and orders."); api.deleteInvoice(invoiceIdUSD); api.deleteInvoice(invoiceIdAUD); api.deleteOrder(orderIdUSD); api.deleteOrder(orderIdAUD); api.deleteUser(userUSD.getId()); api.deleteUser(userAUD.getId()); api.deleteItem(item.getId()); api.deleteItemCategory(itemType.getId()); }