Skip to content

Commit

Permalink
Fix for 3DS2 Redirect and added support for Native flow (#119)
Browse files Browse the repository at this point in the history
* 3DS2 Native & Redirect
* Add billing address recommendation line
  • Loading branch information
Kwok-he-Chu authored Dec 19, 2023
1 parent 516fee3 commit edc6e7c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
21 changes: 18 additions & 3 deletions checkout-example-advanced/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,27 @@ public async Task<ActionResult<PaymentResponse>> 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<LineItem>()
{
new LineItem(quantity: 1, amountIncludingTax: 5000, description: "Sunglasses"),
new LineItem(quantity: 1, amountIncludingTax: 5000, description: "Headphones")
},
AdditionalData = new Dictionary<string, string>() { { "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
};
Expand Down Expand Up @@ -115,6 +127,9 @@ public async Task<IActionResult> 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 };
}

Expand Down
18 changes: 9 additions & 9 deletions checkout-example-advanced/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" />

<link rel="stylesheet"
href="https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/5.40.0/adyen.css"
integrity="sha384-BRZCzbS8n6hZVj8BESE6thGk0zSkUZfUWxL/vhocKu12k3NZ7xpNsIK39O2aWuni"
crossorigin="anonymous" />

<script src="https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/5.40.0/adyen.js"
integrity="sha384-ds1t0hgFCe636DXFRL6ciadL2Wb4Yihh27R4JO7d9CF7sFY3NJE4aPCK0EpzaYXD"
crossorigin="anonymous"></script>

href="https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/5.53.2/adyen.css"
integrity="sha384-9EdBqZRrjozkt+Be5ycjHBTi+4DYrafpC1KyPnNyTBfjBIZ5+oMp8BbgvPLGgsE0"
crossorigin="anonymous">
<script src="https://checkoutshopper-test.adyen.com/checkoutshopper/sdk/5.53.2/adyen.js"
integrity="sha384-ng3HLoZIlQ3BLgyGyGNiwWSx6LEPIlmxVuGRw72skZFt9mL8OweRjp7vcPzSqxTj"
crossorigin="anonymous"></script>
<title>@ViewData["Title"] - Checkout Demo Advanced</title>
</head>
<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Adyen" Version="11.2.1" />
<PackageReference Include="Adyen" Version="13.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.25" />
</ItemGroup>
</Project>
5 changes: 4 additions & 1 deletion checkout-example-advanced/wwwroot/js/adyenImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit edc6e7c

Please sign in to comment.