Skip to content

Commit

Permalink
feat: add apple pay transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
ehrdi committed Aug 23, 2024
1 parent 06cbdf3 commit 6ad2ee8
Show file tree
Hide file tree
Showing 13 changed files with 897 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ApplePaymentDataTokenInformation
/// <value>Version information about the payment token. Currently only EC_v1 for ECC-encrypted data is supported.</value>
[DataMember(Name = "version", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "version")]
public string? Version { get; set; }
public ApplePaymentTokenVersion? Version { get; set; }

/// <summary>
/// Detached PKCS #7 signature, Base64 encoded as string. Signature of the payment and header data. The signature includes the signing certificate, its intermediate CA certificate, and information about the signing algorithm.
Expand Down
13 changes: 13 additions & 0 deletions lib/PCPServerSDKDotNet/Models/ApplePaymentTokenVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace PCPServerSDKDotNet.Models
{
[JsonConverter(typeof(StringEnumConverter))]
public enum ApplePaymentTokenVersion
{
[EnumMember(Value = "EC_V1")]
EcV1
}
}
27 changes: 27 additions & 0 deletions lib/PCPServerSDKDotNet/Models/Network.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace PCPServerSDKDotNet.Models
{
[JsonConverter(typeof(StringEnumConverter))]
public enum NetworkEnum
{
[JsonProperty("MASTERCARD")]
Mastercard,

[JsonProperty("VISA")]
Visa,

[JsonProperty("AMEX")]
Amex,

[JsonProperty("GIROCARD")]
Girocard,

[JsonProperty("DISCOVER")]
Discover,

[JsonProperty("JCB")]
Jcb
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class PaymentProduct320SpecificInput
/// </summary>
[DataMember(Name = "network", EmitDefaultValue = false)]
[JsonProperty(PropertyName = "network")]
public string? Network { get; set; }
public NetworkEnum? Network { get; set; }

/// <summary>
/// Gets or Sets Token
Expand Down
84 changes: 84 additions & 0 deletions lib/PCPServerSDKDotNet/Models/applepay/ApplePayPayment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System.Text.Json.Serialization;

namespace PCPServerSDKDotNet.Models.ApplePay
{
/// <summary>
/// The result of authorizing a payment request that contains payment information.
/// Data in PaymentToken is encrypted. Billing and shipping contact data are not encrypted.
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
public class ApplePayPayment
{
[JsonPropertyName("token")]
[JsonInclude]
public ApplePayPaymentToken Token { get; set; }

[JsonPropertyName("billingContact")]
[JsonInclude]
public ApplePayPaymentContact BillingContact { get; set; }

[JsonPropertyName("shippingContact")]
[JsonInclude]
public ApplePayPaymentContact ShippingContact { get; set; }

public ApplePayPayment() { }

public ApplePayPayment(ApplePayPaymentToken token, ApplePayPaymentContact billingContact, ApplePayPaymentContact shippingContact)
{
Token = token;
BillingContact = billingContact;
ShippingContact = shippingContact;
}

public ApplePayPayment WithToken(ApplePayPaymentToken token)
{
Token = token;
return this;
}

public ApplePayPayment WithBillingContact(ApplePayPaymentContact billingContact)
{
BillingContact = billingContact;
return this;
}

public ApplePayPayment WithShippingContact(ApplePayPaymentContact shippingContact)
{
ShippingContact = shippingContact;
return this;
}

public override bool Equals(object obj)

Check warning on line 51 in lib/PCPServerSDKDotNet/Models/applepay/ApplePayPayment.cs

View workflow job for this annotation

GitHub Actions / test

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).

Check warning on line 51 in lib/PCPServerSDKDotNet/Models/applepay/ApplePayPayment.cs

View workflow job for this annotation

GitHub Actions / test

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).
{
return obj is ApplePayPayment payment &&
EqualityComparer<ApplePayPaymentToken>.Default.Equals(Token, payment.Token) &&
EqualityComparer<ApplePayPaymentContact>.Default.Equals(BillingContact, payment.BillingContact) &&
EqualityComparer<ApplePayPaymentContact>.Default.Equals(ShippingContact, payment.ShippingContact);
}

public override int GetHashCode()
{
return HashCode.Combine(Token, BillingContact, ShippingContact);
}

public override string ToString()
{
var sb = new System.Text.StringBuilder();
sb.Append("class Payment {\n");
sb.Append(" token: ").Append(ToIndentedString(Token)).Append("\n");
sb.Append(" billingContact: ").Append(ToIndentedString(BillingContact)).Append("\n");
sb.Append(" shippingContact: ").Append(ToIndentedString(ShippingContact)).Append("\n");
sb.Append("}");
return sb.ToString();
}

private string ToIndentedString(object obj)
{
if (obj == null)
{
return "null";
}
return obj.ToString().Replace("\n", "\n ");
}
}
}
208 changes: 208 additions & 0 deletions lib/PCPServerSDKDotNet/Models/applepay/ApplePayPaymentContact.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
using Newtonsoft.Json;

namespace PCPServerSDKDotNet.Models.ApplePay
{
/// <summary>
/// The result of authorizing a payment request that contains payment information.
/// Data in PaymentToken is encrypted. Billing and shipping contact data are not encrypted.
/// </summary>
public class ApplePayPaymentContact : IEquatable<ApplePayPaymentContact>
{
[JsonProperty("phoneNumber")]
public string PhoneNumber { get; set; }

[JsonProperty("emailAddress")]
public string EmailAddress { get; set; }

[JsonProperty("givenName")]
public string GivenName { get; set; }

[JsonProperty("familyName")]
public string FamilyName { get; set; }

[JsonProperty("phoneticGivenName")]
public string PhoneticGivenName { get; set; }

[JsonProperty("phoneticFamilyName")]
public string PhoneticFamilyName { get; set; }

[JsonProperty("addressLines")]
public List<string> AddressLines { get; set; }

[JsonProperty("locality")]
public string Locality { get; set; }

[JsonProperty("postalCode")]
public string PostalCode { get; set; }

[JsonProperty("administrativeArea")]
public string AdministrativeArea { get; set; }

[JsonProperty("subAdministrativeArea")]
public string SubAdministrativeArea { get; set; }

[JsonProperty("country")]
public string Country { get; set; }

[JsonProperty("countryCode")]
public string CountryCode { get; set; }

public ApplePayPaymentContact() { }

public ApplePayPaymentContact(string phoneNumber, string emailAddress, string givenName, string familyName,
string phoneticGivenName, string phoneticFamilyName, List<string> addressLines,
string locality, string postalCode, string administrativeArea,
string subAdministrativeArea, string country, string countryCode)
{
PhoneNumber = phoneNumber;
EmailAddress = emailAddress;
GivenName = givenName;
FamilyName = familyName;
PhoneticGivenName = phoneticGivenName;
PhoneticFamilyName = phoneticFamilyName;
AddressLines = addressLines;
Locality = locality;
PostalCode = postalCode;
AdministrativeArea = administrativeArea;
SubAdministrativeArea = subAdministrativeArea;
Country = country;
CountryCode = countryCode;
}

public ApplePayPaymentContact WithPhoneNumber(string phoneNumber)
{
PhoneNumber = phoneNumber;
return this;
}

public ApplePayPaymentContact WithEmailAddress(string emailAddress)
{
EmailAddress = emailAddress;
return this;
}

public ApplePayPaymentContact WithGivenName(string givenName)
{
GivenName = givenName;
return this;
}

public ApplePayPaymentContact WithFamilyName(string familyName)
{
FamilyName = familyName;
return this;
}

public ApplePayPaymentContact WithPhoneticGivenName(string phoneticGivenName)
{
PhoneticGivenName = phoneticGivenName;
return this;
}

public ApplePayPaymentContact WithPhoneticFamilyName(string phoneticFamilyName)
{
PhoneticFamilyName = phoneticFamilyName;
return this;
}

public ApplePayPaymentContact WithAddressLines(List<string> addressLines)
{
AddressLines = addressLines;
return this;
}

public ApplePayPaymentContact WithLocality(string locality)
{
Locality = locality;
return this;
}

public ApplePayPaymentContact WithPostalCode(string postalCode)
{
PostalCode = postalCode;
return this;
}

public ApplePayPaymentContact WithAdministrativeArea(string administrativeArea)
{
AdministrativeArea = administrativeArea;
return this;
}

public ApplePayPaymentContact WithSubAdministrativeArea(string subAdministrativeArea)
{
SubAdministrativeArea = subAdministrativeArea;
return this;
}

public ApplePayPaymentContact WithCountry(string country)
{
Country = country;
return this;
}

public ApplePayPaymentContact WithCountryCode(string countryCode)
{
CountryCode = countryCode;
return this;
}

public override bool Equals(object obj)

Check warning on line 150 in lib/PCPServerSDKDotNet/Models/applepay/ApplePayPaymentContact.cs

View workflow job for this annotation

GitHub Actions / test

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).

Check warning on line 150 in lib/PCPServerSDKDotNet/Models/applepay/ApplePayPaymentContact.cs

View workflow job for this annotation

GitHub Actions / test

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).
{
return Equals(obj as ApplePayPaymentContact);
}

public bool Equals(ApplePayPaymentContact other)

Check warning on line 155 in lib/PCPServerSDKDotNet/Models/applepay/ApplePayPaymentContact.cs

View workflow job for this annotation

GitHub Actions / test

Nullability of reference types in type of parameter 'other' of 'bool ApplePayPaymentContact.Equals(ApplePayPaymentContact other)' doesn't match implicitly implemented member 'bool IEquatable<ApplePayPaymentContact>.Equals(ApplePayPaymentContact? other)' (possibly because of nullability attributes).

Check warning on line 155 in lib/PCPServerSDKDotNet/Models/applepay/ApplePayPaymentContact.cs

View workflow job for this annotation

GitHub Actions / test

Nullability of reference types in type of parameter 'other' of 'bool ApplePayPaymentContact.Equals(ApplePayPaymentContact other)' doesn't match implicitly implemented member 'bool IEquatable<ApplePayPaymentContact>.Equals(ApplePayPaymentContact? other)' (possibly because of nullability attributes).
{
return other != null &&
PhoneNumber == other.PhoneNumber &&
EmailAddress == other.EmailAddress &&
GivenName == other.GivenName &&
FamilyName == other.FamilyName &&
PhoneticGivenName == other.PhoneticGivenName &&
PhoneticFamilyName == other.PhoneticFamilyName &&
EqualityComparer<List<string>>.Default.Equals(AddressLines, other.AddressLines) &&
Locality == other.Locality &&
PostalCode == other.PostalCode &&
AdministrativeArea == other.AdministrativeArea &&
SubAdministrativeArea == other.SubAdministrativeArea &&
Country == other.Country &&
CountryCode == other.CountryCode;
}

public override int GetHashCode()
{
int hash = HashCode.Combine(PhoneNumber, EmailAddress, GivenName, FamilyName, PhoneticGivenName, PhoneticFamilyName, AddressLines, Locality);
hash = HashCode.Combine(hash, PostalCode, AdministrativeArea, SubAdministrativeArea, Country, CountryCode);
return hash;
}

public override string ToString()
{
return $"class ApplePayPaymentContact {{\n" +
$" phoneNumber: {ToIndentedString(PhoneNumber)},\n" +
$" emailAddress: {ToIndentedString(EmailAddress)},\n" +
$" givenName: {ToIndentedString(GivenName)},\n" +
$" familyName: {ToIndentedString(FamilyName)},\n" +
$" phoneticGivenName: {ToIndentedString(PhoneticGivenName)},\n" +
$" phoneticFamilyName: {ToIndentedString(PhoneticFamilyName)},\n" +
$" addressLines: {ToIndentedString(AddressLines)},\n" +
$" locality: {ToIndentedString(Locality)},\n" +
$" postalCode: {ToIndentedString(PostalCode)},\n" +
$" administrativeArea: {ToIndentedString(AdministrativeArea)},\n" +
$" subAdministrativeArea: {ToIndentedString(SubAdministrativeArea)},\n" +
$" country: {ToIndentedString(Country)},\n" +
$" countryCode: {ToIndentedString(CountryCode)}\n" +
$"}}";
}

private string ToIndentedString(object o)
{
if (o == null)
{
return "null";
}
return o.ToString().Replace("\n", "\n ");
}
}
}
Loading

0 comments on commit 6ad2ee8

Please sign in to comment.