Set redirectUrl using hostname #16

Closes #16
This commit is contained in:
Julien Lengrand-Lambert
2022-05-24 10:52:20 +02:00
parent 4eea3ef2d3
commit e415a83817

View File

@@ -10,6 +10,7 @@ import com.adyen.model.checkout.CreateCheckoutSessionRequest;
import com.adyen.model.checkout.CreateCheckoutSessionResponse;
import com.adyen.service.Checkout;
import com.adyen.service.exception.ApiException;
import spark.Request;
public class CheckoutService {
@@ -21,7 +22,7 @@ public class CheckoutService {
checkout = new Checkout(new Client(prop.getProperty("apiKey"), Environment.TEST));
}
public CreateCheckoutSessionResponse checkoutsessions() throws IOException, ApiException {
public CreateCheckoutSessionResponse checkoutsessions(Request req) throws IOException, ApiException {
String orderRef = UUID.randomUUID().toString();
Amount amount = new Amount()
.currency("EUR")
@@ -30,7 +31,7 @@ public class CheckoutService {
checkoutSession.merchantAccount(merchantAccount);
checkoutSession.setChannel(CreateCheckoutSessionRequest.ChannelEnum.WEB);
checkoutSession.setReference(orderRef); // Typically generated by customer CMS
checkoutSession.setReturnUrl("http://localhost:8080/redirect?orderRef=" + orderRef);
checkoutSession.setReturnUrl(req.scheme() + "://" + req.host() + "/redirect?orderRef=" + orderRef);
checkoutSession.setAmount(amount);
return checkout.sessions(checkoutSession);
}