mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 00:48:49 +00:00
intentando meter los ficheros redsys
This commit is contained in:
@ -0,0 +1,53 @@
|
||||
package com.imprimelibros.erp.redsys;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/pagos/redsys")
|
||||
public class RedsysController {
|
||||
|
||||
private final RedsysService service;
|
||||
public RedsysController(RedsysService service) { this.service = service; }
|
||||
|
||||
@PostMapping("/crear")
|
||||
public String crearPago(@RequestParam String order,
|
||||
@RequestParam long amountCents,
|
||||
Model model) {
|
||||
var payReq = new RedsysService.PaymentRequest(order, amountCents, "Compra en ImprimeLibros");
|
||||
var form = service.buildRedirectForm(payReq);
|
||||
model.addAttribute("action", form.action());
|
||||
model.addAttribute("signatureVersion", form.signatureVersion());
|
||||
model.addAttribute("merchantParameters", form.merchantParameters());
|
||||
model.addAttribute("signature", form.signature());
|
||||
return "payments/redsys-redirect"; // Thymeleaf
|
||||
}
|
||||
|
||||
@PostMapping("/notify")
|
||||
@ResponseBody
|
||||
public ResponseEntity<String> notifyRedsys(@RequestParam("Ds_Signature") String dsSig,
|
||||
@RequestParam("Ds_SignatureVersion") String dsSigVer,
|
||||
@RequestParam("Ds_MerchantParameters") String dsParams) throws Exception {
|
||||
var notif = service.validateAndParse(dsSig, dsSigVer, dsParams);
|
||||
|
||||
// 1) Idempotencia: marca el pedido si aún no procesado.
|
||||
// 2) Verifica importe/moneda/pedido contra tu base de datos.
|
||||
// 3) Autoriza en tu sistema si notif.authorized() == true.
|
||||
|
||||
return ResponseEntity.ok("OK");
|
||||
}
|
||||
|
||||
@GetMapping("/ok")
|
||||
public String ok() { return "payments/success"; }
|
||||
|
||||
@GetMapping("/ko")
|
||||
public String ko() { return "payments/failure"; }
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user