@TimedResource @DELETE @Produces(APPLICATION_JSON) @Path("/{paymentMethodId:" + UUID_PATTERN + "}") @ApiOperation(value = "Delete a payment method") @ApiResponses(value = {@ApiResponse(code = 204, message = "Successful operation"), @ApiResponse(code = 400, message = "Invalid paymentMethodId supplied"), @ApiResponse(code = 404, message = "Account or payment method not found")}) public Response deletePaymentMethod(@PathParam("paymentMethodId") final UUID paymentMethodId, @QueryParam(QUERY_DELETE_DEFAULT_PM_WITH_AUTO_PAY_OFF) @DefaultValue("false") final Boolean deleteDefaultPaymentMethodWithAutoPayOff, @QueryParam(QUERY_FORCE_DEFAULT_PM_DELETION) @DefaultValue("false") final Boolean forceDefaultPaymentMethodDeletion, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException, AccountApiException { final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString); final CallContext callContext = context.createCallContextNoAccountId(createdBy, reason, comment, request); final PaymentMethod paymentMethod = paymentApi.getPaymentMethodById(paymentMethodId, false, false, pluginProperties, callContext); final Account account = accountUserApi.getAccountById(paymentMethod.getAccountId(), callContext); paymentApi.deletePaymentMethod(account, paymentMethodId, deleteDefaultPaymentMethodWithAutoPayOff, forceDefaultPaymentMethodDeletion, pluginProperties, callContext); return Response.status(Status.NO_CONTENT).build(); }
@Test(groups = "slow", description = "Verify we can make a refund on payment whose original payment method was deleted. See 694") public void testRefundAfterDeletedPaymentMethod() throws PaymentApiException { final BigDecimal requestedAmount = BigDecimal.TEN; final Payment payment = paymentApi.createPurchase(account, account.getPaymentMethodId(), null, requestedAmount, Currency.EUR, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); paymentApi.deletePaymentMethod(account, account.getPaymentMethodId(), false, true, ImmutableList.<PluginProperty>of(), callContext); final Payment newPayment = paymentApi.createRefund(account, payment.getId(),requestedAmount, Currency.EUR, null, UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext); Assert.assertEquals(newPayment.getTransactions().size(), 2); }
@Test(groups = "slow") public void testAddRemovePaymentMethodWithForcedDeletion() 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, false, true, ImmutableList.<PluginProperty>of(), callContext); checkPaymentMethodPagination(paymentMethodId, baseNbRecords, true); }
@Test(groups = "slow") public void testAddRemovePaymentMethodWithoutForcedDeletion() 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(); try { paymentApi.deletePaymentMethod(account, paymentMethodId, false, false, ImmutableList.<PluginProperty>of(), callContext); } catch (final PaymentApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.PAYMENT_INTERNAL_ERROR.getCode()); } checkPaymentMethodPagination(paymentMethodId, baseNbRecords + 1, false); }
@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); }
paymentApi.deletePaymentMethod(account, account.getPaymentMethodId(), false, false, PLUGIN_PROPERTIES, callContext); } catch (final PaymentApiException e) { failed = true; paymentApi.deletePaymentMethod(account, initDefaultMethod.getId(), true, false, PLUGIN_PROPERTIES, callContext); methods = paymentApi.getAccountPaymentMethods(account.getId(), false, false, PLUGIN_PROPERTIES, callContext); assertEquals(methods.size(), 1); paymentApi.deletePaymentMethod(account, account.getPaymentMethodId(), true, false, PLUGIN_PROPERTIES, callContext);
@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/255") public void testRefundWithDeletedPaymentMethod() throws Exception { // delete payment method busHandler.pushExpectedEvent(NextEvent.TAG); paymentApi.deletePaymentMethod(account, account.getPaymentMethodId(), true, true, new ArrayList<PluginProperty>(), callContext); assertListenerStatus(); // try to create a refund for a payment with its payment method deleted busHandler.pushExpectedEvent(NextEvent.PAYMENT); paymentApi.createRefund(account, payment.getId(), payment.getPurchasedAmount(), payment.getCurrency(), null, UUID.randomUUID().toString(), PLUGIN_PROPERTIES, callContext); assertListenerStatus(); }