Skip to content

Commit

Permalink
Upgrade & add 3ds2 redirect/native
Browse files Browse the repository at this point in the history
Fix frontend
  • Loading branch information
Kwok-he-Chu committed Dec 15, 2023
1 parent 6927a5f commit b16c258
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ResponseEntity<PaymentResponse> payments(@RequestHeader String host, @Req
var orderRef = UUID.randomUUID().toString();
var amount = new Amount()
.currency("EUR")
.value(10000L); // value is 10€ in minor units
.value(10000L); // value is 100€ in minor units

paymentRequest.setMerchantAccount(this.applicationProperty.getMerchantAccount()); // required
paymentRequest.setChannel(PaymentRequest.ChannelEnum.WEB);
Expand All @@ -89,16 +89,27 @@ public ResponseEntity<PaymentResponse> payments(@RequestHeader String host, @Req
new LineItem().quantity(1L).amountIncludingTax(5000L).description("Sunglasses"),
new LineItem().quantity(1L).amountIncludingTax(5000L).description("Headphones"))
);
// required for 3ds2 native flow
paymentRequest.setAdditionalData(Collections.singletonMap("allow3DS2", "true"));
// required for 3ds2 native flow
paymentRequest.setOrigin(request.getScheme() + "://" + host );

var authenticationData = new AuthenticationData();
authenticationData.setAttemptAuthentication(AuthenticationData.AttemptAuthenticationEnum.ALWAYS);
// add the following lines for Native 3DS2:
//var threeDSRequestData = new ThreeDSRequestData();
//threeDSRequestData.setNativeThreeDS(ThreeDSRequestData.NativeThreeDSEnum.PREFERRED);
//authenticationData.setThreeDSRequestData(threeDSRequestData);

paymentRequest.setAuthenticationData(authenticationData);

// required for 3ds2 redirect flow
paymentRequest.setOrigin(request.getScheme() + "://" + host);
// required for 3ds2
paymentRequest.setBrowserInfo(body.getBrowserInfo());
// required by some issuers for 3ds2
paymentRequest.setShopperIP(request.getRemoteAddr());
paymentRequest.setPaymentMethod(body.getPaymentMethod());

// we strongly recommend that you the billingAddress in your request
// card schemes require this for channel web, iOS, and Android implementations
//paymentRequest.setBillingAddress(new Address());
log.info("REST request to make Adyen payment {}", paymentRequest);
var response = paymentsApi.payments(paymentRequest);
return ResponseEntity.ok()
Expand Down Expand Up @@ -133,6 +144,9 @@ public RedirectView redirect(@RequestParam(required = false) String payload, @Re

PaymentCompletionDetails details = new PaymentCompletionDetails();
if (redirectResult != null && !redirectResult.isEmpty()) {
// for redirect, you are redirected to an Adyen domain to complete the 3DS2 challenge
// after completing the 3DS2 challenge, you get the redirect result from Adyen in the returnUrl
// we then pass on the redirectResult
details.redirectResult(redirectResult);
} else if (payload != null && !payload.isEmpty()) {
details.payload(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ async function initCheckout() {
holderNameRequired: true,
name: "Credit or debit card",
amount: {
value: 1000,
value: 10000,
currency: "EUR",
},
},
paypal: {
amount: {
value: 1000,
value: 10000,
currency: "USD",
},
environment: "test", // Change this to "live" when you're ready to accept live PayPal payments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h2>Cart</h2>
</ul>
</div>
<div class="cart-footer"><span class="cart-footer-label">Total:</span><span
class="cart-footer-amount">10.00</span>
class="cart-footer-amount">100.00</span>
<a th:href="@{/checkout(type=${type})}">
<p class="button">Continue to checkout</p>
</a>
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
adyenVersion="21.4.0"
adyenVersion="22.1.0"
springVersion="3.1.4"
springDependendyManagementVersion="1.1.3"

Expand Down

0 comments on commit b16c258

Please sign in to comment.