use of io.swagger.annotations.ApiOperation in project killbill by killbill.
the class AdminResource method updatePaymentTransactionState.
@PUT
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@Path("/payments/{paymentId:" + UUID_PATTERN + "}/transactions/{paymentTransactionId:" + UUID_PATTERN + "}")
@ApiOperation(value = "Update existing paymentTransaction and associated payment state")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid account data supplied") })
public Response updatePaymentTransactionState(final AdminPaymentJson json, @PathParam("paymentId") final String paymentIdStr, @PathParam("paymentTransactionId") final String paymentTransactionIdStr, @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 {
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
final Payment payment = paymentApi.getPayment(UUID.fromString(paymentIdStr), false, false, ImmutableList.<PluginProperty>of(), callContext);
final UUID paymentTransactionId = UUID.fromString(paymentTransactionIdStr);
final PaymentTransaction paymentTransaction = Iterables.tryFind(payment.getTransactions(), new Predicate<PaymentTransaction>() {
@Override
public boolean apply(final PaymentTransaction input) {
return input.getId().equals(paymentTransactionId);
}
}).orNull();
adminPaymentApi.fixPaymentTransactionState(payment, paymentTransaction, TransactionStatus.valueOf(json.getTransactionStatus()), json.getLastSuccessPaymentState(), json.getCurrentPaymentStateName(), ImmutableList.<PluginProperty>of(), callContext);
return Response.status(Status.OK).build();
}
use of io.swagger.annotations.ApiOperation in project killbill by killbill.
the class BundleResource method transferBundle.
@TimedResource
@PUT
@Path("/{bundleId:" + UUID_PATTERN + "}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Transfer a bundle to another account")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid bundle id, requested date or policy supplied"), @ApiResponse(code = 404, message = "Bundle not found") })
public Response transferBundle(final BundleJson json, @PathParam(ID_PARAM_NAME) final String id, @QueryParam(QUERY_REQUESTED_DT) final String requestedDate, @QueryParam(QUERY_BILLING_POLICY) @DefaultValue("END_OF_TERM") final String policyString, @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 EntitlementApiException, SubscriptionApiException, AccountApiException {
verifyNonNullOrEmpty(json, "BundleJson body should be specified");
verifyNonNullOrEmpty(json.getAccountId(), "BundleJson accountId needs to be set");
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final BillingActionPolicy policy = BillingActionPolicy.valueOf(policyString.toUpperCase());
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
final UUID bundleId = UUID.fromString(id);
final SubscriptionBundle bundle = subscriptionApi.getSubscriptionBundle(bundleId, callContext);
final LocalDate inputLocalDate = toLocalDate(requestedDate);
final UUID newBundleId = entitlementApi.transferEntitlementsOverrideBillingPolicy(bundle.getAccountId(), UUID.fromString(json.getAccountId()), bundle.getExternalKey(), inputLocalDate, policy, pluginProperties, callContext);
return uriBuilder.buildResponse(uriInfo, BundleResource.class, "getBundle", newBundleId, request);
}
use of io.swagger.annotations.ApiOperation in project killbill by killbill.
the class BundleResource method getBundles.
@TimedResource
@GET
@Path("/" + PAGINATION)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "List bundles", response = BundleJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getBundles(@QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException {
final TenantContext tenantContext = context.createContext(request);
final Pagination<SubscriptionBundle> bundles = subscriptionApi.getSubscriptionBundles(offset, limit, tenantContext);
final URI nextPageUri = uriBuilder.nextPage(BundleResource.class, "getBundles", bundles.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_AUDIT, auditMode.getLevel().toString()));
final AtomicReference<Map<UUID, AccountAuditLogs>> accountsAuditLogs = new AtomicReference<Map<UUID, AccountAuditLogs>>(new HashMap<UUID, AccountAuditLogs>());
return buildStreamingPaginationResponse(bundles, new Function<SubscriptionBundle, BundleJson>() {
@Override
public BundleJson apply(final SubscriptionBundle bundle) {
// Cache audit logs per account
if (accountsAuditLogs.get().get(bundle.getAccountId()) == null) {
accountsAuditLogs.get().put(bundle.getAccountId(), auditUserApi.getAccountAuditLogs(bundle.getAccountId(), auditMode.getLevel(), tenantContext));
}
try {
return new BundleJson(bundle, null, accountsAuditLogs.get().get(bundle.getAccountId()));
} catch (final CatalogApiException unused) {
// Does not happen because we pass a null Currency
throw new RuntimeException(unused);
}
}
}, nextPageUri);
}
use of io.swagger.annotations.ApiOperation in project killbill by killbill.
the class BundleResource method pauseBundle.
@TimedResource
@PUT
@Path("/{bundleId:" + UUID_PATTERN + "}/" + PAUSE)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Pause a bundle")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid bundle id supplied"), @ApiResponse(code = 404, message = "Bundle not found") })
public Response pauseBundle(@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.pause(bundleId, inputLocalDate, pluginProperties, callContext);
return Response.status(Status.OK).build();
}
use of io.swagger.annotations.ApiOperation in project killbill by killbill.
the class SubscriptionResource method updateSubscriptionBCD.
@TimedResource
@PUT
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
@Path("/{subscriptionId:" + UUID_PATTERN + "}/" + BCD)
@ApiOperation(value = "Update the BCD associated to a subscription")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid entitlement supplied") })
public Response updateSubscriptionBCD(final SubscriptionJson json, @PathParam(ID_PARAM_NAME) final String id, @QueryParam(QUERY_ENTITLEMENT_EFFECTIVE_FROM_DT) final String effectiveFromDateStr, @QueryParam(QUERY_FORCE_NEW_BCD_WITH_PAST_EFFECTIVE_DATE) @DefaultValue("false") final Boolean forceNewBcdWithPastEffectiveDate, @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 SubscriptionApiException, EntitlementApiException, AccountApiException {
verifyNonNullOrEmpty(json, "SubscriptionJson body should be specified");
verifyNonNullOrEmpty(json.getBillCycleDayLocal(), "SubscriptionJson new BCD should be specified");
LocalDate effectiveFromDate = toLocalDate(effectiveFromDateStr);
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
final UUID subscriptionId = UUID.fromString(id);
final Entitlement entitlement = entitlementApi.getEntitlementForId(subscriptionId, callContext);
if (effectiveFromDateStr != null) {
final Account account = accountUserApi.getAccountById(entitlement.getAccountId(), callContext);
final LocalDate accountToday = new LocalDate(clock.getUTCNow(), account.getTimeZone());
int comp = effectiveFromDate.compareTo(accountToday);
switch(comp) {
case -1:
if (!forceNewBcdWithPastEffectiveDate) {
throw new IllegalArgumentException("Changing a subscription BCD in the past may have consequences on previous invoice generated. Use flag forceNewBcdWithPastEffectiveDate to force this behavior");
}
break;
case 0:
// Ensure system will use curremt time for the event so it happens immediately
effectiveFromDate = null;
break;
case 1:
// Future date, normal case where such effectiveFromDateStr is being passed
break;
}
}
entitlement.updateBCD(json.getBillCycleDayLocal(), effectiveFromDate, callContext);
return Response.status(Status.OK).build();
}
Aggregations