
cl.transbank.webpay.modal.WebpayModalTransaction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of transbank-sdk-java Show documentation
Show all versions of transbank-sdk-java Show documentation
Tranbank API integration SDK for Java Projects
The newest version!
package cl.transbank.webpay.modal;
import cl.transbank.common.ApiConstants;
import cl.transbank.common.BaseTransaction;
import cl.transbank.exception.TransbankException;
import cl.transbank.model.Options;
import cl.transbank.model.WebpayApiRequest;
import cl.transbank.util.HttpUtil;
import cl.transbank.util.ValidationUtil;
import cl.transbank.util.WebpayApiResource;
import cl.transbank.webpay.common.TransactionRefundRequest;
import cl.transbank.webpay.exception.*;
import cl.transbank.webpay.modal.requests.*;
import cl.transbank.webpay.modal.responses.*;
import java.io.IOException;
abstract class WebpayModalTransaction extends BaseTransaction {
public WebpayModalTransaction(Options options){
this.options = options;
}
public ModalTransactionCreateResponse create(String buyOrder, String sessionId, double amount) throws IOException, TransactionCreateException {
ValidationUtil.hasTextWithMaxLength(buyOrder, ApiConstants.BUY_ORDER_LENGTH, "buyOrder");
ValidationUtil.hasTextWithMaxLength(sessionId, ApiConstants.SESSION_ID_LENGTH, "sessionId");
String endpoint = String.format("%s/transactions", ApiConstants.WEBPAY_ENDPOINT);
final WebpayApiRequest request = new ModalTransactionCreateRequest(buyOrder, sessionId, amount);
try {
return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.POST, request, options, ModalTransactionCreateResponse.class);
} catch (TransbankException e) {
throw new TransactionCreateException(e);
}
}
public ModalTransactionCommitResponse commit(String token) throws IOException, TransactionCommitException {
ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, ApiConstants.TOKEN_TEXT);
String endpoint = String.format("%s/transactions/%s", ApiConstants.WEBPAY_ENDPOINT,token);
try {
return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.PUT, options, ModalTransactionCommitResponse.class);
} catch (TransbankException e) {
throw new TransactionCommitException(e);
}
}
public ModalTransactionStatusResponse status(String token) throws IOException, TransactionStatusException {
ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, ApiConstants.TOKEN_TEXT);
String endpoint = String.format("%s/transactions/%s", ApiConstants.WEBPAY_ENDPOINT,token);
try {
return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.GET, options, ModalTransactionStatusResponse.class);
} catch (TransbankException e) {
throw new TransactionStatusException(e);
}
}
public ModalTransactionRefundResponse refund(String token, double amount) throws IOException, TransactionRefundException {
ValidationUtil.hasTextWithMaxLength(token, ApiConstants.TOKEN_LENGTH, ApiConstants.TOKEN_TEXT);
String endpoint = String.format("%s/transactions/%s/refunds", ApiConstants.WEBPAY_ENDPOINT,token);
try {
return WebpayApiResource.execute(endpoint, HttpUtil.RequestMethod.POST, new TransactionRefundRequest(amount), options, ModalTransactionRefundResponse.class);
} catch (TransbankException e) {
throw new TransactionRefundException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy