Search in sources :

Example 71 with PluginProperty

use of org.killbill.billing.payment.api.PluginProperty in project killbill by killbill.

the class InvoicePaymentResource method createRefundWithAdjustments.

@TimedResource
@POST
@Path("/{paymentId:" + UUID_PATTERN + "}/" + REFUNDS)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Refund a payment, and adjust the invoice if needed")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid payment id supplied"), @ApiResponse(code = 404, message = "Account or payment not found") })
public Response createRefundWithAdjustments(final InvoicePaymentTransactionJson json, @PathParam("paymentId") final String paymentId, @QueryParam(QUERY_PAYMENT_EXTERNAL) @DefaultValue("false") final Boolean externalPayment, @QueryParam(QUERY_PAYMENT_METHOD_ID) @DefaultValue("") final String paymentMethodId, @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 UriInfo uriInfo, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException, AccountApiException {
    verifyNonNullOrEmpty(json, "InvoicePaymentTransactionJson body should be specified");
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final UUID paymentUuid = UUID.fromString(paymentId);
    final Payment payment = paymentApi.getPayment(paymentUuid, false, false, ImmutableList.<PluginProperty>of(), callContext);
    final Account account = accountUserApi.getAccountById(payment.getAccountId(), callContext);
    final Iterable<PluginProperty> pluginProperties;
    final String transactionExternalKey = json.getTransactionExternalKey() != null ? json.getTransactionExternalKey() : UUIDs.randomUUID().toString();
    final String paymentExternalKey = json.getPaymentExternalKey() != null ? json.getPaymentExternalKey() : UUIDs.randomUUID().toString();
    if (json.isAdjusted() != null && json.isAdjusted()) {
        if (json.getAdjustments() != null && json.getAdjustments().size() > 0) {
            final Map<UUID, BigDecimal> adjustments = new HashMap<UUID, BigDecimal>();
            for (final InvoiceItemJson item : json.getAdjustments()) {
                adjustments.put(UUID.fromString(item.getInvoiceItemId()), item.getAmount());
            }
            pluginProperties = extractPluginProperties(pluginPropertiesString, new PluginProperty("IPCD_REFUND_WITH_ADJUSTMENTS", "true", false), new PluginProperty("IPCD_REFUND_IDS_AMOUNTS", adjustments, false));
        } else {
            pluginProperties = extractPluginProperties(pluginPropertiesString, new PluginProperty("IPCD_REFUND_WITH_ADJUSTMENTS", "true", false));
        }
    } else {
        pluginProperties = extractPluginProperties(pluginPropertiesString);
    }
    final Payment result;
    if (externalPayment) {
        UUID externalPaymentMethodId = Strings.isNullOrEmpty(paymentMethodId) ? null : UUID.fromString(paymentMethodId);
        final Collection<PluginProperty> pluginPropertiesForExternalRefund = new LinkedList<PluginProperty>();
        Iterables.addAll(pluginPropertiesForExternalRefund, pluginProperties);
        pluginPropertiesForExternalRefund.add(new PluginProperty("IPCD_PAYMENT_ID", paymentUuid, false));
        result = paymentApi.createCreditWithPaymentControl(account, externalPaymentMethodId, null, json.getAmount(), account.getCurrency(), paymentExternalKey, transactionExternalKey, pluginPropertiesForExternalRefund, createInvoicePaymentControlPluginApiPaymentOptions(true), callContext);
    } else {
        result = paymentApi.createRefundWithPaymentControl(account, payment.getId(), json.getAmount(), account.getCurrency(), transactionExternalKey, pluginProperties, createInvoicePaymentControlPluginApiPaymentOptions(false), callContext);
    }
    return uriBuilder.buildResponse(uriInfo, InvoicePaymentResource.class, "getInvoicePayment", result.getId(), request);
}
Also used : Account(org.killbill.billing.account.api.Account) HashMap(java.util.HashMap) InvoiceItemJson(org.killbill.billing.jaxrs.json.InvoiceItemJson) CallContext(org.killbill.billing.util.callcontext.CallContext) BigDecimal(java.math.BigDecimal) LinkedList(java.util.LinkedList) PluginProperty(org.killbill.billing.payment.api.PluginProperty) InvoicePayment(org.killbill.billing.invoice.api.InvoicePayment) Payment(org.killbill.billing.payment.api.Payment) UUID(java.util.UUID) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 72 with PluginProperty

use of org.killbill.billing.payment.api.PluginProperty in project killbill by killbill.

the class InvoiceResource method createInstantPayment.

@TimedResource
@POST
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
@Path("/{invoiceId:" + UUID_PATTERN + "}/" + PAYMENTS)
@ApiOperation(value = "Trigger a payment for invoice")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account id or invoice id supplied"), @ApiResponse(code = 404, message = "Account not found") })
public Response createInstantPayment(final InvoicePaymentJson payment, @QueryParam(QUERY_PAYMENT_EXTERNAL) @DefaultValue("false") final Boolean externalPayment, @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, @javax.ws.rs.core.Context final UriInfo uriInfo) throws AccountApiException, PaymentApiException {
    verifyNonNullOrEmpty(payment, "InvoicePaymentJson body should be specified");
    verifyNonNullOrEmpty(payment.getAccountId(), "InvoicePaymentJson accountId needs to be set", payment.getTargetInvoiceId(), "InvoicePaymentJson targetInvoiceId needs to be set", payment.getPurchasedAmount(), "InvoicePaymentJson purchasedAmount needs to be set");
    Preconditions.checkArgument(!externalPayment || payment.getPaymentMethodId() == null, "InvoicePaymentJson should not contain a paymentMethodId when this is an external payment");
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final Account account = accountUserApi.getAccountById(UUID.fromString(payment.getAccountId()), callContext);
    final UUID paymentMethodId = externalPayment ? null : (payment.getPaymentMethodId() != null ? UUID.fromString(payment.getPaymentMethodId()) : account.getPaymentMethodId());
    final UUID invoiceId = UUID.fromString(payment.getTargetInvoiceId());
    final Payment result = createPurchaseForInvoice(account, invoiceId, payment.getPurchasedAmount(), paymentMethodId, externalPayment, (payment.getPaymentExternalKey() != null) ? payment.getPaymentExternalKey() : null, null, pluginProperties, callContext);
    return result != null ? uriBuilder.buildResponse(uriInfo, InvoicePaymentResource.class, "getInvoicePayment", result.getId(), request) : Response.status(Status.NO_CONTENT).build();
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) Account(org.killbill.billing.account.api.Account) InvoicePayment(org.killbill.billing.invoice.api.InvoicePayment) Payment(org.killbill.billing.payment.api.Payment) UUID(java.util.UUID) CallContext(org.killbill.billing.util.callcontext.CallContext) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 73 with PluginProperty

use of org.killbill.billing.payment.api.PluginProperty in project killbill by killbill.

the class AccountResource method getPaymentMethods.

@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 getPaymentMethods(@PathParam("accountId") final String accountId, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @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.createContext(request);
    final Account account = accountUserApi.getAccountById(UUID.fromString(accountId), tenantContext);
    final List<PaymentMethod> methods = paymentApi.getAccountPaymentMethods(account.getId(), 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();
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) Account(org.killbill.billing.account.api.Account) Function(com.google.common.base.Function) PaymentMethodJson(org.killbill.billing.jaxrs.json.PaymentMethodJson) ArrayList(java.util.ArrayList) TenantContext(org.killbill.billing.util.callcontext.TenantContext) PaymentMethod(org.killbill.billing.payment.api.PaymentMethod) AccountAuditLogs(org.killbill.billing.util.audit.AccountAuditLogs) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 74 with PluginProperty

use of org.killbill.billing.payment.api.PluginProperty in project killbill by killbill.

the class BundleResource method resumeBundle.

@TimedResource
@PUT
@Path("/{bundleId:" + UUID_PATTERN + "}/" + RESUME)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Resume a bundle")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid bundle id supplied"), @ApiResponse(code = 404, message = "Bundle not found") })
public Response resumeBundle(@PathParam(ID_PARAM_NAME) final String id, @QueryParam(QUERY_REQUESTED_DT) final String requestedDate, @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 SubscriptionApiException, EntitlementApiException, AccountApiException {
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final CallContext callContext = context.createContext(createdBy, reason, comment, request);
    final UUID bundleId = UUID.fromString(id);
    final LocalDate inputLocalDate = toLocalDate(requestedDate);
    entitlementApi.resume(bundleId, inputLocalDate, pluginProperties, callContext);
    return Response.status(Status.OK).build();
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) UUID(java.util.UUID) CallContext(org.killbill.billing.util.callcontext.CallContext) LocalDate(org.joda.time.LocalDate) Path(javax.ws.rs.Path) TimedResource(org.killbill.commons.metrics.TimedResource) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 75 with PluginProperty

use of org.killbill.billing.payment.api.PluginProperty in project killbill by killbill.

the class PaymentResource method getPaymentByExternalKey.

@TimedResource(name = "getPayment")
@GET
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a payment by external key", response = PaymentJson.class)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Payment not found") })
public Response getPaymentByExternalKey(@QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_WITH_ATTEMPTS) @DefaultValue("false") final Boolean withAttempts, @QueryParam(QUERY_EXTERNAL_KEY) final String paymentExternalKey, @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 PaymentApiException {
    verifyNonNullOrEmpty(paymentExternalKey, "Payment externalKey needs to be specified");
    final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
    final TenantContext tenantContext = context.createContext(request);
    final Payment payment = paymentApi.getPaymentByExternalKey(paymentExternalKey, withPluginInfo, withAttempts, pluginProperties, tenantContext);
    final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(payment.getAccountId(), auditMode.getLevel(), tenantContext);
    final PaymentJson result = new PaymentJson(payment, accountAuditLogs);
    return Response.status(Response.Status.OK).entity(result).build();
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) Payment(org.killbill.billing.payment.api.Payment) TenantContext(org.killbill.billing.util.callcontext.TenantContext) PaymentJson(org.killbill.billing.jaxrs.json.PaymentJson) AccountAuditLogs(org.killbill.billing.util.audit.AccountAuditLogs) TimedResource(org.killbill.commons.metrics.TimedResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

PluginProperty (org.killbill.billing.payment.api.PluginProperty)105 UUID (java.util.UUID)45 Account (org.killbill.billing.account.api.Account)42 ApiOperation (io.swagger.annotations.ApiOperation)35 ApiResponses (io.swagger.annotations.ApiResponses)35 Produces (javax.ws.rs.Produces)35 TimedResource (org.killbill.commons.metrics.TimedResource)35 Test (org.testng.annotations.Test)33 Path (javax.ws.rs.Path)32 Payment (org.killbill.billing.payment.api.Payment)30 CallContext (org.killbill.billing.util.callcontext.CallContext)29 ArrayList (java.util.ArrayList)19 LocalDate (org.joda.time.LocalDate)19 Consumes (javax.ws.rs.Consumes)17 BigDecimal (java.math.BigDecimal)16 TenantContext (org.killbill.billing.util.callcontext.TenantContext)15 GET (javax.ws.rs.GET)14 POST (javax.ws.rs.POST)13 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)13 AccountAuditLogs (org.killbill.billing.util.audit.AccountAuditLogs)13