-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the Wallet API (#327)
* #326 Implement wallet client * #326 Create a custom json converter so the epoch and expires at are returned as a datetime instead of a long * #326 Update version * Add documentation on Wallet Client * #326 Add language to Wallet API example
- Loading branch information
1 parent
e5d86f7
commit b1a98be
Showing
9 changed files
with
146 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Threading.Tasks; | ||
using Mollie.Api.Models.Wallet.Request; | ||
using Mollie.Api.Models.Wallet.Response; | ||
|
||
namespace Mollie.Api.Client.Abstract { | ||
public interface IWalletClient { | ||
Task<ApplePayPaymentSessionResponse> RequestApplePayPaymentSessionAsync(ApplePayPaymentSessionRequest request); | ||
} | ||
} |
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,16 @@ | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Mollie.Api.Client.Abstract; | ||
using Mollie.Api.Models.Wallet.Request; | ||
using Mollie.Api.Models.Wallet.Response; | ||
|
||
namespace Mollie.Api.Client { | ||
public class WalletClient : BaseMollieClient, IWalletClient { | ||
public WalletClient(string apiKey, HttpClient httpClient = null) : base(apiKey, httpClient) { | ||
} | ||
|
||
public async Task<ApplePayPaymentSessionResponse> RequestApplePayPaymentSessionAsync(ApplePayPaymentSessionRequest request) { | ||
return await this.PostAsync<ApplePayPaymentSessionResponse>("wallets/applepay/sessions", request).ConfigureAwait(false); | ||
} | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
src/Mollie.Api/JsonConverters/MicrosecondEpochConverter.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,18 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
|
||
namespace Mollie.Api.JsonConverters { | ||
public class MicrosecondEpochConverter : DateTimeConverterBase | ||
{ | ||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { | ||
var longValue = long.Parse(reader.Value.ToString()); | ||
return DateTimeOffset.FromUnixTimeMilliseconds(longValue).UtcDateTime; | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Mollie.Api/Models/Wallet/Request/ApplePayPaymentSessionRequest.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,15 @@ | ||
namespace Mollie.Api.Models.Wallet.Request { | ||
public class ApplePayPaymentSessionRequest { | ||
/// <summary> | ||
/// The validationUrl you got from the ApplePayValidateMerchant event. | ||
/// A list of all valid host names for merchant validation is available. You should white list these in your | ||
/// application and reject any validationUrl that have a host name not in the list. | ||
/// </summary> | ||
public string ValidationUrl { get; set; } | ||
|
||
/// <summary> | ||
/// The domain of your web shop, that is visible in the browser’s location bar. For example pay.myshop.com. | ||
/// </summary> | ||
public string Domain { get; set; } | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Mollie.Api/Models/Wallet/Response/ApplePayPaymentSessionResponse.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,18 @@ | ||
using System; | ||
using Mollie.Api.JsonConverters; | ||
using Newtonsoft.Json; | ||
|
||
namespace Mollie.Api.Models.Wallet.Response { | ||
public class ApplePayPaymentSessionResponse { | ||
[JsonConverter(typeof(MicrosecondEpochConverter))] | ||
public DateTime EpochTimestamp { get; set; } | ||
[JsonConverter(typeof(MicrosecondEpochConverter))] | ||
public DateTime ExpiresAt { get; set; } | ||
public string MerchantSessionIdentifier { get; set; } | ||
public string Nonce { get; set; } | ||
public string MerchantIdentifier { get; set; } | ||
public string DomainName { get; set; } | ||
public string DisplayName { get; set; } | ||
public string Signature { get; set; } | ||
} | ||
} |
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,49 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Mollie.Api.Client; | ||
using Mollie.Api.Models.Wallet.Request; | ||
using Xunit; | ||
|
||
namespace Mollie.Tests.Unit.Client; | ||
|
||
public class WalletClientTest : BaseClientTests { | ||
private const string defaultApplePayPaymentSessionResponse = @"{ | ||
""epochTimestamp"": 1555507053169, | ||
""expiresAt"": 1555510653169, | ||
""merchantSessionIdentifier"": ""SSH2EAF8AFAEAA94DEEA898162A5DAFD36E_916523AAED1343F5BC5815E12BEE9250AFFDC1A17C46B0DE5A943F0F94927C24"", | ||
""nonce"": ""0206b8db"", | ||
""merchantIdentifier"": ""BD62FEB196874511C22DB28A9E14A89E3534C93194F73EA417EC566368D391EB"", | ||
""domainName"": ""pay.example.org"", | ||
""displayName"": ""Chuck Norris's Store"", | ||
""signature"": ""308006092a864886f7...8cc030ad3000000000000"" | ||
}"; | ||
|
||
[Fact] | ||
public async Task RequestApplePayPaymentSessionAsync_ResponseIsDeserializedInExpectedFormat() { | ||
// Arrange | ||
var request = new ApplePayPaymentSessionRequest() { | ||
Domain = "pay.mywebshop.com", | ||
ValidationUrl = "https://apple-pay-gateway-cert.apple.com/paymentservices/paymentSession" | ||
}; | ||
var mockHttp = this.CreateMockHttpMessageHandler( | ||
HttpMethod.Post, | ||
$"{BaseMollieClient.ApiEndPoint}wallets/applepay/sessions", | ||
defaultApplePayPaymentSessionResponse); | ||
using var walletClient = new WalletClient("abcde", mockHttp.ToHttpClient()); | ||
|
||
// Act | ||
var response = await walletClient.RequestApplePayPaymentSessionAsync(request); | ||
|
||
// Assert | ||
response.EpochTimestamp.Should().Be(DateTimeOffset.FromUnixTimeMilliseconds(1555507053169).UtcDateTime); | ||
response.ExpiresAt.Should().Be(DateTimeOffset.FromUnixTimeMilliseconds(1555510653169).UtcDateTime); | ||
response.MerchantSessionIdentifier.Should().Be("SSH2EAF8AFAEAA94DEEA898162A5DAFD36E_916523AAED1343F5BC5815E12BEE9250AFFDC1A17C46B0DE5A943F0F94927C24"); | ||
response.Nonce.Should().Be("0206b8db"); | ||
response.MerchantIdentifier.Should().Be("BD62FEB196874511C22DB28A9E14A89E3534C93194F73EA417EC566368D391EB"); | ||
response.DomainName.Should().Be("pay.example.org"); | ||
response.DisplayName.Should().Be("Chuck Norris's Store"); | ||
response.Signature.Should().Be("308006092a864886f7...8cc030ad3000000000000"); | ||
} | ||
} |