mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 00:48:49 +00:00
añadidos ficheros a falta de modificar el servicio y el controlador redsys
This commit is contained in:
@ -0,0 +1,180 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 0007-payments-core
|
||||
author: jjo
|
||||
changes:
|
||||
# 1) payment_methods
|
||||
- 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 } }
|
||||
- addUniqueConstraint:
|
||||
tableName: payment_methods
|
||||
columnNames: token_id
|
||||
constraintName: uq_payment_methods_token
|
||||
|
||||
# 2) payments (una intención de cobro por pedido)
|
||||
- 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 } }
|
||||
- addForeignKeyConstraint:
|
||||
baseTableName: payments
|
||||
baseColumnNames: payment_method_id
|
||||
referencedTableName: payment_methods
|
||||
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} ] }
|
||||
- addUniqueConstraint:
|
||||
tableName: payments
|
||||
columnNames: gateway, gateway_order_id
|
||||
constraintName: uq_payments_gateway_order
|
||||
|
||||
# 3) payment_transactions (libro mayor: AUTH/CAPTURE/REFUND/VOID)
|
||||
- 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 } }
|
||||
- addForeignKeyConstraint:
|
||||
baseTableName: payment_transactions
|
||||
baseColumnNames: payment_id
|
||||
referencedTableName: payments
|
||||
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)
|
||||
- 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 }
|
||||
- addForeignKeyConstraint:
|
||||
baseTableName: refunds
|
||||
baseColumnNames: payment_id
|
||||
referencedTableName: payments
|
||||
referencedColumnNames: id
|
||||
constraintName: fk_ref_payment
|
||||
onDelete: CASCADE
|
||||
- addForeignKeyConstraint:
|
||||
baseTableName: refunds
|
||||
baseColumnNames: transaction_id
|
||||
referencedTableName: payment_transactions
|
||||
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)
|
||||
- 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 } }
|
||||
- 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)
|
||||
- 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 }
|
||||
- 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} ] }
|
||||
@ -10,4 +10,6 @@ databaseChangeLog:
|
||||
- include:
|
||||
file: db/changelog/changesets/0005-add-carts-onlyoneshipment.yml
|
||||
- include:
|
||||
file: db/changelog/changesets/0006-add-cart-direcciones.yml
|
||||
file: db/changelog/changesets/0006-add-cart-direcciones.yml
|
||||
- include:
|
||||
file: db/changelog/changesets/0007-payments-core.yml
|
||||
@ -38,8 +38,13 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<button id="btn-checkout" onclick="location.href='/checkout'" class="btn btn-secondary w-100 mt-2"
|
||||
th:text="#{checkout.make-payment}" disabled>Checkout</button>
|
||||
<form th:action="@{/pagos/redsys/crear}" method="post">
|
||||
<input type="hidden" name="order" value="123456789012" />
|
||||
<input type="hidden" name="amountCents" th:value="${summary.amountCents}" />
|
||||
<button id="btn-checkout" type="submit" class="btn btn-secondary w-100 mt-2"
|
||||
th:text="#{checkout.make-payment}" disabled>Checkout</button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<!-- end table-responsive -->
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user