@TimedResource(name = "processPayment")
@POST
@Path("/" + PAYMENTS)
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Trigger a payment using the account external key (authorization, purchase or credit)", response = PaymentJson.class)
@ApiResponses(value = {@ApiResponse(code = 201, message = "Payment transaction created successfully"),
@ApiResponse(code = 400, message = "Invalid account external key supplied"),
@ApiResponse(code = 404, message = "Account not found"),
@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 processPaymentByExternalKey(@MetricTag(tag = "type", property = "transactionType") final PaymentTransactionJson json,
@ApiParam(required = true) @QueryParam(QUERY_EXTERNAL_KEY) final String externalKey,
@QueryParam(QUERY_PAYMENT_METHOD_ID) final UUID paymentMethodId,
@QueryParam(QUERY_PAYMENT_CONTROL_PLUGIN_NAME) final List<String> paymentControlPluginNames,
@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 {
final CallContext callContext = context.createCallContextNoAccountId(createdBy, reason, comment, request);
final Account account = accountUserApi.getAccountByKey(externalKey, callContext);
return processPayment(json, account, paymentMethodId, paymentControlPluginNames, pluginPropertiesString, uriInfo, callContext, request);
}