www in docker support

This commit is contained in:
MaddoScientisto 2026-04-22 18:41:37 +02:00
commit c227fce036
2145 changed files with 399596 additions and 58 deletions

View file

@ -0,0 +1,139 @@
package it.acxent.bank.paypalcheckout;
import com.paypal.core.PayPalEnvironment;
import com.paypal.core.PayPalHttpClient;
import com.paypal.http.HttpRequest;
import com.paypal.http.HttpResponse;
import com.paypal.http.exceptions.HttpException;
import com.paypal.http.serializer.Json;
import com.paypal.orders.AmountWithBreakdown;
import com.paypal.orders.ApplicationContext;
import com.paypal.orders.LinkDescription;
import com.paypal.orders.Order;
import com.paypal.orders.OrderRequest;
import com.paypal.orders.OrdersCreateRequest;
import com.paypal.orders.OrdersGetRequest;
import com.paypal.orders.PurchaseUnitRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
public class PayPalOrder {
private PayPalHttpClient client;
private PayPalReq payPalReq;
private boolean useSandbox = true;
public PayPalOrder(PayPalReq payPalReq) {
setPayPalReq(payPalReq);
this.useSandbox = getPayPalReq().isUseSandbox();
}
private OrderRequest buildMinimumRequestBody() {
OrderRequest orderRequest = new OrderRequest();
orderRequest.checkoutPaymentIntent("CAPTURE");
ApplicationContext applicationContext = new ApplicationContext().cancelUrl(getPayPalReq().getCancelURL())
.returnUrl(getPayPalReq().getReturnUrl());
orderRequest.applicationContext(applicationContext);
List<PurchaseUnitRequest> purchaseUnitRequests = new ArrayList<>();
PurchaseUnitRequest purchaseUnitRequest = new PurchaseUnitRequest()
.amountWithBreakdown(new AmountWithBreakdown()
.currencyCode(getPayPalReq().getCurrency()).value(String.valueOf(getPayPalReq().getAmt())))
.description(getPayPalReq().getDESC());
purchaseUnitRequests.add(purchaseUnitRequest);
orderRequest.purchaseUnits(purchaseUnitRequests);
return orderRequest;
}
public HttpResponse<Order> createOrder(boolean debug) throws IOException {
OrdersCreateRequest request = new OrdersCreateRequest();
request.header("prefer", "return=representation");
request.requestBody(buildMinimumRequestBody());
HttpResponse<Order> response = getClient().execute((HttpRequest)request);
if (debug &&
response.statusCode() == 201) {
System.out.println("Order with Minimum Payload: ");
System.out.println("Status Code: " + response.statusCode());
System.out.println("Status: " + ((Order)response.result()).status());
System.out.println("Order ID: " + ((Order)response.result()).id());
System.out.println("Intent: " + ((Order)response.result()).checkoutPaymentIntent());
System.out.println("Links: ");
for (LinkDescription link : (Iterable<LinkDescription>)((Order)response.result()).links())
System.out.println("\t" + link.rel() + ": " + link.href() + "\tCall Type: " + link.method());
System.out.println("Total Amount: " + ((Order)response.result()).purchaseUnits().get(0).amountWithBreakdown().currencyCode() + " " + ((Order)
response.result()).purchaseUnits().get(0).amountWithBreakdown().value());
System.out.println("Full response body:");
System.out.println(new JSONObject(new Json().serialize(response.result())).toString(4));
}
return response;
}
public static void main(String[] args) {
try {
PayPalReq ppr = new PayPalReq();
new PayPalOrder(ppr).createOrder(true);
} catch (HttpException e) {
System.out.println(e.getLocalizedMessage());
} catch (Exception e) {
e.printStackTrace();
}
}
public PayPalReq getPayPalReq() {
return this.payPalReq;
}
public void setPayPalReq(PayPalReq payPalReq) {
this.payPalReq = payPalReq;
}
public PayPalHttpClient getClient() {
if (this.client == null) {
System.out.println("clientid: " + getPayPalReq().getPaypalClientId());
System.out.println("clientSc: " + getPayPalReq().getPaypalClientSecret());
if (this.useSandbox) {
PayPalEnvironment.Sandbox sandbox = new PayPalEnvironment.Sandbox(getPayPalReq().getPaypalClientId(),
getPayPalReq().getPaypalClientSecret());
this.client = new PayPalHttpClient((PayPalEnvironment)sandbox);
} else {
PayPalEnvironment.Live live = new PayPalEnvironment.Live(getPayPalReq().getPaypalClientId(),
getPayPalReq().getPaypalClientSecret());
this.client = new PayPalHttpClient((PayPalEnvironment)live);
}
}
return this.client;
}
public String prettyPrint(JSONObject jo, String pre) {
Iterator<?> keys = jo.keys();
StringBuilder pretty = new StringBuilder();
while (keys.hasNext()) {
String key = (String)keys.next();
pretty.append(String.format("%s%s: ", pre, StringUtils.capitalize(key)));
if (jo.get(key) instanceof JSONObject) {
pretty.append(prettyPrint(jo.getJSONObject(key), pre + "\t"));
continue;
}
if (jo.get(key) instanceof org.json.JSONArray) {
int sno = 1;
for (Object jsonObject : (Iterable<Object>)jo.getJSONArray(key)) {
pretty.append(String.format("\n%s\t%d:\n", pre, sno++));
pretty.append(prettyPrint((JSONObject)jsonObject, pre + "\t\t"));
}
continue;
}
pretty.append(String.format("%s\n", jo.getString(key)));
}
return pretty.toString();
}
public HttpResponse<Order> getOrder(String orderId) throws IOException {
OrdersGetRequest request = new OrdersGetRequest(orderId);
HttpResponse<Order> response = getClient().execute((HttpRequest)request);
return response;
}
}

View file

@ -0,0 +1,291 @@
package it.acxent.bank.paypalcheckout;
import it.acxent.bank._BankAdapter;
import it.acxent.common.Parm;
import it.acxent.common.StatusMsg;
import it.acxent.db.ApplParmFull;
import it.acxent.db.DBAdapter;
import java.net.URLEncoder;
public class PayPalReq extends _BankAdapter {
private String paypalClientId;
private String paypalClientSecret;
private boolean useSandbox = false;
private double amt;
private long id_ordine;
private String cancelURL;
private String returnUrl;
private String paypalOrderId;
private String TOKEN;
private String PAYERID;
private String SHIPTOCITY;
private String SHIPTOCOUNTRYCODE;
private String SHIPTONAME;
private String SHIPTOSTATE;
private String SHIPTOSTREET;
private String SHIPTOZIP;
private String DESC;
private String currency;
public static final String P_CHECKOUT_APPLICATION_CLIENT_ID = "PAYPAL_CHECKOUT_APPLICATION_CLIENT_ID";
public static final String P_CHECKOUT_APPLICATION_CLIENT_SECRET = "PAYPAL_CHECKOUT_APPLICATION_CLIENT_SECRET";
public static final String P_CHECKOUT_USE_SANDBOX = "P_PAYPAL_CHECKOUT_USE_SANDBOX";
public static final String P_CANCEL_URL = "PAYPAL_CANCELURL";
public static final String P_CURRENCY = "PAYPAL_CURRENCY";
public static final String P_PAYMENT_OK_PAGE = "PAYPAL_OK";
public static final String P_RETURN_URL = "PAYPAL_RETURNURL";
public double getAmt() {
return this.amt;
}
public void setAmt(double amt) {
this.amt = amt;
}
public String getCancelURL() {
return (this.cancelURL == null) ? "" : this.cancelURL;
}
public void setCancelURL(String cancelURL) {
this.cancelURL = cancelURL;
}
public String getReturnUrl() {
return (this.returnUrl == null) ? "" : this.returnUrl;
}
public void setReturnUrl(String returnUrl) {
this.returnUrl = returnUrl;
}
public String getTOKEN() {
return (this.TOKEN == null) ? "" : this.TOKEN;
}
public void setTOKEN(String token) {
this.TOKEN = token;
}
public String getPAYERID() {
return this.PAYERID;
}
public void setPAYERID(String payerid) {
this.PAYERID = payerid;
}
public String getSHIPTOCITY() {
return (this.SHIPTOCITY == null) ? "" : this.SHIPTOCITY;
}
public String getSHIPTOCOUNTRYCODE() {
return (this.SHIPTOCOUNTRYCODE == null) ? "" : this.SHIPTOCOUNTRYCODE;
}
public String getSHIPTONAME() {
return (this.SHIPTONAME == null) ? "" : this.SHIPTONAME;
}
public String getSHIPTOSTATE() {
return (this.SHIPTOSTATE == null) ? "" : this.SHIPTOSTATE;
}
public String getSHIPTOSTREET() {
return (this.SHIPTOSTREET == null) ? "" : this.SHIPTOSTREET;
}
public String getSHIPTOZIP() {
return (this.SHIPTOZIP == null) ? "" : this.SHIPTOZIP;
}
public long getId_ordine() {
return this.id_ordine;
}
public void setId_ordine(long id_ordine) {
this.id_ordine = id_ordine;
}
public String getShippingAddressString() {
return "SHIPTONAME=" + URLEncoder.encode(getSHIPTONAME()) + "&DESC=" + URLEncoder.encode(getDESC()) + "&SHIPTOSTREET=" +
URLEncoder.encode(getSHIPTOSTREET()) + "&SHIPTOCITY=" + URLEncoder.encode(getSHIPTOCITY()) + "&SHIPTOSTATE=" +
URLEncoder.encode(getSHIPTOSTATE()) + "&SHIPTOCOUNTRYCODE=" + URLEncoder.encode(getSHIPTOCOUNTRYCODE()) + "&SHIPTOZIP=" +
URLEncoder.encode(getSHIPTOZIP()) + "&ADDROVERRIDE=1";
}
public void setSHIPTOCITY(String shiptocity) {
this.SHIPTOCITY = shiptocity;
}
public void setSHIPTOCOUNTRYCODE(String shiptocountrycode) {
this.SHIPTOCOUNTRYCODE = shiptocountrycode;
}
public void setSHIPTONAME(String shiptoname) {
this.SHIPTONAME = shiptoname;
}
public void setSHIPTOSTATE(String shiptostate) {
this.SHIPTOSTATE = shiptostate;
}
public void setSHIPTOSTREET(String shiptostreet) {
this.SHIPTOSTREET = shiptostreet;
}
public void setSHIPTOZIP(String shiptozip) {
this.SHIPTOZIP = shiptozip;
}
public static void initApplicationParms(ApplParmFull ap) {
boolean debug = false;
if (ap != null) {
DBAdapter.logDebug(debug, "payPal chechout initParms: start");
String l_tipoParm = "PAYPAL";
Parm bean = new Parm(ap);
l_tipoParm = "PAYPAL_CHECKOUT";
StatusMsg.updateMsgByTag(ap, "INIT", l_tipoParm);
bean.findByCodice("PAYPAL_CANCELURL");
bean.setFlgAdmin(0L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("PAYPAL_CANCELURL");
bean.setDescrizione("PAYPAL_CANCELURL");
bean.setFlgTipo(0L);
bean.setNota("PAYPAL_CANCELURL");
bean.save();
bean.findByCodice("PAYPAL_CURRENCY");
bean.setFlgAdmin(0L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("PAYPAL_CURRENCY");
bean.setDescrizione("PAYPAL_CURRENCY");
bean.setFlgTipo(0L);
if (bean.getTesto().equals(""))
bean.setTesto("EUR");
bean.setNota("PAYPAL_CURRENCY");
bean.save();
bean.findByCodice("PAYPAL_OK");
bean.setFlgAdmin(0L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("PAYPAL_OK");
bean.setDescrizione("PAYPAL_OK");
bean.setFlgTipo(0L);
if (bean.getTesto().equals(""))
bean.setTesto("payPalRes.jsp");
bean.setNota("PAYPAL_OK");
bean.save();
bean.findByCodice("PAYPAL_RETURNURL");
bean.setFlgAdmin(0L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("PAYPAL_RETURNURL");
bean.setDescrizione("PAYPAL_RETURNURL");
bean.setFlgTipo(0L);
bean.setNota("PAYPAL_RETURNURL");
bean.save();
bean.findByCodice("PAYPAL_CHECKOUT_APPLICATION_CLIENT_ID");
bean.setFlgAdmin(0L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("PAYPAL_CHECKOUT_APPLICATION_CLIENT_ID");
bean.setDescrizione("PAYPAL_CHECKOUT_APPLICATION_CLIENT_ID");
bean.setFlgTipo(0L);
bean.setNota("PAYPAL_CHECKOUT_APPLICATION_CLIENT_SECRET");
bean.save();
bean.findByCodice("PAYPAL_CHECKOUT_APPLICATION_CLIENT_SECRET");
bean.setFlgAdmin(0L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("PAYPAL_CHECKOUT_APPLICATION_CLIENT_SECRET");
bean.setDescrizione("PAYPAL_CHECKOUT_APPLICATION_CLIENT_SECRET");
bean.setFlgTipo(0L);
bean.setNota("PAYPAL_CHECKOUT_APPLICATION_CLIENT_SECRET");
bean.save();
bean.findByCodice("PAYPAL_CHECKOUT_APPLICATION_CLIENT_SECRET");
bean.setFlgAdmin(0L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("PAYPAL_CHECKOUT_APPLICATION_CLIENT_SECRET");
bean.setDescrizione("PAYPAL_CHECKOUT_APPLICATION_CLIENT_SECRET");
bean.setFlgTipo(0L);
bean.setNota("PAYPAL_CHECKOUT_APPLICATION_CLIENT_SECRET");
bean.save();
bean.findByCodice("P_PAYPAL_CHECKOUT_USE_SANDBOX");
bean.setFlgAdmin(1L);
bean.setTipoParm(l_tipoParm);
bean.setCodice("P_PAYPAL_CHECKOUT_USE_SANDBOX");
bean.setDescrizione("P_PAYPAL_CHECKOUT_USE_SANDBOX");
bean.setFlgTipo(5L);
bean.setNota("P_PAYPAL_CHECKOUT_USE_SANDBOX");
bean.save();
DBAdapter.logDebug(debug, "payPal chechout initParms: stop");
}
}
public String getDESC() {
return (this.DESC == null) ? "" : this.DESC.trim();
}
public void setDESC(String dESC) {
this.DESC = dESC;
}
public String getCurrency() {
return (this.currency == null) ? "EUR" : this.currency.trim();
}
public void setCurrency(String currency) {
this.currency = currency;
}
public String getPaypalClientId() {
return this.paypalClientId;
}
public void setPaypalClientId(String paypalClientId) {
this.paypalClientId = paypalClientId;
}
public String getPaypalClientSecret() {
return this.paypalClientSecret;
}
public void setPaypalClientSecret(String paypalClientSecret) {
this.paypalClientSecret = paypalClientSecret;
}
public boolean isUseSandbox() {
return this.useSandbox;
}
public void setUseSandbox(boolean useSandbox) {
this.useSandbox = useSandbox;
}
public String getPaypalOrderId() {
return (this.paypalOrderId == null) ? "" : this.paypalOrderId.trim();
}
public void setPaypalOrderId(String paypalOrderId) {
this.paypalOrderId = paypalOrderId;
}
}