@GET @Path("/{accountId:" + UUID_PATTERN + "}/" + PAYMENT_METHODS) @Produces(APPLICATION_JSON) public Response getPaymentMethods(@PathParam("accountId") final String accountId, @QueryParam(QUERY_PAYMENT_METHOD_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, PaymentApiException { final TenantContext tenantContext = context.createContext(request); final Account account = accountUserApi.getAccountById(UUID.fromString(accountId), tenantContext); final List<PaymentMethod> methods = paymentApi.getPaymentMethods(account, withPluginInfo, tenantContext); final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext); final List<PaymentMethodJson> json = new ArrayList<PaymentMethodJson>(Collections2.transform(methods, new Function<PaymentMethod, PaymentMethodJson>() { @Override public PaymentMethodJson apply(final PaymentMethod input) { return PaymentMethodJson.toPaymentMethodJson(account, input, accountAuditLogs); } })); return Response.status(Status.OK).entity(json).build(); }
paymentMethods = paymentApi.getPaymentMethods(offset, limit, tenantContext); } else { paymentMethods = paymentApi.getPaymentMethods(offset, limit, pluginName, tenantContext);
@Test(groups = "fast") public void testPaymentMethods() throws Exception { List<PaymentMethod> methods = paymentApi.getPaymentMethods(account, false, callContext); assertEquals(methods.size(), 1); Mockito.when(account.getPaymentMethodId()).thenReturn(newPaymentMethodId); methods = paymentApi.getPaymentMethods(account, false, callContext); assertEquals(methods.size(), 2); methods = paymentApi.getPaymentMethods(account, false, callContext); assertEquals(methods.size(), 1); methods = paymentApi.getPaymentMethods(account, false, callContext); assertEquals(methods.size(), 0);
@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()); }