Search in sources :

Example 56 with Account

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");
}
Also used : Account(org.killbill.billing.account.api.Account) PluginProperty(org.killbill.billing.payment.api.PluginProperty) PaymentMethodPlugin(org.killbill.billing.payment.api.PaymentMethodPlugin) PaymentMethod(org.killbill.billing.payment.api.PaymentMethod) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 57 with Account

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());
}
Also used : Account(org.killbill.billing.account.api.Account) PaymentMethodModelDao(org.killbill.billing.payment.dao.PaymentMethodModelDao) PaymentMethod(org.killbill.billing.payment.api.PaymentMethod) UUID(java.util.UUID) DefaultNoOpPaymentMethodPlugin(org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin) Test(org.testng.annotations.Test)

Example 58 with Account

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);
}
Also used : Account(org.killbill.billing.account.api.Account) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 59 with Account

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);
}
Also used : Account(org.killbill.billing.account.api.Account) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 60 with Account

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");
}
Also used : PaymentAttemptModelDao(org.killbill.billing.payment.dao.PaymentAttemptModelDao) Account(org.killbill.billing.account.api.Account) Invoice(org.killbill.billing.invoice.api.Invoice) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Payment(org.killbill.billing.payment.api.Payment) PaymentTransactionModelDao(org.killbill.billing.payment.dao.PaymentTransactionModelDao) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Aggregations

Account (org.killbill.billing.account.api.Account)305 Test (org.testng.annotations.Test)198 LocalDate (org.joda.time.LocalDate)139 BigDecimal (java.math.BigDecimal)90 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)87 Invoice (org.killbill.billing.invoice.api.Invoice)84 DateTime (org.joda.time.DateTime)71 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)63 UUID (java.util.UUID)62 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)59 ApiOperation (io.swagger.annotations.ApiOperation)48 ApiResponses (io.swagger.annotations.ApiResponses)48 ArrayList (java.util.ArrayList)48 Produces (javax.ws.rs.Produces)48 AccountData (org.killbill.billing.account.api.AccountData)47 TimedResource (org.killbill.commons.metrics.TimedResource)47 Path (javax.ws.rs.Path)42 PluginProperty (org.killbill.billing.payment.api.PluginProperty)42 DefaultAccount (org.killbill.billing.account.api.DefaultAccount)41 Payment (org.killbill.billing.payment.api.Payment)40