19 package org.turro.financials.cart;
21 import java.io.UnsupportedEncodingException;
22 import java.security.InvalidAlgorithmParameterException;
23 import java.security.InvalidKeyException;
24 import java.security.NoSuchAlgorithmException;
25 import java.util.HashMap;
26 import java.util.logging.Level;
27 import java.util.logging.Logger;
28 import javax.crypto.BadPaddingException;
29 import javax.crypto.IllegalBlockSizeException;
30 import javax.crypto.NoSuchPaddingException;
31 import org.turro.string.Strings;
32 import org.turro.elephant.context.ElephantContext;
33 import org.turro.elephant.context.IConstructor;
34 import org.turro.elephant.util.DecimalFormats;
35 import org.turro.marker.ElephantMarker;
36 import sis.redsys.api.ApiMacSha256;
44 private final HashMap<String, String> properties =
new HashMap<>();
47 ApiMacSha256 apiMacSha256 =
new ApiMacSha256();
51 apiMacSha256.setParameter(
"DS_MERCHANT_ORDER", order);
55 apiMacSha256.setParameter(
"DS_MERCHANT_TRANSACTIONTYPE",
"0");
65 marker.
put(
"pos_url",
"https://sis-t.redsys.es:25443/sis/realizarPago");
67 marker.
put(
"pos_url",
"https://sis.redsys.es/sis/realizarPago");
70 marker.
put(
"pos_params", apiMacSha256.createMerchantParameters());
72 }
catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException | IllegalStateException |
73 NoSuchPaddingException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException ex) {
83 String version = constructor.
getParameter(
"Ds_SignatureVersion",
true),
84 params = constructor.
getParameter(
"Ds_MerchantParameters",
true),
85 signature = constructor.
getParameter(
"Ds_Signature",
true);
87 if(Strings.isBlank(signature)) {
91 properties.put(
"Ds_SignatureVersion", version);
92 properties.put(
"Ds_MerchantParameters", params);
93 properties.put(
"Ds_Signature", signature);
95 ApiMacSha256 apiMacSha256 =
new ApiMacSha256();
99 apiMacSha256.decodeMerchantParameters(params);
103 return calculated.equals(signature);
105 }
catch (UnsupportedEncodingException | InvalidKeyException | NoSuchAlgorithmException | IllegalStateException |
106 NoSuchPaddingException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException ex) {
114 ApiMacSha256 apiMacSha256 =
new ApiMacSha256();
116 String version = constructor.
getParameter(
"Ds_SignatureVersion",
true),
117 params = constructor.
getParameter(
"Ds_MerchantParameters",
true),
118 signature = constructor.
getParameter(
"Ds_Signature",
true);
122 apiMacSha256.decodeMerchantParameters(params);
124 String response = apiMacSha256.getParameter(
"Ds_Response"),
125 order = apiMacSha256.getParameter(
"Ds_Order");
127 properties.put(
"Ds_Order", order);
129 if(!Strings.isBlank(response) && Long.valueOf(response) < 100) {
133 }
catch (UnsupportedEncodingException ex) {
141 for(String k : properties.keySet()) {
142 Logger.getLogger(
RedsysPOS.class.getName()).log(Level.INFO, k +
":" + properties.get(k));
static String getSiteName()
static String getServerUrl(String scheme)
static String logMsg(String msg)
static Cart deserializeForOrder(String order)
boolean isOnlineNotification(IConstructor constructor)
void addParameters(ElephantMarker marker, double amount, String order)
Cart isAccepted(IConstructor constructor)
String getMerchantLanguage()
String getMerchantTerminal()
boolean isMerchantTestScope()
String getMerchantCurrency()
String getNotificationPath()
String getMerchantKeyType()
static ShopContext getInstance()
Object put(Object key, Object value)
String getParameter(String param)