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();
}
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();
}
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();
}
use of org.killbill.billing.payment.api.PluginProperty in project killbill by killbill.
the class PaymentResource method createComboPayment.
@TimedResource
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@Path("/" + COMBO)
@ApiOperation(value = "Combo api to create a new payment transaction on a existing (or not) account ")
@ApiResponses(value = { @ApiResponse(code = 201, message = "Payment transaction created successfully"), @ApiResponse(code = 400, message = "Invalid data for Account or PaymentMethod"), @ApiResponse(code = 402, message = "Transaction declined by gateway"), @ApiResponse(code = 422, message = "Payment is aborted by a control plugin"), @ApiResponse(code = 502, message = "Failed to submit payment transaction"), @ApiResponse(code = 503, message = "Payment in unknown status, failed to receive gateway response"), @ApiResponse(code = 504, message = "Payment operation timeout") })
public Response createComboPayment(@MetricTag(tag = "type", property = "transactionType") final ComboPaymentTransactionJson json, @QueryParam(QUERY_PAYMENT_CONTROL_PLUGIN_NAME) final List<String> paymentControlPluginNames, @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, "ComboPaymentTransactionJson body should be specified");
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
final Account account = getOrCreateAccount(json.getAccount(), callContext);
final Iterable<PluginProperty> paymentMethodPluginProperties = extractPluginProperties(json.getPaymentMethodPluginProperties());
final UUID paymentMethodId = getOrCreatePaymentMethod(account, json.getPaymentMethod(), paymentMethodPluginProperties, callContext);
final PaymentTransactionJson paymentTransactionJson = json.getTransaction();
final TransactionType transactionType = TransactionType.valueOf(paymentTransactionJson.getTransactionType());
final PaymentOptions paymentOptions = createControlPluginApiPaymentOptions(paymentControlPluginNames);
final Payment result;
final Iterable<PluginProperty> transactionPluginProperties = extractPluginProperties(json.getTransactionPluginProperties());
final Currency currency = paymentTransactionJson.getCurrency() == null ? account.getCurrency() : Currency.valueOf(paymentTransactionJson.getCurrency());
// If we need to specify a paymentId (e.g 3DS authorization, we can use regular API, no need for combo call)
final UUID paymentId = null;
switch(transactionType) {
case AUTHORIZE:
result = paymentApi.createAuthorizationWithPaymentControl(account, paymentMethodId, paymentId, paymentTransactionJson.getAmount(), currency, paymentTransactionJson.getPaymentExternalKey(), paymentTransactionJson.getTransactionExternalKey(), transactionPluginProperties, paymentOptions, callContext);
break;
case PURCHASE:
result = paymentApi.createPurchaseWithPaymentControl(account, paymentMethodId, paymentId, paymentTransactionJson.getAmount(), currency, paymentTransactionJson.getPaymentExternalKey(), paymentTransactionJson.getTransactionExternalKey(), transactionPluginProperties, paymentOptions, callContext);
break;
case CREDIT:
result = paymentApi.createCreditWithPaymentControl(account, paymentMethodId, paymentId, paymentTransactionJson.getAmount(), currency, paymentTransactionJson.getPaymentExternalKey(), paymentTransactionJson.getTransactionExternalKey(), transactionPluginProperties, paymentOptions, callContext);
break;
default:
return Response.status(Status.PRECONDITION_FAILED).entity("TransactionType " + transactionType + " is not allowed for an account").build();
}
return createPaymentResponse(uriInfo, result, transactionType, paymentTransactionJson.getTransactionExternalKey(), request);
}
use of org.killbill.billing.payment.api.PluginProperty in project killbill by killbill.
the class PaymentResource method voidPaymentInternal.
private Response voidPaymentInternal(final PaymentTransactionJson json, @Nullable final String paymentIdStr, final List<String> paymentControlPluginNames, final List<String> pluginPropertiesString, final String createdBy, final String reason, final String comment, final UriInfo uriInfo, final HttpServletRequest request) throws PaymentApiException, AccountApiException {
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final CallContext callContext = context.createContext(createdBy, reason, comment, request);
final Payment initialPayment = getPaymentByIdOrKey(paymentIdStr, json.getPaymentExternalKey(), pluginProperties, callContext);
final Account account = accountUserApi.getAccountById(initialPayment.getAccountId(), callContext);
final String transactionExternalKey = json != null ? json.getTransactionExternalKey() : null;
final PaymentOptions paymentOptions = createControlPluginApiPaymentOptions(paymentControlPluginNames);
final Payment payment = paymentApi.createVoidWithPaymentControl(account, initialPayment.getId(), transactionExternalKey, pluginProperties, paymentOptions, callContext);
return createPaymentResponse(uriInfo, payment, TransactionType.VOID, json.getTransactionExternalKey(), request);
}
Aggregations