-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Use primary constructors where relevant. - Use collection literals where relevant. - Simplify JSON serialization with `HttpClient`. - Fix some typos. - Fix indentation.
- Loading branch information
1 parent
ab6d2ac
commit a18cd4e
Showing
7 changed files
with
30 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,24 @@ | ||
// Copyright (c) Just Eat, 2016. All rights reserved. | ||
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information. | ||
|
||
using System.Net.Mime; | ||
using System.Text; | ||
using System.Text.Json; | ||
|
||
namespace JustEat.ApplePayJS.Clients; | ||
|
||
public class ApplePayClient | ||
public class ApplePayClient(HttpClient httpClient) | ||
{ | ||
private readonly HttpClient _httpClient; | ||
|
||
public ApplePayClient(HttpClient httpClient) | ||
{ | ||
_httpClient = httpClient; | ||
} | ||
|
||
public async Task<JsonDocument> GetMerchantSessionAsync( | ||
Uri requestUri, | ||
MerchantSessionRequest request, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
// POST the data to create a valid Apple Pay merchant session. | ||
string json = JsonSerializer.Serialize(request); | ||
|
||
using var content = new StringContent(json, Encoding.UTF8, MediaTypeNames.Application.Json); | ||
|
||
using var response = await _httpClient.PostAsync(requestUri, content, cancellationToken); | ||
using var response = await httpClient.PostAsJsonAsync(requestUri, request, cancellationToken); | ||
|
||
response.EnsureSuccessStatusCode(); | ||
|
||
// Read the opaque merchant session JSON from the response body. | ||
using var stream = await response.Content.ReadAsStreamAsync(); | ||
|
||
return await JsonDocument.ParseAsync(stream, cancellationToken: cancellationToken); | ||
var merchantSession = await response.Content.ReadFromJsonAsync<JsonDocument>(cancellationToken); | ||
return merchantSession!; | ||
} | ||
} |
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
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