Skip to content

Commit

Permalink
Fix over 200 nullability warnings - 600 left to go
Browse files Browse the repository at this point in the history
  • Loading branch information
Viincenttt committed Mar 24, 2024
1 parent d20e223 commit ea1a457
Show file tree
Hide file tree
Showing 74 changed files with 314 additions and 301 deletions.
4 changes: 2 additions & 2 deletions src/Mollie.Api/Client/BaseMollieClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ protected async Task<T> GetAsync<T>(UrlObjectLink<T> urlObject) {
return await this.GetAsync<T>(urlObject.Href).ConfigureAwait(false);
}

protected async Task<T> PostAsync<T>(string relativeUri, object data) {
protected async Task<T> PostAsync<T>(string relativeUri, object? data) {
return await this.SendHttpRequest<T>(HttpMethod.Post, relativeUri, data).ConfigureAwait(false);
}

protected async Task<T> PatchAsync<T>(string relativeUri, object data) {
protected async Task<T> PatchAsync<T>(string relativeUri, object? data) {
return await this.SendHttpRequest<T>(new HttpMethod("PATCH"), relativeUri, data).ConfigureAwait(false);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Mollie.Api.Models.Balance.Response.BalanceReport;
using Mollie.Api.Models.Balance.Response.BalanceReport.Specific.StatusBalance;
using Mollie.Api.Models.Balance.Response.BalanceReport.Specific.TransactionCategories;
Expand All @@ -7,11 +8,11 @@ public class BalanceReportResponseFactory {
public BalanceReportResponse Create(string reportGrouping) {
switch (reportGrouping) {
case ReportGrouping.StatusBalances:
return new StatusBalanceReportResponse();
return Activator.CreateInstance<StatusBalanceReportResponse>();
case ReportGrouping.TransactionCategories:
return new TransactionCategoriesReportResponse();
return Activator.CreateInstance<TransactionCategoriesReportResponse>();
default:
return new BalanceReportResponse();
return Activator.CreateInstance<BalanceReportResponse>();
}
}
}
Expand Down
17 changes: 9 additions & 8 deletions src/Mollie.Api/Framework/Factories/BalanceTransactionFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Mollie.Api.Models.Balance.Response.BalanceTransaction;
using System;
using Mollie.Api.Models.Balance.Response.BalanceTransaction;
using Mollie.Api.Models.Balance.Response.BalanceTransaction.Specific;

namespace Mollie.Api.Framework.Factories {
Expand All @@ -11,24 +12,24 @@ public BalanceTransaction Create(string type) {
case BalanceTransactionContextType.ChargebackReversal:
case BalanceTransactionContextType.ApplicationFee:
case BalanceTransactionContextType.SplitPayment:
return new PaymentBalanceTransaction();
return Activator.CreateInstance<PaymentBalanceTransaction>();
case BalanceTransactionContextType.Capture:
return new CaptureBalanceTransaction();
return Activator.CreateInstance<CaptureBalanceTransaction>();
case BalanceTransactionContextType.Refund:
case BalanceTransactionContextType.ReturnedRefund:
case BalanceTransactionContextType.PlatformPaymentRefund:
return new RefundBalanceTransaction();
return Activator.CreateInstance<RefundBalanceTransaction>();
case BalanceTransactionContextType.Chargeback:
case BalanceTransactionContextType.PlatformPaymentChargeback:
return new ChargebackBalanceTransaction();
return Activator.CreateInstance<ChargebackBalanceTransaction>();
case BalanceTransactionContextType.OutgoingTransfer:
case BalanceTransactionContextType.CanceledOutgoingTransfer:
case BalanceTransactionContextType.ReturnedTransfer:
return new SettlementBalanceTransaction();
return Activator.CreateInstance<SettlementBalanceTransaction>();
case BalanceTransactionContextType.InvoiceCompensation:
return new InvoiceBalanceTransaction();
return Activator.CreateInstance<InvoiceBalanceTransaction>();
default:
return new BalanceTransaction();
return Activator.CreateInstance<BalanceTransaction>();
}
}
}
Expand Down
41 changes: 23 additions & 18 deletions src/Mollie.Api/Framework/Factories/PaymentResponseFactory.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,48 @@
using Mollie.Api.Models.Payment;
using System;
using Mollie.Api.Models.Payment;
using Mollie.Api.Models.Payment.Response;
using Mollie.Api.Models.Payment.Response.Specific;

namespace Mollie.Api.Framework.Factories {
public class PaymentResponseFactory {
public PaymentResponse Create(string paymentMethod) {
public PaymentResponse Create(string? paymentMethod) {
if (string.IsNullOrEmpty(paymentMethod)) {
return Activator.CreateInstance<PaymentResponse>();
}

switch (paymentMethod) {
case PaymentMethod.BankTransfer:
return new BankTransferPaymentResponse();
return Activator.CreateInstance<BankTransferPaymentResponse>();
case PaymentMethod.CreditCard:
return new CreditCardPaymentResponse();
return Activator.CreateInstance<CreditCardPaymentResponse>();
case PaymentMethod.Ideal:
return new IdealPaymentResponse();
return Activator.CreateInstance<IdealPaymentResponse>();
case PaymentMethod.Giropay:
return new GiropayPaymentResponse();
return Activator.CreateInstance<GiropayPaymentResponse>();
case PaymentMethod.Eps:
return new EpsPaymentResponse();
return Activator.CreateInstance<EpsPaymentResponse>();
case PaymentMethod.Bancontact:
return new BancontactPaymentResponse();
return Activator.CreateInstance<BancontactPaymentResponse>();
case PaymentMethod.PayPal:
return new PayPalPaymentResponse();
return Activator.CreateInstance<PayPalPaymentResponse>();
case PaymentMethod.PaySafeCard:
return new PaySafeCardPaymentResponse();
return Activator.CreateInstance<PaySafeCardPaymentResponse>();
case PaymentMethod.Sofort:
return new SofortPaymentResponse();
return Activator.CreateInstance<SofortPaymentResponse>();
case PaymentMethod.Belfius:
return new BelfiusPaymentResponse();
return Activator.CreateInstance<BelfiusPaymentResponse>();
case PaymentMethod.DirectDebit:
return new SepaDirectDebitResponse();
return Activator.CreateInstance<SepaDirectDebitResponse>();
case PaymentMethod.Kbc:
return new KbcPaymentResponse();
return Activator.CreateInstance<KbcPaymentResponse>();
case PaymentMethod.GiftCard:
return new GiftcardPaymentResponse();
return Activator.CreateInstance<GiftcardPaymentResponse>();
case PaymentMethod.IngHomePay:
return new IngHomePayPaymentResponse();
return Activator.CreateInstance<IngHomePayPaymentResponse>();
case PaymentMethod.PointOfSale:
return new PointOfSalePaymentResponse();
return Activator.CreateInstance<PointOfSalePaymentResponse>();
default:
return new PaymentResponse();
return Activator.CreateInstance<PaymentResponse>();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Mollie.Api/JsonConverters/PaymentResponseConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public PaymentResponseConverter(PaymentResponseFactory paymentResponseFactory) {
}

protected override PaymentResponse Create(Type objectType, JObject jObject) {
string paymentMethod = this.GetPaymentMethod(jObject);
string? paymentMethod = GetPaymentMethod(jObject);

return this._paymentResponseFactory.Create(paymentMethod);
}

private string GetPaymentMethod(JObject jObject) {
private string? GetPaymentMethod(JObject jObject) {
if (this.FieldExists("method", jObject)) {
string paymentMethodValue = (string) jObject["method"];
string paymentMethodValue = (string) jObject["method"]!;
if (!string.IsNullOrEmpty(paymentMethodValue)) {
return paymentMethodValue;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Mollie.Api/Models/Amount.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;

namespace Mollie.Api.Models {
public class Amount {
Expand All @@ -20,6 +21,7 @@ public class Amount {
/// </summary>
public string Value { get; set; }

[JsonConstructor]
public Amount(string currency, string value) {
this.Currency = currency;
this.Value = value;
Expand All @@ -35,8 +37,6 @@ public Amount(string currency, decimal value) {
this.Value = ConvertDecimalAmountToStringAmount(currency, value);
}

public Amount() { }

/// <summary>
/// Implicit cast operator from Amount to decimal.
/// </summary>
Expand All @@ -54,20 +54,20 @@ private static string ConvertDecimalAmountToStringAmount(string currency, decima
}

public override string ToString() {
return $"{this.Value} {this.Currency}";
return $"{Value} {Currency}";
}

public override bool Equals(object obj) {
public override bool Equals(object? obj) {
if (obj is Amount amount) {
return this.Currency == amount.Currency && this.Value == amount.Value;
return Currency == amount.Currency && Value == amount.Value;
}

return false;
}

public override int GetHashCode() {
unchecked {
return ((Currency != null ? Currency.GetHashCode() : 0) * 397) ^ (Value != null ? Value.GetHashCode() : 0);
return (Currency.GetHashCode() * 397) ^ Value.GetHashCode();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class BalanceReportResponse : IResponseObject {
/// <summary>
/// Indicates the response contains a balance report object. Will always contain balance-report for this endpoint.
/// </summary>
public string Resource { get; set; }
public required string Resource { get; init; }

/// <summary>
/// The ID of a Balance this report is generated for.
Expand Down
4 changes: 2 additions & 2 deletions src/Mollie.Api/Models/Balance/Response/BalanceResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public class BalanceResponse : IResponseObject {
/// <summary>
/// Indicates the response contains a balance object. Will always contain balance for this endpoint.
/// </summary>
public string Resource { get; set; }
public required string Resource { get; init; }

/// <summary>
/// The identifier uniquely referring to this balance. Mollie assigns this identifier at balance creation time. For example bal_gVMhHKqSSRYJyPsuoPNFH.
/// </summary>
public string Id { get; set; }
public required string Id { get; init; }

/// <summary>
/// The balance’s date and time of creation, in ISO 8601 format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ public class BalanceTransaction {
/// Indicates the response contains a balance transaction object. Will always contain balance_transaction
/// for this endpoint.
/// </summary>
public string Resource { get; set; }
public required string Resource { get; init; }

/// <summary>
/// The identifier uniquely referring to this balance transaction. Mollie assigns this identifier at
/// transaction creation time. For example baltr_QM24QwzUWR4ev4Xfgyt29d.
/// </summary>
public string Id { get; set; }
public required string Id { get; init; }

/// <summary>
/// The type of movement, for example payment or refund. See Mollie docs for a full list of values
Expand Down
4 changes: 2 additions & 2 deletions src/Mollie.Api/Models/Capture/Response/CaptureResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ public class CaptureResponse : IResponseObject {
/// <summary>
/// Indicates the response contains a capture object. Will always contain capture for this endpoint.
/// </summary>
public string Resource { get; set; }
public required string Resource { get; init; }

/// <summary>
/// The capture’s unique identifier, for example cpt_4qqhO89gsT.
/// </summary>
public string Id { get; set; }
public required string Id { get; init; }

/// <summary>
/// The mode used to create this capture.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace Mollie.Api.Models.ClientLink.Response
{
public class ClientLinkResponse
{
public string Id { get; set; }
public required string Id { get; init; }

public string Resource { get; set; }
public required string Resource { get; init; }

[JsonProperty("_links")]
public ClientLinkResponseLinks Links { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions src/Mollie.Api/Models/Customer/CustomerResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ public class CustomerResponse : IResponseObject {
/// <summary>
/// Indicates the response contains a customer object. Will always contain customer for this endpoint.
/// </summary>
public string Resource { get; set; }
public required string Resource { get; init; }

/// <summary>
/// The customer's unique identifier, for example cst_4pmbK7CqtT.
/// Store this identifier for later recurring payments.
/// </summary>
public string Id { get; set; }
public required string Id { get; init; }

/// <summary>
/// The mode used to create this payment. Mode determines whether a payment is real or a test payment.
Expand Down Expand Up @@ -63,8 +63,8 @@ public class CustomerResponse : IResponseObject {
[JsonProperty("_links")]
public CustomerResponseLinks Links { get; set; }

public T GetMetadata<T>(JsonSerializerSettings jsonSerializerSettings = null) {
return JsonConvert.DeserializeObject<T>(this.Metadata, jsonSerializerSettings);
public T? GetMetadata<T>(JsonSerializerSettings? jsonSerializerSettings = null) {
return JsonConvert.DeserializeObject<T>(Metadata, jsonSerializerSettings);
}
}
}
2 changes: 1 addition & 1 deletion src/Mollie.Api/Models/Invoice/InvoiceResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class InvoiceResponse : IResponseObject {
/// <summary>
/// Indicates the response contains an invoice object. Will always contain invoice for this endpoint.
/// </summary>
public string Resource { get; set; }
public required string Resource { get; init; }

/// <summary>
/// The invoice's unique identifier, for example inv_FrvewDA3Pr.
Expand Down
4 changes: 2 additions & 2 deletions src/Mollie.Api/Models/Issuer/IssuerResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ public class IssuerResponse : IResponseObject {
/// <summary>
/// Contains "issuer"
/// </summary>
public string Resource { get; set; }
public required string Resource { get; init; }

/// <summary>
/// The issuer's unique identifier, for example ideal_ABNANL2A. When creating a payment, specify this ID as the issuer
/// parameter to forward
/// the consumer to their banking environment directly.
/// </summary>
public string Id { get; set; }
public required string Id { get; init; }

/// <summary>
/// The issuer's full name, for example 'ABN AMRO'.
Expand Down
4 changes: 2 additions & 2 deletions src/Mollie.Api/Models/Mandate/MandateResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public class MandateResponse : IResponseObject {
/// <summary>
/// Indicates the response contains a mandate object. Will always contain mandate for this endpoint.
/// </summary>
public string Resource { get; set; }
public required string Resource { get; init; }

/// <summary>
/// Unique identifier of you mandate.
/// </summary>
public string Id { get; set; }
public required string Id { get; init; }

/// <summary>
/// Current status of mandate - See the Mollie.Api.Models.Mandate.MandateStatus class for a full
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class OnboardingStatusResponse {
/// <summary>
/// Indicates the response contains an onboarding object. Will always contain onboarding for this endpoint.
/// </summary>
public string Resource { get; set; }
public required string Resource { get; init; }

/// <summary>
/// The name of the organization.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace Mollie.Api.Models.Order.Request.ManageOrderLines {
public class ManageOrderLinesUpdateOperationData : OrderLineUpdateRequest {
public string Id { get; set; }
public required string Id { get; init; }
}
}
2 changes: 1 addition & 1 deletion src/Mollie.Api/Models/Order/Request/OrderLineDetails.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Mollie.Api.Models.Order {
public class OrderLineDetails {
public string Id { get; set; }
public required string Id { get; init; }
public int? Quantity { get; set; }
public Amount Amount { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class OrderLineUpdateRequest {
/// </summary>
public bool? Testmode { get; set; }

public void SetMetadata(object metadataObj, JsonSerializerSettings jsonSerializerSettings = null) {
public void SetMetadata(object metadataObj, JsonSerializerSettings? jsonSerializerSettings = null) {
this.Metadata = JsonConvert.SerializeObject(metadataObj, jsonSerializerSettings);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mollie.Api/Models/Order/Request/OrderRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public string Method {
/// </summary>
public bool? Testmode { get; set; }

public void SetMetadata(object metadataObj, JsonSerializerSettings jsonSerializerSettings = null) {
public void SetMetadata(object metadataObj, JsonSerializerSettings? jsonSerializerSettings = null) {
this.Metadata = JsonConvert.SerializeObject(metadataObj, jsonSerializerSettings);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mollie.Api/Models/Order/Response/OrderLineResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class OrderLineResponse {
/// <summary>
/// The order line’s unique identifier, for example odl_dgtxyl.
/// </summary>
public string Id { get; set; }
public required string Id { get; init; }

/// <summary>
/// The ID of the order the line belongs too, for example ord_kEn1PlbGa.
Expand Down
Loading

0 comments on commit ea1a457

Please sign in to comment.