Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add In-Person Payments Card Acquisition Flow #112

Merged
merged 79 commits into from
Nov 21, 2023
Merged
Changes from 1 commit
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
7fdaf85
Initial commit
Kwok-he-Chu Aug 10, 2023
2f1ba2d
Update .csproj
Kwok-he-Chu Aug 10, 2023
afcdbe2
Fix namespace in csproj
Aug 10, 2023
4dd1149
POS poc for connecting with the cloud terminal api synchronously
Aug 11, 2023
309710b
Fix startup
Aug 11, 2023
0d7dd4b
Remove unnecessary views
Aug 16, 2023
7fdab6f
Added reversals, cleaned up code
Aug 18, 2023
2176df1
Move comments to AdyenOptions class
Aug 18, 2023
880189f
Merge branch 'main' into IPP-cloud-terminal-api-example
Aug 18, 2023
e0823a0
Fix comment
Aug 18, 2023
6cd2b50
Fix redirect
Aug 21, 2023
1c3bc21
Added table selection frontend
Aug 22, 2023
7e20ffb
Add tables buttons and js to send the request from the front-end and …
Aug 22, 2023
8a5c789
Added error handling screens
Aug 22, 2023
c64f0e9
Added resulthandling and non awaits for firing the requests from js
Aug 23, 2023
a860ffd
Proper error handling, matching conventions in our terminal api error
Aug 23, 2023
6d37e1c
WIP
Aug 23, 2023
573ceb1
Make css prettier
Aug 23, 2023
84f2e99
Add table fetching from backend, instead of hardcoding in on frontend
Aug 24, 2023
4ebabab
Fix interface
Aug 25, 2023
ffe53b4
Added javascript abort controller for cancellation
Aug 27, 2023
ebc1434
Beautifying the frontend and added some comments
Aug 27, 2023
cfb94b5
Keep track of table status
Kwok-he-Chu Aug 28, 2023
8fc54b3
Fix comments
Kwok-he-Chu Aug 28, 2023
4da4542
Added webhooks for refunds
Kwok-he-Chu Aug 29, 2023
2876528
WIP styling and added frontend checks
Kwok-he-Chu Aug 29, 2023
57119bb
Better styling
Kwok-he-Chu Aug 29, 2023
a7e6bf7
Send abort request upon cancellation
Kwok-he-Chu Aug 29, 2023
efff255
Update README, comments and disable frontend buttons according to the…
Aug 30, 2023
a64b77a
Include in-person-payments-example in gitpod.yml
Kwok-he-Chu Aug 31, 2023
8fa3758
Reset PaymentStatus when a failure occurs
Kwok-he-Chu Aug 31, 2023
e39f910
Do not throw nullargument exception when POS_POI_ID is empty
Kwok-he-Chu Aug 31, 2023
4e1be34
Remove dropin
Kwok-he-Chu Sep 14, 2023
1d9bf31
Fix gitpod.yml
Kwok-he-Chu Sep 14, 2023
012311e
Update PR feedback
Kwok-he-Chu Sep 18, 2023
c2d556b
Update PR feedback
Kwok-he-Chu Sep 18, 2023
cb77c42
Update readme.md
Kwok-he-Chu Sep 18, 2023
3e4f03f
Add readme.md to paths-ignore on build and E2E
Kwok-he-Chu Sep 18, 2023
a392775
Fix payment status for reversal
Sep 19, 2023
277b0b9
Card Acquisition poc
Sep 20, 2023
217fd88
Added comments
Sep 20, 2023
d53d646
Merge branch 'main' into hackathon-integration-ipp
Kwok-he-Chu Sep 22, 2023
0c47f3c
Initial Added Card Acquisition
Kwok-he-Chu Sep 22, 2023
a88c40d
Add Controller
Kwok-he-Chu Sep 22, 2023
1b054a2
Return response
Kwok-he-Chu Sep 22, 2023
3492258
Card acquisition call
Kwok-he-Chu Sep 22, 2023
715c57d
Added Abort service for normal cancellations and CardAcquisition
Sep 22, 2023
981d3af
Backend card acquisition done
Sep 24, 2023
a7b165c
Wip
Sep 24, 2023
ce19db2
Added points assignments for existing customers
Kwok-he-Chu Sep 25, 2023
91f4ea5
Register classes
Kwok-he-Chu Sep 25, 2023
e42b5f8
Hackaton update
Sep 25, 2023
053b582
ECOM + IPP unified commerce card acquisition demo V0.1
Sep 26, 2023
3cbf89b
Final touch, resetting does not clear the pizza menu's identifiers fo…
Kwok-he-Chu Sep 26, 2023
0df7f8b
Preparing loyalty ipp example
Kwok-he-Chu Oct 19, 2023
e7d6eba
WIP
Kwok-he-Chu Oct 19, 2023
c5f110d
Wip
Kwok-he-Chu Oct 26, 2023
6002019
Add links and info to main page
Kwok-he-Chu Oct 26, 2023
4d4e5b4
Remove refund statuses
Kwok-he-Chu Oct 27, 2023
30e1f54
Remove reversals from card acqsuition
Oct 31, 2023
28c7e88
Fix js
Oct 31, 2023
278a9d9
Fix
Oct 31, 2023
0c811ac
Remove TODOs
Oct 31, 2023
849a228
Rename table to "pizza"
Oct 31, 2023
69b0ffe
Remove IPP - payment and reversals
Oct 31, 2023
e86e258
Rename to loyalty-button
Oct 31, 2023
f286b34
Fix models for card acquisitions
Kwok-he-Chu Nov 9, 2023
2a59073
Decode UTF-based card acquisition responses to show the error
Kwok-he-Chu Nov 9, 2023
8379fb0
Cleanup loyalty example, added abort requests
Kwok-he-Chu Nov 10, 2023
368aaf2
Ready for review
Kwok-he-Chu Nov 13, 2023
4f816d7
Update readme.md
Kwok-he-Chu Nov 13, 2023
ed15492
Update readme.md
Kwok-he-Chu Nov 13, 2023
34d727c
Merge branch 'main' into hackathon-demo-branch-ipp-card-acq
Kwok-he-Chu Nov 13, 2023
a89f097
Fix main readme.md
Kwok-he-Chu Nov 13, 2023
288e021
Remove tableservice, its renamed to repository
Kwok-he-Chu Nov 13, 2023
8b28de9
Rename to AdminPanel and fix some display issues
Nov 13, 2023
7356993
Added card, processed feedback
Kwok-he-Chu Nov 21, 2023
c929217
Update readme.md
Kwok-he-Chu Nov 21, 2023
16c37c4
Update README
Kwok-he-Chu Nov 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into hackathon-demo-branch-ipp-card-acq
Kwok-he-Chu committed Nov 13, 2023
commit 34d727cfdb440f60fc30dec1eb6fc1114b2f870d
12 changes: 12 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -91,3 +91,15 @@ jobs:
run: docker run --rm -d --name authorisation-adjustment-example-image -p 8080:80 -e ADYEN_API_KEY="${{ secrets.ADYEN_API_KEY }}" -e ADYEN_MERCHANT_ACCOUNT=${{ secrets.ADYEN_MERCHANT_ACCOUNT }} -e ADYEN_CLIENT_KEY=${{ secrets.ADYEN_CLIENT_KEY }} -e ADYEN_HMAC_KEY=${{ secrets.ADYEN_HMAC_KEY }} authorisation-adjustment-example-image:latest
- name: Run testing suite against authorisation-adjustment-example-image
run: docker run --rm --name adyen-testing-suite -e ADYEN_HMAC_KEY=${{ secrets.ADYEN_HMAC_KEY }} -e PLAYWRIGHT_FOLDERNAME=authorisation-adjustment --network host ghcr.io/adyen-examples/adyen-testing-suite:main

giving:
runs-on: ubuntu-latest
steps:
- name: Giving project
uses: actions/checkout@v3
- name: Build giving-example image
run: docker build -t giving-example-image:latest giving-example
- name: Start giving-example container
run: docker run --rm -d --name giving-example-image -p 8080:80 -e ADYEN_API_KEY="${{ secrets.ADYEN_API_KEY }}" -e ADYEN_MERCHANT_ACCOUNT=${{ secrets.ADYEN_MERCHANT_ACCOUNT }} -e ADYEN_CLIENT_KEY=${{ secrets.ADYEN_CLIENT_KEY }} -e ADYEN_HMAC_KEY=${{ secrets.ADYEN_HMAC_KEY }} giving-example-image:latest
- name: Run testing suite against giving-example-image
run: docker run --rm --name adyen-testing-suite -e ADYEN_HMAC_KEY=${{ secrets.ADYEN_HMAC_KEY }} -e PLAYWRIGHT_FOLDERNAME=giving --network host ghcr.io/adyen-examples/adyen-testing-suite:main
8 changes: 8 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -52,6 +52,14 @@ tasks:
fi
dotnet run --project giftcard-example
;;

"giving-example")
if [ -z ${ADYEN_HMAC_KEY+x} ] || [[ -z ${ADYEN_API_KEY+x} ]] || [[ -z ${ADYEN_CLIENT_KEY+x} ]] || [[ -z ${ADYEN_MERCHANT_ACCOUNT+x} ]]; then
echo "Expected environment variables not found. Please set the ADYEN_HMAC_KEY, ADYEN_API_KEY, ADYEN_CLIENT_KEY, ADYEN_MERCHANT_ACCOUNT environment variables in https://gitpod.io/variables and restart."
exit 1
fi
dotnet run --project giving-example
;;

"in-person-payments-example")
if [ -z ${ADYEN_HMAC_KEY+x} ] || [[ -z ${ADYEN_API_KEY+x} ]] || [[ -z ${ADYEN_MERCHANT_ACCOUNT+x} ]] || [[ -z ${ADYEN_POS_POI_ID+x} ]]; then
8 changes: 8 additions & 0 deletions adyen-dotnet-online-payments.sln
Original file line number Diff line number Diff line change
@@ -27,6 +27,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "authorisation-adjustment-ex
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "adyen-dotnet-authorisation-adjustment-example", "authorisation-adjustment-example\adyen-dotnet-authorisation-adjustment-example.csproj", "{EC4006F7-EC06-4DBC-A9F7-2273AE677AC2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "giving-example", "giving-example", "{1552682B-E1EA-4324-9564-B9683056ACDB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "adyen-dotnet-giving-example", "giving-example\adyen-dotnet-giving-example.csproj", "{10B87E36-1604-4129-93F5-EAB4009D220B}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "in-person-payments-example", "in-person-payments-example", "{56A21E4A-3DE5-45C6-BCDF-FE238CBC7A90}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "adyen-dotnet-in-person-payments-example", "in-person-payments-example\adyen-dotnet-in-person-payments-example.csproj", "{07EC4E54-8D9E-4BDA-975D-4C428DDE5DC0}"
@@ -65,6 +68,10 @@ Global
{EC4006F7-EC06-4DBC-A9F7-2273AE677AC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC4006F7-EC06-4DBC-A9F7-2273AE677AC2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC4006F7-EC06-4DBC-A9F7-2273AE677AC2}.Release|Any CPU.Build.0 = Release|Any CPU
{10B87E36-1604-4129-93F5-EAB4009D220B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{10B87E36-1604-4129-93F5-EAB4009D220B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{10B87E36-1604-4129-93F5-EAB4009D220B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{10B87E36-1604-4129-93F5-EAB4009D220B}.Release|Any CPU.Build.0 = Release|Any CPU
{07EC4E54-8D9E-4BDA-975D-4C428DDE5DC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07EC4E54-8D9E-4BDA-975D-4C428DDE5DC0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07EC4E54-8D9E-4BDA-975D-4C428DDE5DC0}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -84,6 +91,7 @@ Global
{A4303B5C-301E-432F-B8AC-571096DF5273} = {F3A61AF3-5126-417B-9AB2-A0F99B119325}
{26D67844-2033-4C06-A55A-5B50CFDEB0BC} = {B2582A34-631C-4130-B35D-838FA98297EA}
{EC4006F7-EC06-4DBC-A9F7-2273AE677AC2} = {61BDBE25-C448-4640-A4C7-E6744FA2D44F}
{10B87E36-1604-4129-93F5-EAB4009D220B} = {1552682B-E1EA-4324-9564-B9683056ACDB}
{07EC4E54-8D9E-4BDA-975D-4C428DDE5DC0} = {56A21E4A-3DE5-45C6-BCDF-FE238CBC7A90}
{930A2423-CDAF-4B18-80D9-06D714E71A8D} = {D2F4FD65-09D6-4C33-8582-5FDA3F10F749}
EndGlobalSection
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>adyen_dotnet_authorisation_adjustment_example</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Adyen" Version="11.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.21" />
<PackageReference Include="Adyen" Version="11.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.22" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions authorisation-adjustment-example/readme.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@

This repository includes an adjust authorisation example for the following three use cases after a pre-authorised payment: incremental, decremental adjustments. Within this demo app, you'll find a simplified version of a hotel booking, where the shopper perform a booking and administrators can **[1] adjust** (increase/decrease) the payment amount, **[2] extend** the authorisation expiry date, **[3] capture** the final amount and **[4] reverse** (cancel or refund) an authorised payment

> **Note:** We've included a technical [blog post](https://www.adyen.com/knowledge-hub/pre-authorizations-and-authorization-adjustments-for-developers) that explains every step of this demo.

![Authorisation Adjustment Demo](wwwroot/images/cardauthorisationadjustment.gif)

This demo leverages Adyen's API Library for .NET ([GitHub](https://github.com/Adyen/adyen-dotnet-api-library) | [Docs](https://docs.adyen.com/development-resources/libraries?tab=c__5#csharp)).
5 changes: 2 additions & 3 deletions checkout-example-advanced/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Adyen.Model.Checkout;
using adyen_dotnet_checkout_example_advanced.Options;
using adyen_dotnet_checkout_example_advanced.Options;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using System.Threading;

namespace adyen_dotnet_checkout_example_advanced.Controllers
{
@@ -13,6 +11,7 @@ public HomeController(IOptions<AdyenOptions> options)
{
_clientKey = options.Value.ADYEN_CLIENT_KEY;
}

[Route("/")]
public IActionResult Index()
{
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Adyen" Version="11.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.21" />
<PackageReference Include="Adyen" Version="11.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.22" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion checkout-example-advanced/readme.md
Original file line number Diff line number Diff line change
@@ -164,6 +164,6 @@ Before testing, please make sure to [add the payment methods to your Adyen Accou
## Usage
To try out this application with test card numbers, visit [Test card numbers](https://docs.adyen.com/development-resources/test-cards/test-card-numbers). We recommend saving some test cards in your browser so you can test your integration faster in the future.

1. Visit the main page, pick a payment method, follow the instructions to make authorize a payment.
1. Visit the main page, pick a payment method, follow the instructions to make a payment request.

2. Visit the Customer Area `Developers` → `API logs` to view your logs.
4 changes: 2 additions & 2 deletions checkout-example/adyen-dotnet-checkout-example.csproj
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Adyen" Version="11.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.21" />
<PackageReference Include="Adyen" Version="11.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.22" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion checkout-example/readme.md
Original file line number Diff line number Diff line change
@@ -163,6 +163,6 @@ Before testing, please make sure to [add the payment methods to your Adyen Accou
## Usage
To try out this application with test card numbers, visit [Test card numbers](https://docs.adyen.com/development-resources/test-cards/test-card-numbers). We recommend saving some test cards in your browser so you can test your integration faster in the future.

1. Visit the main page, pick a payment method, follow the instructions to make authorize a payment.
1. Visit the main page, pick a payment method, follow the instructions to make a payment request.

2. Visit the Customer Area `Developers` → `API logs` to view your logs.
4 changes: 2 additions & 2 deletions giftcard-example/adyen-dotnet-giftcard-example.csproj
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Adyen" Version="11.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.21" />
<PackageReference Include="Adyen" Version="11.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.22" />
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions giving-example/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
211 changes: 211 additions & 0 deletions giving-example/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
using Adyen.Model.Checkout;
using Adyen.Service.Checkout;
using adyen_dotnet_giving_example.Models.Requests;
using adyen_dotnet_giving_example.Options;
using adyen_dotnet_giving_example.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using PaymentRequest = Adyen.Model.Checkout.PaymentRequest;

namespace adyen_dotnet_giving_example.Controllers
{
[ApiController]
public class ApiController : ControllerBase
{
private const string DonationToken = "DonationToken";
private const string PaymentOriginalPspReference = "PaymentOriginalPspReference";

private readonly ILogger<ApiController> _logger;
private readonly IUrlService _urlService;
private readonly IPaymentsService _paymentsService;
private readonly string _merchantAccount;

public ApiController(IPaymentsService paymentsService, ILogger<ApiController> logger, IUrlService urlService, IOptions<AdyenOptions> options)
{
_logger = logger;
_urlService = urlService;
_paymentsService = paymentsService;
_merchantAccount = options.Value.ADYEN_MERCHANT_ACCOUNT;
}

[HttpPost("api/donations")]
public async Task<ActionResult<PaymentMethodsResponse>> Donations([FromBody] DonationAmountRequest amountRequest, CancellationToken cancellationToken = default)
{
try
{
string pspReference = HttpContext.Session.GetString(PaymentOriginalPspReference);
string donationToken = HttpContext.Session.GetString(DonationToken);

if (string.IsNullOrWhiteSpace(pspReference))
{
_logger.LogInformation("Could not find the PspReference in the stored session.");
return NotFound();
}

if (string.IsNullOrWhiteSpace(donationToken))
{
_logger.LogInformation("Could not find the DonationToken in the stored session.");
return NotFound();
}

var response = await _paymentsService.DonationsAsync(new DonationPaymentRequest()
{
Amount = new Amount(amountRequest.Currency, amountRequest.Value),
Reference = Guid.NewGuid().ToString(),
PaymentMethod = new CheckoutPaymentMethod(new CardDetails()),
DonationToken = donationToken,
DonationOriginalPspReference = pspReference,
DonationAccount = "MyCharity_Giving_TEST", // Set your donation account here.
ReturnUrl = $"{_urlService.GetHostUrl()}",
MerchantAccount = _merchantAccount,
ShopperInteraction = DonationPaymentRequest.ShopperInteractionEnum.ContAuth
}, cancellationToken: cancellationToken);

HttpContext.Session.Remove(PaymentOriginalPspReference);
HttpContext.Session.Remove(DonationToken);

return Ok(response);
}
catch(Adyen.HttpClient.HttpClientException e)
{
_logger.LogError($"Request for PaymentMethods failed:\n{e.ResponseBody}\n");
throw;
}
}

[HttpPost("api/getPaymentMethods")]
public async Task<ActionResult<PaymentMethodsResponse>> GetPaymentMethods(CancellationToken cancellationToken = default)
{
var paymentMethodsRequest = new PaymentMethodsRequest()
{
MerchantAccount = _merchantAccount,
Channel = PaymentMethodsRequest.ChannelEnum.Web
};

try
{
var res = await _paymentsService.PaymentMethodsAsync(paymentMethodsRequest, cancellationToken: cancellationToken);
_logger.LogInformation($"Response for PaymentMethods:\n{res}\n");
return res;
}
catch (Adyen.HttpClient.HttpClientException e)
{
_logger.LogError($"Request for PaymentMethods failed:\n{e.ResponseBody}\n");
throw;
}
}

[HttpPost("api/initiatePayment")]
public async Task<ActionResult<PaymentResponse>> InitiatePayment(PaymentRequest request, CancellationToken cancellationToken = default)
{
var orderRef = Guid.NewGuid();
var paymentRequest = new PaymentRequest()
{
MerchantAccount = _merchantAccount, // Required.
Reference = orderRef.ToString(), // Required.
Channel = PaymentRequest.ChannelEnum.Web,
Amount = new Amount("EUR", 10000), // Value is 100€ in minor units.

// Required for 3DS2 redirect flow.
ReturnUrl = $"{_urlService.GetHostUrl()}/api/handleShopperRedirect?orderRef={orderRef}",

AdditionalData = new Dictionary<string, string>() { { "allow3DS2", "true" } },
Origin = _urlService.GetHostUrl(),
BrowserInfo = new BrowserInfo() { UserAgent = HttpContext.Request.Headers["user-agent"] }, // Add more browser info here.
ShopperIP = HttpContext.Connection.RemoteIpAddress?.ToString(),
PaymentMethod = request.PaymentMethod
};

try
{
var res = await _paymentsService.PaymentsAsync(paymentRequest, cancellationToken: cancellationToken);
_logger.LogInformation($"Response for Payment:\n{res}\n");

HttpContext.Session.SetString(PaymentOriginalPspReference, res.PspReference);

if (string.IsNullOrWhiteSpace(res.DonationToken))
{
_logger.LogError("The payments endpoint did not return a donationToken, please enable this in your Customer Area. See README.");
}
else
{
HttpContext.Session.SetString(DonationToken, res.DonationToken);
}

return res;
}
catch (Adyen.HttpClient.HttpClientException e)
{
_logger.LogError($"Request for Payment failed:\n{e.ResponseBody}\n");
throw;
}
}

[HttpPost("api/submitAdditionalDetails")]
public async Task<ActionResult<PaymentDetailsResponse>> SubmitAdditionalDetails(PaymentDetailsRequest request, CancellationToken cancellationToken = default)
{
try
{
var res = await _paymentsService.PaymentsDetailsAsync(request, cancellationToken: cancellationToken);
_logger.LogInformation($"Response for PaymentDetails:\n{res}\n");
return res;
}
catch (Adyen.HttpClient.HttpClientException e)
{
_logger.LogError($"Request for PaymentDetails failed:\n{e.ResponseBody}\n");
throw;
}
}

[HttpGet("api/handleShopperRedirect")]
public async Task<IActionResult> HandleShoppperRedirect(string payload = null, string redirectResult = null, CancellationToken cancellationToken = default)
{
var detailsRequest = new PaymentDetailsRequest();
if (!string.IsNullOrWhiteSpace(redirectResult))
{
detailsRequest.Details = new PaymentCompletionDetails() { RedirectResult = redirectResult };
}

if (!string.IsNullOrWhiteSpace(payload))
{
detailsRequest.Details = new PaymentCompletionDetails() { Payload = payload };
}

try
{
var res = await _paymentsService.PaymentsDetailsAsync(detailsRequest, cancellationToken: cancellationToken);
_logger.LogInformation($"Response for PaymentDetails:\n{res}\n");
string redirectUrl = "/result/";
switch (res.ResultCode)
{
case PaymentDetailsResponse.ResultCodeEnum.Authorised:
redirectUrl += "success";
break;
case PaymentDetailsResponse.ResultCodeEnum.Pending:
case PaymentDetailsResponse.ResultCodeEnum.Received:
redirectUrl += "pending";
break;
case PaymentDetailsResponse.ResultCodeEnum.Refused:
redirectUrl += "failed";
break;
default:
redirectUrl += "error";
break;
}

return Redirect(redirectUrl + "?reason=" + res.ResultCode);
}
catch (Adyen.HttpClient.HttpClientException e)
{
_logger.LogError($"Request for PaymentDetails failed:\n{e.ResponseBody}\n");
throw;
}
}
}
}
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.