Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update payment response. Payment context sources #433

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading