Search in sources :

Example 1 with StripeSCACreditCardToken

use of alfio.model.transaction.token.StripeSCACreditCardToken in project alf.io by alfio-event.

the class StripeWebhookPaymentManager method processSuccessfulPaymentIntent.

private PaymentWebhookResult processSuccessfulPaymentIntent(Transaction transaction, PaymentIntent paymentIntent, TicketReservation reservation, PurchaseContext purchaseContext) {
    var charge = paymentIntent.getCharges().getData().get(0);
    var chargeId = charge.getId();
    long gtwFee = Optional.ofNullable(charge.getBalanceTransactionObject()).map(BalanceTransaction::getFee).orElse(0L);
    // this serializes
    transactionRepository.lockByIdForUpdate(transaction.getId());
    int affectedRows = transactionRepository.updateIfStatus(transaction.getId(), chargeId, transaction.getPaymentId(), purchaseContext.now(clockProvider), transaction.getPlatformFee(), gtwFee, Transaction.Status.COMPLETE, Map.of(), Transaction.Status.PENDING);
    List<Map<String, Object>> modifications = List.of(Map.of("paymentId", chargeId, "paymentMethod", "stripe"));
    if (affectedRows == 0) {
        // the transaction was already confirmed by someone else.
        // We can safely return the chargeId, but we write in the auditing that we skipped the confirmation
        auditingRepository.insert(reservation.getId(), null, purchaseContext, Audit.EventType.PAYMENT_ALREADY_CONFIRMED, new Date(), Audit.EntityType.RESERVATION, reservation.getId(), modifications);
        return PaymentWebhookResult.successful(new StripeSCACreditCardToken(transaction.getPaymentId(), chargeId, null));
    }
    auditingRepository.insert(reservation.getId(), null, purchaseContext, Audit.EventType.PAYMENT_CONFIRMED, new Date(), Audit.EntityType.RESERVATION, reservation.getId(), modifications);
    return PaymentWebhookResult.successful(new StripeSCACreditCardToken(transaction.getPaymentId(), chargeId, null));
}
Also used : StripeSCACreditCardToken(alfio.model.transaction.token.StripeSCACreditCardToken)

Aggregations

StripeSCACreditCardToken (alfio.model.transaction.token.StripeSCACreditCardToken)1