@Override public PaymentMethodPlugin getPaymentMethodDetail(final UUID kbAccountId, final UUID kbPaymentMethodId, final TenantContext context) throws PaymentPluginApiException { return new DefaultNoOpPaymentMethodPlugin(kbPaymentMethodId, "unknown", false, Collections.<PaymentMethodKVInfo>emptyList()); }
@Override public void addPaymentMethod(final UUID kbAccountId, final UUID kbPaymentMethodId, final PaymentMethodPlugin paymentMethodProps, final boolean setDefault, final CallContext context) throws PaymentPluginApiException { final PaymentMethodPlugin realWithID = new DefaultNoOpPaymentMethodPlugin(kbPaymentMethodId, paymentMethodProps); List<PaymentMethodPlugin> pms = paymentMethods.get(kbPaymentMethodId.toString()); if (pms == null) { pms = new LinkedList<PaymentMethodPlugin>(); paymentMethods.put(kbPaymentMethodId.toString(), pms); } pms.add(realWithID); }
public ExternalPaymentProviderPlugin getExternalPaymentProviderPlugin(final Account account, final InternalCallContext context) throws PaymentApiException { // Check if this account has already used the external payment plugin // If not, it's the first time - add a payment method for it if (getExternalPaymentMethod(account, context) == null) { final DefaultNoOpPaymentMethodPlugin props = new DefaultNoOpPaymentMethodPlugin(UUID.randomUUID().toString(), false, ImmutableList.<PaymentMethodKVInfo>of()); addPaymentMethod(ExternalPaymentProviderPlugin.PLUGIN_NAME, account, false, props, context); } return (ExternalPaymentProviderPlugin) getPaymentPluginApi(ExternalPaymentProviderPlugin.PLUGIN_NAME); }
@Test(groups = "fast") public void testEquals() throws Exception { final String externalId = UUID.randomUUID().toString(); final boolean isDefault = false; final List<PaymentMethodKVInfo> props = ImmutableList.<PaymentMethodKVInfo>of(new PaymentMethodKVInfo(UUID.randomUUID().toString(), UUID.randomUUID().toString(), false)); final DefaultNoOpPaymentMethodPlugin paymentMethod = new DefaultNoOpPaymentMethodPlugin(externalId, isDefault, props); Assert.assertEquals(paymentMethod, paymentMethod); final DefaultNoOpPaymentMethodPlugin samePaymentMethod = new DefaultNoOpPaymentMethodPlugin(externalId, isDefault, props); Assert.assertEquals(samePaymentMethod, paymentMethod); final DefaultNoOpPaymentMethodPlugin otherPaymentMethod = new DefaultNoOpPaymentMethodPlugin(externalId, isDefault, ImmutableList.<PaymentMethodKVInfo>of()); Assert.assertNotEquals(otherPaymentMethod, paymentMethod); }
@BeforeMethod(groups = "fast") public void beforeMethod() throws Exception { super.beforeMethod(); final PaymentMethodPlugin paymentMethodInfo = new DefaultNoOpPaymentMethodPlugin(UUID.randomUUID().toString(), true, null); testHelper.addTestPaymentMethod(account, paymentMethodInfo); }
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 account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(UUID.randomUUID()); Mockito.when(account.getExternalKey()).thenReturn(externalKey); Mockito.when(account.getName()).thenReturn(name); Mockito.when(account.getFirstNameLength()).thenReturn(10); Mockito.when(account.getPhone()).thenReturn("123-456-7890"); Mockito.when(account.getEmail()).thenReturn(email); Mockito.when(account.getCurrency()).thenReturn(Currency.USD); Mockito.when(account.getBillCycleDayLocal()).thenReturn(1); Mockito.when(account.isMigrated()).thenReturn(false); Mockito.when(account.isNotifiedForInvoices()).thenReturn(false); Mockito.when(AccountApi.getAccountById(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(AccountApi.getAccountByKey(Mockito.anyString(), Mockito.<InternalTenantContext>any())).thenReturn(account); if (addPaymentMethod) { final PaymentMethodPlugin pm = new DefaultNoOpPaymentMethodPlugin(UUID.randomUUID().toString(), true, null); addTestPaymentMethod(account, pm); } return account; }
@Test(groups = "slow") public void testRefreshWithNewPaymentMethod() throws Exception { final Account account = testHelper.createTestAccount("foo@bar.com", true); Assert.assertEquals(getPluginApi().getPaymentMethods(account.getId(), true, 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.<PaymentMethodKVInfo>of()), false, callContext); // Verify that the refresh does indeed show 2 PMs final List<PaymentMethod> methods = paymentMethodProcessor.refreshPaymentMethods(MockPaymentProviderPlugin.PLUGIN_NAME, account, internalCallContext); Assert.assertEquals(methods.size(), 2); checkPaymentMethodExistsWithStatus(methods, existingPMId, true); checkPaymentMethodExistsWithStatus(methods, newPmId, true); }
assertEquals(initDefaultMethod.getId(), account.getPaymentMethodId()); final PaymentMethodPlugin newPaymenrMethod = new DefaultNoOpPaymentMethodPlugin(UUID.randomUUID().toString(), true, null); final UUID newPaymentMethodId = paymentApi.addPaymentMethod(MockPaymentProviderPlugin.PLUGIN_NAME, account, true, newPaymenrMethod, callContext); Mockito.when(account.getPaymentMethodId()).thenReturn(newPaymentMethodId);
@Test(groups = "slow") public void testRefreshWithDeletedPaymentMethod() throws Exception { final Account account = testHelper.createTestAccount("super@bar.com", true); Assert.assertEquals(getPluginApi().getPaymentMethods(account.getId(), true, callContext).size(), 1); final UUID firstPmId = account.getPaymentMethodId(); final UUID secondPmId = paymentApi.addPaymentMethod(MockPaymentProviderPlugin.PLUGIN_NAME, account, true, new DefaultNoOpPaymentMethodPlugin(UUID.randomUUID().toString(), false, null), callContext); Assert.assertEquals(getPluginApi().getPaymentMethods(account.getId(), true, callContext).size(), 2); Assert.assertEquals(paymentApi.getPaymentMethods(account, false, callContext).size(), 2); // Remove second PM from plugin getPluginApi().deletePaymentMethod(account.getId(), secondPmId, callContext); Assert.assertEquals(getPluginApi().getPaymentMethods(account.getId(), true, callContext).size(), 1); Assert.assertEquals(paymentApi.getPaymentMethods(account, false, callContext).size(), 2); // Verify that the refresh sees that PM as being deleted now final List<PaymentMethod> methods = paymentMethodProcessor.refreshPaymentMethods(MockPaymentProviderPlugin.PLUGIN_NAME, account, internalCallContext); Assert.assertEquals(methods.size(), 1); checkPaymentMethodExistsWithStatus(methods, firstPmId, true); PaymentMethodModelDao deletedPMModel = paymentDao.getPaymentMethodIncludedDeleted(secondPmId, internalCallContext); Assert.assertNotNull(deletedPMModel); Assert.assertFalse(deletedPMModel.isActive()); }