Skip to content

Commit

Permalink
Update payment response post and get with account holder and payment …
Browse files Browse the repository at this point in the history
…plan. Add payment context sources (#433)
  • Loading branch information
armando-rodriguez-cko authored Oct 18, 2024
1 parent da32d63 commit 23b08a2
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 39 deletions.
3 changes: 2 additions & 1 deletion src/CheckoutSdk/Common/PaymentSourceType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public enum PaymentSourceType
[EnumMember(Value = "trustly")] Trustly,
[EnumMember(Value = "cvconnect")] Cvconnect,
[EnumMember(Value = "sepa")] Sepa,
[EnumMember(Value = "sequra")] Sequra
[EnumMember(Value = "sequra")] Sequra,
[EnumMember(Value = "tabby")] Tabby
}
}
19 changes: 19 additions & 0 deletions src/CheckoutSdk/Payments/AccountUpdateStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Runtime.Serialization;

namespace Checkout.Payments
{
public enum AccountUpdateStatus
{
[EnumMember(Value = "card_updated")]
CardUpdated,

[EnumMember(Value = "card_expiry_updated")]
CardExpiryUpdated,

[EnumMember(Value = "card_closed")]
CardClosed,

[EnumMember(Value = "contact_cardholder")]
ContactCardholder
}
}
13 changes: 13 additions & 0 deletions src/CheckoutSdk/Payments/AmountVariabilityType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Runtime.Serialization;

namespace Checkout.Payments
{
public enum AmountVariabilityType
{
[EnumMember(Value = "Fixed")]
Fixed,

[EnumMember(Value = "Variable")]
Variable
}
}
24 changes: 24 additions & 0 deletions src/CheckoutSdk/Payments/PaymentPlan.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;

namespace Checkout.Payments
{
public class PaymentPlan
{
// Recurring
public AmountVariabilityType? AmountVariability { get; set; }

// Installment
public bool? Financing { get; set; }

public string Amount { get; set; }

// Common properties
public int? DaysBetweenPayments { get; set; }

public int? TotalNumberOfPayments { get; set; }

public int? CurrentPaymentNumber { get; set; }

public DateTime Expiry { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Checkout.Common;

namespace Checkout.Payments.Request.Source.Contexts
{
public class PaymentContextsStcpaySource : AbstractRequestSource
{
public PaymentContextsStcpaySource() : base(PaymentSourceType.Stcpay)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Checkout.Common;

namespace Checkout.Payments.Request.Source.Contexts
{
public class PaymentContextsTabbySource : AbstractRequestSource
{
public PaymentContextsTabbySource() : base(PaymentSourceType.Tabby)
{
}
}
}
32 changes: 19 additions & 13 deletions src/CheckoutSdk/Payments/Response/GetPaymentResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,42 @@ public class GetPaymentResponse : Resource

public DateTime? RequestedOn { get; set; }

public string ProcessedOn { get; set; }

[JsonConverter(typeof(PaymentResponseSourceTypeConverter))]
public IResponseSource Source { get; set; }

[JsonConverter(typeof(PaymentResponseDestinationTypeConverter))]
public IPaymentResponseDestination Destination { get; set; }

[JsonConverter(typeof(PaymentResponseSenderTypeConverter))]
public ISender Sender { get; set; }

public long? Amount { get; set; }

public long? AmountRequested { get; set; }


[JsonConverter(typeof(PaymentResponseSenderTypeConverter))]
public ISender Sender { get; set; }

public Currency? Currency { get; set; }

public PaymentType? PaymentType { get; set; }

public string Reference { get; set; }
public PaymentPlan PaymentPlan { get; set; }

public string Reference { get; set; }

public string Description { get; set; }

public bool? Approved { get; set; }

public DateTime? ExpiresOn { get; set; }

public PaymentStatus? Status { get; set; }

public PaymentResponseBalances Balances { get; set; }

[JsonProperty(PropertyName = "3ds")] public ThreeDsData ThreeDs { get; set; }


[JsonProperty(PropertyName = "3ds")]
public ThreeDsData ThreeDs { get; set; }

public RiskAssessment Risk { get; set; }

Expand Down Expand Up @@ -83,8 +89,8 @@ public class GetPaymentResponse : Resource

public bool? CkoNetworkTokenAvailable { get; set; }

public string ProcessedOn { get; set; }

public PaymentInstruction Instruction { get; set; }


}
}
52 changes: 28 additions & 24 deletions src/CheckoutSdk/Payments/Response/PaymentResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,51 @@ namespace Checkout.Payments.Response
{
public class PaymentResponse : Resource
{
public string Id { get; set; }

public string ActionId { get; set; }

public long? Amount { get; set; }

public bool? Approved { get; set; }

public string AuthCode { get; set; }

public string Id { get; set; }


public long? AmountRequested { get; set; }

public Currency? Currency { get; set; }

public CustomerResponse Customer { get; set; }

[JsonConverter(typeof(PaymentResponseSourceTypeConverter))]
public IResponseSource Source { get; set; }

public bool? Approved { get; set; }

public PaymentStatus? Status { get; set; }

[JsonProperty(PropertyName = "3ds")] public ThreeDsEnrollment ThreeDs { get; set; }

public string Reference { get; set; }

public string AuthCode { get; set; }

public string ResponseCode { get; set; }

public string ResponseSummary { get; set; }



public DateTime? ExpiresOn { get; set; }

[JsonProperty(PropertyName = "3ds")]
public ThreeDsEnrollment ThreeDs { get; set; }

public RiskAssessment Risk { get; set; }


[JsonConverter(typeof(PaymentResponseSourceTypeConverter))]
public IResponseSource Source { get; set; }

public CustomerResponse Customer { get; set; }

public PaymentResponseBalances Balances { get; set; }

public DateTime? ProcessedOn { get; set; }

public DateTime? ExpiresOn { get; set; }

public PaymentResponseBalances Balances { get; set; }
public string Reference { get; set; }

public PaymentProcessing Processing { get; set; }

public string Eci { get; set; }

public string SchemeId { get; set; }

public PaymentRetryResponse Retry { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public class CardResponseSource : AbstractResponseSource, IResponseSource

public string EncryptedCardNumber { get; set; }

public AccountUpdateStatus? AccountUpdateStatus { get; set; }

public AccountHolder AccountHolder { get; set; }

public new PaymentSourceType? Type()
{
return base.Type;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Checkout.Common;

namespace Checkout.Payments.Response.Source.Contexts
{
public class PaymentContextsStcpayResponseSource : AbstractPaymentContextsResponseSource, IResponseSource
{
public new PaymentSourceType? Type()
{
return base.Type;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Checkout.Common;

namespace Checkout.Payments.Response.Source.Contexts
{
public class PaymentContextsTabbyResponseSource : AbstractPaymentContextsResponseSource, IResponseSource
{
public new PaymentSourceType? Type()
{
return base.Type;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ private static IResponseSource CreateResponse(string sourceType)
{
return new PaymentContextsKlarnaResponseSource();
}

if (CheckoutUtils.GetEnumMemberValue(PaymentSourceType.Stcpay).Equals(sourceType))
{
return new PaymentContextsStcpayResponseSource();
}

if (CheckoutUtils.GetEnumMemberValue(PaymentSourceType.Tabby).Equals(sourceType))
{
return new PaymentContextsTabbyResponseSource();
}

return new AlternativePaymentSourceResponse();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Checkout.Common;
using Checkout.Payments.Request.Source.Apm;
using Checkout.Payments.Request.Source.Contexts;
using Checkout.Sessions;
using Shouldly;
Expand Down Expand Up @@ -73,6 +74,54 @@ await CheckErrorItem(
async () => await DefaultApi.PaymentContextsClient().RequestPaymentContexts(paymentContextsRequest),
"apm_service_unavailable");
}

[Fact(Skip = "unavailable")]
private async Task ShouldMakeAStcpayPaymentContextRequest()
{
var paymentContextsRequest = new PaymentContextsRequest
{
Source = new PaymentContextsStcpaySource(),
Amount = 1000,
Currency = Currency.EUR,
PaymentType = PaymentType.Regular,
Capture = true,
ProcessingChannelId = System.Environment.GetEnvironmentVariable("CHECKOUT_PROCESSING_CHANNEL_ID"),
SuccessUrl = "https://example.com/payments/success",
FailureUrl = "https://example.com/payments/fail",
Items = new List<PaymentContextsItems>
{
new PaymentContextsItems { Name = "mask", Quantity = 1, UnitPrice = 1000, TotalAmount = 1000 }
},
};

await CheckErrorItem(
async () => await DefaultApi.PaymentContextsClient().RequestPaymentContexts(paymentContextsRequest),
"apm_not_supported");
}

[Fact]
private async Task ShouldMakeATabbyPaymentContextRequest()
{
var paymentContextsRequest = new PaymentContextsRequest
{
Source = new PaymentContextsTabbySource(),
Amount = 1000,
Currency = Currency.EUR,
PaymentType = PaymentType.Regular,
Capture = true,
ProcessingChannelId = System.Environment.GetEnvironmentVariable("CHECKOUT_PROCESSING_CHANNEL_ID"),
SuccessUrl = "https://example.com/payments/success",
FailureUrl = "https://example.com/payments/fail",
Items = new List<PaymentContextsItems>
{
new PaymentContextsItems { Name = "mask", Quantity = 1, UnitPrice = 1000, TotalAmount = 1000 }
},
};

await CheckErrorItem(
async () => await DefaultApi.PaymentContextsClient().RequestPaymentContexts(paymentContextsRequest),
"currency_not_supported");
}

[Fact]
private async Task ShouldGetAPaymentContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPaymen
ApmCurrencyNotSupported);
}

[Fact]
[Fact(Skip = "unavailable")]
private async Task ShouldMakePlaidPayment()
{
var request = new PaymentRequest
Expand Down

0 comments on commit 23b08a2

Please sign in to comment.