From edc6e7c5da3a7badc92168eae9c8e73c4a72fca3 Mon Sep 17 00:00:00 2001 From: Kwok He Chu <105217051+Kwok-he-Chu@users.noreply.github.com> Date: Tue, 19 Dec 2023 18:20:57 +0100 Subject: [PATCH] Fix for 3DS2 Redirect and added support for Native flow (#119) * 3DS2 Native & Redirect * Add billing address recommendation line --- .../Controllers/ApiController.cs | 21 ++++++++++++++++--- .../Views/Shared/_Layout.cshtml | 18 ++++++++-------- ...en-dotnet-checkout-example-advanced.csproj | 2 +- .../wwwroot/js/adyenImplementation.js | 5 ++++- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/checkout-example-advanced/Controllers/ApiController.cs b/checkout-example-advanced/Controllers/ApiController.cs index b7f7340e..d28d3334 100644 --- a/checkout-example-advanced/Controllers/ApiController.cs +++ b/checkout-example-advanced/Controllers/ApiController.cs @@ -67,15 +67,27 @@ public async Task> InitiatePayment(PaymentRequest // Used for klarna, klarna is not supported everywhere, hence why we've defaulted to countryCode "NL" as it supports the following payment methods below: // "Pay now", "Pay later" and "Pay over time", see docs for more info: https://docs.adyen.com/payment-methods/klarna#supported-countries. - CountryCode = "NL", + CountryCode = "NL", LineItems = new List() { new LineItem(quantity: 1, amountIncludingTax: 5000, description: "Sunglasses"), new LineItem(quantity: 1, amountIncludingTax: 5000, description: "Headphones") }, - AdditionalData = new Dictionary() { { "allow3DS2", "true" } }, + + // We strongly recommend that you the billingAddress in your request. + // Card schemes require this for channel web, iOS, and Android implementations. + //BillingAddress = new BillingAddress() { ... }, + AuthenticationData = new AuthenticationData() + { + AttemptAuthentication = AuthenticationData.AttemptAuthenticationEnum.Always, + // Add the following line for Native 3DS2: + //ThreeDSRequestData = new ThreeDSRequestData() + //{ + // NativeThreeDS = ThreeDSRequestData.NativeThreeDSEnum.Preferred + //} + }, Origin = _urlService.GetHostUrl(), - BrowserInfo = new BrowserInfo() { UserAgent = HttpContext.Request.Headers["user-agent"] }, // Add more browser info here. + BrowserInfo = request.BrowserInfo, ShopperIP = HttpContext.Connection.RemoteIpAddress?.ToString(), PaymentMethod = request.PaymentMethod }; @@ -115,6 +127,9 @@ public async Task HandleShoppperRedirect(string payload = null, s var detailsRequest = new PaymentDetailsRequest(); if (!string.IsNullOrWhiteSpace(redirectResult)) { + // 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. detailsRequest.Details = new PaymentCompletionDetails() { RedirectResult = redirectResult }; } diff --git a/checkout-example-advanced/Views/Shared/_Layout.cshtml b/checkout-example-advanced/Views/Shared/_Layout.cshtml index 04cc195c..49f6c3a4 100644 --- a/checkout-example-advanced/Views/Shared/_Layout.cshtml +++ b/checkout-example-advanced/Views/Shared/_Layout.cshtml @@ -7,16 +7,16 @@ - + - - - + href="https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/5.53.2/adyen.css" + integrity="sha384-9EdBqZRrjozkt+Be5ycjHBTi+4DYrafpC1KyPnNyTBfjBIZ5+oMp8BbgvPLGgsE0" + crossorigin="anonymous"> + + + @ViewData["Title"] - Checkout Demo Advanced diff --git a/checkout-example-advanced/adyen-dotnet-checkout-example-advanced.csproj b/checkout-example-advanced/adyen-dotnet-checkout-example-advanced.csproj index ce16f1b9..15f08ea5 100644 --- a/checkout-example-advanced/adyen-dotnet-checkout-example-advanced.csproj +++ b/checkout-example-advanced/adyen-dotnet-checkout-example-advanced.csproj @@ -6,7 +6,7 @@ - + diff --git a/checkout-example-advanced/wwwroot/js/adyenImplementation.js b/checkout-example-advanced/wwwroot/js/adyenImplementation.js index 868d6a02..7381787f 100644 --- a/checkout-example-advanced/wwwroot/js/adyenImplementation.js +++ b/checkout-example-advanced/wwwroot/js/adyenImplementation.js @@ -42,7 +42,9 @@ async function initCheckout() { } }, onAdditionalDetails: (state, component) => { - handleSubmission(state, component, "/api/submitAdditionalDetails"); + if (state.isValid) { + handleSubmission(state, component, "/api/submitAdditionalDetails"); + } }, }; const checkout = await new AdyenCheckout(configuration); @@ -81,6 +83,7 @@ async function sendPostRequest(url, data) { // Handles responses sent from your server to the client function handleServerResponse(res, component) { if (res.action) { + console.info(res); component.handleAction(res.action); } else { switch (res.resultCode) {