Skip to content

Commit

Permalink
Merge pull request #183 from Judopay/JR-7178-UpdateApiForPartnerApi620
Browse files Browse the repository at this point in the history
Jr 7178 update api for partner api 6.20
  • Loading branch information
Stuart-Baillie authored Sep 21, 2023
2 parents 1c0778d + b6b4fc3 commit 56c3001
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 8 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# Change Log
All notable changes to this project will be documented in this file.

## 4.0 Changes (Note this contains breaking changes)
## 4.1 Changes on 2023-09
- Update Api-Version to 6.20
- Add ShortUrl to WebPaymentResponseModel
- Add DelayedAuthorisation request attribute to WebPaymentRequestModel (for use in PreAuths only)
- Add ShortReference and DelayedAuthorisation to GetWebPaymentResponseModel

## 4.0 Changes on 2023-04-18 (Note this contains breaking changes)
- Update Api-Version to 6.19
- Update UserAgent to start with JudoDotNetSDK
- Update PaymentModel to remove PartnerServiceFee, ConsumerLocation and DeviceCategory (use
Expand Down
2 changes: 1 addition & 1 deletion JudoPayDotNet/Http/VersioningHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal class VersioningHandler : DelegatingHandler
{
public const string API_VERSION_HEADER = "api-version";

internal const string DEFAULT_API_VERSION = "6.19";
internal const string DEFAULT_API_VERSION = "6.20";

private readonly string _apiVersionValue;

Expand Down
6 changes: 6 additions & 0 deletions JudoPayDotNet/Models/GetWebPaymentResponseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,11 @@ public class GetWebPaymentResponseModel : WebPaymentRequestModel
/// </summary>
[DataMember(EmitDefaultValue = true)]
public int? NoOfAuthAttempts { get; set; }

[DataMember(EmitDefaultValue = false)]
public string ShortReference { get; private set; }

[DataMember(EmitDefaultValue = false)]
public bool? DelayedAuthorisation { get; private set; }
}
}
7 changes: 7 additions & 0 deletions JudoPayDotNet/Models/WebPaymentRequestModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ public WebPaymentRequestModel()
[DataMember(EmitDefaultValue = false)]
public PrimaryAccountDetailsModel PrimaryAccountDetails { get; set; }

/// <summary>
/// Only set this flag on payment sessions for PreAuths, to authenticate a card holder with 3D secure without
/// performing payment authorisation.
/// </summary>
[DataMember(EmitDefaultValue = false)]
public bool? DelayedAuthorisation { get; set; }

private Dictionary<string, string> _httpHeaders;

/// <summary>
Expand Down
17 changes: 11 additions & 6 deletions JudoPayDotNet/Models/WebPaymentResponseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@ public class WebPaymentResponseModel
// ReSharper restore ClassNeverInstantiated.Global
{
/// <summary>
/// Gets or sets the post URL.
/// URL prefix to launch Judo hosted web payments page (follow with ?reference={Reference})
/// </summary>
/// <value>
/// The post URL.
/// </value>
[DataMember(EmitDefaultValue = false)]
public string PostUrl { get; set; }
public string PostUrl { get; private set; }

/// <summary>
/// Judopay generated reference for the web payment.
/// </summary>
[DataMember(EmitDefaultValue = false)]
public string Reference { get; set; }
public string Reference { get; private set; }

[DataMember(EmitDefaultValue = false)]
private string PayByLinkUrl { get; set; }

/// <summary>
/// Short URL to launch Judo hosted web payments page
/// </summary>
public string ShortUrl => PayByLinkUrl;
}
// ReSharper restore UnusedAutoPropertyAccessor.Global
}
25 changes: 25 additions & 0 deletions JudoPayDotNetIntegrationTests/CheckCardTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,31 @@ public async Task PrimaryAccountDetailsCheckCard()
Assert.AreEqual("Success", response.Response.Result);
}

[Test]
public async Task ThreeDSecureMpiCheckCard()
{
var checkCardModel = GetCheckCardModel();
// Given a CheckCardModel with ThreeDSecureMpiModel
var threeDSecureMpi = new ThreeDSecureMpiModel
{
DsTransId = "539c3e09-ee16-404b-9eee-96941e9e012e",
Cavv = "AAkBAgOViQAAAABkgmJXdAoPFww=",
Eci = "05",
ThreeDSecureVersion = "2.1.0"
};
checkCardModel.ThreeDSecureMpi = threeDSecureMpi;

var response = await JudoPayApiBase.CheckCards.Create(checkCardModel);

Assert.IsNotNull(response);
Assert.IsFalse(response.HasError);

var receipt = response.Response as PaymentReceiptModel;
Assert.IsNotNull(receipt?.ThreeDSecure);
Assert.AreEqual(threeDSecureMpi.Eci, receipt.ThreeDSecure.Eci);
}


internal class RegisterCheckCardTestSource
{
public static IEnumerable ValidateFailureTestCases
Expand Down
117 changes: 117 additions & 0 deletions JudoPayDotNetIntegrationTests/WebPaymentsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,123 @@ public void CheckCardSessionCancel()
Assert.AreEqual(result.Response.Reference, cancelResult.Response.Reference);
}

[Test]
public void GetShortReferenceFromWebPayment()
{
// Given a WebPayment session
var yourConsumerReference = "432438862";
var webPaymentRequest = new WebPaymentRequestModel
{
JudoId = Configuration.Judoid,
YourConsumerReference = yourConsumerReference,
Amount = 25
};

var webPaymentResult = JudoPayApiBase.WebPayments.Payments.Create(webPaymentRequest).Result;
Assert.NotNull(webPaymentResult);
Assert.IsFalse(webPaymentResult.HasError);

var webPaymentReference = webPaymentResult.Response.Reference;
Assert.NotNull(webPaymentReference);

var shortUrl = webPaymentResult.Response.ShortUrl;

// When session is retrieved by reference
var paymentSession = JudoPayApiBase.WebPayments.Transactions.Get(
webPaymentReference).Result;

Assert.IsNotNull(paymentSession);
Assert.IsFalse(paymentSession.HasError);

// Then shortReference on payment session matches end of shortUrl from response
Assert.IsNotNull(paymentSession.Response.ShortReference);
var shortRef = shortUrl?.Substring(shortUrl.LastIndexOf('/') + 1);
Assert.AreEqual(shortRef,
paymentSession.Response.ShortReference);
}

[Test]
[TestCase(true)]
[TestCase(false)]
[TestCase(null)]
public void GetDelayedAuthorisationFromWebPayment(bool? delayedAuthorisation)
{
// Given a WebPayment session
var yourConsumerReference = "432438862";
var webPaymentRequest = new WebPaymentRequestModel
{
JudoId = Configuration.Judoid,
YourConsumerReference = yourConsumerReference,
Amount = 25,
DelayedAuthorisation = delayedAuthorisation
};

// For a PreAuth
var webPaymentResult = JudoPayApiBase.WebPayments.PreAuths.Create(webPaymentRequest).Result;
Assert.NotNull(webPaymentResult);
Assert.IsFalse(webPaymentResult.HasError);
var webPaymentReference = webPaymentResult.Response.Reference;
Assert.NotNull(webPaymentReference);

// When session is retrieved by reference
var paymentSession = JudoPayApiBase.WebPayments.Transactions.Get(
webPaymentReference).Result;

Assert.IsNotNull(paymentSession);
Assert.IsFalse(paymentSession.HasError);

// Then delayedAuthorisation on respones matches that on session
Assert.AreEqual(delayedAuthorisation, paymentSession.Response.DelayedAuthorisation);
}

[Test]
public void GetReceiptFromCompletedWebPayment()
{
// Given a WebPayment session
var yourConsumerReference = "432438862";
var webPaymentRequest = new WebPaymentRequestModel
{
JudoId = Configuration.Judoid,
YourConsumerReference = yourConsumerReference,
Amount = 25
};

var webPaymentResult = JudoPayApiBase.WebPayments.Payments.Create(webPaymentRequest).Result;
Assert.NotNull(webPaymentResult);
Assert.IsFalse(webPaymentResult.HasError);

var webPaymentReference = webPaymentResult.Response.Reference;
Assert.NotNull(webPaymentReference);

// And an associated payment (passing webPaymentReference)
var paymentWithCard = GetCardPaymentModel();
paymentWithCard.WebPaymentReference = webPaymentReference;

// Set other fields to be identical for the authentication to be successful
paymentWithCard.Amount = webPaymentRequest.Amount;
paymentWithCard.YourConsumerReference = webPaymentRequest.YourConsumerReference;
paymentWithCard.YourPaymentReference = webPaymentRequest.YourPaymentReference;

var paymentResponse = JudoPayApiBase.Payments.Create(paymentWithCard).Result;

Assert.IsNotNull(paymentResponse);
Assert.IsFalse(paymentResponse.HasError);
Assert.AreEqual("Success", paymentResponse.Response.Result);

// When session is retrieved by reference
var paymentSession = JudoPayApiBase.WebPayments.Transactions.Get(
webPaymentReference).Result;

Assert.IsNotNull(paymentSession);
Assert.IsFalse(paymentSession.HasError);

// Then receipt on payment session matches that of transaction
Assert.IsNotNull(paymentSession.Response.Receipt);
Assert.AreEqual(paymentResponse.Response.ReceiptId,
paymentSession.Response.Receipt.ReceiptId);
}


internal class WebPaymentsTestSource
{
public static IEnumerable ValidateFailureTestCases
Expand Down

0 comments on commit 56c3001

Please sign in to comment.