@POST @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) @Path("/{invoiceId:" + UUID_PATTERN + "}/" + PAYMENTS) public Response createInstantPayment(final PaymentJson payment, @QueryParam(QUERY_PAYMENT_EXTERNAL) @DefaultValue("false") final Boolean externalPayment, @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, @javax.ws.rs.core.Context final UriInfo uriInfo) throws AccountApiException, PaymentApiException { final CallContext callContext = context.createContext(createdBy, reason, comment, request); final Account account = accountUserApi.getAccountById(UUID.fromString(payment.getAccountId()), callContext); final UUID invoiceId = UUID.fromString(payment.getInvoiceId()); if (externalPayment) { paymentApi.createExternalPayment(account, invoiceId, payment.getAmount(), callContext); } else { paymentApi.createPayment(account, invoiceId, payment.getAmount(), callContext); } return uriBuilder.buildResponse(uriInfo, InvoiceResource.class, "getPayments", payment.getInvoiceId()); }
@DELETE @Produces(APPLICATION_JSON) @Path("/{paymentMethodId:" + UUID_PATTERN + "}") public Response deletePaymentMethod(@PathParam("paymentMethodId") final String paymentMethodId, @QueryParam(QUERY_DELETE_DEFAULT_PM_WITH_AUTO_PAY_OFF) @DefaultValue("false") final Boolean deleteDefaultPaymentMethodWithAutoPayOff, @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 CallContext callContext = context.createContext(createdBy, reason, comment, request); final PaymentMethod paymentMethod = paymentApi.getPaymentMethodById(UUID.fromString(paymentMethodId), false, false, callContext); final Account account = accountUserApi.getAccountById(paymentMethod.getAccountId(), callContext); paymentApi.deletedPaymentMethod(account, UUID.fromString(paymentMethodId), deleteDefaultPaymentMethodWithAutoPayOff, callContext); return Response.status(Status.OK).build(); }
@GET @Path("/{accountId:" + UUID_PATTERN + "}/" + PAYMENTS) @Produces(APPLICATION_JSON) public Response getPayments(@PathParam("accountId") final String accountId, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException { final List<Payment> payments = paymentApi.getAccountPayments(UUID.fromString(accountId), context.createContext(request)); final List<PaymentJson> result = new ArrayList<PaymentJson>(payments.size()); for (final Payment payment : payments) { result.add(new PaymentJson(payment, null)); } return Response.status(Status.OK).entity(result).build(); }
@PUT @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @Path("/{accountId:" + UUID_PATTERN + "}/" + PAYMENT_METHODS + "/{paymentMethodId:" + UUID_PATTERN + "}/" + PAYMENT_METHODS_DEFAULT_PATH_POSTFIX) public Response setDefaultPaymentMethod(@PathParam("accountId") final String accountId, @PathParam("paymentMethodId") final String paymentMethodId, @QueryParam(QUERY_PAY_ALL_UNPAID_INVOICES) @DefaultValue("false") final Boolean payAllUnpaidInvoices, @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 AccountApiException, PaymentApiException { final CallContext callContext = context.createContext(createdBy, reason, comment, request); final Account account = accountUserApi.getAccountById(UUID.fromString(accountId), callContext); paymentApi.setDefaultPaymentMethod(account, UUID.fromString(paymentMethodId), callContext); if (payAllUnpaidInvoices) { final Collection<Invoice> unpaidInvoices = invoiceApi.getUnpaidInvoicesByAccountId(account.getId(), clock.getUTCToday(), callContext); for (final Invoice invoice : unpaidInvoices) { paymentApi.createPayment(account, invoice.getId(), invoice.getBalance(), callContext); } } return Response.status(Status.OK).build(); }
@Test(groups = "fast") public void testPaymentMethods() throws Exception { List<PaymentMethod> methods = paymentApi.getPaymentMethods(account, false, callContext); assertEquals(methods.size(), 1); final UUID newPaymentMethodId = paymentApi.addPaymentMethod(MockPaymentProviderPlugin.PLUGIN_NAME, account, true, newPaymenrMethod, callContext); Mockito.when(account.getPaymentMethodId()).thenReturn(newPaymentMethodId); methods = paymentApi.getPaymentMethods(account, false, callContext); assertEquals(methods.size(), 2); paymentApi.deletedPaymentMethod(account, newPaymentMethodId, false, callContext); } catch (PaymentApiException e) { failed = true; paymentApi.deletedPaymentMethod(account, initDefaultMethod.getId(), true, callContext); methods = paymentApi.getPaymentMethods(account, false, callContext); assertEquals(methods.size(), 1); paymentApi.deletedPaymentMethod(account, newPaymentMethodId, true, callContext); methods = paymentApi.getPaymentMethods(account, false, callContext); assertEquals(methods.size(), 0);
final Payment payment = paymentApi.getPayment(paymentUuid, false, callContext); final Account account = accountUserApi.getAccountById(payment.getAccountId(), callContext); adjustments.put(UUID.fromString(item.getInvoiceItemId()), item.getAmount()); result = paymentApi.createRefundWithItemsAdjustments(account, paymentUuid, adjustments, callContext); } else { result = paymentApi.createRefundWithAdjustment(account, paymentUuid, json.getAmount(), callContext); result = paymentApi.createRefund(account, paymentUuid, json.getAmount(), callContext);
@POST @Path("/{accountId:" + UUID_PATTERN + "}/" + PAYMENT_METHODS) @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) public Response createPaymentMethod(final PaymentMethodJson json, @PathParam("accountId") final String accountId, @QueryParam(QUERY_PAYMENT_METHOD_IS_DEFAULT) @DefaultValue("false") final Boolean isDefault, @QueryParam(QUERY_PAY_ALL_UNPAID_INVOICES) @DefaultValue("false") final Boolean payAllUnpaidInvoices, @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 UriInfo uriInfo, @javax.ws.rs.core.Context final HttpServletRequest request) throws AccountApiException, PaymentApiException { final CallContext callContext = context.createContext(createdBy, reason, comment, request); final PaymentMethod data = json.toPaymentMethod(accountId); final Account account = accountUserApi.getAccountById(data.getAccountId(), callContext); final boolean hasDefaultPaymentMethod = account.getPaymentMethodId() != null || isDefault; final Collection<Invoice> unpaidInvoices = payAllUnpaidInvoices ? invoiceApi.getUnpaidInvoicesByAccountId(account.getId(), clock.getUTCToday(), callContext) : Collections.<Invoice>emptyList(); if (payAllUnpaidInvoices && unpaidInvoices.size() > 0 && !hasDefaultPaymentMethod) { return Response.status(Status.BAD_REQUEST).build(); } final UUID paymentMethodId = paymentApi.addPaymentMethod(data.getPluginName(), account, isDefault, data.getPluginDetail(), callContext); if (payAllUnpaidInvoices && unpaidInvoices.size() > 0) { for (final Invoice invoice : unpaidInvoices) { paymentApi.createPayment(account, invoice.getId(), invoice.getBalance(), callContext); } } return uriBuilder.buildResponse(PaymentMethodResource.class, "getPaymentMethod", paymentMethodId, uriInfo.getBaseUri().toString()); }
@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()); }
paymentApi.createPayment(account, invoice.getId(), requestedAmount, callContext); } catch (PaymentApiException e) { Assert.assertEquals(e.getCode(), ErrorCode.PAYMENT_NO_DEFAULT_PAYMENT_METHOD.getCode()); final List<Payment> payments = paymentApi.getAccountPayments(account.getId(), callContext); Assert.assertEquals(payments.size(), 1);
final List<Payment> payments = paymentApi.getAccountPayments(accountId, tenantContext); final List<Refund> refunds = paymentApi.getAccountRefunds(account, tenantContext); final Multimap<UUID, Refund> refundsByPayment = ArrayListMultimap.<UUID, Refund>create(); for (final Refund refund : refunds) {
paymentApi.createPayment(account, invoice.getId(), invoice.getBalance(), callContext);
@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(); }
public void addTestPaymentMethod(final Account account, final PaymentMethodPlugin paymentMethodInfo) throws Exception { final UUID paymentMethodId = paymentApi.addPaymentMethod(MockPaymentProviderPlugin.PLUGIN_NAME, account, true, paymentMethodInfo, context); Mockito.when(account.getPaymentMethodId()).thenReturn(paymentMethodId); } }
@GET @Path("/{accountId:" + UUID_PATTERN + "}/" + REFUNDS) @Produces(APPLICATION_JSON) public Response getRefunds(@PathParam("accountId") final String accountId, @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<Refund> refunds = paymentApi.getAccountRefunds(account, tenantContext); final List<RefundJson> result = new ArrayList<RefundJson>(Collections2.transform(refunds, new Function<Refund, RefundJson>() { @Override public RefundJson apply(Refund input) { // TODO Return adjusted items and audits return new RefundJson(input, null, null); } })); return Response.status(Status.OK).entity(result).build(); }
paymentApi.createPayment(account, invoice.getId(), invoice.getBalance(), callContext);
paymentMethods = paymentApi.getPaymentMethods(offset, limit, tenantContext); } else { paymentMethods = paymentApi.getPaymentMethods(offset, limit, pluginName, tenantContext);
@POST @Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) @Path("/{accountId:" + UUID_PATTERN + "}/" + PAYMENTS) public Response payAllInvoices(@PathParam("accountId") final String accountId, @QueryParam(QUERY_PAYMENT_EXTERNAL) @DefaultValue("false") final Boolean externalPayment, @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 AccountApiException, PaymentApiException { final CallContext callContext = context.createContext(createdBy, reason, comment, request); final Account account = accountUserApi.getAccountById(UUID.fromString(accountId), callContext); final Collection<Invoice> unpaidInvoices = invoiceApi.getUnpaidInvoicesByAccountId(account.getId(), clock.getUTCToday(), callContext); for (final Invoice invoice : unpaidInvoices) { if (externalPayment) { paymentApi.createExternalPayment(account, invoice.getId(), invoice.getBalance(), callContext); } else { paymentApi.createPayment(account, invoice.getId(), invoice.getBalance(), callContext); } } return Response.status(Status.OK).build(); }
final Payment paymentInfo = paymentApi.createPayment(account, invoice.getId(), requestedAmount, callContext); if (expectedAmount == null) { fail("Expected to fail because requested amount > invoice amount");