use of org.killbill.billing.catalog.api.Currency in project killbill by killbill.
the class PaymentResource method captureAuthorizationInternal.
private Response captureAuthorizationInternal(final PaymentTransactionJson json, @Nullable final UUID paymentId, 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 {
verifyNonNullOrEmpty(json, "PaymentTransactionJson body should be specified");
verifyNonNullOrEmpty(json.getAmount(), "PaymentTransactionJson amount needs to be set");
final Iterable<PluginProperty> pluginPropertiesFromBody = extractPluginProperties(json.getProperties());
final Iterable<PluginProperty> pluginPropertiesFromQuery = extractPluginProperties(pluginPropertiesString);
final Iterable<PluginProperty> pluginProperties = Iterables.concat(pluginPropertiesFromQuery, pluginPropertiesFromBody);
final CallContext callContext = context.createCallContextNoAccountId(createdBy, reason, comment, request);
final Payment initialPayment = getPaymentByIdOrKey(paymentId, json.getPaymentExternalKey(), pluginProperties, callContext);
final Account account = accountUserApi.getAccountById(initialPayment.getAccountId(), callContext);
final Currency currency = json.getCurrency() == null ? account.getCurrency() : json.getCurrency();
final PaymentOptions paymentOptions = createControlPluginApiPaymentOptions(paymentControlPluginNames);
final Payment payment = paymentApi.createCaptureWithPaymentControl(account, initialPayment.getId(), json.getAmount(), currency, json.getEffectiveDate(), json.getTransactionExternalKey(), pluginProperties, paymentOptions, callContext);
return createPaymentResponse(uriInfo, payment, TransactionType.CAPTURE, json.getTransactionExternalKey(), request);
}
use of org.killbill.billing.catalog.api.Currency 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 ", response = PaymentJson.class)
@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.createCallContextNoAccountId(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 = 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() : 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.getEffectiveDate(), paymentTransactionJson.getPaymentExternalKey(), paymentTransactionJson.getTransactionExternalKey(), transactionPluginProperties, paymentOptions, callContext);
break;
case PURCHASE:
result = paymentApi.createPurchaseWithPaymentControl(account, paymentMethodId, paymentId, paymentTransactionJson.getAmount(), currency, paymentTransactionJson.getEffectiveDate(), paymentTransactionJson.getPaymentExternalKey(), paymentTransactionJson.getTransactionExternalKey(), transactionPluginProperties, paymentOptions, callContext);
break;
case CREDIT:
result = paymentApi.createCreditWithPaymentControl(account, paymentMethodId, paymentId, paymentTransactionJson.getAmount(), currency, paymentTransactionJson.getEffectiveDate(), 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.catalog.api.Currency in project killbill by killbill.
the class SubscriptionResourceHelpers method buildUsagePrices.
private static void buildUsagePrices(final Currency currency, final PhasePriceJson input, final Collection<UsagePriceOverride> usagePrices) {
for (final UsagePriceJson usageOverrideJson : input.getUsagePrices()) {
final List<TierPriceOverride> tierPriceOverrides = new LinkedList<TierPriceOverride>();
for (final TierPriceJson tierPriceJson : usageOverrideJson.getTierPrices()) {
final List<TieredBlockPriceOverride> blockPriceOverrides = new LinkedList<TieredBlockPriceOverride>();
for (final BlockPriceJson block : tierPriceJson.getBlockPrices()) {
blockPriceOverrides.add(new TieredBlockPriceOverride() {
@Override
public String getUnitName() {
return block.getUnitName();
}
@Override
public Double getSize() {
return block.getSize();
}
@Override
public BigDecimal getPrice() {
return block.getPrice();
}
@Override
public Currency getCurrency() {
return currency;
}
@Override
public Double getMax() {
return block.getMax();
}
});
}
tierPriceOverrides.add(new TierPriceOverride() {
@Override
public List<TieredBlockPriceOverride> getTieredBlockPriceOverrides() {
return blockPriceOverrides;
}
});
}
usagePrices.add(new UsagePriceOverride() {
@Override
public String getName() {
return usageOverrideJson.getUsageName();
}
@Override
public UsageType getUsageType() {
return usageOverrideJson.getUsageType();
}
@Override
public List<TierPriceOverride> getTierPriceOverrides() {
return tierPriceOverrides;
}
});
}
}
use of org.killbill.billing.catalog.api.Currency in project killbill by killbill.
the class SubscriptionResourceHelpers method buildPlanPhasePriceOverride.
private static PlanPhasePriceOverride buildPlanPhasePriceOverride(final PlanSpecifier spec, final Currency currency, final PhasePriceJson input, final List<UsagePriceOverride> usagePrices) {
if (input.getPhaseName() != null) {
return new PlanPhasePriceOverride() {
@Override
public String getPhaseName() {
return input.getPhaseName();
}
@Override
public PlanPhaseSpecifier getPlanPhaseSpecifier() {
return null;
}
@Override
public Currency getCurrency() {
return currency;
}
@Override
public BigDecimal getFixedPrice() {
return input.getFixedPrice();
}
@Override
public BigDecimal getRecurringPrice() {
return input.getRecurringPrice();
}
@Override
public List<UsagePriceOverride> getUsagePriceOverrides() {
return usagePrices;
}
};
}
final PhaseType phaseType = input.getPhaseType() != null ? PhaseType.valueOf(input.getPhaseType()) : null;
final PlanPhaseSpecifier planPhaseSpecifier = spec.getPlanName() != null ? new PlanPhaseSpecifier(spec.getPlanName(), phaseType) : new PlanPhaseSpecifier(spec.getProductName(), spec.getBillingPeriod(), spec.getPriceListName(), phaseType);
final Currency resolvedCurrency = input.getFixedPrice() != null || input.getRecurringPrice() != null ? currency : null;
return new PlanPhasePriceOverride() {
@Override
public String getPhaseName() {
return null;
}
@Override
public PlanPhaseSpecifier getPlanPhaseSpecifier() {
return planPhaseSpecifier;
}
@Override
public Currency getCurrency() {
return resolvedCurrency;
}
@Override
public BigDecimal getFixedPrice() {
return input.getFixedPrice();
}
@Override
public BigDecimal getRecurringPrice() {
return input.getRecurringPrice();
}
@Override
public List<UsagePriceOverride> getUsagePriceOverrides() {
return usagePrices;
}
};
}
use of org.killbill.billing.catalog.api.Currency in project killbill by killbill.
the class TestInvoiceJsonWithBundleKeys method createCreditJson.
private InvoiceItemJson createCreditJson() {
final BigDecimal creditAmount = BigDecimal.TEN;
final UUID creditId = UUID.randomUUID();
final Currency currency = Currency.USD;
final UUID invoiceId = UUID.randomUUID();
final LocalDate effectiveDate = clock.getUTCToday();
final UUID accountId = UUID.randomUUID();
return new InvoiceItemJson(creditId, invoiceId, null, accountId, null, null, null, null, null, null, null, null, null, null, null, InvoiceItemType.CBA_ADJ, null, effectiveDate, effectiveDate, creditAmount, null, currency, null, null, null, null, null);
}
Aggregations