cl.transbank.webpay.Webpay 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
package cl.transbank.webpay;
import cl.transbank.patpass.PatPassByWebpayNormal;
import cl.transbank.webpay.configuration.Configuration;
import cl.transbank.webpay.security.SoapSignature;
import java.util.HashMap;
import java.util.Map;
public class Webpay {
public static final String INTERNAL_NAME_INTEGRACION = "integracion";
public static final String INTERNAL_NAME_PRODUCCION = "produccion";
public enum Environment {
/*
There are only 2 Webpay environments by 2018:
- Produccion: The live system
- Integracion: The test system used when integrating and making sure
everything works.
We have many aliases for those two environments due to historic reasons
and also because we are trying to get a bit of consistency with the
terminology used with Onepay.
*/
INTEGRACION(INTERNAL_NAME_INTEGRACION),
CERTIFICACION(INTERNAL_NAME_INTEGRACION), // For backwards compat with libwebpay
TEST(INTERNAL_NAME_INTEGRACION), // Alternative name consistent with onepay
PRODUCCION(INTERNAL_NAME_PRODUCCION),
LIVE(INTERNAL_NAME_PRODUCCION); // Alternative name consistent with onepay
private final String internalName;
Environment(String internalName) {
this.internalName = internalName;
}
public String getInternalName() {
return internalName;
}
}
private static final Map WEBPAY_CERTS;
static {
WEBPAY_CERTS = new HashMap<>();
WEBPAY_CERTS.put(INTERNAL_NAME_INTEGRACION,"-----BEGIN CERTIFICATE-----\n" +
"MIIC8jCCAdoCCQDZgAhqEGGRFjANBgkqhkiG9w0BAQsFADA7MQswCQYDVQQGEwJD\n" +
"TDERMA8GA1UEBwwIU0FOVElBR08xDDAKBgNVBAoMA1RCSzELMAkGA1UEAwwCMjAw\n" +
"HhcNMjEwODI1MTMyMjE2WhcNMzEwODIzMTMyMjE2WjA7MQswCQYDVQQGEwJDTDER\n" +
"MA8GA1UEBwwIU0FOVElBR08xDDAKBgNVBAoMA1RCSzELMAkGA1UEAwwCMjAwggEi\n" +
"MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDTJ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12/89hfsfVN6iRH9UOE+SKoR/jHtvLMhVHpa80HVK1qdlfqUTZo=\n" +
"-----END CERTIFICATE-----"
);
}
SoapSignature signature;
Configuration configuration;
WebpayNormal normalTransaction;
WebpayOneClick oneClickTransaction;
WebpayMallNormal mallNormalTransaction;
WebpayComplete completeTransaction;
WebpayCapture captureTransaction;
WebpayNullify nullifyTransaction;
PatPassByWebpayNormal patPassByWebpayTransaction;
@Deprecated
public Webpay(Environment env, String commerceCode, SoapSignature signature){
this(env, commerceCode);
setSignature(signature);
}
@Deprecated
public Webpay(Environment env, String commerceCode){
this(newConfigurationFromEnvAndCommerceCode(env, commerceCode));
}
private static Configuration newConfigurationFromEnvAndCommerceCode(Environment env, String commerceCode) {
Configuration config = new Configuration();
config.setEnvironment(env);
config.setCommerceCode(commerceCode);
return config;
}
public Webpay(Configuration conf){
this.configuration = conf;
SoapSignature sig = new SoapSignature();
sig .setPrivateCertificate(conf.getPrivateKey(), conf.getPublicCert());
if (conf.getWebpayCert() != null) {
// For backwards compatibility with the old libwebpay and in case
// someone wants to override the certificate
// (perhaps they don't want to update the SDK because of a code
// freeze or something like that)
sig.setWebpayCertificate(conf.getWebpayCert());
} else {
sig.setWebpayCertificate(getWebPayCertificate(conf.getEnvironment()));
}
setSignature(sig);
}
private String getWebPayCertificate(Environment environment) {
return WEBPAY_CERTS.get(environment.getInternalName());
}
public void setSignature(SoapSignature signature){
this.signature = signature;
}
public synchronized WebpayNormal getNormalTransaction() throws Exception {
if (normalTransaction == null){
normalTransaction = new WebpayNormal(
configuration.getEnvironment(),
configuration.getCommerceCode(), signature);
}
return normalTransaction;
}
public synchronized WebpayOneClick getOneClickTransaction() throws Exception {
if (oneClickTransaction == null){
oneClickTransaction = new WebpayOneClick(
configuration.getEnvironment(),
configuration.getCommerceCode(), signature);
}
return oneClickTransaction;
}
public synchronized WebpayMallNormal getMallNormalTransaction() throws Exception {
if (mallNormalTransaction == null){
mallNormalTransaction = new WebpayMallNormal(
configuration.getEnvironment(),
configuration.getCommerceCode(), signature);
}
return mallNormalTransaction;
}
public synchronized WebpayComplete getCompleteTransaction() throws Exception {
if (completeTransaction == null){
completeTransaction = new WebpayComplete(
configuration.getEnvironment(),
configuration.getCommerceCode(), signature);
}
return completeTransaction;
}
public synchronized WebpayCapture getCaptureTransaction() throws Exception {
if (captureTransaction == null){
captureTransaction = new WebpayCapture(
configuration.getEnvironment(),
configuration.getCommerceCode(), signature);
}
return captureTransaction;
}
public synchronized WebpayNullify getNullifyTransaction() throws Exception {
if (nullifyTransaction == null){
nullifyTransaction = new WebpayNullify(
configuration.getEnvironment(),
configuration.getCommerceCode(), signature);
}
return nullifyTransaction;
}
public synchronized PatPassByWebpayNormal getPatPassByWebpayTransaction() throws Exception {
if (patPassByWebpayTransaction == null){
patPassByWebpayTransaction = new PatPassByWebpayNormal(configuration, signature);
}
return patPassByWebpayTransaction;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy