Skip to content

Commit

Permalink
Use new lang version (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
trejjam authored Oct 9, 2024
1 parent d1b32bc commit 652b156
Show file tree
Hide file tree
Showing 47 changed files with 354 additions and 407 deletions.
13 changes: 10 additions & 3 deletions props/PayPal.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<Project>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Release'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
<NoWarn>$(NoWarn);MA0002;MA0012;MA0051;MA0061</NoWarn>
<WarningsAsErrors>$(WarningsAsErrors);MA0007</WarningsAsErrors>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class AuthorizeOrderSample
request.SetPreferReturn(EPreferReturn.Representation);
request.SetRequestBody(new AuthorizeRequest());
}
);
).ConfigureAwait(false);

if (debug && response != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class CaptureOrderSample
request.SetPreferReturn(EPreferReturn.Representation);
request.SetRequestBody(new CaptureRequest());
}
);
).ConfigureAwait(false);

if (debug && response != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ private static async Task Main()
{
var payPalHttpClient = SampleHttpClientFactory.CreateHttpClient();

var accessToken = await payPalHttpClient.AuthenticateAsync();
var accessToken = await payPalHttpClient.AuthenticateAsync().ConfigureAwait(false);

Console.WriteLine("Running Authorize Intent Flow..");
var createOrderResponse = await payPalHttpClient.CreateOrder(accessToken!);
var createOrderResponse = await payPalHttpClient.CreateOrder(accessToken!).ConfigureAwait(false);

Console.WriteLine("Status: {0}", createOrderResponse!.Status);
Console.WriteLine("Order Id: {0}", createOrderResponse.Id);
Expand All @@ -33,7 +33,7 @@ private static async Task Main()
Console.Read();

Console.WriteLine("Authorizing the Order....");
var authorizeOrderResponse = await payPalHttpClient.AuthorizeOrder(accessToken!, createOrderResponse.Id);
var authorizeOrderResponse = await payPalHttpClient.AuthorizeOrder(accessToken!, createOrderResponse.Id).ConfigureAwait(false);

Console.WriteLine("Status: {0}", authorizeOrderResponse!.Status);
var authorizationId = authorizeOrderResponse.PurchaseUnits.Single().Payments.Authorizations.Single().Id;
Expand All @@ -52,7 +52,7 @@ private static async Task Main()
Console.WriteLine("AuthorizedAmount: {0}", authorizedAmount);

Console.WriteLine("Capturing the payment...");
var captureOrderResponse = await payPalHttpClient.CaptureOrder(accessToken!, authorizationId);
var captureOrderResponse = await payPalHttpClient.CaptureOrder(accessToken!, authorizationId).ConfigureAwait(false);

Console.WriteLine("Status: {0}", captureOrderResponse!.Status);
Console.WriteLine("Capture Id: {0}", captureOrderResponse.Id);
Expand All @@ -63,7 +63,7 @@ private static async Task Main()
}

Console.WriteLine("Refunding the Order....");
var refundOrderResponse = await payPalHttpClient.CapturesRefund(accessToken!, captureOrderResponse.Id);
var refundOrderResponse = await payPalHttpClient.CapturesRefund(accessToken!, captureOrderResponse.Id).ConfigureAwait(false);

Console.WriteLine("Status: {0}", refundOrderResponse!.Status);
Console.WriteLine("Refund Id: {0}", refundOrderResponse.Id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ passed an argument to this method.
public static async Task<Order?> CaptureOrder(this IPayPalHttpClient payPalHttpClient, AccessToken accessToken,
string orderId, bool debug = false)
{
var response = await payPalHttpClient.CaptureOrderAsync(accessToken, orderId);
var response = await payPalHttpClient.CaptureOrderAsync(accessToken, orderId).ConfigureAwait(false);

if (debug && response != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

namespace PayPal.Sdk.Checkout.Samples.CaptureIntentExamples;

public static class RunAll
public static class RunAllCaptureIntentFlow
{
//Rename to Main1 => Main
[SuppressMessage("ReSharper", "UnusedMember.Local")]
private static async Task Main1()
{
var payPalHttpClient = SampleHttpClientFactory.CreateHttpClient();

var accessToken = await payPalHttpClient.AuthenticateAsync();
var accessToken = await payPalHttpClient.AuthenticateAsync().ConfigureAwait(false);

Console.WriteLine("Running Capture Intent Flow..");
var createOrderResponse = await payPalHttpClient.CreateOrder(accessToken!, true);
var createOrderResponse = await payPalHttpClient.CreateOrder(accessToken!, true).ConfigureAwait(false);

Console.WriteLine("Status: {0}", createOrderResponse!.Status);
Console.WriteLine("Order Id: {0}", createOrderResponse.Id);
Expand All @@ -35,7 +35,7 @@ private static async Task Main1()
Console.Read();

Console.WriteLine("Capturing the payment...");
var captureOrderResponse = await payPalHttpClient.CaptureOrder(accessToken!, createOrderResponse.Id, true);
var captureOrderResponse = await payPalHttpClient.CaptureOrder(accessToken!, createOrderResponse.Id, true).ConfigureAwait(false);

var captureId = "";
Console.WriteLine("Status: {0}", captureOrderResponse!.Status);
Expand All @@ -61,7 +61,7 @@ private static async Task Main1()
Console.WriteLine("CaptureAmount: {0}", captureAmount);

Console.WriteLine("Refunding the Order....");
var refundOrderResponse = await payPalHttpClient.CapturesRefund(accessToken!, captureId, true);
var refundOrderResponse = await payPalHttpClient.CapturesRefund(accessToken!, captureId, true).ConfigureAwait(false);
Console.WriteLine("Status: {0}", refundOrderResponse!.Status);
Console.WriteLine("Refund Id: {0}", refundOrderResponse.Id);
Console.WriteLine("Links:");
Expand Down
12 changes: 7 additions & 5 deletions samples/PayPal.Sdk.Checkout.Samples/CapturesRefundSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ 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<PaymentRefund?> CapturesRefund(this IPayPalHttpClient httpClient, AccessToken accessToken,
string captureId, bool debug = false)
public static async Task<PaymentRefund?> CapturesRefund(
this IPayPalHttpClient httpClient, AccessToken accessToken,
string captureId, bool debug = false
)
{
var response = await httpClient.CapturesRefundAsync(
accessToken,
Expand All @@ -27,11 +29,11 @@ public static class CapturesRefundSample
Amount = new PaymentMoney
{
Value = "20.00",
CurrencyCode = "USD"
}
CurrencyCode = "USD",
},
});
}
);
).ConfigureAwait(false);

if (debug && response != null)
{
Expand Down
56 changes: 28 additions & 28 deletions samples/PayPal.Sdk.Checkout.Samples/CreateOrderSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ private static OrderRequest BuildRequestBody()
UserAction = EUserAction.Continue,
ShippingPreference = EShippingPreference.SetProvidedAddress,
},
PurchaseUnits = new List<PurchaseUnitRequest>
{
new()
PurchaseUnits =
[
new PurchaseUnitRequest
{
ReferenceId = "PUHF",
Description = "Sporting Goods",
Expand All @@ -46,29 +46,29 @@ private static OrderRequest BuildRequestBody()
ItemTotal = new Money
{
CurrencyCode = "USD",
Value = "180.00"
Value = "180.00",
},
Shipping = new Money
{
CurrencyCode = "USD",
Value = "20.00"
Value = "20.00",
},
Handling = new Money
{
CurrencyCode = "USD",
Value = "10.00"
Value = "10.00",
},
TaxTotal = new Money
{
CurrencyCode = "USD",
Value = "20.00"
Value = "20.00",
},
ShippingDiscount = new Money
{
CurrencyCode = "USD",
Value = "10.00"
}
}
Value = "10.00",
},
},
},
Items = new List<Item>
{
Expand All @@ -80,12 +80,12 @@ private static OrderRequest BuildRequestBody()
UnitAmount = new Money
{
CurrencyCode = "USD",
Value = "90.00"
Value = "90.00",
},
Tax = new Money
{
CurrencyCode = "USD",
Value = "10.00"
Value = "10.00",
},
Quantity = "1",
Category = EItemCategory.PhysicalGoods,
Expand All @@ -98,22 +98,22 @@ private static OrderRequest BuildRequestBody()
UnitAmount = new Money
{
CurrencyCode = "USD",
Value = "45.00"
Value = "45.00",
},
Tax = new Money
{
CurrencyCode = "USD",
Value = "5.00"
Value = "5.00",
},
Quantity = "2",
Category = EItemCategory.PhysicalGoods,
}
},
},
ShippingDetail = new ShippingDetail
{
Name = new ShippingName
{
FullName = "John Doe"
FullName = "John Doe",
},
AddressPortable = new AddressPortable
{
Expand All @@ -122,11 +122,11 @@ private static OrderRequest BuildRequestBody()
AdminArea2 = "San Francisco",
AdminArea1 = "CA",
PostalCode = "94107",
CountryCode = "US"
}
}
}
}
CountryCode = "US",
},
},
},
],
};

return orderRequest;
Expand All @@ -142,7 +142,7 @@ private static OrderRequest BuildRequestBody()
{
request.SetPreferReturn(EPreferReturn.Representation);
request.SetRequestBody(BuildRequestBody());
});
}).ConfigureAwait(false);

if (debug && response != null)
{
Expand Down Expand Up @@ -174,7 +174,7 @@ private static OrderRequest BuildRequestBodyWithMinimumFields()
ApplicationContext = new ApplicationContext
{
CancelUrl = "https://www.example.com",
ReturnUrl = "https://www.example.com"
ReturnUrl = "https://www.example.com",
},
PurchaseUnits = new List<PurchaseUnitRequest>
{
Expand All @@ -183,10 +183,10 @@ private static OrderRequest BuildRequestBodyWithMinimumFields()
AmountWithBreakdown = new AmountWithBreakdown
{
CurrencyCode = "USD",
Value = "220.00"
}
}
}
Value = "220.00",
},
},
},
};

return orderRequest;
Expand All @@ -202,7 +202,7 @@ private static OrderRequest BuildRequestBodyWithMinimumFields()
{
request.SetPreferReturn(EPreferReturn.Representation);
request.SetRequestBody(BuildRequestBodyWithMinimumFields());
});
}).ConfigureAwait(false);

if (debug && response != null)
{
Expand Down
2 changes: 1 addition & 1 deletion samples/PayPal.Sdk.Checkout.Samples/GetOrderSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class GetOrderSample
var response = await httpClient.GetOrderAsync(
accessToken,
orderId
);
).ConfigureAwait(false);

if (debug && response != null)
{
Expand Down
10 changes: 5 additions & 5 deletions samples/PayPal.Sdk.Checkout.Samples/PatchOrderSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ private static IReadOnlyCollection<StringPatch> BuildPatches()
{
Op = "replace",
Path = "/intent",
Value = "CAPTURE"
Value = "CAPTURE",
},
new()
{
Op = "replace",
Path = "/purchase_units/@reference_id=='PUHF'/description",
Value = "Physical Goods"
}
Value = "Physical Goods",
},
};
return patches;
}
Expand All @@ -44,12 +44,12 @@ await httpClient.OrdersPatchRequestAsync(
accessToken,
orderId,
BuildPatches()
);
).ConfigureAwait(false);

var response = await httpClient.GetOrderAsync(
accessToken,
orderId
);
).ConfigureAwait(false);

if (debug && response != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<ProjectReference Include="..\..\src\PayPal.Sdk.Checkout\PayPal.Sdk.Checkout.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.169" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
Expand Down
20 changes: 7 additions & 13 deletions src/PayPal.Sdk.Checkout/Authentication/AccessToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@

namespace PayPal.Sdk.Checkout.Authentication;

public class AccessToken
public class AccessToken(
DateTime? receivedDate = null
)
{
[JsonPropertyName("access_token")]
public string Token { get; set; } = null!;
[JsonPropertyName("access_token")] public string Token { get; set; } = null!;

[JsonPropertyName("token_type")]
public string TokenType { get; set; } = null!;
[JsonPropertyName("token_type")] public string TokenType { get; set; } = null!;

[JsonPropertyName("expires_in")]
public int ExpiresIn { get; set; }
[JsonPropertyName("expires_in")] public int ExpiresIn { get; set; }

private DateTime ReceivedDate { get; }
private DateTime ReceivedDate { get; } = receivedDate ?? DateTime.Now;

[JsonConstructor]
public AccessToken(
Expand All @@ -26,11 +25,6 @@ public AccessToken(
ExpiresIn = expiresIn;
}

public AccessToken(DateTime? receivedDate = null)
{
ReceivedDate = receivedDate ?? DateTime.Now;
}

public bool IsExpired(DateTime? now = null)
{
var expireDate = ReceivedDate.Add(TimeSpan.FromSeconds(ExpiresIn));
Expand Down
Loading

0 comments on commit 652b156

Please sign in to comment.