Search in sources :

Example 1 with PaymentInformation

use of alfio.model.PaymentInformation in project alf.io by alfio-event.

the class BaseStripeManager method getInfo.

Optional<PaymentInformation> getInfo(Transaction transaction, PurchaseContext purchaseContext) {
    try {
        Optional<RequestOptions> requestOptionsOptional = options(purchaseContext);
        if (requestOptionsOptional.isPresent()) {
            RequestOptions options = requestOptionsOptional.get();
            Charge charge = Charge.retrieve(transaction.getTransactionId(), options);
            String paidAmount = MonetaryUtil.formatCents(charge.getAmount(), charge.getCurrency());
            String refundedAmount = MonetaryUtil.formatCents(charge.getAmountRefunded(), charge.getCurrency());
            List<BalanceTransaction.Fee> fees = retrieveBalanceTransaction(charge.getBalanceTransaction(), options).getFeeDetails();
            return Optional.of(new PaymentInformation(paidAmount, refundedAmount, getFeeAmount(fees, "stripe_fee"), getFeeAmount(fees, "application_fee")));
        }
        return Optional.empty();
    } catch (StripeException e) {
        return Optional.empty();
    }
}
Also used : RequestOptions(com.stripe.net.RequestOptions) Charge(com.stripe.model.Charge) PaymentInformation(alfio.model.PaymentInformation)

Example 2 with PaymentInformation

use of alfio.model.PaymentInformation in project alf.io by alfio-event.

the class StripeManager method getInfo.

Optional<PaymentInformation> getInfo(Transaction transaction, Event event) {
    try {
        Optional<RequestOptions> requestOptionsOptional = options(event);
        if (requestOptionsOptional.isPresent()) {
            RequestOptions options = requestOptionsOptional.get();
            Charge charge = Charge.retrieve(transaction.getTransactionId(), options);
            String paidAmount = MonetaryUtil.formatCents(charge.getAmount());
            String refundedAmount = MonetaryUtil.formatCents(charge.getAmountRefunded());
            List<Fee> fees = retrieveBalanceTransaction(charge.getBalanceTransaction(), options).getFeeDetails();
            return Optional.of(new PaymentInformation(paidAmount, refundedAmount, getFeeAmount(fees, "stripe_fee"), getFeeAmount(fees, "application_fee")));
        }
        return Optional.empty();
    } catch (StripeException e) {
        return Optional.empty();
    }
}
Also used : RequestOptions(com.stripe.net.RequestOptions) Fee(com.stripe.model.Fee) Charge(com.stripe.model.Charge) PaymentInformation(alfio.model.PaymentInformation)

Example 3 with PaymentInformation

use of alfio.model.PaymentInformation in project alf.io by alfio-event.

the class SaferpayManager method getInfo.

@Override
public Optional<PaymentInformation> getInfo(Transaction transaction, PurchaseContext purchaseContext) {
    var configuration = loadConfiguration(purchaseContext);
    var requestBody = new TransactionInquireRequestBuilder(transaction.getTransactionId(), 0).addAuthentication(configuration.get(SAFERPAY_CUSTOMER_ID).getRequiredValue(), transaction.getReservationId()).build();
    var request = buildRequest(configuration, "/Payment/v1/Transaction/Inquire", requestBody);
    try {
        var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8));
        if (!HttpUtils.callSuccessful(response)) {
            LOGGER.warn("Cannot retrieve transaction info. Status {}, body {}", response.statusCode(), response.body());
            return Optional.empty();
        }
        LOGGER.debug("received successful response {}", response.body());
        var responseBody = JsonParser.parseString(response.body()).getAsJsonObject();
        var amount = responseBody.get(TRANSACTION).getAsJsonObject().get("Amount").getAsJsonObject();
        var centsAsString = amount.get("Value").getAsString();
        var formattedAmount = MonetaryUtil.formatCents(Integer.parseInt(centsAsString), amount.get("CurrencyCode").getAsString());
        return Optional.of(new PaymentInformation(formattedAmount, null, null, null));
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        LOGGER.error("Request interrupted while calling getInfo", e);
    } catch (Exception ex) {
        LOGGER.error("unexpected error while calling getInfo", ex);
    }
    return Optional.empty();
}
Also used : PaymentInformation(alfio.model.PaymentInformation)

Example 4 with PaymentInformation

use of alfio.model.PaymentInformation in project alf.io by alfio-event.

the class MollieWebhookPaymentManager method getInfo.

@Override
public Optional<PaymentInformation> getInfo(Transaction transaction, PurchaseContext purchaseContext) {
    ConfigurationLevel configurationLevel = purchaseContext.getConfigurationLevel();
    var configuration = getConfiguration(configurationLevel);
    try {
        var getPaymentResponse = callGetPayment(transaction.getPaymentId(), configuration, configurationLevel);
        if (HttpUtils.callSuccessful(getPaymentResponse)) {
            try (var responseReader = new InputStreamReader(getPaymentResponse.body(), UTF_8)) {
                var body = new MolliePaymentDetails(JsonParser.parseReader(responseReader).getAsJsonObject());
                var paidAmount = body.getPaidAmount();
                var refundAmount = body.getRefundAmount().map(PaymentAmount::getValue).orElse(null);
                return Optional.of(new PaymentInformation(paidAmount.getValue(), refundAmount, null, null));
            }
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        log.warn("Request interrupted while calling getInfo", e);
    } catch (Exception e) {
        log.warn("got exception while calling getInfo", e);
    }
    return Optional.empty();
}
Also used : ConfigurationLevel(alfio.manager.system.ConfigurationLevel) InputStreamReader(java.io.InputStreamReader) PaymentInformation(alfio.model.PaymentInformation) IOException(java.io.IOException)

Aggregations

PaymentInformation (alfio.model.PaymentInformation)4 Charge (com.stripe.model.Charge)2 RequestOptions (com.stripe.net.RequestOptions)2 ConfigurationLevel (alfio.manager.system.ConfigurationLevel)1 Fee (com.stripe.model.Fee)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1