Search in sources :

Example 1 with DefaultNoOpPaymentMethodPlugin

use of org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin in project killbill by killbill.

the class TestPaymentHelper method createTestAccount.

public Account createTestAccount(final String email, final boolean addPaymentMethod) throws Exception {
    final String name = "First" + UUID.randomUUID().toString() + " " + "Last" + UUID.randomUUID().toString();
    final String externalKey = UUID.randomUUID().toString();
    final Account accountData = Mockito.mock(Account.class);
    Mockito.when(accountData.getId()).thenReturn(UUID.randomUUID());
    Mockito.when(accountData.getExternalKey()).thenReturn(externalKey);
    Mockito.when(accountData.getName()).thenReturn(name);
    Mockito.when(accountData.getFirstNameLength()).thenReturn(10);
    Mockito.when(accountData.getPhone()).thenReturn("123-456-7890");
    Mockito.when(accountData.getEmail()).thenReturn(email);
    Mockito.when(accountData.getCurrency()).thenReturn(Currency.USD);
    Mockito.when(accountData.getBillCycleDayLocal()).thenReturn(1);
    Mockito.when(accountData.isMigrated()).thenReturn(false);
    Mockito.when(accountData.getTimeZone()).thenReturn(DateTimeZone.UTC);
    final DateTime utcNow = clock.getUTCNow();
    Mockito.when(accountData.getCreatedDate()).thenReturn(utcNow);
    Mockito.when(accountData.getReferenceTime()).thenReturn(utcNow);
    final MutableCallContext mutableCallContext = new MutableCallContext(internalCallContext);
    Account account;
    if (isFastTest()) {
        account = GuicyKillbillTestSuiteNoDB.createMockAccount(accountData, accountApi, accountInternalApi, immutableAccountInternalApi, nonEntityDao, clock, internalCallContextFactory, mutableCallContext, internalCallContext);
    } else {
        account = accountApi.createAccount(accountData, context);
    }
    GuicyKillbillTestSuite.refreshCallContext(account.getId(), clock, internalCallContextFactory, mutableCallContext, internalCallContext);
    if (addPaymentMethod) {
        final PaymentMethodPlugin pm = new DefaultNoOpPaymentMethodPlugin(UUID.randomUUID().toString(), true, null);
        account = addTestPaymentMethod(account, pm);
    }
    return account;
}
Also used : Account(org.killbill.billing.account.api.Account) MutableCallContext(org.killbill.billing.callcontext.MutableCallContext) DefaultNoOpPaymentMethodPlugin(org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin) PaymentMethodPlugin(org.killbill.billing.payment.api.PaymentMethodPlugin) DateTime(org.joda.time.DateTime) DefaultNoOpPaymentMethodPlugin(org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin)

Example 2 with DefaultNoOpPaymentMethodPlugin

use of org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin in project killbill by killbill.

the class TestPaymentApiNoDB method testPaymentMethods.

@Test(groups = "fast")
public void testPaymentMethods() throws Exception {
    List<PaymentMethod> methods = paymentApi.getAccountPaymentMethods(account.getId(), false, false, PLUGIN_PROPERTIES, callContext);
    assertEquals(methods.size(), 1);
    final PaymentMethod initDefaultMethod = methods.get(0);
    assertEquals(initDefaultMethod.getId(), account.getPaymentMethodId());
    final PaymentMethodPlugin newPaymentMethod = new DefaultNoOpPaymentMethodPlugin(UUID.randomUUID().toString(), true, null);
    account = testHelper.addTestPaymentMethod(account, newPaymentMethod, PLUGIN_PROPERTIES);
    methods = paymentApi.getAccountPaymentMethods(account.getId(), false, false, PLUGIN_PROPERTIES, callContext);
    assertEquals(methods.size(), 2);
    boolean failed = false;
    try {
        paymentApi.deletePaymentMethod(account, account.getPaymentMethodId(), false, false, PLUGIN_PROPERTIES, callContext);
    } catch (final PaymentApiException e) {
        failed = true;
    }
    assertTrue(failed);
    paymentApi.deletePaymentMethod(account, initDefaultMethod.getId(), true, false, PLUGIN_PROPERTIES, callContext);
    methods = paymentApi.getAccountPaymentMethods(account.getId(), false, false, PLUGIN_PROPERTIES, callContext);
    assertEquals(methods.size(), 1);
    // NOW retry with default payment method with special flag
    paymentApi.deletePaymentMethod(account, account.getPaymentMethodId(), true, false, PLUGIN_PROPERTIES, callContext);
    methods = paymentApi.getAccountPaymentMethods(account.getId(), false, false, PLUGIN_PROPERTIES, callContext);
    assertEquals(methods.size(), 0);
}
Also used : DefaultNoOpPaymentMethodPlugin(org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin) DefaultNoOpPaymentMethodPlugin(org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin) Test(org.testng.annotations.Test)

Example 3 with DefaultNoOpPaymentMethodPlugin

use of org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin 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, 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, 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 4 with DefaultNoOpPaymentMethodPlugin

use of org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin in project killbill by killbill.

the class TestPaymentApiWithControl method testCreateAuthWithControl.

// Verify Payment control API can be used to change the paymentMethodId on the fly and this is reflected in the created Payment.
@Test(groups = "slow")
public void testCreateAuthWithControl() throws PaymentApiException {
    final PaymentMethodPlugin paymentMethodInfo = new DefaultNoOpPaymentMethodPlugin(UUID.randomUUID().toString(), false, null);
    final UUID newPaymentMethodId = paymentApi.addPaymentMethod(account, null, MockPaymentProviderPlugin.PLUGIN_NAME, false, paymentMethodInfo, ImmutableList.<PluginProperty>of(), callContext);
    testPaymentControlPluginApi.setNewPaymentMethodId(newPaymentMethodId);
    final Payment payment = paymentApi.createAuthorizationWithPaymentControl(account, null, null, BigDecimal.TEN, Currency.USD, null, null, UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), PAYMENT_OPTIONS, callContext);
    Assert.assertEquals(payment.getPaymentMethodId(), newPaymentMethodId);
    verifyOnSuccess(payment.getId(), payment.getExternalKey(), payment.getTransactions().get(0).getId(), payment.getTransactions().get(0).getExternalKey(), BigDecimal.TEN, Currency.USD);
}
Also used : DefaultNoOpPaymentMethodPlugin(org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin) UUID(java.util.UUID) DefaultNoOpPaymentMethodPlugin(org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin) Test(org.testng.annotations.Test)

Example 5 with DefaultNoOpPaymentMethodPlugin

use of org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin in project killbill by killbill.

the class TestPaymentApi method testSearchPayments.

@Test(groups = "slow")
public void testSearchPayments() throws Exception {
    // Add a second, non-default, payment method
    final PaymentMethodPlugin pm = new DefaultNoOpPaymentMethodPlugin(UUID.randomUUID().toString(), false, null);
    final UUID secondPmId = testHelper.addTestPaymentMethod(MockPaymentProviderPlugin.PLUGIN_NAME + "2", account, pm, ImmutableList.<PluginProperty>of());
    Pagination<Payment> foundPayments = paymentApi.searchPayments("all", 0L, 10L, true, false, ImmutableList.<PluginProperty>of(), callContext);
    Assert.assertFalse(foundPayments.iterator().hasNext());
    Assert.assertEquals(foundPayments.getMaxNbRecords(), (Long) 0L);
    Assert.assertEquals(foundPayments.getTotalNbRecords(), (Long) 0L);
    foundPayments = paymentApi.searchPayments("A", 0L, 10L, true, false, ImmutableList.<PluginProperty>of(), callContext);
    Assert.assertFalse(foundPayments.iterator().hasNext());
    Assert.assertEquals(foundPayments.getMaxNbRecords(), (Long) 0L);
    Assert.assertEquals(foundPayments.getTotalNbRecords(), (Long) 0L);
    foundPayments = paymentApi.searchPayments("B", 0L, 10L, true, false, ImmutableList.<PluginProperty>of(), callContext);
    Assert.assertFalse(foundPayments.iterator().hasNext());
    Assert.assertEquals(foundPayments.getMaxNbRecords(), (Long) 0L);
    Assert.assertEquals(foundPayments.getTotalNbRecords(), (Long) 0L);
    final Payment payment1 = paymentApi.createPurchase(account, account.getPaymentMethodId(), null, BigDecimal.TEN, Currency.USD, clock.getUTCNow(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(new PluginProperty("group", "all", false), new PluginProperty("marker", "A", false)), callContext);
    foundPayments = paymentApi.searchPayments("all", 0L, 10L, true, false, ImmutableList.<PluginProperty>of(), callContext);
    Assert.assertTrue(foundPayments.iterator().hasNext());
    Assert.assertEquals(foundPayments.getMaxNbRecords(), (Long) 1L);
    Assert.assertEquals(foundPayments.getTotalNbRecords(), (Long) 1L);
    foundPayments = paymentApi.searchPayments("A", 0L, 10L, true, false, ImmutableList.<PluginProperty>of(), callContext);
    Assert.assertTrue(foundPayments.iterator().hasNext());
    Assert.assertEquals(foundPayments.getMaxNbRecords(), (Long) 1L);
    Assert.assertEquals(foundPayments.getTotalNbRecords(), (Long) 1L);
    Assert.assertEquals(foundPayments.iterator().next().getId(), payment1.getId());
    foundPayments = paymentApi.searchPayments("B", 0L, 10L, true, false, ImmutableList.<PluginProperty>of(), callContext);
    Assert.assertFalse(foundPayments.iterator().hasNext());
    Assert.assertEquals(foundPayments.getMaxNbRecords(), (Long) 1L);
    Assert.assertEquals(foundPayments.getTotalNbRecords(), (Long) 0L);
    final Payment payment2 = paymentApi.createPurchase(account, secondPmId, null, BigDecimal.TEN, Currency.USD, clock.getUTCNow(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(new PluginProperty("group", "all", false), new PluginProperty("marker", "B", false)), callContext);
    foundPayments = paymentApi.searchPayments("all", 0L, 10L, true, false, ImmutableList.<PluginProperty>of(), callContext);
    Assert.assertTrue(foundPayments.iterator().hasNext());
    Assert.assertEquals(foundPayments.getMaxNbRecords(), (Long) 2L);
    Assert.assertEquals(foundPayments.getTotalNbRecords(), (Long) 2L);
    foundPayments = paymentApi.searchPayments("A", 0L, 10L, true, false, ImmutableList.<PluginProperty>of(), callContext);
    Assert.assertTrue(foundPayments.iterator().hasNext());
    Assert.assertEquals(foundPayments.getMaxNbRecords(), (Long) 2L);
    Assert.assertEquals(foundPayments.getTotalNbRecords(), (Long) 1L);
    Assert.assertEquals(foundPayments.iterator().next().getId(), payment1.getId());
    foundPayments = paymentApi.searchPayments("B", 0L, 10L, true, false, ImmutableList.<PluginProperty>of(), callContext);
    Assert.assertTrue(foundPayments.iterator().hasNext());
    Assert.assertEquals(foundPayments.getMaxNbRecords(), (Long) 2L);
    Assert.assertEquals(foundPayments.getTotalNbRecords(), (Long) 1L);
    Assert.assertEquals(foundPayments.iterator().next().getId(), payment2.getId());
}
Also used : DefaultNoOpPaymentMethodPlugin(org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin) UUID(java.util.UUID) DefaultNoOpPaymentMethodPlugin(org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin) Test(org.testng.annotations.Test)

Aggregations

DefaultNoOpPaymentMethodPlugin (org.killbill.billing.payment.provider.DefaultNoOpPaymentMethodPlugin)9 Test (org.testng.annotations.Test)6 UUID (java.util.UUID)5 Account (org.killbill.billing.account.api.Account)3 PaymentMethod (org.killbill.billing.payment.api.PaymentMethod)3 DateTime (org.joda.time.DateTime)1 MutableCallContext (org.killbill.billing.callcontext.MutableCallContext)1 DefaultPaymentMethod (org.killbill.billing.payment.api.DefaultPaymentMethod)1 PaymentMethodPlugin (org.killbill.billing.payment.api.PaymentMethodPlugin)1 PluginProperty (org.killbill.billing.payment.api.PluginProperty)1 PaymentMethodModelDao (org.killbill.billing.payment.dao.PaymentMethodModelDao)1 BeforeMethod (org.testng.annotations.BeforeMethod)1