@Test(groups = "fast", description = "Test if Account constructor can accept null values") public void testConstructorAcceptsNullValues() throws Exception { final AccountData accountData = getNullAccountData(); final Account account = new DefaultAccount(UUID.randomUUID(), accountData); Assert.assertNull(account.getExternalKey()); Assert.assertNull(account.getEmail()); Assert.assertNull(account.getName()); Assert.assertNull(account.getFirstNameLength()); Assert.assertNull(account.getCurrency()); Assert.assertEquals(account.getBillCycleDayLocal(), (Integer) 0); Assert.assertNull(account.getPaymentMethodId()); Assert.assertNull(account.getTimeZone()); Assert.assertNull(account.getLocale()); Assert.assertNull(account.getAddress1()); Assert.assertNull(account.getAddress2()); Assert.assertNull(account.getCompanyName()); Assert.assertNull(account.getCity()); Assert.assertNull(account.getStateOrProvince()); Assert.assertNull(account.getCountry()); Assert.assertNull(account.getPostalCode()); Assert.assertNull(account.getPhone()); Assert.assertNull(account.isMigrated()); }
private void checkAccountEquals(final Account finalAccount, final Account delegateAccount) { Assert.assertEquals(finalAccount.getExternalKey(), delegateAccount.getExternalKey()); Assert.assertEquals(finalAccount.getEmail(), delegateAccount.getEmail()); Assert.assertEquals(finalAccount.getName(), delegateAccount.getName()); Assert.assertEquals(finalAccount.getFirstNameLength(), delegateAccount.getFirstNameLength()); Assert.assertEquals(finalAccount.getCurrency(), delegateAccount.getCurrency()); Assert.assertEquals(finalAccount.getBillCycleDayLocal(), delegateAccount.getBillCycleDayLocal()); Assert.assertEquals(finalAccount.getPaymentMethodId(), delegateAccount.getPaymentMethodId()); Assert.assertEquals(finalAccount.getTimeZone(), delegateAccount.getTimeZone()); Assert.assertEquals(finalAccount.getLocale(), delegateAccount.getLocale()); Assert.assertEquals(finalAccount.getAddress1(), delegateAccount.getAddress1()); Assert.assertEquals(finalAccount.getAddress2(), delegateAccount.getAddress2()); Assert.assertEquals(finalAccount.getCompanyName(), delegateAccount.getCompanyName()); Assert.assertEquals(finalAccount.getCity(), delegateAccount.getCity()); Assert.assertEquals(finalAccount.getStateOrProvince(), delegateAccount.getStateOrProvince()); Assert.assertEquals(finalAccount.getCountry(), delegateAccount.getCountry()); Assert.assertEquals(finalAccount.getPostalCode(), delegateAccount.getPostalCode()); Assert.assertEquals(finalAccount.getPhone(), delegateAccount.getPhone()); Assert.assertEquals(finalAccount.getNotes(), delegateAccount.getNotes()); Assert.assertEquals(finalAccount.isMigrated(), delegateAccount.isMigrated()); }
Assert.assertEquals(updatedAccount2.getCurrency(), updatedAccount1.getCurrency()); Assert.assertEquals(updatedAccount2.getBillCycleDayLocal(), updatedAccount1.getBillCycleDayLocal()); Assert.assertEquals(updatedAccount2.getPaymentMethodId(), updatedAccount1.getPaymentMethodId()); Assert.assertEquals(updatedAccount2.getTimeZone(), updatedAccount1.getTimeZone()); Assert.assertEquals(updatedAccount2.getLocale(), updatedAccount1.getLocale());
Assert.assertEquals(retrievedAccount.getBillCycleDayLocal(), account.getBillCycleDayLocal()); Assert.assertEquals(retrievedAccount.getCurrency(), account.getCurrency()); Assert.assertEquals(retrievedAccount.getPaymentMethodId(), account.getPaymentMethodId()); Assert.assertEquals(retrievedAccount.getTimeZone(), account.getTimeZone()); Assert.assertEquals(retrievedAccount.getLocale(), account.getLocale());
accountData.setFirstNameLength(firstNameLength); accountData.setPaymentMethodId(paymentMethodId != null ? paymentMethodId : currentAccount.getPaymentMethodId()); accountData.setTimeZone(timeZone != null ? timeZone : currentAccount.getTimeZone()); accountData.setLocale(locale != null ? locale : currentAccount.getLocale());
@Test(groups = "slow", description = "Verify we can make a refund on payment whose original payment method was deleted. See 694") public void testRefundAfterDeletedPaymentMethod() throws PaymentApiException { final BigDecimal requestedAmount = BigDecimal.TEN; final Payment payment = paymentApi.createPurchase(account, account.getPaymentMethodId(), null, requestedAmount, Currency.EUR, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); paymentApi.deletePaymentMethod(account, account.getPaymentMethodId(), false, true, ImmutableList.<PluginProperty>of(), callContext); final Payment newPayment = paymentApi.createRefund(account, payment.getId(),requestedAmount, Currency.EUR, null, UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); Assert.assertEquals(newPayment.getTransactions().size(), 2); }
@Test(groups = "slow") public void testCreatePurchaseWithControlPluginRuntimeException() throws Exception { mockPaymentControlProviderPlugin.throwsException(new IllegalStateException()); final BigDecimal requestedAmount = BigDecimal.TEN; final String paymentExternalKey = "pay controle external key"; final String transactionExternalKey = "txn control external key"; try { paymentApi.createPurchaseWithPaymentControl( account, account.getPaymentMethodId(), null, requestedAmount, Currency.AED, null, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), CONTROL_PLUGIN_OPTIONS, callContext); fail(); } catch (PaymentApiException e) { assertTrue(e.getCause() instanceof IllegalStateException); } }
@Test(groups = "slow") public void testCreatePurchasePaymentPluginException() { mockPaymentProviderPlugin.makeNextPaymentFailWithException(); final BigDecimal requestedAmount = BigDecimal.TEN; final String paymentExternalKey = "pay external key"; final String transactionExternalKey = "txn external key"; try { paymentApi.createPurchase(account, account.getPaymentMethodId(), null, requestedAmount, Currency.AED, null, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext); fail(); } catch (PaymentApiException e) { assertTrue(e.getCause() instanceof PaymentPluginApiException); } }
@Test(groups = "slow") public void testSimpleAuthCaptureWithInvalidPaymentId() throws Exception { final BigDecimal requestedAmount = new BigDecimal("80.0091"); final Payment initialPayment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); try { paymentApi.createCapture(account, UUID.randomUUID(), requestedAmount, account.getCurrency(), null, UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); Assert.fail("Expected capture to fail..."); } catch (final PaymentApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.PAYMENT_NO_SUCH_PAYMENT.getCode()); final Payment latestPayment = paymentApi.getPayment(initialPayment.getId(), true, false, ImmutableList.<PluginProperty>of(), callContext); assertEquals(latestPayment, initialPayment); } }
@Test(groups = "slow") public void testSimpleAuthCaptureWithInvalidCurrency() throws Exception { final BigDecimal requestedAmount = new BigDecimal("80.0091"); final Payment initialPayment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); try { paymentApi.createCapture(account, initialPayment.getId(), requestedAmount, Currency.AMD, null, UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); Assert.fail("Expected capture to fail..."); } catch (final PaymentApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.PAYMENT_INVALID_PARAMETER.getCode()); final Payment latestPayment = paymentApi.getPayment(initialPayment.getId(), true, false, ImmutableList.<PluginProperty>of(), callContext); assertEquals(latestPayment, initialPayment); } }
@Override public Payment answer(final InvocationOnMock invocation) throws Throwable { final List<Payment> payments = paymentApi.getAccountPayments(account.getId(), false, false, ImmutableList.<PluginProperty>of(), (TenantContext) invocation.getArguments()[6]); final Payment payment; if (payments == null || payments.isEmpty()) { payment = buildPayment(account.getId(), account.getPaymentMethodId(), (Currency) invocation.getArguments()[3], killbillApi); } else { payment = payments.get(payments.size() - 1); } final PaymentTransaction chargeback = buildPaymentTransaction(payment, TransactionType.CHARGEBACK, (Currency) invocation.getArguments()[3]); Mockito.when(chargeback.getTransactionStatus()).thenReturn(TransactionStatus.SUCCESS); return payment; } });
@Override public PriorPaymentControlResult priorCall(final PaymentControlContext paymentControlContext, final Iterable<PluginProperty> properties) throws PaymentControlApiException { return new DefaultPriorPaymentControlResult(aborted, account.getPaymentMethodId(), null, null, null, getAdjustedProperties(properties, newPriorCallProperties, removedPriorCallProperties)); }
@Test(groups = "slow") public void testAddRemovePaymentMethodWithForcedDeletion() throws Exception { final Long baseNbRecords = paymentApi.getPaymentMethods(0L, 1000L, false, ImmutableList.<PluginProperty>of(), callContext).getMaxNbRecords(); Assert.assertEquals(baseNbRecords, (Long) 1L); final Account account = testHelper.createTestAccount(UUID.randomUUID().toString(), true); final UUID paymentMethodId = account.getPaymentMethodId(); checkPaymentMethodPagination(paymentMethodId, baseNbRecords + 1, false); paymentApi.deletePaymentMethod(account, paymentMethodId, false, true, ImmutableList.<PluginProperty>of(), callContext); checkPaymentMethodPagination(paymentMethodId, baseNbRecords, true); }
@Test(groups = "slow") public void testAddRemovePaymentMethodWithoutForcedDeletion() throws Exception { final Long baseNbRecords = paymentApi.getPaymentMethods(0L, 1000L, false, ImmutableList.<PluginProperty>of(), callContext).getMaxNbRecords(); Assert.assertEquals(baseNbRecords, (Long) 1L); final Account account = testHelper.createTestAccount(UUID.randomUUID().toString(), true); final UUID paymentMethodId = account.getPaymentMethodId(); try { paymentApi.deletePaymentMethod(account, paymentMethodId, false, false, ImmutableList.<PluginProperty>of(), callContext); } catch (final PaymentApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.PAYMENT_INTERNAL_ERROR.getCode()); } checkPaymentMethodPagination(paymentMethodId, baseNbRecords + 1, false); }
@Test(groups = "slow") public void testAddRemovePaymentMethod() throws Exception { final Long baseNbRecords = paymentApi.getPaymentMethods(0L, 1000L, false, ImmutableList.<PluginProperty>of(), callContext).getMaxNbRecords(); Assert.assertEquals(baseNbRecords, (Long) 1L); final Account account = testHelper.createTestAccount(UUID.randomUUID().toString(), true); final UUID paymentMethodId = account.getPaymentMethodId(); checkPaymentMethodPagination(paymentMethodId, baseNbRecords + 1, false); paymentApi.deletePaymentMethod(account, paymentMethodId, true, false, ImmutableList.<PluginProperty>of(), callContext); List<PaymentMethod> paymentMethods = paymentApi.getAccountPaymentMethods(account.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext); assertEquals(paymentMethods.size(), 0); paymentMethods = paymentApi.getAccountPaymentMethods(account.getId(), true, false, ImmutableList.<PluginProperty>of(), callContext); assertEquals(paymentMethods.size(), 1); checkPaymentMethodPagination(paymentMethodId, baseNbRecords, true); }
@Test(groups = "slow") public void testCreatePurchaseWithTimeout() throws Exception { final BigDecimal requestedAmount = BigDecimal.TEN; final String paymentExternalKey = "ohhhh"; final String transactionExternalKey = "naaahhh"; mockPaymentProviderPlugin.makePluginWaitSomeMilliseconds((int) (paymentConfig.getPaymentPluginTimeout().getMillis() + 100)); try { paymentApi.createPurchase(account, account.getPaymentMethodId(), null, requestedAmount, Currency.AED, null, paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext); fail(); } catch (PaymentApiException e) { assertEquals(e.getCode(), ErrorCode.PAYMENT_PLUGIN_TIMEOUT.getCode()); } }
@Test(groups = "slow") public void testSetDefaultPaymentMethodSameAccount() throws Exception { final Account account = testHelper.createTestAccount("foo@bar.com", true); // Add new payment method final UUID newPaymentMethod = paymentMethodProcessor.createOrGetExternalPaymentMethod("pmExternalKey", account, PLUGIN_PROPERTIES, callContext, internalCallContext); paymentMethodProcessor.setDefaultPaymentMethod(account, newPaymentMethod, PLUGIN_PROPERTIES, callContext, internalCallContext); final Account accountById = accountApi.getAccountById(account.getId(), internalCallContext); Assert.assertEquals(accountById.getPaymentMethodId(), newPaymentMethod); }
@Test(groups = "slow") public void testRefreshWithNewPaymentMethod() throws Exception { final Account account = testHelper.createTestAccount("foo@bar.com", true); Assert.assertEquals(getPluginApi().getPaymentMethods(account.getId(), true, PLUGIN_PROPERTIES, callContext).size(), 1); final UUID existingPMId = account.getPaymentMethodId(); // Add new payment in plugin directly final UUID newPmId = UUID.randomUUID(); getPluginApi().addPaymentMethod(account.getId(), newPmId, new DefaultNoOpPaymentMethodPlugin(UUID.randomUUID().toString(), false, ImmutableList.<PluginProperty>of()), false, PLUGIN_PROPERTIES, callContext); // Verify that the refresh does indeed show 2 PMs final List<PaymentMethod> methods = paymentMethodProcessor.refreshPaymentMethods(MockPaymentProviderPlugin.PLUGIN_NAME, account, PLUGIN_PROPERTIES, callContext, internalCallContext); Assert.assertEquals(methods.size(), 2); checkPaymentMethodExistsWithStatus(methods, existingPMId, true); checkPaymentMethodExistsWithStatus(methods, newPmId, true); }
@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/255") public void testRefundWithDeletedPaymentMethod() throws Exception { // delete payment method busHandler.pushExpectedEvent(NextEvent.TAG); paymentApi.deletePaymentMethod(account, account.getPaymentMethodId(), true, true, new ArrayList<PluginProperty>(), callContext); assertListenerStatus(); // try to create a refund for a payment with its payment method deleted busHandler.pushExpectedEvent(NextEvent.PAYMENT); paymentApi.createRefund(account, payment.getId(), payment.getPurchasedAmount(), payment.getCurrency(), null, UUID.randomUUID().toString(), PLUGIN_PROPERTIES, callContext); assertListenerStatus(); }
/** * ******************************************** ACCOUNT ******************************************************* */ public void checkAccountCreated(final Account account, final CallContext context) { final AccountAuditLogs result = auditUserApi.getAccountAuditLogs(account.getId(), AuditLevel.FULL, context); checkAuditLog(ChangeType.INSERT, context, result.getAuditLogsForAccount().get(0), account.getId(), AccountSqlDao.class, true, true); // Payment method if (account.getPaymentMethodId() != null) { checkAuditLog(ChangeType.UPDATE, context, result.getAuditLogsForAccount().get(1), account.getId(), AccountSqlDao.class, true, true); } }