mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-13 00:48:49 +00:00
limpieza del proyecto. Transferencias falta devolución
This commit is contained in:
@ -6,11 +6,13 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.imprimelibros.erp.common.Utils;
|
||||
@ -20,7 +22,6 @@ import com.imprimelibros.erp.datatables.DataTablesRequest;
|
||||
import com.imprimelibros.erp.datatables.DataTablesResponse;
|
||||
import com.imprimelibros.erp.i18n.TranslationService;
|
||||
import com.imprimelibros.erp.payments.model.Payment;
|
||||
import com.imprimelibros.erp.payments.model.PaymentStatus;
|
||||
import com.imprimelibros.erp.payments.model.PaymentTransaction;
|
||||
import com.imprimelibros.erp.payments.model.PaymentTransactionStatus;
|
||||
import com.imprimelibros.erp.payments.model.PaymentTransactionType;
|
||||
@ -29,23 +30,28 @@ import com.imprimelibros.erp.users.User;
|
||||
import com.imprimelibros.erp.users.UserDao;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/pagos")
|
||||
@PreAuthorize("hasRole('SUPERADMIN')")
|
||||
public class PaymentController {
|
||||
|
||||
protected final PaymentService paymentService;
|
||||
protected final MessageSource messageSource;
|
||||
protected final TranslationService translationService;
|
||||
protected final PaymentTransactionRepository repoPaymentTransaction;
|
||||
protected final UserDao repoUser;
|
||||
|
||||
public PaymentController(PaymentTransactionRepository repoPaymentTransaction, UserDao repoUser,
|
||||
MessageSource messageSource, TranslationService translationService) {
|
||||
MessageSource messageSource, TranslationService translationService, PaymentService paymentService) {
|
||||
this.repoPaymentTransaction = repoPaymentTransaction;
|
||||
this.repoUser = repoUser;
|
||||
this.messageSource = messageSource;
|
||||
this.translationService = translationService;
|
||||
this.paymentService = paymentService;
|
||||
|
||||
}
|
||||
|
||||
@GetMapping()
|
||||
@ -58,7 +64,10 @@ public class PaymentController {
|
||||
"pagos.refund.text",
|
||||
"pagos.refund.success",
|
||||
"pagos.refund.error.general",
|
||||
"pagos.refund.error.invalid-number");
|
||||
"pagos.refund.error.invalid-number",
|
||||
"pagos.transferencia.finalizar.title",
|
||||
"pagos.transferencia.finalizar.text",
|
||||
"pagos.transferencia.finalizar.success");
|
||||
|
||||
Map<String, String> translations = translationService.getTranslations(locale, keys);
|
||||
model.addAttribute("languageBundle", translations);
|
||||
@ -181,8 +190,10 @@ public class PaymentController {
|
||||
"payment.amountRefundedCents",
|
||||
"createdAt", "updatedAt");
|
||||
|
||||
Specification<PaymentTransaction> base = Specification.allOf(
|
||||
(root, query, cb) -> cb.equal(root.get("status"), PaymentTransactionStatus.pending));
|
||||
Specification<PaymentTransaction> base = (root, query, cb) -> cb.or(
|
||||
cb.equal(root.get("status"), PaymentTransactionStatus.pending),
|
||||
cb.equal(root.get("status"), PaymentTransactionStatus.succeeded));
|
||||
|
||||
base = base.and((root, query, cb) -> cb.equal(root.get("type"), PaymentTransactionType.CAPTURE));
|
||||
base = base.and((root, query, cb) -> cb.equal(root.get("payment").get("gateway"), "bank_transfer"));
|
||||
|
||||
@ -218,7 +229,7 @@ public class PaymentController {
|
||||
})
|
||||
.add("transfer_id", pago -> {
|
||||
if (pago.getPayment() != null) {
|
||||
return "TRANSF-" + pago.getPayment().getGatewayOrderId();
|
||||
return "TRANSF-" + pago.getPayment().getOrderId();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
@ -258,15 +269,15 @@ public class PaymentController {
|
||||
if (p != null) {
|
||||
String actions = "";
|
||||
if (pago.getStatus() != PaymentTransactionStatus.succeeded) {
|
||||
actions += "<span class=\'badge bg-secondary btn-mark-as-completed \' data-dsOrderId=\'"
|
||||
+ p.getGatewayOrderId()
|
||||
actions += "<span class=\'badge bg-success btn-mark-as-completed \' data-paymentId=\'"
|
||||
+ p.getId()
|
||||
+ "\' data-transactionId=\'" + pago.getPayment().getId()
|
||||
+ "\' style=\'cursor: pointer;\'>"
|
||||
+ messageSource.getMessage("pagos.table.finalizar", null, locale) + "</span> ";
|
||||
|
||||
}
|
||||
if (pago.getAmountCents() - p.getAmountRefundedCents() > 0) {
|
||||
actions += "<span class=\'badge bg-secondary btn-refund-payment \' data-dsOrderId=\'"
|
||||
if ((pago.getAmountCents() - p.getAmountRefundedCents() > 0) && pago.getStatus() == PaymentTransactionStatus.succeeded) {
|
||||
actions += "<span class=\'badge bg-secondary btn-transfer-refund \' data-dsOrderId=\'"
|
||||
+ p.getGatewayOrderId()
|
||||
+ "\' data-transactionId=\'" + pago.getPayment().getId()
|
||||
+ "\' data-amount=\'" + (pago.getAmountCents() - p.getAmountRefundedCents())
|
||||
@ -281,4 +292,21 @@ public class PaymentController {
|
||||
|
||||
}
|
||||
|
||||
@PostMapping(value = "/transfer/completed/{id}", produces = "application/json")
|
||||
public ResponseEntity<Map<String, Object>> markTransferAsCaptured(@PathVariable Long id) {
|
||||
|
||||
Map<String, Object> response;
|
||||
try {
|
||||
paymentService.markBankTransferAsCaptured(id);
|
||||
response = Map.of("success", true);
|
||||
return ResponseEntity.ok(response);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
response = Map.of("success", false);
|
||||
response.put("error", e.getMessage());
|
||||
return ResponseEntity.badRequest().body(response);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -16,7 +16,6 @@ import com.imprimelibros.erp.payments.repo.WebhookEventRepository;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class PaymentService {
|
||||
|
||||
@ -9,7 +9,6 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
|
||||
Reference in New Issue
Block a user