-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Integration-Example: Authorisation Adjustment (#91)
* Initial commit - Authorisation Adjustment * Modified solution to follow advanced-checkoutflow and use manual capture + preauth in additionalData to make a payment of 249.99 * Add incremental/decremental/extend adjustment services * Added capture * Added reversals * Added styling, frontend bindings & respective views * Updated build.yml and e2e.yml to ignore running tests when readme is updated * Added GIF Authorisation Adjustment Card --------- Co-authored-by: Kwok He Chu <>
- Loading branch information
1 parent
18e42fa
commit 025d54e
Showing
74 changed files
with
28,456 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
163 changes: 163 additions & 0 deletions
163
authorisation-adjustment-example/Controllers/AdminController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
using Adyen.HttpClient; | ||
using Adyen.Model.Checkout; | ||
using Adyen.Service.Checkout; | ||
using adyen_dotnet_authorisation_adjustment_example.Models; | ||
using adyen_dotnet_authorisation_adjustment_example.Options; | ||
using adyen_dotnet_authorisation_adjustment_example.Repositories; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace adyen_dotnet_authorisation_adjustment_example.Controllers | ||
{ | ||
public class AdminController : Controller | ||
{ | ||
private readonly IPaymentRepository _repository; | ||
private readonly IModificationsService _modificationsService; | ||
private readonly ILogger<AdminController> _logger; | ||
private readonly string _merchantAccount; | ||
|
||
public AdminController(IPaymentRepository repository, IModificationsService modificationsService, IOptions<AdyenOptions> options, ILogger<AdminController> logger) | ||
{ | ||
_repository = repository; | ||
_merchantAccount = options.Value.ADYEN_MERCHANT_ACCOUNT; | ||
_modificationsService = modificationsService; | ||
_logger = logger; | ||
} | ||
|
||
[Route("admin")] | ||
public IActionResult Index() | ||
{ | ||
List<PaymentModel> payments = new List<PaymentModel>(); | ||
foreach (var kvp in _repository.Payments) | ||
{ | ||
payments.Add(_repository.FindLatestPaymentByReference(kvp.Key)); | ||
} | ||
ViewBag.Payments = payments; | ||
return View(); | ||
} | ||
|
||
[Route("admin/details/{reference}")] | ||
public IActionResult Details(string reference) | ||
{ | ||
// We fetch all payments (regardless whether its authorised/refused) that we have stored in our local repository and show it. | ||
ViewBag.Payments = _repository.FindByReference(reference) | ||
.OrderBy(x=> x.DateTime) | ||
.ToList(); | ||
return View(); | ||
} | ||
|
||
[HttpGet("admin/result/{status}/{reference}")] | ||
public IActionResult Result(string reference, string status, [FromQuery(Name = "reason")] string refusalReason) | ||
{ | ||
string msg; | ||
string img; | ||
switch (status) | ||
{ | ||
case "received": | ||
msg = $"Request received for Merchant Reference: {reference}. Wait a bit to receive the asynchronous webhook response."; | ||
img = "success"; | ||
break; | ||
default: | ||
msg = $"Error! Refusal reason: {refusalReason}"; | ||
img = "failed"; | ||
break; | ||
} | ||
ViewBag.Status = status; | ||
ViewBag.Msg = msg; | ||
ViewBag.Img = img; | ||
return View(); | ||
} | ||
|
||
[HttpPost("admin/update-payment-amount")] | ||
public async Task<ActionResult<PaymentAmountUpdateResource>> UpdatePaymentAmount([FromBody] UpdatePaymentAmountRequest request, CancellationToken cancellationToken = default) | ||
{ | ||
PaymentModel payment = _repository.FindLatestPaymentByReference(request.Reference); | ||
|
||
if (payment == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
try | ||
{ | ||
var createPaymentAmountUpdateRequest = new CreatePaymentAmountUpdateRequest() | ||
{ | ||
MerchantAccount = _merchantAccount, // Required | ||
Amount = new Amount() { Value = request.Amount, Currency = payment.Currency }, | ||
Reference = payment.Reference, | ||
IndustryUsage = CreatePaymentAmountUpdateRequest.IndustryUsageEnum.DelayedCharge, | ||
}; | ||
|
||
var response = await _modificationsService.UpdateAuthorisedAmountAsync(payment.GetOriginalPspReference(), createPaymentAmountUpdateRequest, cancellationToken: cancellationToken); | ||
return Ok(response); | ||
} | ||
catch (HttpClientException e) | ||
{ | ||
_logger.LogError(e.ToString()); | ||
return BadRequest(); | ||
} | ||
} | ||
|
||
[HttpPost("admin/capture-payment")] | ||
public async Task<ActionResult<PaymentCaptureResource>> CapturePayment([FromBody] CreateCapturePaymentRequest request, CancellationToken cancellationToken = default) | ||
{ | ||
PaymentModel payment = _repository.FindLatestPaymentByReference(request.Reference); | ||
|
||
if (payment == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
try | ||
{ | ||
var createPaymentCaptureRequest = new CreatePaymentCaptureRequest() | ||
{ | ||
MerchantAccount = _merchantAccount, // Required. | ||
Amount = new Amount() { Value = payment.Amount, Currency = payment.Currency }, // Required. | ||
Reference = payment.Reference | ||
}; | ||
|
||
var response = await _modificationsService.CaptureAuthorisedPaymentAsync(payment.GetOriginalPspReference(), createPaymentCaptureRequest, cancellationToken: cancellationToken); | ||
return Ok(response); // Note that the response will have a different PSPReference compared to the initial pre-authorisation. | ||
} | ||
catch (HttpClientException e) | ||
{ | ||
_logger.LogError(e.ToString()); | ||
return BadRequest(); | ||
} | ||
} | ||
|
||
[HttpPost("admin/reversal-payment")] | ||
public async Task<ActionResult<PaymentReversalResource>> ReversalPayment([FromBody] CreateReversalPaymentRequest request, CancellationToken cancellationToken = default) | ||
{ | ||
PaymentModel payment = _repository.FindLatestPaymentByReference(request.Reference); | ||
|
||
if (payment == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
try | ||
{ | ||
var createPaymentReversalRequest = new CreatePaymentReversalRequest() | ||
{ | ||
MerchantAccount = _merchantAccount, // Required. | ||
Reference = payment.Reference | ||
}; | ||
|
||
var response = await _modificationsService.RefundOrCancelPaymentAsync(payment.GetOriginalPspReference(), createPaymentReversalRequest, cancellationToken: cancellationToken); | ||
return Ok(response); | ||
} | ||
catch (HttpClientException e) | ||
{ | ||
_logger.LogError(e.ToString()); | ||
return BadRequest(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.