@TimedResource @GET @Path("/{accountId:" + UUID_PATTERN + "}/" + PAYMENT_METHODS) @Produces(APPLICATION_JSON) @ApiOperation(value = "Retrieve account payment methods", response = PaymentMethodJson.class, responseContainer = "List") @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid account id supplied"), @ApiResponse(code = 404, message = "Account not found")}) public Response getPaymentMethodsForAccount(@PathParam("accountId") final UUID accountId, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_INCLUDED_DELETED) @DefaultValue("false") final Boolean includedDeleted, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, PaymentApiException { final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString); final TenantContext tenantContext = context.createTenantContextWithAccountId(accountId, request); final Account account = accountUserApi.getAccountById(accountId, tenantContext); final List<PaymentMethod> methods = paymentApi.getAccountPaymentMethods(account.getId(), includedDeleted, withPluginInfo, pluginProperties, 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(); }
protected List<PaymentMethod> getPaymentMethodsForAccount(final UUID accountId, final TenantContext context) throws OSGIServiceNotAvailable { final PaymentApi paymentApi = getPaymentUserApi(); try { // Try to get all payment methods, with plugin information // TODO this will not return deleted payment methods return paymentApi.getAccountPaymentMethods(accountId, false, true, PLUGIN_PROPERTIES, context); } catch (final PaymentApiException e) { logService.log(LogService.LOG_INFO, "Error retrieving payment methods for accountId " + accountId + ": " + e.getMessage()); throw new OSGIServiceNotAvailable(e); } }
public static PaymentMethod buildPaymentMethod(final UUID accountId, final UUID paymentMethodId, final String pluginName, @Nullable final OSGIKillbill killbillApi) throws PaymentApiException { final PaymentMethod paymentMethod = Mockito.mock(PaymentMethod.class); Mockito.when(paymentMethod.getId()).thenReturn(paymentMethodId); Mockito.when(paymentMethod.getExternalKey()).thenReturn(UUID.randomUUID().toString()); Mockito.when(paymentMethod.isActive()).thenReturn(true); Mockito.when(paymentMethod.getPluginName()).thenReturn(pluginName); if (killbillApi != null) { Mockito.when(killbillApi.getPaymentApi().getAccountPaymentMethods(Mockito.eq(accountId), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.<Iterable<PluginProperty>>any(), Mockito.<TenantContext>any())).thenReturn(ImmutableList.<PaymentMethod>of(paymentMethod)); Mockito.when(killbillApi.getPaymentApi().getPaymentMethodById(Mockito.eq(paymentMethod.getId()), Mockito.anyBoolean(), Mockito.anyBoolean(), Mockito.<Iterable<PluginProperty>>any(), Mockito.<TenantContext>any())).thenReturn(paymentMethod); } return paymentMethod; }
@Test(groups = "slow") public void testAddRemovePaymentMethod() throws Exception { final Long baseNbRecords = paymentApi.getPaymentMethods(0L, 1000L, false, ImmutableList.<PluginProperty>of(), callContext).getMaxNbRecords(); Assert.assertEquals(baseNbRecords, (Long) 1L); final Account account = testHelper.createTestAccount(UUID.randomUUID().toString(), true); final UUID paymentMethodId = account.getPaymentMethodId(); checkPaymentMethodPagination(paymentMethodId, baseNbRecords + 1, false); paymentApi.deletePaymentMethod(account, paymentMethodId, true, false, ImmutableList.<PluginProperty>of(), callContext); List<PaymentMethod> paymentMethods = paymentApi.getAccountPaymentMethods(account.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext); assertEquals(paymentMethods.size(), 0); paymentMethods = paymentApi.getAccountPaymentMethods(account.getId(), true, false, ImmutableList.<PluginProperty>of(), callContext); assertEquals(paymentMethods.size(), 1); checkPaymentMethodPagination(paymentMethodId, baseNbRecords, true); }
final List<PaymentMethod> accountPaymentMethods = paymentApi.getAccountPaymentMethods(account.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext);
@Test(groups = "fast") public void testPaymentMethods() throws Exception { List<PaymentMethod> methods = paymentApi.getAccountPaymentMethods(account.getId(), false, false, PLUGIN_PROPERTIES, callContext); assertEquals(methods.size(), 1); account = testHelper.addTestPaymentMethod(account, newPaymentMethod, PLUGIN_PROPERTIES); methods = paymentApi.getAccountPaymentMethods(account.getId(), false, false, PLUGIN_PROPERTIES, callContext); assertEquals(methods.size(), 2); methods = paymentApi.getAccountPaymentMethods(account.getId(), false, false, PLUGIN_PROPERTIES, callContext); assertEquals(methods.size(), 1); methods = paymentApi.getAccountPaymentMethods(account.getId(), false, false, PLUGIN_PROPERTIES, 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, 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()); }