Skip to content

Commit

Permalink
Refactor AddressDto to handle non-nullable address (#642)
Browse files Browse the repository at this point in the history
This commit modifies the handling of address in AddressDto, specifically, the constructor now no longer accepts a nullable Address, enforcing that an Address must be provided. For classes employing AddressDto - "PayerRequestDto" and "RiskIndicatorRequestDto" - modifications were made to handle potential null Addresses, checking for null before initializing a new AddressDto.
  • Loading branch information
zunkas authored Jul 22, 2024
1 parent c0822e4 commit 1c3aebd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
22 changes: 11 additions & 11 deletions src/SwedbankPay.Sdk.Infrastructure/AddressDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ namespace SwedbankPay.Sdk.Infrastructure;

internal record AddressDto
{
public AddressDto(Sdk.PaymentOrder.Address? address)
public AddressDto(Sdk.PaymentOrder.Address address)
{
Name = address?.Name;
FirstName = address?.FirstName;
LastName = address?.LastName;
Email = address?.Email?.ToString();
Msisdn = address?.Msisdn?.ToString();
StreetAddress = address?.StreetAddress;
CoAddress = address?.CoAddress;
City = address?.City;
ZipCode = address?.ZipCode;
CountryCode = address?.CountryCode?.ToString();
Name = address.Name;
FirstName = address.FirstName;
LastName = address.LastName;
Email = address.Email?.ToString();
Msisdn = address.Msisdn?.ToString();
StreetAddress = address.StreetAddress;
CoAddress = address.CoAddress;
City = address.City;
ZipCode = address.ZipCode;
CountryCode = address.CountryCode?.ToString();
}

public string? Name { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public PayerRequestDto(Sdk.PaymentOrder.Payer.Payer payer)
Msisdn = payer.Msisdn?.ToString();
WorkPhoneNumber = payer.WorkPhoneNumber?.ToString();
HomePhoneNumber = payer.HomePhoneNumber?.ToString();
BillingAddress = new AddressDto(payer.BillingAddress);
ShippingAddress = new AddressDto(payer.ShippingAddress);
BillingAddress = payer.BillingAddress != null ? new AddressDto(payer.BillingAddress) : null;
ShippingAddress = payer.ShippingAddress != null ? new AddressDto(payer.ShippingAddress) : null;
AccountInfo = new AccountInfoDto(payer.AccountInfo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public RiskIndicatorRequestDto(Sdk.PaymentOrder.RiskIndicator.RiskIndicator risk
ShipIndicator = riskIndicator.ShipIndicator?.Value;
GiftCardPurchase = riskIndicator.GiftCardPurchase;
ReOrderPurchaseIndicator = riskIndicator.ReOrderPurchaseIndicator?.Value;
PickUpAddress = new AddressDto(riskIndicator.PickUpAddress);
PickUpAddress = riskIndicator.PickUpAddress != null ? new AddressDto(riskIndicator.PickUpAddress) : null;
}

public string? DeliveryEmailAddress { get; }
Expand Down

0 comments on commit 1c3aebd

Please sign in to comment.