testeando el notify

This commit is contained in:
2025-11-03 19:31:28 +01:00
parent 88650fc5e8
commit 725cff9b51
10 changed files with 716 additions and 226 deletions

View File

@ -22,4 +22,4 @@ safekat.api.password=Safekat2024
redsys.environment=test
redsys.urls.ok=http://localhost:8080/pagos/redsys/ok
redsys.urls.ko=http://localhost:8080/pagos/redsys/ko
redsys.urls.notify=http://localhost:8080/pagos/redsys/notify
redsys.urls.notify=https://hns2jx2x-8080.uks1.devtunnels.ms/pagos/redsys/notify

View File

@ -7,53 +7,172 @@ databaseChangeLog:
- createTable:
tableName: payment_methods
columns:
- column: { name: id, type: BIGINT AUTO_INCREMENT, constraints: { primaryKey: true, nullable: false } }
- column: { name: user_id, type: BIGINT }
- column: { name: type, type: ENUM('card','bizum','bank_transfer'), constraints: { nullable: false } }
- column: { name: brand, type: VARCHAR(32) }
- column: { name: last4, type: VARCHAR(4) }
- column: { name: exp_month, type: TINYINT }
- column: { name: exp_year, type: SMALLINT }
- column: { name: fingerprint, type: VARCHAR(128) }
- column: { name: token_id, type: VARCHAR(128) } # alias/token de pasarela (nunca PAN)
- column: { name: sepa_mandate_id, type: VARCHAR(128) }
- column: { name: payer_email, type: VARCHAR(190) }
- column: { name: metadata, type: JSON }
- column: { name: created_at, type: DATETIME, defaultValueComputed: CURRENT_TIMESTAMP, constraints: { nullable: false } }
- column: { name: updated_at, type: DATETIME, defaultValueComputed: CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, constraints: { nullable: false } }
- column:
name: id
type: BIGINT AUTO_INCREMENT
constraints:
primaryKey: true
nullable: false
- column:
name: user_id
type: BIGINT
- column:
name: type
type: "ENUM('card','bizum','bank_transfer')"
constraints:
nullable: false
- column:
name: brand
type: VARCHAR(32)
- column:
name: last4
type: VARCHAR(4)
- column:
name: exp_month
type: TINYINT
- column:
name: exp_year
type: SMALLINT
- column:
name: fingerprint
type: VARCHAR(128)
- column:
name: token_id
type: VARCHAR(128)
- column:
name: sepa_mandate_id
type: VARCHAR(128)
- column:
name: payer_email
type: VARCHAR(190)
- column:
name: metadata
type: JSON
- column:
name: created_at
type: DATETIME
defaultValueComputed: CURRENT_TIMESTAMP
constraints:
nullable: false
- column:
name: updated_at
type: DATETIME
defaultValueComputed: "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
constraints:
nullable: false
- addUniqueConstraint:
tableName: payment_methods
columnNames: token_id
constraintName: uq_payment_methods_token
# 2) payments (una intención de cobro por pedido)
# 2) payments
- createTable:
tableName: payments
columns:
- column: { name: id, type: BIGINT AUTO_INCREMENT, constraints: { primaryKey: true, nullable: false } }
- column: { name: order_id, type: BIGINT, constraints: { nullable: false } } # tu pedido interno
- column: { name: user_id, type: BIGINT }
- column: { name: payment_method_id, type: BIGINT }
- column: { name: currency, type: CHAR(3), constraints: { nullable: false } }
- column: { name: amount_total_cents, type: BIGINT, constraints: { nullable: false } }
- column: { name: amount_captured_cents, type: BIGINT, defaultValueNumeric: 0, constraints: { nullable: false } }
- column: { name: amount_refunded_cents, type: BIGINT, defaultValueNumeric: 0, constraints: { nullable: false } }
- column: { name: status, type: ENUM('requires_payment_method','requires_action','authorized','captured','partially_refunded','refunded','canceled','failed'), defaultValue: requires_payment_method, constraints: { nullable: false } }
- column: { name: capture_method, type: ENUM('automatic','manual'), defaultValue: automatic, constraints: { nullable: false } }
- column: { name: gateway, type: VARCHAR(32), constraints: { nullable: false } } # 'redsys'
- column: { name: gateway_payment_id, type: VARCHAR(128) } # id en pasarela
- column: { name: gateway_order_id, type: VARCHAR(12) } # Ds_Order
- column: { name: authorization_code, type: VARCHAR(32) }
- column: { name: three_ds_status, type: ENUM('not_applicable','attempted','challenge','succeeded','failed'), defaultValue: not_applicable, constraints: { nullable: false } }
- column: { name: descriptor, type: VARCHAR(22) }
- column: { name: client_ip, type: VARBINARY(16) }
- column: { name: authorized_at, type: DATETIME }
- column: { name: captured_at, type: DATETIME }
- column: { name: canceled_at, type: DATETIME }
- column: { name: failed_at, type: DATETIME }
- column: { name: metadata, type: JSON }
- column: { name: created_at, type: DATETIME, defaultValueComputed: CURRENT_TIMESTAMP, constraints: { nullable: false } }
- column: { name: updated_at, type: DATETIME, defaultValueComputed: CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, constraints: { nullable: false } }
- column:
name: id
type: BIGINT AUTO_INCREMENT
constraints:
primaryKey: true
nullable: false
- column:
name: order_id
type: BIGINT
- column:
name: user_id
type: BIGINT
- column:
name: payment_method_id
type: BIGINT
- column:
name: currency
type: CHAR(3)
constraints:
nullable: false
- column:
name: amount_total_cents
type: BIGINT
constraints:
nullable: false
- column:
name: amount_captured_cents
type: BIGINT
defaultValueNumeric: 0
constraints:
nullable: false
- column:
name: amount_refunded_cents
type: BIGINT
defaultValueNumeric: 0
constraints:
nullable: false
- column:
name: status
type: "ENUM('requires_payment_method','requires_action','authorized','captured','partially_refunded','refunded','canceled','failed')"
defaultValue: "requires_payment_method"
constraints:
nullable: false
- column:
name: capture_method
type: "ENUM('automatic','manual')"
defaultValue: "automatic"
constraints:
nullable: false
- column:
name: gateway
type: VARCHAR(32)
constraints:
nullable: false
- column:
name: gateway_payment_id
type: VARCHAR(128)
- column:
name: gateway_order_id
type: VARCHAR(12)
- column:
name: authorization_code
type: VARCHAR(32)
- column:
name: three_ds_status
type: "ENUM('not_applicable','attempted','challenge','succeeded','failed')"
defaultValue: "not_applicable"
constraints:
nullable: false
- column:
name: descriptor
type: VARCHAR(22)
- column:
name: client_ip
type: VARBINARY(16)
- column:
name: authorized_at
type: DATETIME
- column:
name: captured_at
type: DATETIME
- column:
name: canceled_at
type: DATETIME
- column:
name: failed_at
type: DATETIME
- column:
name: metadata
type: JSON
- column:
name: created_at
type: DATETIME
defaultValueComputed: CURRENT_TIMESTAMP
constraints:
nullable: false
- column:
name: updated_at
type: DATETIME
defaultValueComputed: "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
constraints:
nullable: false
- addForeignKeyConstraint:
baseTableName: payments
baseColumnNames: payment_method_id
@ -61,34 +180,104 @@ databaseChangeLog:
referencedColumnNames: id
constraintName: fk_payments_payment_methods
onDelete: SET NULL
- createIndex: { tableName: payments, indexName: idx_payments_order, columns: [ {name: order_id} ] }
- createIndex: { tableName: payments, indexName: idx_payments_gateway, columns: [ {name: gateway}, {name: gateway_payment_id} ] }
- createIndex: { tableName: payments, indexName: idx_payments_status, columns: [ {name: status} ] }
- createIndex:
tableName: payments
indexName: idx_payments_order
columns:
- column:
name: order_id
- createIndex:
tableName: payments
indexName: idx_payments_gateway
columns:
- column:
name: gateway
- column:
name: gateway_payment_id
- createIndex:
tableName: payments
indexName: idx_payments_status
columns:
- column:
name: status
- addUniqueConstraint:
tableName: payments
columnNames: gateway, gateway_order_id
constraintName: uq_payments_gateway_order
# 3) payment_transactions (libro mayor: AUTH/CAPTURE/REFUND/VOID)
# 3) payment_transactions
- createTable:
tableName: payment_transactions
columns:
- column: { name: id, type: BIGINT AUTO_INCREMENT, constraints: { primaryKey: true, nullable: false } }
- column: { name: payment_id, type: BIGINT, constraints: { nullable: false } }
- column: { name: type, type: ENUM('AUTH','CAPTURE','REFUND','VOID'), constraints: { nullable: false } }
- column: { name: status, type: ENUM('pending','succeeded','failed'), constraints: { nullable: false } }
- column: { name: amount_cents, type: BIGINT, constraints: { nullable: false } }
- column: { name: currency, type: CHAR(3), constraints: { nullable: false } }
- column: { name: gateway_transaction_id, type: VARCHAR(128) }
- column: { name: gateway_response_code, type: VARCHAR(64) }
- column: { name: avs_result, type: VARCHAR(8) }
- column: { name: cvv_result, type: VARCHAR(8) }
- column: { name: three_ds_version, type: VARCHAR(16) }
- column: { name: idempotency_key, type: VARCHAR(128) }
- column: { name: request_payload, type: JSON }
- column: { name: response_payload, type: JSON }
- column: { name: processed_at, type: DATETIME }
- column: { name: created_at, type: DATETIME, defaultValueComputed: CURRENT_TIMESTAMP, constraints: { nullable: false } }
- column:
name: id
type: BIGINT AUTO_INCREMENT
constraints:
primaryKey: true
nullable: false
- column:
name: payment_id
type: BIGINT
constraints:
nullable: false
- column:
name: type
type: "ENUM('AUTH','CAPTURE','REFUND','VOID')"
constraints:
nullable: false
- column:
name: status
type: "ENUM('pending','succeeded','failed')"
constraints:
nullable: false
- column:
name: amount_cents
type: BIGINT
constraints:
nullable: false
- column:
name: currency
type: CHAR(3)
constraints:
nullable: false
- column:
name: gateway_transaction_id
type: VARCHAR(128)
- column:
name: gateway_response_code
type: VARCHAR(64)
- column:
name: avs_result
type: VARCHAR(8)
- column:
name: cvv_result
type: VARCHAR(8)
- column:
name: three_ds_version
type: VARCHAR(16)
- column:
name: idempotency_key
type: VARCHAR(128)
- column:
name: request_payload
type: JSON
- column:
name: response_payload
type: JSON
- column:
name: processed_at
type: DATETIME
- column:
name: created_at
type: DATETIME
defaultValueComputed: CURRENT_TIMESTAMP
constraints:
nullable: false
- addForeignKeyConstraint:
baseTableName: payment_transactions
baseColumnNames: payment_id
@ -96,30 +285,92 @@ databaseChangeLog:
referencedColumnNames: id
constraintName: fk_tx_payment
onDelete: CASCADE
- addUniqueConstraint:
tableName: payment_transactions
columnNames: gateway_transaction_id
constraintName: uq_tx_gateway_txid
- createIndex: { tableName: payment_transactions, indexName: idx_tx_pay, columns: [ {name: payment_id} ] }
- createIndex: { tableName: payment_transactions, indexName: idx_tx_type_status, columns: [ {name: type}, {name: status} ] }
- createIndex: { tableName: payment_transactions, indexName: idx_tx_idem, columns: [ {name: idempotency_key} ] }
# 4) refunds (orquestador de devoluciones)
- createIndex:
tableName: payment_transactions
indexName: idx_tx_pay
columns:
- column:
name: payment_id
- createIndex:
tableName: payment_transactions
indexName: idx_tx_type_status
columns:
- column:
name: type
- column:
name: status
- createIndex:
tableName: payment_transactions
indexName: idx_tx_idem
columns:
- column:
name: idempotency_key
# 4) refunds
- createTable:
tableName: refunds
columns:
- column: { name: id, type: BIGINT AUTO_INCREMENT, constraints: { primaryKey: true, nullable: false } }
- column: { name: payment_id, type: BIGINT, constraints: { nullable: false } }
- column: { name: transaction_id, type: BIGINT } # REFUND en payment_transactions
- column: { name: amount_cents, type: BIGINT, constraints: { nullable: false } }
- column: { name: reason, type: ENUM('customer_request','partial_return','pricing_adjustment','duplicate','fraud','other'), defaultValue: customer_request, constraints: { nullable: false } }
- column: { name: status, type: ENUM('pending','succeeded','failed','canceled'), defaultValue: pending, constraints: { nullable: false } }
- column: { name: requested_by_user_id, type: BIGINT }
- column: { name: requested_at, type: DATETIME, defaultValueComputed: CURRENT_TIMESTAMP, constraints: { nullable: false } }
- column: { name: processed_at, type: DATETIME }
- column: { name: gateway_refund_id, type: VARCHAR(128) }
- column: { name: notes, type: VARCHAR(500) }
- column: { name: metadata, type: JSON }
- column:
name: id
type: BIGINT AUTO_INCREMENT
constraints:
primaryKey: true
nullable: false
- column:
name: payment_id
type: BIGINT
constraints:
nullable: false
- column:
name: transaction_id
type: BIGINT
- column:
name: amount_cents
type: BIGINT
constraints:
nullable: false
- column:
name: reason
type: "ENUM('customer_request','partial_return','pricing_adjustment','duplicate','fraud','other')"
defaultValue: "customer_request"
constraints:
nullable: false
- column:
name: status
type: "ENUM('pending','succeeded','failed','canceled')"
defaultValue: "pending"
constraints:
nullable: false
- column:
name: requested_by_user_id
type: BIGINT
- column:
name: requested_at
type: DATETIME
defaultValueComputed: CURRENT_TIMESTAMP
constraints:
nullable: false
- column:
name: processed_at
type: DATETIME
- column:
name: gateway_refund_id
type: VARCHAR(128)
- column:
name: notes
type: VARCHAR(500)
- column:
name: metadata
type: JSON
- addForeignKeyConstraint:
baseTableName: refunds
baseColumnNames: payment_id
@ -127,6 +378,7 @@ databaseChangeLog:
referencedColumnNames: id
constraintName: fk_ref_payment
onDelete: CASCADE
- addForeignKeyConstraint:
baseTableName: refunds
baseColumnNames: transaction_id
@ -134,47 +386,138 @@ databaseChangeLog:
referencedColumnNames: id
constraintName: fk_ref_tx
onDelete: SET NULL
- addUniqueConstraint:
tableName: refunds
columnNames: gateway_refund_id
constraintName: uq_refund_gateway_id
- createIndex: { tableName: refunds, indexName: idx_ref_pay, columns: [ {name: payment_id} ] }
- createIndex: { tableName: refunds, indexName: idx_ref_status, columns: [ {name: status} ] }
# 5) webhooks (para Redsys: notificaciones asincrónicas)
- createIndex:
tableName: refunds
indexName: idx_ref_pay
columns:
- column:
name: payment_id
- createIndex:
tableName: refunds
indexName: idx_ref_status
columns:
- column:
name: status
# 5) webhook_events
- createTable:
tableName: webhook_events
columns:
- column: { name: id, type: BIGINT AUTO_INCREMENT, constraints: { primaryKey: true, nullable: false } }
- column: { name: provider, type: VARCHAR(32), constraints: { nullable: false } } # 'redsys'
- column: { name: event_type, type: VARCHAR(64), constraints: { nullable: false } }
- column: { name: event_id, type: VARCHAR(128) }
- column: { name: signature, type: VARCHAR(512) }
- column: { name: payload, type: JSON, constraints: { nullable: false } }
- column: { name: processed, type: TINYINT(1), defaultValueNumeric: 0, constraints: { nullable: false } }
- column: { name: processed_at, type: DATETIME }
- column: { name: attempts, type: INT, defaultValueNumeric: 0, constraints: { nullable: false } }
- column: { name: last_error, type: VARCHAR(500) }
- column: { name: created_at, type: DATETIME, defaultValueComputed: CURRENT_TIMESTAMP, constraints: { nullable: false } }
- column:
name: id
type: BIGINT AUTO_INCREMENT
constraints:
primaryKey: true
nullable: false
- column:
name: provider
type: VARCHAR(32)
constraints:
nullable: false
- column:
name: event_type
type: VARCHAR(64)
constraints:
nullable: false
- column:
name: event_id
type: VARCHAR(128)
- column:
name: signature
type: VARCHAR(512)
- column:
name: payload
type: JSON
constraints:
nullable: false
- column:
name: processed
type: TINYINT(1)
defaultValueNumeric: 0
constraints:
nullable: false
- column:
name: processed_at
type: DATETIME
- column:
name: attempts
type: INT
defaultValueNumeric: 0
constraints:
nullable: false
- column:
name: last_error
type: VARCHAR(500)
- column:
name: created_at
type: DATETIME
defaultValueComputed: CURRENT_TIMESTAMP
constraints:
nullable: false
- addUniqueConstraint:
tableName: webhook_events
columnNames: provider, event_id
constraintName: uq_webhook_provider_event
- createIndex: { tableName: webhook_events, indexName: idx_webhook_processed, columns: [ {name: processed} ] }
# 6) idempotency_keys (evitar doble REFUND o reprocesos)
- createIndex:
tableName: webhook_events
indexName: idx_webhook_processed
columns:
- column:
name: processed
# 6) idempotency_keys
- createTable:
tableName: idempotency_keys
columns:
- column: { name: id, type: BIGINT AUTO_INCREMENT, constraints: { primaryKey: true, nullable: false } }
- column: { name: scope, type: ENUM('payment','refund','webhook'), constraints: { nullable: false } }
- column: { name: idem_key, type: VARCHAR(128), constraints: { nullable: false } }
- column: { name: resource_id, type: BIGINT }
- column: { name: response_cache, type: JSON }
- column: { name: created_at, type: DATETIME, defaultValueComputed: CURRENT_TIMESTAMP, constraints: { nullable: false } }
- column: { name: expires_at, type: DATETIME }
- column:
name: id
type: BIGINT AUTO_INCREMENT
constraints:
primaryKey: true
nullable: false
- column:
name: scope
type: "ENUM('payment','refund','webhook')"
constraints:
nullable: false
- column:
name: idem_key
type: VARCHAR(128)
constraints:
nullable: false
- column:
name: resource_id
type: BIGINT
- column:
name: response_cache
type: JSON
- column:
name: created_at
type: DATETIME
defaultValueComputed: CURRENT_TIMESTAMP
constraints:
nullable: false
- column:
name: expires_at
type: DATETIME
- addUniqueConstraint:
tableName: idempotency_keys
columnNames: scope, idem_key
constraintName: uq_idem_scope_key
- createIndex: { tableName: idempotency_keys, indexName: idx_idem_resource, columns: [ {name: resource_id} ] }
- createIndex:
tableName: idempotency_keys
indexName: idx_idem_resource
columns:
- column:
name: resource_id

View File

@ -133,6 +133,7 @@ $(() => {
const html = await response.text();
$('#direccion-div').append(html);
$('#addBillingAddressBtn').addClass('d-none');
$('#btn-checkout').prop('disabled', false);
hideLoader();
return true;
}
@ -149,6 +150,13 @@ $(() => {
const $div = $card.parent();
$card.remove();
$('#addBillingAddressBtn').removeClass('d-none');
$('#btn-checkout').prop('disabled', true);
});
$('input[name="paymentMethod"]').on('change', function() {
const method = $(this).val();
// set the hidden input value in the form
$('input[name="method"]').val(method);
});
});

View File

@ -3,7 +3,7 @@
<div class="row g-4">
<div class="col-lg-4 col-sm-6">
<div class="form-check card-radio">
<input id="paymentMethod01" name="paymentMethod" type="radio" class="form-check-input" checked>
<input id="paymentMethod01" name="paymentMethod" type="radio" class="form-check-input" checked value="card">
<label class="form-check-label" for="paymentMethod01">
<span class="fs-16 text-muted me-2"><i class="mdi mdi-credit-card-outline align-bottom"></i></span>
<span class="fs-14 text-wrap" th:text="#{checkout.payment.card}"></span>
@ -13,7 +13,7 @@
</div>
<div class="col-lg-4 col-sm-6">
<div class="form-check card-radio">
<input id="paymentMethod02" name="paymentMethod" type="radio" class="form-check-input">
<input id="paymentMethod02" name="paymentMethod" type="radio" class="form-check-input" value="bizum">
<label class="form-check-label" for="paymentMethod02">
<span class="fs-16 text-muted me-2"><i class="mdi mdi-wallet-outline align-bottom"></i></span>
<span class="fs-14 text-wrap" th:text="#{checkout.payment.bizum}"></span>
@ -24,7 +24,7 @@
<div class="col-lg-4 col-sm-6">
<div class="form-check card-radio">
<input id="paymentMethod03" name="paymentMethod" type="radio" class="form-check-input">
<input id="paymentMethod03" name="paymentMethod" type="radio" class="form-check-input" value="bank-transfer">
<label class="form-check-label" for="paymentMethod03">
<span class="fs-16 text-muted me-2"><i class="mdi mdi-bank-transfer align-bottom"></i></span>
<span class="fs-14 text-wrap" th:text="#{checkout.payment.bank-transfer}"></span>

View File

@ -39,8 +39,8 @@
</tbody>
</table>
<form th:action="@{/pagos/redsys/crear}" method="post">
<input type="hidden" name="order" value="123456789012" />
<input type="hidden" name="amountCents" th:value="${summary.amountCents}" />
<input type="hidden" name="method" value="card"/>
<button id="btn-checkout" type="submit" class="btn btn-secondary w-100 mt-2"
th:text="#{checkout.make-payment}" disabled>Checkout</button>
</form>