use of org.killbill.billing.account.api.Account in project killbill by killbill.
the class TestPaymentMethodProcessorNoDB method testPaymentMethodExternalKeySetByPluginIfNonSpecified.
@Test(groups = "fast")
public void testPaymentMethodExternalKeySetByPluginIfNonSpecified() throws Exception {
final Account account = Mockito.mock(Account.class);
final UUID accountId = UUID.randomUUID();
Mockito.when(account.getId()).thenReturn(accountId);
Mockito.when(account.getExternalKey()).thenReturn(accountId.toString());
final PaymentMethodPlugin paymentMethodPlugin = Mockito.mock(PaymentMethodPlugin.class);
final Iterable<PluginProperty> properties = ImmutableList.<PluginProperty>of();
// By default, the external payment plugin sets the external payment method id to "unknown"
final UUID paymentMethodId2 = paymentMethodProcessor.addPaymentMethod(null, "__EXTERNAL_PAYMENT__", account, false, paymentMethodPlugin, properties, callContext, internalCallContext);
final PaymentMethod paymentMethod2 = paymentMethodProcessor.getPaymentMethodById(paymentMethodId2, false, false, properties, callContext, internalCallContext);
Assert.assertEquals(paymentMethod2.getExternalKey(), "unknown");
}
use of org.killbill.billing.account.api.Account in project killbill by killbill.
the class TestPaymentMethodProcessorRefreshWithDB method testRefreshWithDeletedPaymentMethod.
@Test(groups = "slow")
public void testRefreshWithDeletedPaymentMethod() throws Exception {
final Account account = testHelper.createTestAccount("super@bar.com", true);
Assert.assertEquals(getPluginApi().getPaymentMethods(account.getId(), true, PLUGIN_PROPERTIES, callContext).size(), 1);
final UUID firstPmId = account.getPaymentMethodId();
String secondPaymentMethodExternalKey = UUID.randomUUID().toString();
final UUID secondPmId = paymentApi.addPaymentMethod(account, secondPaymentMethodExternalKey, MockPaymentProviderPlugin.PLUGIN_NAME, true, new DefaultNoOpPaymentMethodPlugin(secondPaymentMethodExternalKey, false, null), PLUGIN_PROPERTIES, callContext);
Assert.assertEquals(getPluginApi().getPaymentMethods(account.getId(), true, PLUGIN_PROPERTIES, callContext).size(), 2);
Assert.assertEquals(paymentApi.getAccountPaymentMethods(account.getId(), false, PLUGIN_PROPERTIES, callContext).size(), 2);
// Remove second PM from plugin
getPluginApi().deletePaymentMethod(account.getId(), secondPmId, PLUGIN_PROPERTIES, callContext);
Assert.assertEquals(getPluginApi().getPaymentMethods(account.getId(), true, PLUGIN_PROPERTIES, callContext).size(), 1);
Assert.assertEquals(paymentApi.getAccountPaymentMethods(account.getId(), false, PLUGIN_PROPERTIES, callContext).size(), 2);
// Verify that the refresh sees that PM as being deleted now
final List<PaymentMethod> methods = paymentMethodProcessor.refreshPaymentMethods(MockPaymentProviderPlugin.PLUGIN_NAME, account, PLUGIN_PROPERTIES, callContext, internalCallContext);
Assert.assertEquals(methods.size(), 1);
checkPaymentMethodExistsWithStatus(methods, firstPmId, true);
final PaymentMethodModelDao deletedPMModel = paymentDao.getPaymentMethodIncludedDeleted(secondPmId, internalCallContext);
Assert.assertNotNull(deletedPMModel);
Assert.assertFalse(deletedPMModel.isActive());
}
use of org.killbill.billing.account.api.Account in project killbill by killbill.
the class TestPaymentMethodProcessorWithDB method testSetDefaultPaymentMethodSameAccount.
@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);
}
use of org.killbill.billing.account.api.Account in project killbill by killbill.
the class TestPaymentMethodProcessorWithDB method testSetDefaultPaymentMethodDifferentAccount.
@Test(groups = "slow", expectedExceptions = PaymentApiException.class, expectedExceptionsMessageRegExp = ".*Payment method .* has a different account id")
public void testSetDefaultPaymentMethodDifferentAccount() throws Exception {
final Account account = testHelper.createTestAccount("foo@bar.com", true);
final Account secondAccount = testHelper.createTestAccount("foo2@bar.com", true);
// Add new payment method
final UUID newPaymentMethod = paymentMethodProcessor.createOrGetExternalPaymentMethod("pmExternalKey", secondAccount, PLUGIN_PROPERTIES, callContext, internalCallContext);
paymentMethodProcessor.setDefaultPaymentMethod(account, newPaymentMethod, PLUGIN_PROPERTIES, callContext, internalCallContext);
}
use of org.killbill.billing.account.api.Account in project killbill by killbill.
the class TestRetryService method testAbortedPlugin.
// PLUGIN_EXCEPTION will lead to UNKNOWN row that will not be retried by the plugin
@Test(groups = "fast")
public void testAbortedPlugin() throws Exception {
final Account account = testHelper.createTestAccount("yiyi.gmail.com", true);
final Invoice invoice = testHelper.createTestInvoice(account, clock.getUTCToday(), Currency.USD);
final BigDecimal amount = new BigDecimal("10.00");
final UUID subscriptionId = UUID.randomUUID();
final UUID bundleId = UUID.randomUUID();
final LocalDate startDate = clock.getUTCToday();
final LocalDate endDate = startDate.plusMonths(1);
invoice.addInvoiceItem(new MockRecurringInvoiceItem(invoice.getId(), account.getId(), subscriptionId, bundleId, "test plan", "test phase", null, startDate, endDate, amount, new BigDecimal("1.0"), Currency.USD));
setPaymentFailure(FailureType.PLUGIN_EXCEPTION);
boolean failed = false;
final String paymentExternalKey = UUID.randomUUID().toString();
final String transactionExternalKey = UUID.randomUUID().toString();
try {
pluginControlPaymentProcessor.createPurchase(false, account, account.getPaymentMethodId(), null, amount, Currency.USD, paymentExternalKey, transactionExternalKey, createPropertiesForInvoice(invoice), ImmutableList.<String>of(InvoicePaymentControlPluginApi.PLUGIN_NAME), callContext, internalCallContext);
} catch (final PaymentApiException e) {
failed = true;
}
assertTrue(failed);
Payment payment = getPaymentForExternalKey(paymentExternalKey);
List<PaymentAttemptModelDao> attempts = paymentDao.getPaymentAttempts(paymentExternalKey, internalCallContext);
assertEquals(attempts.size(), 1);
final List<PaymentTransactionModelDao> transactions = paymentDao.getTransactionsForPayment(payment.getId(), internalCallContext);
assertEquals(transactions.size(), 1);
attempts = paymentDao.getPaymentAttempts(payment.getExternalKey(), internalCallContext);
final int expectedAttempts = 1;
assertEquals(attempts.size(), expectedAttempts);
assertEquals(attempts.get(0).getStateName(), "ABORTED");
}
Aggregations