Skip to content

Commit

Permalink
Support .NET AOT (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
trejjam authored Nov 18, 2023
1 parent e81e8d0 commit e510382
Show file tree
Hide file tree
Showing 67 changed files with 209 additions and 271 deletions.
1 change: 1 addition & 0 deletions PayPal.Sdk.Checkout.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.config\dotnet-tools.json = .config\dotnet-tools.json
GitVersion.yml = GitVersion.yml
props\PayPal.props = props\PayPal.props
nuget.config = nuget.config
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GithubWorkflows", "GithubWorkflows", "{7DF6DE1B-F6ED-4AC7-8D75-1A95E6EF3390}"
Expand Down
26 changes: 26 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<packageSources>
<clear />
<add key="nuget"
value="https://api.nuget.org/v3/index.json"
protocolVersion="3" />
<add key="json-converter-source-generator"
value="https://f.feedz.io/aviationexam/json-converter-source-generator/nuget/index.json"
protocolVersion="3" />
</packageSources>
<packageSourceMapping>
<!-- key value for <packageSource> should match key values from <packageSources> element -->

<!--
<packageSource key="json-converter-source-generator">
<package pattern="Aviationexam.GeneratedJsonConverters.SourceGenerator" />
</packageSource>
-->

<packageSource key="nuget">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class CaptureOrderSample
/// <summary>
/// This method can be used to capture the payment on the approved authorization.
/// </summary>
public static async Task<Capture?> CaptureOrder(this IPayPalHttpClient httpClient, AccessToken accessToken, string authorizationId, bool debug = false)
public static async Task<PaymentCapture?> CaptureOrder(this IPayPalHttpClient httpClient, AccessToken accessToken, string authorizationId, bool debug = false)
{
var response = await httpClient.CapturePaymentAsync(
accessToken,
Expand Down
4 changes: 2 additions & 2 deletions samples/PayPal.Sdk.Checkout.Samples/CapturesRefundSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class CapturesRefundSample
/// <summary>
/// Method for refund the capture. Valid capture Id should be passed an argument to this method.
/// </summary>
public static async Task<Refund?> CapturesRefund(this IPayPalHttpClient httpClient, AccessToken accessToken,
public static async Task<PaymentRefund?> CapturesRefund(this IPayPalHttpClient httpClient, AccessToken accessToken,
string captureId, bool debug = false)
{
var response = await httpClient.CapturesRefundAsync(
Expand All @@ -24,7 +24,7 @@ public static class CapturesRefundSample
request.SetPreferReturn(EPreferReturn.Representation);
request.SetRequestBody(new RefundRequest
{
Amount = new Money
Amount = new PaymentMoney
{
Value = "20.00",
CurrencyCode = "USD"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public AccessTokenRequest(
string? refreshToken = null
) : base(
"/v1/oauth2/token", HttpMethod.Post,
PayPalAuthenticationJsonSerializerContext.CustomConverters.AccessToken
PayPalJsonSerializerContext.Default.AccessToken
)
{
Authorization = new AuthenticationHeaderValue("Basic", options.AuthorizationString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public RefreshTokenRequest(
PayPalOptions options, string code
) : base(
"/v1/identity/openidconnect/tokenservice", HttpMethod.Post,
PayPalAuthenticationJsonSerializerContext.CustomConverters.RefreshToken
PayPalJsonSerializerContext.Default.RefreshToken
)
{
Authorization = new AuthenticationHeaderValue("Basic", options.AuthorizationString());
Expand Down
3 changes: 3 additions & 0 deletions src/PayPal.Sdk.Checkout/Configuration/EPayPalEnvironment.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Aviationexam.GeneratedJsonConverters.Attributes;

namespace PayPal.Sdk.Checkout.Configuration;

[EnumJsonConverter]
public enum EPayPalEnvironment : byte
{
Sandbox = 0,
Expand Down
3 changes: 3 additions & 0 deletions src/PayPal.Sdk.Checkout/ContractEnums/EPreferReturn.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Aviationexam.GeneratedJsonConverters.Attributes;

namespace PayPal.Sdk.Checkout.ContractEnums;

[EnumJsonConverter]
public enum EPreferReturn : byte
{
Representation = 0,
Expand Down
61 changes: 0 additions & 61 deletions src/PayPal.Sdk.Checkout/Core/Converters/JsonStringEnumConverter.cs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using PayPalAuthentication = PayPal.Sdk.Checkout.Authentication;
using PayPalOrders = PayPal.Sdk.Checkout.Orders;
using PayPalPayments = PayPal.Sdk.Checkout.Payments;

namespace PayPal.Sdk.Checkout.Core.MessageSerializers;

[JsonSourceGenerationOptions(
WriteIndented = true,
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
GenerationMode = JsonSourceGenerationMode.Default
)]
[JsonSerializable(typeof(PayPalAuthentication.AccessToken))]
[JsonSerializable(typeof(PayPalAuthentication.RefreshToken))]
[JsonSerializable(typeof(PayPalOrders.AuthorizeRequest))]
[JsonSerializable(typeof(IReadOnlyCollection<PayPalOrders.StringPatch>))]
[JsonSerializable(typeof(PayPalOrders.Order))]
[JsonSerializable(typeof(PayPalOrders.OrderActionRequest))]
[JsonSerializable(typeof(PayPalOrders.OrderCaptureRequest))]
[JsonSerializable(typeof(PayPalOrders.OrderRequest))]
[JsonSerializable(typeof(PayPalPayments.CaptureRequest))]
[JsonSerializable(typeof(PayPalPayments.PaymentAuthorization))]
[JsonSerializable(typeof(PayPalPayments.PaymentCapture))]
[JsonSerializable(typeof(PayPalPayments.PaymentRefund))]
[JsonSerializable(typeof(PayPalPayments.ReauthorizeRequest))]
[JsonSerializable(typeof(PayPalPayments.RefundRequest))]
internal partial class PayPalJsonSerializerContext : JsonSerializerContext
{
static PayPalJsonSerializerContext()
{
// register generated converters to options
UseEnumConverters(s_defaultOptions.Converters);

#if NET8_0_OR_GREATER
Default = new PayPalJsonSerializerContext(new System.Text.Json.JsonSerializerOptions(s_defaultOptions));
#endif
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace PayPal.Sdk.Checkout.Extensions;

public static class IoCExtensions
public static class DependencyInjectionExtensions
{
public static IServiceCollection AddPayPalCheckout(
this IServiceCollection services,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace PayPal.Sdk.Checkout.Extensions;

public static class PaymentRequestExtensions
{
public static async Task<Capture?> CapturePaymentAsync(
public static async Task<PaymentCapture?> CapturePaymentAsync(
this IPayPalHttpClient payPalHttpClient,
AccessToken accessToken,
string authorizationId,
Expand All @@ -21,12 +21,12 @@ public static class PaymentRequestExtensions

configureRequest?.Invoke(request);

var response = await payPalHttpClient.ExecuteAsync<AuthorizationsCaptureRequest, CaptureRequest, Capture>(request, accessToken, cancellationToken);
var response = await payPalHttpClient.ExecuteAsync<AuthorizationsCaptureRequest, CaptureRequest, PaymentCapture>(request, accessToken, cancellationToken);

return response.ResponseBody;
}

public static async Task<Refund?> CapturesRefundAsync(
public static async Task<PaymentRefund?> CapturesRefundAsync(
this IPayPalHttpClient payPalHttpClient,
AccessToken accessToken,
string captureId,
Expand All @@ -38,7 +38,7 @@ public static class PaymentRequestExtensions

configureRequest?.Invoke(request);

var response = await payPalHttpClient.ExecuteAsync<CapturesRefundRequest, RefundRequest, Refund>(request, accessToken, cancellationToken);
var response = await payPalHttpClient.ExecuteAsync<CapturesRefundRequest, RefundRequest, PaymentRefund>(request, accessToken, cancellationToken);

return response.ResponseBody;
}
Expand Down
2 changes: 2 additions & 0 deletions src/PayPal.Sdk.Checkout/Orders/EAuthorizationStatus.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Aviationexam.GeneratedJsonConverters.Attributes;
using System.Runtime.Serialization;

namespace PayPal.Sdk.Checkout.Orders;

[EnumJsonConverter]
public enum EAuthorizationStatus : byte
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/PayPal.Sdk.Checkout/Orders/ECaptureStatus.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Aviationexam.GeneratedJsonConverters.Attributes;
using System.Runtime.Serialization;

namespace PayPal.Sdk.Checkout.Orders;

[EnumJsonConverter]
public enum ECaptureStatus : byte
{
/// <summary>
Expand Down
Loading

0 comments on commit e510382

Please sign in to comment.