Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
],
"remoteUser": "vscode",
"mounts": [
"source=transbank-maven-cache,target=/home/vscode/.m2,type=volume",
"source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,type=bind,consistency=cached"
],
"features": {
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ Toda la historia de cambios de este proyecto será documentada en este archivo.
El formato está basado en [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
y este proyecto adhiere a [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.0] - 08-09-2026

Esta versión agrega soporte para el producto Oneclick Mall.

### Agrega

- Se agrega el producto Webpay Oneclick Mall en su modalidad sincrónica.
- Se agrega el producto Webpay Oneclick Mall en su modalidad diferida.

## [1.0.1] - 03-10-2025

Pequeñas correcciones aplicadas.
Expand Down
23 changes: 12 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.5</version>
<relativePath/> <!-- lookup parent from repository -->
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>cl.transbank.webpay</groupId>
<artifactId>transbank-sdk-java-example</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<name>transbank-sdk-java-example</name>
<description>Proyecto de Ejemplo SDK JAVA</description>
<url/>
<url />
<licenses>
<license/>
<license />
</licenses>
<developers>
<developer/>
<developer />
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
<connection />
<developerConnection />
<tag />
<url />
</scm>
<properties>
<java.version>17</java.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
package cl.transbank.webpay.example.controllers;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cl.transbank.common.IntegrationApiKeys;
import cl.transbank.common.IntegrationCommerceCodes;
import cl.transbank.common.IntegrationType;
import cl.transbank.webpay.common.WebpayOptions;
import cl.transbank.webpay.exception.*;
import cl.transbank.webpay.exception.InscriptionDeleteException;
import cl.transbank.webpay.exception.InscriptionFinishException;
import cl.transbank.webpay.exception.InscriptionStartException;
import cl.transbank.webpay.exception.TransactionAuthorizeException;
import cl.transbank.webpay.exception.TransactionCaptureException;
import cl.transbank.webpay.exception.TransactionRefundException;
import cl.transbank.webpay.exception.TransactionStatusException;
import cl.transbank.webpay.oneclick.Oneclick;
import cl.transbank.webpay.oneclick.model.MallTransactionCreateDetails;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;

@Log4j2
@Controller
Expand All @@ -29,9 +36,9 @@ public class OneclickMallDeferredController extends BaseController {
private static final String TEMPLATE_FOLDER = "oneclick_mall_deferred";
private static final String BASE_URL = "/oneclick-mall-deferred";
private static final String PRODUCT = "Webpay Oneclick Mall Diferido";
private static final String MODEL_NAVIGATION = "navigation";
private static final String MODEL_RESPONSE = "response_data";
private static final String MODEL_RESPONSE_JSON = "response_data_json";
private static final String MODEL_NAVIGATION = "navigation";
private static final String MODEL_RESPONSE = "response_data";
private static final String MODEL_RESPONSE_JSON = "response_data_json";

private static final String VIEW_START = TEMPLATE_FOLDER + "/start";
private static final String VIEW_FINISH = TEMPLATE_FOLDER + "/finish";
Expand Down Expand Up @@ -96,8 +103,7 @@ public OneclickMallDeferredController() {
var options = new WebpayOptions(
IntegrationCommerceCodes.ONECLICK_MALL_DEFERRED,
IntegrationApiKeys.WEBPAY,
IntegrationType.TEST
);
IntegrationType.TEST);
inscription = new Oneclick.MallInscription(options);
transaction = new Oneclick.MallTransaction(options);
}
Expand All @@ -106,12 +112,13 @@ private void addBreadcrumbs(Model model, String label, String url) {
Map<String, String> breadcrumbs = new LinkedHashMap<>();
breadcrumbs.put("Inicio", "/");
breadcrumbs.put(PRODUCT, BASE_URL + "/");
if (label != null) breadcrumbs.put(label, url);
if (label != null)
breadcrumbs.put(label, url);
model.addAttribute("product", PRODUCT);
model.addAttribute("breadcrumbs", breadcrumbs);
}

@GetMapping("/")
@GetMapping({ "/start" })
public String start(HttpServletRequest req, Model model)
throws IOException, InscriptionStartException {

Expand All @@ -120,15 +127,14 @@ public String start(HttpServletRequest req, Model model)

String username = "user_" + getRandomNumber();
String email = "user." + getRandomNumber() + "@example.com";
String returnUrl = req.getRequestURL().toString() + "finish";
String returnUrl = req.getRequestURL().toString().replace("start", "finish");

var resp = inscription.start(username, email, returnUrl);

model.addAttribute("request_data", Map.of(
"username", username,
"email", email,
"returnUrl", returnUrl
));
"returnUrl", returnUrl));
model.addAttribute(MODEL_RESPONSE, resp);
model.addAttribute(MODEL_RESPONSE_JSON, toJson(resp));
model.addAttribute("url", resp.getUrlWebpay());
Expand All @@ -142,17 +148,17 @@ public String start(HttpServletRequest req, Model model)

@GetMapping("/finish")
public String finish(HttpServletRequest req,
@RequestParam Map<String, String> params,
@RequestParam(name = "TBK_TOKEN", required = false) String token,
@RequestParam(name = "TBK_ORDEN_COMPRA", required = false) String ordenCompra,
Model model)
@RequestParam Map<String, String> params,
@RequestParam(name = "TBK_TOKEN", required = false) String token,
@RequestParam(name = "TBK_ORDEN_COMPRA", required = false) String ordenCompra,
Model model)
throws IOException, InscriptionFinishException {

model.addAttribute(MODEL_NAVIGATION, NAV_FINISH);
model.addAttribute(MODEL_NAVIGATION, NAV_FINISH);
addBreadcrumbs(model, "Finalizar inscripción", "#");

if (ordenCompra != null) {
model.addAttribute(MODEL_NAVIGATION, NAV_FINISH_RECOVER);
model.addAttribute(MODEL_NAVIGATION, NAV_FINISH_RECOVER);
model.addAttribute("request_data_json", toJson(params));
return VIEW_RECOVER_ERROR;
}
Expand All @@ -172,8 +178,7 @@ public String finish(HttpServletRequest req,
req.getSession().setAttribute("tbkUser", resp.getTbkUser());
model.addAttribute("request_data", Map.of(
"username", username,
"tbkUser", resp.getTbkUser()
));
"tbkUser", resp.getTbkUser()));
model.addAttribute("token", token);
model.addAttribute("username", username);
model.addAttribute("tbk_user", resp.getTbkUser());
Expand All @@ -185,11 +190,11 @@ public String finish(HttpServletRequest req,

@GetMapping("/delete")
public String delete(@RequestParam String username,
@RequestParam("tbk_user") String tbkUser,
Model model)
@RequestParam("tbk_user") String tbkUser,
Model model)
throws IOException, InscriptionDeleteException {

model.addAttribute(MODEL_NAVIGATION, NAV_DELETE);
model.addAttribute(MODEL_NAVIGATION, NAV_DELETE);
addBreadcrumbs(model, "Eliminar inscripción", "#");

inscription.delete(tbkUser, username);
Expand All @@ -211,7 +216,7 @@ public String authorize(
Model model)
throws IOException, TransactionAuthorizeException {

model.addAttribute(MODEL_NAVIGATION, NAV_AUTHORIZE);
model.addAttribute(MODEL_NAVIGATION, NAV_AUTHORIZE);
addBreadcrumbs(model, "Autorizar transacción", "#");

String buyOrder = "buyOrder_" + getRandomNumber();
Expand All @@ -224,14 +229,12 @@ public String authorize(
amount1,
childCode1,
childBuyOrder1,
(byte) installments1
)
(byte) installments1)
.add(
amount2,
childCode2,
childBuyOrder2,
(byte) installments2
);
(byte) installments2);

var resp = transaction.authorize(username, tbkUser, buyOrder, details);

Expand All @@ -244,8 +247,8 @@ public String authorize(
@GetMapping("/status")
public String status(@RequestParam("buy_order") String buyOrder, Model model)
throws IOException, TransactionStatusException {
model.addAttribute(MODEL_NAVIGATION, NAV_STATUS);

model.addAttribute(MODEL_NAVIGATION, NAV_STATUS);
addBreadcrumbs(model, "Consultar estado", "#");

var resp = transaction.status(buyOrder);
Expand All @@ -256,13 +259,13 @@ public String status(@RequestParam("buy_order") String buyOrder, Model model)

@GetMapping("/refund")
public String refund(@RequestParam("buy_order") String buyOrder,
@RequestParam("child_buy_order") String childBuyOrder,
@RequestParam("child_commerce_code") String childCommerceCode,
@RequestParam double amount,
Model model)
@RequestParam("child_buy_order") String childBuyOrder,
@RequestParam("child_commerce_code") String childCommerceCode,
@RequestParam double amount,
Model model)
throws IOException, TransactionRefundException {

model.addAttribute(MODEL_NAVIGATION, NAV_REFUND);
model.addAttribute(MODEL_NAVIGATION, NAV_REFUND);
addBreadcrumbs(model, "Reembolso", "#");

model.addAttribute("buy_order", buyOrder);
Expand All @@ -282,7 +285,7 @@ public String capture(
Model model)
throws IOException, TransactionCaptureException {

model.addAttribute(MODEL_NAVIGATION, NAV_CAPTURE);
model.addAttribute(MODEL_NAVIGATION, NAV_CAPTURE);
addBreadcrumbs(model, "Capturar", "#");

model.addAttribute("buy_order", buyOrder);
Expand Down
Loading
Loading