From dcdc1a5a1501ad30065179f8d4721f9cc0eb556a Mon Sep 17 00:00:00 2001 From: Armando Ibarra Date: Wed, 14 Sep 2022 08:42:23 -0500 Subject: [PATCH] Added support for Reports API --- src/CheckoutSdk/CheckoutApi.cs | 316 ++--- src/CheckoutSdk/ICheckoutApi.cs | 99 +- src/CheckoutSdk/OAuthScope.cs | 86 +- src/CheckoutSdk/Reports/AccountResponse.cs | 11 + src/CheckoutSdk/Reports/FileResponse.cs | 15 + src/CheckoutSdk/Reports/IReportsClient.cs | 12 + .../Reports/ReportDetailsResponse.cs | 30 + src/CheckoutSdk/Reports/ReportsClient.cs | 32 + src/CheckoutSdk/Reports/ReportsQuery.cs | 17 + src/CheckoutSdk/Reports/ReportsResponse.cs | 14 + .../RequestApmPaymentsIntegrationTest.cs | 1040 ++++++++--------- .../Reports/ReportsClientTest.cs | 62 + .../Reports/ReportsIntegrationTest.cs | 66 ++ test/CheckoutSdkTest/SandboxTestFixture.cs | 294 ++--- 14 files changed, 1183 insertions(+), 911 deletions(-) create mode 100644 src/CheckoutSdk/Reports/AccountResponse.cs create mode 100644 src/CheckoutSdk/Reports/FileResponse.cs create mode 100644 src/CheckoutSdk/Reports/IReportsClient.cs create mode 100644 src/CheckoutSdk/Reports/ReportDetailsResponse.cs create mode 100644 src/CheckoutSdk/Reports/ReportsClient.cs create mode 100644 src/CheckoutSdk/Reports/ReportsQuery.cs create mode 100644 src/CheckoutSdk/Reports/ReportsResponse.cs create mode 100644 test/CheckoutSdkTest/Reports/ReportsClientTest.cs create mode 100644 test/CheckoutSdkTest/Reports/ReportsIntegrationTest.cs diff --git a/src/CheckoutSdk/CheckoutApi.cs b/src/CheckoutSdk/CheckoutApi.cs index 05400e3c..b4a5cf9d 100644 --- a/src/CheckoutSdk/CheckoutApi.cs +++ b/src/CheckoutSdk/CheckoutApi.cs @@ -1,154 +1,162 @@ -using Checkout.Accounts; -using Checkout.Balances; -using Checkout.Customers; -using Checkout.Disputes; -using Checkout.Forex; -using Checkout.Instruments; -using Checkout.Payments; -using Checkout.Payments.Hosted; -using Checkout.Payments.Links; -using Checkout.Risk; -using Checkout.Sessions; -using Checkout.Tokens; -using Checkout.Transfers; -using Checkout.Workflows; - -namespace Checkout -{ - public class CheckoutApi : ICheckoutApi - { - private readonly ITokensClient _tokensClient; - private readonly ICustomersClient _customersClient; - private readonly IPaymentsClient _paymentsClient; - private readonly IInstrumentsClient _instrumentsClient; - private readonly IDisputesClient _disputesClient; - private readonly IRiskClient _riskClient; - private readonly IForexClient _forexClient; - private readonly IWorkflowsClient _workflowsClient; - private readonly ISessionsClient _sessionsClient; - private readonly IAccountsClient _accountsClient; - private readonly IPaymentLinksClient _paymentLinksClient; - private readonly IHostedPaymentsClient _hostedPaymentsClient; - private readonly IBalancesClient _balancesClient; - private readonly ITransfersClient _transfersClient; - - public CheckoutApi(CheckoutConfiguration configuration) - { - var baseApiClient = BaseApiClient(configuration); - _tokensClient = new TokensClient(baseApiClient, configuration); - _customersClient = new CustomersClient(baseApiClient, configuration); - _paymentsClient = new PaymentsClient(baseApiClient, configuration); - _instrumentsClient = new InstrumentsClient(baseApiClient, configuration); - _disputesClient = new DisputesClient(baseApiClient, configuration); - _riskClient = new RiskClient(baseApiClient, configuration); - _forexClient = new ForexClient(baseApiClient, configuration); - _workflowsClient = new WorkflowsClient(baseApiClient, configuration); - _sessionsClient = new SessionsClient(baseApiClient, configuration); - _accountsClient = new AccountsClient( - baseApiClient, - FilesApiClient(configuration), - configuration); - _paymentLinksClient = new PaymentLinksClient(baseApiClient, configuration); - _hostedPaymentsClient = new HostedPaymentsClient(baseApiClient, configuration); - _balancesClient = new BalancesClient(BalancesApiClient(configuration), - configuration); - _transfersClient = new TransfersClient(TransfersApiClient(configuration), - configuration); - } - - private static ApiClient BaseApiClient(CheckoutConfiguration configuration) - { - return new ApiClient(configuration.HttpClientFactory, - configuration.Environment.GetAttribute().ApiUri); - } - - private static ApiClient FilesApiClient(CheckoutConfiguration configuration) - { - return new ApiClient(configuration.HttpClientFactory, - configuration.Environment.GetAttribute().FilesApiUri); - } - - private static ApiClient TransfersApiClient(CheckoutConfiguration configuration) - { - return new ApiClient(configuration.HttpClientFactory, - configuration.Environment.GetAttribute().TransfersApiUri); - } - - private static ApiClient BalancesApiClient(CheckoutConfiguration configuration) - { - return new ApiClient(configuration.HttpClientFactory, - configuration.Environment.GetAttribute().BalancesApiUri); - } - - - public ITokensClient TokensClient() - { - return _tokensClient; - } - - public ICustomersClient CustomersClient() - { - return _customersClient; - } - - public IPaymentsClient PaymentsClient() - { - return _paymentsClient; - } - - public IInstrumentsClient InstrumentsClient() - { - return _instrumentsClient; - } - - public IDisputesClient DisputesClient() - { - return _disputesClient; - } - - public IRiskClient RiskClient() - { - return _riskClient; - } - - public IForexClient ForexClient() - { - return _forexClient; - } - - public IWorkflowsClient WorkflowsClient() - { - return _workflowsClient; - } - - public ISessionsClient SessionsClient() - { - return _sessionsClient; - } - - public IAccountsClient AccountsClient() - { - return _accountsClient; - } - - public IPaymentLinksClient PaymentLinksClient() - { - return _paymentLinksClient; - } - - public IHostedPaymentsClient HostedPaymentsClient() - { - return _hostedPaymentsClient; - } - - public IBalancesClient BalancesClient() - { - return _balancesClient; - } - - public ITransfersClient TransfersClient() - { - return _transfersClient; - } - } -} \ No newline at end of file +using Checkout.Accounts; +using Checkout.Balances; +using Checkout.Customers; +using Checkout.Disputes; +using Checkout.Forex; +using Checkout.Instruments; +using Checkout.Payments; +using Checkout.Payments.Hosted; +using Checkout.Payments.Links; +using Checkout.Reports; +using Checkout.Risk; +using Checkout.Sessions; +using Checkout.Tokens; +using Checkout.Transfers; +using Checkout.Workflows; + +namespace Checkout +{ + public class CheckoutApi : ICheckoutApi + { + private readonly ITokensClient _tokensClient; + private readonly ICustomersClient _customersClient; + private readonly IPaymentsClient _paymentsClient; + private readonly IInstrumentsClient _instrumentsClient; + private readonly IDisputesClient _disputesClient; + private readonly IRiskClient _riskClient; + private readonly IForexClient _forexClient; + private readonly IWorkflowsClient _workflowsClient; + private readonly ISessionsClient _sessionsClient; + private readonly IAccountsClient _accountsClient; + private readonly IPaymentLinksClient _paymentLinksClient; + private readonly IHostedPaymentsClient _hostedPaymentsClient; + private readonly IBalancesClient _balancesClient; + private readonly ITransfersClient _transfersClient; + private readonly IReportsClient _reportsClient; + + public CheckoutApi(CheckoutConfiguration configuration) + { + var baseApiClient = BaseApiClient(configuration); + _tokensClient = new TokensClient(baseApiClient, configuration); + _customersClient = new CustomersClient(baseApiClient, configuration); + _paymentsClient = new PaymentsClient(baseApiClient, configuration); + _instrumentsClient = new InstrumentsClient(baseApiClient, configuration); + _disputesClient = new DisputesClient(baseApiClient, configuration); + _riskClient = new RiskClient(baseApiClient, configuration); + _forexClient = new ForexClient(baseApiClient, configuration); + _workflowsClient = new WorkflowsClient(baseApiClient, configuration); + _sessionsClient = new SessionsClient(baseApiClient, configuration); + _accountsClient = new AccountsClient( + baseApiClient, + FilesApiClient(configuration), + configuration); + _paymentLinksClient = new PaymentLinksClient(baseApiClient, configuration); + _hostedPaymentsClient = new HostedPaymentsClient(baseApiClient, configuration); + _balancesClient = new BalancesClient(BalancesApiClient(configuration), + configuration); + _transfersClient = new TransfersClient(TransfersApiClient(configuration), + configuration); + _reportsClient = new ReportsClient(baseApiClient, configuration); + } + + private static ApiClient BaseApiClient(CheckoutConfiguration configuration) + { + return new ApiClient(configuration.HttpClientFactory, + configuration.Environment.GetAttribute().ApiUri); + } + + private static ApiClient FilesApiClient(CheckoutConfiguration configuration) + { + return new ApiClient(configuration.HttpClientFactory, + configuration.Environment.GetAttribute().FilesApiUri); + } + + private static ApiClient TransfersApiClient(CheckoutConfiguration configuration) + { + return new ApiClient(configuration.HttpClientFactory, + configuration.Environment.GetAttribute().TransfersApiUri); + } + + private static ApiClient BalancesApiClient(CheckoutConfiguration configuration) + { + return new ApiClient(configuration.HttpClientFactory, + configuration.Environment.GetAttribute().BalancesApiUri); + } + + + public ITokensClient TokensClient() + { + return _tokensClient; + } + + public ICustomersClient CustomersClient() + { + return _customersClient; + } + + public IPaymentsClient PaymentsClient() + { + return _paymentsClient; + } + + public IInstrumentsClient InstrumentsClient() + { + return _instrumentsClient; + } + + public IDisputesClient DisputesClient() + { + return _disputesClient; + } + + public IRiskClient RiskClient() + { + return _riskClient; + } + + public IForexClient ForexClient() + { + return _forexClient; + } + + public IWorkflowsClient WorkflowsClient() + { + return _workflowsClient; + } + + public ISessionsClient SessionsClient() + { + return _sessionsClient; + } + + public IAccountsClient AccountsClient() + { + return _accountsClient; + } + + public IPaymentLinksClient PaymentLinksClient() + { + return _paymentLinksClient; + } + + public IHostedPaymentsClient HostedPaymentsClient() + { + return _hostedPaymentsClient; + } + + public IBalancesClient BalancesClient() + { + return _balancesClient; + } + + public ITransfersClient TransfersClient() + { + return _transfersClient; + } + + public IReportsClient ReportsClient() + { + return _reportsClient; + } + } +} diff --git a/src/CheckoutSdk/ICheckoutApi.cs b/src/CheckoutSdk/ICheckoutApi.cs index 9529f73a..1f3b1c08 100644 --- a/src/CheckoutSdk/ICheckoutApi.cs +++ b/src/CheckoutSdk/ICheckoutApi.cs @@ -1,48 +1,51 @@ -using Checkout.Accounts; -using Checkout.Balances; -using Checkout.Customers; -using Checkout.Disputes; -using Checkout.Forex; -using Checkout.Instruments; -using Checkout.Payments; -using Checkout.Payments.Hosted; -using Checkout.Payments.Links; -using Checkout.Risk; -using Checkout.Sessions; -using Checkout.Tokens; -using Checkout.Transfers; -using Checkout.Workflows; - -namespace Checkout -{ - public interface ICheckoutApi : ICheckoutApiClient - { - ITokensClient TokensClient(); - - ICustomersClient CustomersClient(); - - IPaymentsClient PaymentsClient(); - - IInstrumentsClient InstrumentsClient(); - - IDisputesClient DisputesClient(); - - IRiskClient RiskClient(); - - IForexClient ForexClient(); - - IWorkflowsClient WorkflowsClient(); - - ISessionsClient SessionsClient(); - - IAccountsClient AccountsClient(); - - IPaymentLinksClient PaymentLinksClient(); - - IHostedPaymentsClient HostedPaymentsClient(); - - IBalancesClient BalancesClient(); - - ITransfersClient TransfersClient(); - } -} \ No newline at end of file +using Checkout.Accounts; +using Checkout.Balances; +using Checkout.Customers; +using Checkout.Disputes; +using Checkout.Forex; +using Checkout.Instruments; +using Checkout.Payments; +using Checkout.Payments.Hosted; +using Checkout.Payments.Links; +using Checkout.Reports; +using Checkout.Risk; +using Checkout.Sessions; +using Checkout.Tokens; +using Checkout.Transfers; +using Checkout.Workflows; + +namespace Checkout +{ + public interface ICheckoutApi : ICheckoutApiClient + { + ITokensClient TokensClient(); + + ICustomersClient CustomersClient(); + + IPaymentsClient PaymentsClient(); + + IInstrumentsClient InstrumentsClient(); + + IDisputesClient DisputesClient(); + + IRiskClient RiskClient(); + + IForexClient ForexClient(); + + IWorkflowsClient WorkflowsClient(); + + ISessionsClient SessionsClient(); + + IAccountsClient AccountsClient(); + + IPaymentLinksClient PaymentLinksClient(); + + IHostedPaymentsClient HostedPaymentsClient(); + + IBalancesClient BalancesClient(); + + ITransfersClient TransfersClient(); + + IReportsClient ReportsClient(); + } +} diff --git a/src/CheckoutSdk/OAuthScope.cs b/src/CheckoutSdk/OAuthScope.cs index c81a879b..5904e39d 100644 --- a/src/CheckoutSdk/OAuthScope.cs +++ b/src/CheckoutSdk/OAuthScope.cs @@ -1,42 +1,44 @@ -namespace Checkout -{ - public enum OAuthScope - { - [OAuthScope("vault")] Vault, - [OAuthScope("vault:instruments")] VaultInstruments, - [OAuthScope("vault:tokenization")] VaultTokenization, - [OAuthScope("vault:customers")] VaultCustomers, - [OAuthScope("gateway")] Gateway, - [OAuthScope("gateway:payment")] GatewayPayment, - [OAuthScope("gateway:payment-details")] GatewayPaymentDetails, - [OAuthScope("gateway:payment-authorizations")] GatewayPaymentAuthorization, - [OAuthScope("gateway:payment-voids")] GatewayPaymentVoids, - [OAuthScope("gateway:payment-captures")] GatewayPaymentCaptures, - [OAuthScope("gateway:payment-refunds")] GatewayPaymentRefunds, - [OAuthScope("fx")] Fx, - [OAuthScope("payouts:bank-details")] PayoutsBankDetails, - [OAuthScope("sessions:app")] SessionsApp, - [OAuthScope("sessions:browser")] SessionsBrowser, - [OAuthScope("disputes")] Disputes, - [OAuthScope("disputes:view")] DisputesView, - [OAuthScope("disputes:provide-evidence")] DisputesProvideEvidence, - [OAuthScope("disputes:accept")] DisputesAccept, - [OAuthScope("marketplace")] Marketplace, - [OAuthScope("accounts")] Accounts, - [OAuthScope("transfers")] Transfers, - [OAuthScope("transfers:create")] TransfersCreate, - [OAuthScope("transfers:view")] TransfersView, - [OAuthScope("flow")] Flow, - [OAuthScope("flow:workflows")] FlowWorkflows, - [OAuthScope("flow:events")] FlowEvents, - [OAuthScope("files")] Files, - [OAuthScope("files:retrieve")] FilesRetrieve, - [OAuthScope("files:upload")] FilesUpload, - [OAuthScope("files:download")] FilesDownload, - [OAuthScope("balances")] Balances, - [OAuthScope("balances:view")] BalancesView, - [OAuthScope("middleware")] Middleware, - [OAuthScope("middleware:merchants-secret")] MiddlewareMerchantsSecret, - [OAuthScope("middleware:merchants-public")] MiddlewareMerchantsPublic - } -} \ No newline at end of file +namespace Checkout +{ + public enum OAuthScope + { + [OAuthScope("vault")] Vault, + [OAuthScope("vault:instruments")] VaultInstruments, + [OAuthScope("vault:tokenization")] VaultTokenization, + [OAuthScope("vault:customers")] VaultCustomers, + [OAuthScope("gateway")] Gateway, + [OAuthScope("gateway:payment")] GatewayPayment, + [OAuthScope("gateway:payment-details")] GatewayPaymentDetails, + [OAuthScope("gateway:payment-authorizations")] GatewayPaymentAuthorization, + [OAuthScope("gateway:payment-voids")] GatewayPaymentVoids, + [OAuthScope("gateway:payment-captures")] GatewayPaymentCaptures, + [OAuthScope("gateway:payment-refunds")] GatewayPaymentRefunds, + [OAuthScope("fx")] Fx, + [OAuthScope("payouts:bank-details")] PayoutsBankDetails, + [OAuthScope("sessions:app")] SessionsApp, + [OAuthScope("sessions:browser")] SessionsBrowser, + [OAuthScope("disputes")] Disputes, + [OAuthScope("disputes:view")] DisputesView, + [OAuthScope("disputes:provide-evidence")] DisputesProvideEvidence, + [OAuthScope("disputes:accept")] DisputesAccept, + [OAuthScope("marketplace")] Marketplace, + [OAuthScope("accounts")] Accounts, + [OAuthScope("transfers")] Transfers, + [OAuthScope("transfers:create")] TransfersCreate, + [OAuthScope("transfers:view")] TransfersView, + [OAuthScope("flow")] Flow, + [OAuthScope("flow:workflows")] FlowWorkflows, + [OAuthScope("flow:events")] FlowEvents, + [OAuthScope("files")] Files, + [OAuthScope("files:retrieve")] FilesRetrieve, + [OAuthScope("files:upload")] FilesUpload, + [OAuthScope("files:download")] FilesDownload, + [OAuthScope("balances")] Balances, + [OAuthScope("balances:view")] BalancesView, + [OAuthScope("middleware")] Middleware, + [OAuthScope("middleware:merchants-secret")] MiddlewareMerchantsSecret, + [OAuthScope("middleware:merchants-public")] MiddlewareMerchantsPublic, + [OAuthScope("reporting")] Reporting, + [OAuthScope("reporting:view")] ReportingView + } +} diff --git a/src/CheckoutSdk/Reports/AccountResponse.cs b/src/CheckoutSdk/Reports/AccountResponse.cs new file mode 100644 index 00000000..4e2db44e --- /dev/null +++ b/src/CheckoutSdk/Reports/AccountResponse.cs @@ -0,0 +1,11 @@ +using Checkout.Common; + +namespace Checkout.Reports +{ + public class AccountResponse + { + public string ClientId { get; set; } + + public string EntityId { get; set; } + } +} diff --git a/src/CheckoutSdk/Reports/FileResponse.cs b/src/CheckoutSdk/Reports/FileResponse.cs new file mode 100644 index 00000000..c328b11f --- /dev/null +++ b/src/CheckoutSdk/Reports/FileResponse.cs @@ -0,0 +1,15 @@ +using Checkout.Common; +using Newtonsoft.Json; + +namespace Checkout.Reports +{ + public class FileResponse : Resource + { + public string Id { get; set; } + + [JsonProperty(PropertyName = "filename")] + public string FileName { get; set; } + + public string Format { get; set; } + } +} diff --git a/src/CheckoutSdk/Reports/IReportsClient.cs b/src/CheckoutSdk/Reports/IReportsClient.cs new file mode 100644 index 00000000..92232c8e --- /dev/null +++ b/src/CheckoutSdk/Reports/IReportsClient.cs @@ -0,0 +1,12 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace Checkout.Reports +{ + public interface IReportsClient + { + Task GetAllReports(ReportsQuery query, CancellationToken cancellationToken = default); + + Task GetReportDetails(string reportId, CancellationToken cancellationToken = default); + } +} diff --git a/src/CheckoutSdk/Reports/ReportDetailsResponse.cs b/src/CheckoutSdk/Reports/ReportDetailsResponse.cs new file mode 100644 index 00000000..8b0dc817 --- /dev/null +++ b/src/CheckoutSdk/Reports/ReportDetailsResponse.cs @@ -0,0 +1,30 @@ +using Checkout.Common; +using System; +using System.Collections.Generic; + +namespace Checkout.Reports +{ + public class ReportDetailsResponse : Resource + { + public string Id { get; set; } + + public string CreatedOn { get; set; } + + public string LastModifiedOn { get; set; } + + public string Type { get; set; } + + public string Description { get; set; } + + public AccountResponse Account { get; set; } + + public IList Tags { get; set; } + + public DateTime? From { get; set; } + + public DateTime? To { get; set; } + + public IList Files { get; set; } + + } +} diff --git a/src/CheckoutSdk/Reports/ReportsClient.cs b/src/CheckoutSdk/Reports/ReportsClient.cs new file mode 100644 index 00000000..17721415 --- /dev/null +++ b/src/CheckoutSdk/Reports/ReportsClient.cs @@ -0,0 +1,32 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace Checkout.Reports +{ + public class ReportsClient : AbstractClient, IReportsClient + { + private const string ReportsPath = "reports"; + + public ReportsClient(IApiClient apiClient, + CheckoutConfiguration configuration) : base(apiClient, configuration, SdkAuthorizationType.SecretKeyOrOAuth) + { + } + + public Task GetAllReports( + ReportsQuery query, + CancellationToken cancellationToken = default) + { + return ApiClient.Query(ReportsPath, SdkAuthorization(), query, cancellationToken); + } + + public Task GetReportDetails( + string reportId, + CancellationToken cancellationToken = default) + { + return ApiClient.Get( + BuildPath(ReportsPath, reportId), + SdkAuthorization(), + cancellationToken); + } + } +} diff --git a/src/CheckoutSdk/Reports/ReportsQuery.cs b/src/CheckoutSdk/Reports/ReportsQuery.cs new file mode 100644 index 00000000..6ae19386 --- /dev/null +++ b/src/CheckoutSdk/Reports/ReportsQuery.cs @@ -0,0 +1,17 @@ +using System; + +namespace Checkout.Reports +{ + public class ReportsQuery + { + public DateTime? CreatedAfter { get; set; } + + public DateTime? CreatedBefore { get; set; } + + public string EntityId { get; set; } + + public int? Limit { get; set; } + + public string PaginationToken { get; set; } + } +} diff --git a/src/CheckoutSdk/Reports/ReportsResponse.cs b/src/CheckoutSdk/Reports/ReportsResponse.cs new file mode 100644 index 00000000..06df7a9f --- /dev/null +++ b/src/CheckoutSdk/Reports/ReportsResponse.cs @@ -0,0 +1,14 @@ +using Checkout.Common; +using System.Collections.Generic; + +namespace Checkout.Reports +{ + public class ReportsResponse : Resource + { + public int? Count { get; set; } + + public int? Limit { get; set; } + + public IList Data { get; set; } + } +} diff --git a/test/CheckoutSdkTest/Payments/RequestApmPaymentsIntegrationTest.cs b/test/CheckoutSdkTest/Payments/RequestApmPaymentsIntegrationTest.cs index 66efff3f..55531b32 100644 --- a/test/CheckoutSdkTest/Payments/RequestApmPaymentsIntegrationTest.cs +++ b/test/CheckoutSdkTest/Payments/RequestApmPaymentsIntegrationTest.cs @@ -1,521 +1,521 @@ -using Checkout.Common; -using Checkout.Payments.Request; -using Checkout.Payments.Request.Source.Apm; -using Checkout.Payments.Response.Source; -using Shouldly; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Xunit; -using Product = Checkout.Payments.Request.Product; - -namespace Checkout.Payments -{ - public class RequestApmPaymentsIntegrationTest : AbstractPaymentsIntegrationTest - { - [Fact] - private async Task ShouldMakeAliPayPayment() - { - var source = RequestAlipayPlusSource.RequestAlipayPlusCnSource(); - source = RequestAlipayPlusSource.RequestAlipayPlusGCashSource(); - source = RequestAlipayPlusSource.RequestAlipayPlusHkSource(); - source = RequestAlipayPlusSource.RequestAlipayPlusDanaSource(); - source = RequestAlipayPlusSource.RequestAlipayPlusKakaoPaySource(); - source = RequestAlipayPlusSource.RequestAlipayPlusTrueMoneySource(); - source = RequestAlipayPlusSource.RequestAlipayPlusTngSource(); - source = RequestAlipayPlusSource.RequestAliPayPlusSource(); - - var request = new PaymentRequest - { - Source = source, - Amount = 10L, - Currency = Currency.EUR, - ProcessingChannelId = "pc_5jp2az55l3cuths25t5p3xhwru", - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure", - }; - - try - { - await DefaultApi.PaymentsClient().RequestPayment(request); - } - catch (Exception e) - { - e.ShouldBeAssignableTo(); - } - } - - [Fact] - private async Task ShouldMakeIdealPayment() - { - var idealSource = new RequestIdealSource { Bic = "INGBNL2A", Description = "ORD50234E89", Language = "nl" }; - - var paymentRequest = new PaymentRequest - { - Source = idealSource, - Currency = Currency.EUR, - Amount = 1000, - Capture = true, - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure" - }; - - var paymentResponse = await DefaultApi.PaymentsClient().RequestPayment(paymentRequest); - - paymentResponse.ShouldNotBeNull(); - paymentResponse.Status.ShouldNotBeNull(); - paymentResponse.ResponseSummary.ShouldNotBeNull(); - paymentResponse.Links.ShouldNotBeNull(); - - var payment = await DefaultApi.PaymentsClient().GetPaymentDetails(paymentResponse.Id); - - payment.ShouldNotBeNull(); - - payment.Status.ShouldNotBeNull(); - payment.Links.ShouldNotBeNull(); - - payment.Source.ShouldBeOfType(typeof(AlternativePaymentSourceResponse)); - var source = (AlternativePaymentSourceResponse)payment.Source; - source.Count.ShouldBePositive(); - source.Type().ShouldBe(PaymentSourceType.Ideal); - } - - [Fact] - private async Task ShouldMakeSofortPayment() - { - var sofortSource = new RequestSofortSource(); - - var paymentRequest = new PaymentRequest - { - Source = sofortSource, - Currency = Currency.EUR, - Amount = 100, - Capture = true, - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure" - }; - - var paymentResponse = await DefaultApi.PaymentsClient().RequestPayment(paymentRequest); - - paymentResponse.ShouldNotBeNull(); - paymentResponse.Status.ShouldBe(PaymentStatus.Pending); - paymentResponse.ResponseSummary.ShouldBeNull(); - paymentResponse.Links["self"].ShouldNotBeNull(); - paymentResponse.Links["redirect"].ShouldNotBeNull(); - - var payment = await DefaultApi.PaymentsClient().GetPaymentDetails(paymentResponse.Id); - - payment.ShouldNotBeNull(); - - payment.Status.ShouldBe(PaymentStatus.Pending); - payment.Links["self"].ShouldNotBeNull(); - - payment.Source.ShouldBeOfType(typeof(AlternativePaymentSourceResponse)); - var source = (AlternativePaymentSourceResponse)payment.Source; - source.Count.ShouldBePositive(); - source.Type().ShouldBe(PaymentSourceType.Sofort); - } - - [Fact(Skip = "Preview")] - private async Task ShouldMakeTamaraPayment() - { - ICheckoutApi previewApi = CheckoutSdk.Builder() - .OAuth() - .ClientCredentials( - System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_PREVIEW_OAUTH_CLIENT_ID"), - System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_PREVIEW_OAUTH_CLIENT_SECRET")) - .Environment(Environment.Sandbox) - .Build(); - - var tamaraSource = new RequestTamaraSource(); - tamaraSource.BillingAddress = new Address - { - AddressLine1 = "Cecilia Chapman", - AddressLine2 = "711-2880 Nulla St.", - City = "Mankato", - State = "Mississippi", - Zip = "96522", - Country = CountryCode.SA - }; - - var paymentRequest = new PaymentRequest - { - Source = tamaraSource, - Currency = Currency.SAR, - Amount = 10000, - Capture = true, - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure", - Reference = "ORD-5023-4E89", - Processing = new ProcessingSettings { TaxAmount = 500, ShippingAmount = 1000 }, - ProcessingChannelId = "pc_zs5fqhybzc2e3jmq3efvybybpq", - Customer = new CustomerRequest - { - Name = "Cecilia Chapman", - Email = "c.chapman@example.com", - Phone = new Phone { CountryCode = "+966", Number = "113 496 0000" } - }, - Items = new List - { - new Product - { - Name = "Item name", - Quantity = 3, - UnitPrice = 100, - TotalAmount = 100, - TaxAmount = 19, - DiscountAmount = 2, - Reference = "some description about item", - ImageUrl = "https://some_s3bucket.com", - Url = "https://some.website.com/item", - Sku = "123687000111" - } - } - }; - - var paymentResponse = await previewApi.PaymentsClient().RequestPayment(paymentRequest); - - paymentResponse.ShouldNotBeNull(); - paymentResponse.Id.ShouldNotBeNullOrEmpty(); - paymentResponse.Reference.ShouldNotBeNullOrEmpty(); - paymentResponse.Status.ShouldBe(PaymentStatus.Pending); - paymentResponse.Links.ShouldNotBeEmpty(); - paymentResponse.Customer.Id.ShouldNotBeNullOrEmpty(); - paymentResponse.Customer.Name.ShouldNotBeEmpty(); - paymentResponse.Customer.Email.ShouldNotBeEmpty(); - paymentResponse.Customer.Phone.ShouldNotBeNull(); - paymentResponse.Processing.PartnerPaymentId.ShouldNotBeNull(); - paymentResponse.Links.ShouldNotBeEmpty(); - } - - [Fact] - private async Task ShouldMakeAfterPayPayment() - { - var request = new PaymentRequest - { - Source = new RequestAfterPaySource { AccountHolder = new AccountHolder() }, - Amount = 10L, - Currency = Currency.EUR, - ProcessingChannelId = "pc_5jp2az55l3cuths25t5p3xhwru", - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure", - }; - - try - { - await DefaultApi.PaymentsClient().RequestPayment(request); - } - catch (Exception e) - { - e.ShouldBeAssignableTo(); - } - } - - [Fact] - private async Task ShouldMakeBenefitPayment() - { - var request = new PaymentRequest - { - Source = new RequestBenefitSource(), - Amount = 10L, - Currency = Currency.BHD, - Reference = "REFERENCE", - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure", - }; - - await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), - PayeeNotOnboarded); - } - - [Fact] - private async Task ShouldMakeQPayPayment() - { - var request = new PaymentRequest - { - Source = new RequestQPaySource - { - Quantity = 1, Description = "QPay Demo Payment", Language = "en", NationalId = "070AYY010BU234M" - }, - Amount = 10L, - Currency = Currency.QAR, - Reference = "REFERENCE", - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure", - }; - - await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), - PayeeNotOnboarded); - } - - [Fact] - private async Task ShouldMakeMbwayPayment() - { - var request = new PaymentRequest - { - Source = new RequestMbwaySource(), - Amount = 10L, - Currency = Currency.BHD, - Reference = "REFERENCE", - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure", - }; - - await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), - ApmServiceUnavailable); - } - - [Fact] - private async Task ShouldMakeEpsPayment() - { - var request = new PaymentRequest - { - Source = new RequestEpsSource { Purpose = "Mens black t-shirt L" }, - Amount = 10L, - Currency = Currency.EUR, - Reference = "REFERENCE", - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure", - }; - - await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), - PayeeNotOnboarded); - } - - [Fact] - private async Task ShouldMakeGiropayPayment() - { - var request = new PaymentRequest - { - Source = new RequestGiropaySource { Purpose = "CKO Giropay test", }, - Amount = 10L, - Currency = Currency.EUR, - Reference = "REFERENCE", - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure", - }; - - await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), - PayeeNotOnboarded); - } - - [Fact] - private async Task ShouldMakePrzelewy24Payment() - { - var request = new PaymentRequest - { - Source = new RequestP24Source - { - PaymentCountry = CountryCode.PL, - AccountHolderName = "Bruce Wayne", - AccountHolderEmail = "bruce@wayne-enterprises.com", - BillingDescriptor = "P24 Demo Payment" - }, - Currency = Currency.PLN, - Amount = 100, - Reference = Guid.NewGuid().ToString(), - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure" - }; - - await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), - PayeeNotOnboarded); - } - - [Fact] - private async Task ShouldMakeKnetPayment() - { - var request = new PaymentRequest - { - Source = new RequestKnetSource { Language = "en", }, - Currency = Currency.KWD, - Amount = 100, - Reference = Guid.NewGuid().ToString(), - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure" - }; - - await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), - PayeeNotOnboarded); - } - - [Fact] - private async Task ShouldMakeBancontactPayment() - { - var request = new PaymentRequest - { - Source = new RequestBancontactSource - { - PaymentCountry = CountryCode.BE, - AccountHolderName = "Bruce Wayne", - BillingDescriptor = "CKO Demo - bancontact", - }, - Currency = Currency.EUR, - Amount = 10, - Reference = Guid.NewGuid().ToString(), - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure" - }; - - await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), - PayeeNotOnboarded); - } - - [Fact] - private async Task ShouldMakeMultiBancoPayment() - { - var request = new PaymentRequest - { - Source = new RequestMultiBancoSource - { - PaymentCountry = CountryCode.PT, - AccountHolderName = "Bruce Wayne", - BillingDescriptor = "Multibanco Demo Payment" - }, - Currency = Currency.EUR, - Amount = 10, - Reference = Guid.NewGuid().ToString(), - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure" - }; - - await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), - PayeeNotOnboarded); - } - - [Fact] - private async Task ShouldMakePostFinancePayment() - { - var request = new PaymentRequest - { - Source = new RequestPostFinanceSource - { - PaymentCountry = CountryCode.CH, - AccountHolderName = "Bruce Wayne", - BillingDescriptor = "Multibanco Demo Payment" - }, - Currency = Currency.EUR, - Amount = 10, - Reference = Guid.NewGuid().ToString(), - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure" - }; - - await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), - PayeeNotOnboarded); - } - - [Fact] - private async Task ShouldMakeStcPayPayment() - { - var request = new PaymentRequest - { - Source = new RequestStcPaySource(), - Currency = Currency.SAR, - Amount = 10, - Reference = Guid.NewGuid().ToString(), - Customer = new PaymentCustomerRequest - { - Email = GenerateRandomEmail(), Name = "Louis Smith", Phone = GetPhone() - }, - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure" - }; - - await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), - "merchant_data_delegated_authentication_failed"); - } - - [Fact] - private async Task ShouldMakeAlmaPayment() - { - var request = new PaymentRequest - { - Source = new RequestAlmaSource { BillingAddress = GetAddress() }, - Currency = Currency.EUR, - Amount = 10, - Reference = Guid.NewGuid().ToString(), - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure" - }; - - await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), - PayeeNotOnboarded); - } - - [Fact] - private async Task ShouldMakeKlarnaPayment() - { - var request = new PaymentRequest - { - Source = new RequestKlarnaSource { AccountHolder = GetAccountHolder() }, - Currency = Currency.QAR, - Amount = 10, - Reference = Guid.NewGuid().ToString(), - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure" - }; - - await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), - ApmServiceUnavailable); - } - - [Fact] - private async Task ShouldMakePayPalPayment() - { - var request = new PaymentRequest - { - Source = new RequestPayPalSource - { - plan = new BillingPlan - { - Type = BillingPlanType.ChannelInitiatedBillingSingleAgreement, - SkipShippingAddress = true, - ImmutableShippingAddress = false - } - }, - Items = new List { new Product { Name = "Laptop", Quantity = 1, UnitPrice = 10, } }, - Currency = Currency.EUR, - Amount = 10, - Reference = Guid.NewGuid().ToString(), - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure" - }; - - await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), - PayeeNotOnboarded); - } - - [Fact] - private async Task ShouldMakeFawryPayment() - { - var request = new PaymentRequest - { - Source = new RequestFawrySource - { - Description = "Fawry Demo Payment", - CustomerMobile = "01058375055", - CustomerEmail = "bruce@wayne-enterprises.com", - Products = new FawryProduct[] - { - new FawryProduct - { - ProductId = "0123456789", - Quantity = 1, - Price = 10, - Description = "Fawry Demo Product" - } - } - }, - Currency = Currency.EGP, - Amount = 10, - Reference = Guid.NewGuid().ToString(), - SuccessUrl = "https://testing.checkout.com/sucess", - FailureUrl = "https://testing.checkout.com/failure" - }; - - await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), - PayeeNotOnboarded); - } - } +using Checkout.Common; +using Checkout.Payments.Request; +using Checkout.Payments.Request.Source.Apm; +using Checkout.Payments.Response.Source; +using Shouldly; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Xunit; +using Product = Checkout.Payments.Request.Product; + +namespace Checkout.Payments +{ + public class RequestApmPaymentsIntegrationTest : AbstractPaymentsIntegrationTest + { + [Fact] + private async Task ShouldMakeAliPayPayment() + { + var source = RequestAlipayPlusSource.RequestAlipayPlusCnSource(); + source = RequestAlipayPlusSource.RequestAlipayPlusGCashSource(); + source = RequestAlipayPlusSource.RequestAlipayPlusHkSource(); + source = RequestAlipayPlusSource.RequestAlipayPlusDanaSource(); + source = RequestAlipayPlusSource.RequestAlipayPlusKakaoPaySource(); + source = RequestAlipayPlusSource.RequestAlipayPlusTrueMoneySource(); + source = RequestAlipayPlusSource.RequestAlipayPlusTngSource(); + source = RequestAlipayPlusSource.RequestAliPayPlusSource(); + + var request = new PaymentRequest + { + Source = source, + Amount = 10L, + Currency = Currency.EUR, + ProcessingChannelId = "pc_5jp2az55l3cuths25t5p3xhwru", + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure", + }; + + try + { + await DefaultApi.PaymentsClient().RequestPayment(request); + } + catch (Exception e) + { + e.ShouldBeAssignableTo(); + } + } + + [Fact] + private async Task ShouldMakeIdealPayment() + { + var idealSource = new RequestIdealSource { Bic = "INGBNL2A", Description = "ORD50234E89", Language = "nl" }; + + var paymentRequest = new PaymentRequest + { + Source = idealSource, + Currency = Currency.EUR, + Amount = 1000, + Capture = true, + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure" + }; + + var paymentResponse = await DefaultApi.PaymentsClient().RequestPayment(paymentRequest); + + paymentResponse.ShouldNotBeNull(); + paymentResponse.Status.ShouldNotBeNull(); + paymentResponse.ResponseSummary.ShouldNotBeNull(); + paymentResponse.Links.ShouldNotBeNull(); + + var payment = await DefaultApi.PaymentsClient().GetPaymentDetails(paymentResponse.Id); + + payment.ShouldNotBeNull(); + + payment.Status.ShouldNotBeNull(); + payment.Links.ShouldNotBeNull(); + + payment.Source.ShouldBeOfType(typeof(AlternativePaymentSourceResponse)); + var source = (AlternativePaymentSourceResponse)payment.Source; + source.Count.ShouldBePositive(); + source.Type().ShouldBe(PaymentSourceType.Ideal); + } + + [Fact] + private async Task ShouldMakeSofortPayment() + { + var sofortSource = new RequestSofortSource(); + + var paymentRequest = new PaymentRequest + { + Source = sofortSource, + Currency = Currency.EUR, + Amount = 100, + Capture = true, + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure" + }; + + var paymentResponse = await DefaultApi.PaymentsClient().RequestPayment(paymentRequest); + + paymentResponse.ShouldNotBeNull(); + paymentResponse.Status.ShouldBe(PaymentStatus.Pending); + paymentResponse.ResponseSummary.ShouldBeNull(); + paymentResponse.Links["self"].ShouldNotBeNull(); + paymentResponse.Links["redirect"].ShouldNotBeNull(); + + var payment = await DefaultApi.PaymentsClient().GetPaymentDetails(paymentResponse.Id); + + payment.ShouldNotBeNull(); + + payment.Status.ShouldBe(PaymentStatus.Pending); + payment.Links["self"].ShouldNotBeNull(); + + payment.Source.ShouldBeOfType(typeof(AlternativePaymentSourceResponse)); + var source = (AlternativePaymentSourceResponse)payment.Source; + source.Count.ShouldBePositive(); + source.Type().ShouldBe(PaymentSourceType.Sofort); + } + + [Fact(Skip = "Preview")] + private async Task ShouldMakeTamaraPayment() + { + ICheckoutApi previewApi = CheckoutSdk.Builder() + .OAuth() + .ClientCredentials( + System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_PREVIEW_OAUTH_CLIENT_ID"), + System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_PREVIEW_OAUTH_CLIENT_SECRET")) + .Environment(Environment.Sandbox) + .Build(); + + var tamaraSource = new RequestTamaraSource(); + tamaraSource.BillingAddress = new Address + { + AddressLine1 = "Cecilia Chapman", + AddressLine2 = "711-2880 Nulla St.", + City = "Mankato", + State = "Mississippi", + Zip = "96522", + Country = CountryCode.SA + }; + + var paymentRequest = new PaymentRequest + { + Source = tamaraSource, + Currency = Currency.SAR, + Amount = 10000, + Capture = true, + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure", + Reference = "ORD-5023-4E89", + Processing = new ProcessingSettings { TaxAmount = 500, ShippingAmount = 1000 }, + ProcessingChannelId = "pc_zs5fqhybzc2e3jmq3efvybybpq", + Customer = new CustomerRequest + { + Name = "Cecilia Chapman", + Email = "c.chapman@example.com", + Phone = new Phone { CountryCode = "+966", Number = "113 496 0000" } + }, + Items = new List + { + new Product + { + Name = "Item name", + Quantity = 3, + UnitPrice = 100, + TotalAmount = 100, + TaxAmount = 19, + DiscountAmount = 2, + Reference = "some description about item", + ImageUrl = "https://some_s3bucket.com", + Url = "https://some.website.com/item", + Sku = "123687000111" + } + } + }; + + var paymentResponse = await previewApi.PaymentsClient().RequestPayment(paymentRequest); + + paymentResponse.ShouldNotBeNull(); + paymentResponse.Id.ShouldNotBeNullOrEmpty(); + paymentResponse.Reference.ShouldNotBeNullOrEmpty(); + paymentResponse.Status.ShouldBe(PaymentStatus.Pending); + paymentResponse.Links.ShouldNotBeEmpty(); + paymentResponse.Customer.Id.ShouldNotBeNullOrEmpty(); + paymentResponse.Customer.Name.ShouldNotBeEmpty(); + paymentResponse.Customer.Email.ShouldNotBeEmpty(); + paymentResponse.Customer.Phone.ShouldNotBeNull(); + paymentResponse.Processing.PartnerPaymentId.ShouldNotBeNull(); + paymentResponse.Links.ShouldNotBeEmpty(); + } + + [Fact] + private async Task ShouldMakeAfterPayPayment() + { + var request = new PaymentRequest + { + Source = new RequestAfterPaySource { AccountHolder = new AccountHolder() }, + Amount = 10L, + Currency = Currency.EUR, + ProcessingChannelId = "pc_5jp2az55l3cuths25t5p3xhwru", + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure", + }; + + try + { + await DefaultApi.PaymentsClient().RequestPayment(request); + } + catch (Exception e) + { + e.ShouldBeAssignableTo(); + } + } + + [Fact] + private async Task ShouldMakeBenefitPayment() + { + var request = new PaymentRequest + { + Source = new RequestBenefitSource(), + Amount = 10L, + Currency = Currency.BHD, + Reference = "REFERENCE", + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure", + }; + + await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), + PayeeNotOnboarded); + } + + [Fact] + private async Task ShouldMakeQPayPayment() + { + var request = new PaymentRequest + { + Source = new RequestQPaySource + { + Quantity = 1, Description = "QPay Demo Payment", Language = "en", NationalId = "070AYY010BU234M" + }, + Amount = 10L, + Currency = Currency.QAR, + Reference = "REFERENCE", + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure", + }; + + await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), + PayeeNotOnboarded); + } + + [Fact] + private async Task ShouldMakeMbwayPayment() + { + var request = new PaymentRequest + { + Source = new RequestMbwaySource(), + Amount = 10L, + Currency = Currency.BHD, + Reference = "REFERENCE", + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure", + }; + + await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), + "cko_processing_channel_id_invalid"); + } + + [Fact] + private async Task ShouldMakeEpsPayment() + { + var request = new PaymentRequest + { + Source = new RequestEpsSource { Purpose = "Mens black t-shirt L" }, + Amount = 10L, + Currency = Currency.EUR, + Reference = "REFERENCE", + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure", + }; + + await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), + PayeeNotOnboarded); + } + + [Fact] + private async Task ShouldMakeGiropayPayment() + { + var request = new PaymentRequest + { + Source = new RequestGiropaySource { Purpose = "CKO Giropay test", }, + Amount = 10L, + Currency = Currency.EUR, + Reference = "REFERENCE", + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure", + }; + + await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), + PayeeNotOnboarded); + } + + [Fact] + private async Task ShouldMakePrzelewy24Payment() + { + var request = new PaymentRequest + { + Source = new RequestP24Source + { + PaymentCountry = CountryCode.PL, + AccountHolderName = "Bruce Wayne", + AccountHolderEmail = "bruce@wayne-enterprises.com", + BillingDescriptor = "P24 Demo Payment" + }, + Currency = Currency.PLN, + Amount = 100, + Reference = Guid.NewGuid().ToString(), + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure" + }; + + await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), + PayeeNotOnboarded); + } + + [Fact] + private async Task ShouldMakeKnetPayment() + { + var request = new PaymentRequest + { + Source = new RequestKnetSource { Language = "en", }, + Currency = Currency.KWD, + Amount = 100, + Reference = Guid.NewGuid().ToString(), + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure" + }; + + await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), + PayeeNotOnboarded); + } + + [Fact] + private async Task ShouldMakeBancontactPayment() + { + var request = new PaymentRequest + { + Source = new RequestBancontactSource + { + PaymentCountry = CountryCode.BE, + AccountHolderName = "Bruce Wayne", + BillingDescriptor = "CKO Demo - bancontact", + }, + Currency = Currency.EUR, + Amount = 10, + Reference = Guid.NewGuid().ToString(), + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure" + }; + + await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), + PayeeNotOnboarded); + } + + [Fact] + private async Task ShouldMakeMultiBancoPayment() + { + var request = new PaymentRequest + { + Source = new RequestMultiBancoSource + { + PaymentCountry = CountryCode.PT, + AccountHolderName = "Bruce Wayne", + BillingDescriptor = "Multibanco Demo Payment" + }, + Currency = Currency.EUR, + Amount = 10, + Reference = Guid.NewGuid().ToString(), + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure" + }; + + await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), + PayeeNotOnboarded); + } + + [Fact] + private async Task ShouldMakePostFinancePayment() + { + var request = new PaymentRequest + { + Source = new RequestPostFinanceSource + { + PaymentCountry = CountryCode.CH, + AccountHolderName = "Bruce Wayne", + BillingDescriptor = "Multibanco Demo Payment" + }, + Currency = Currency.EUR, + Amount = 10, + Reference = Guid.NewGuid().ToString(), + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure" + }; + + await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), + PayeeNotOnboarded); + } + + [Fact] + private async Task ShouldMakeStcPayPayment() + { + var request = new PaymentRequest + { + Source = new RequestStcPaySource(), + Currency = Currency.SAR, + Amount = 10, + Reference = Guid.NewGuid().ToString(), + Customer = new PaymentCustomerRequest + { + Email = GenerateRandomEmail(), Name = "Louis Smith", Phone = GetPhone() + }, + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure" + }; + + await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), + "merchant_data_delegated_authentication_failed"); + } + + [Fact] + private async Task ShouldMakeAlmaPayment() + { + var request = new PaymentRequest + { + Source = new RequestAlmaSource { BillingAddress = GetAddress() }, + Currency = Currency.EUR, + Amount = 10, + Reference = Guid.NewGuid().ToString(), + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure" + }; + + await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), + PayeeNotOnboarded); + } + + [Fact] + private async Task ShouldMakeKlarnaPayment() + { + var request = new PaymentRequest + { + Source = new RequestKlarnaSource { AccountHolder = GetAccountHolder() }, + Currency = Currency.QAR, + Amount = 10, + Reference = Guid.NewGuid().ToString(), + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure" + }; + + await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), + ApmServiceUnavailable); + } + + [Fact] + private async Task ShouldMakePayPalPayment() + { + var request = new PaymentRequest + { + Source = new RequestPayPalSource + { + plan = new BillingPlan + { + Type = BillingPlanType.ChannelInitiatedBillingSingleAgreement, + SkipShippingAddress = true, + ImmutableShippingAddress = false + } + }, + Items = new List { new Product { Name = "Laptop", Quantity = 1, UnitPrice = 10, } }, + Currency = Currency.EUR, + Amount = 10, + Reference = Guid.NewGuid().ToString(), + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure" + }; + + await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), + PayeeNotOnboarded); + } + + [Fact] + private async Task ShouldMakeFawryPayment() + { + var request = new PaymentRequest + { + Source = new RequestFawrySource + { + Description = "Fawry Demo Payment", + CustomerMobile = "01058375055", + CustomerEmail = "bruce@wayne-enterprises.com", + Products = new FawryProduct[] + { + new FawryProduct + { + ProductId = "0123456789", + Quantity = 1, + Price = 10, + Description = "Fawry Demo Product" + } + } + }, + Currency = Currency.EGP, + Amount = 10, + Reference = Guid.NewGuid().ToString(), + SuccessUrl = "https://testing.checkout.com/sucess", + FailureUrl = "https://testing.checkout.com/failure" + }; + + await CheckErrorItem(async () => await DefaultApi.PaymentsClient().RequestPayment(request), + PayeeNotOnboarded); + } + } } \ No newline at end of file diff --git a/test/CheckoutSdkTest/Reports/ReportsClientTest.cs b/test/CheckoutSdkTest/Reports/ReportsClientTest.cs new file mode 100644 index 00000000..354fd70c --- /dev/null +++ b/test/CheckoutSdkTest/Reports/ReportsClientTest.cs @@ -0,0 +1,62 @@ +using Moq; +using Shouldly; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Checkout.Reports +{ + public class ReportsClientTest : UnitTestFixture + { + private readonly SdkAuthorization _authorization = new SdkAuthorization(PlatformType.Default, ValidPreviousSk); + private readonly Mock _apiClient = new Mock(); + private readonly Mock _sdkCredentials = new Mock(PlatformType.Default); + private readonly Mock _httpClientFactory = new Mock(); + private readonly Mock _configuration; + + public ReportsClientTest() + { + _sdkCredentials.Setup(credentials => credentials.GetSdkAuthorization(SdkAuthorizationType.SecretKeyOrOAuth)) + .Returns(_authorization); + + _configuration = new Mock(_sdkCredentials.Object, + Environment.Sandbox, _httpClientFactory.Object); + } + + [Fact] + private async Task ShouldGetAllReports() + { + var request = new ReportsQuery(); + var responseAsync = new ReportsResponse(); + + _apiClient.Setup(apiClient => + apiClient.Query("reports", _authorization, request, + CancellationToken.None)) + .ReturnsAsync(() => responseAsync); + + IReportsClient client = new ReportsClient(_apiClient.Object, _configuration.Object); + + var response = await client.GetAllReports(request); + + response.ShouldNotBeNull(); + } + + [Fact] + private async Task ShouldGetReportDetails() + { + const string reportId = "rpt_1234"; + var responseAsync = new ReportDetailsResponse(); + + _apiClient.Setup(apiClient => + apiClient.Get($"reports/{reportId}", _authorization, + CancellationToken.None)) + .ReturnsAsync(() => responseAsync); + + IReportsClient client = new ReportsClient(_apiClient.Object, _configuration.Object); + + var response = await client.GetReportDetails(reportId); + + response.ShouldNotBeNull(); + } + } +} diff --git a/test/CheckoutSdkTest/Reports/ReportsIntegrationTest.cs b/test/CheckoutSdkTest/Reports/ReportsIntegrationTest.cs new file mode 100644 index 00000000..893e4b47 --- /dev/null +++ b/test/CheckoutSdkTest/Reports/ReportsIntegrationTest.cs @@ -0,0 +1,66 @@ +using Castle.Core.Internal; +using Shouldly; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace Checkout.Reports +{ + public class ReportsIntegrationTest : SandboxTestFixture + { + public ReportsIntegrationTest() : base(PlatformType.Default) + { + } + + private readonly ReportsQuery _query = new ReportsQuery + { + CreatedAfter = DateTime.Now.Subtract(TimeSpan.FromDays(7)), + CreatedBefore = DateTime.Now + }; + + [Fact] + private async Task ShouldGetAllReports() + { + var reports = await DefaultApi.ReportsClient().GetAllReports(_query); + + reports.ShouldNotBeNull(); + if (!reports.Data.IsNullOrEmpty()) + { + foreach (var report in reports.Data) + { + report.Id.ShouldNotBeNull(); + report.CreatedOn.ShouldNotBeNull(); + report.Type.ShouldNotBeNull(); + report.Account.ShouldNotBeNull(); + report.Account.ClientId.ShouldNotBeNull(); + report.Account.EntityId.ShouldNotBeNull(); + report.From.ShouldNotBeNull(); + report.To.ShouldNotBeNull(); + report.Files.ShouldNotBeNull(); + } + } + } + + [Fact] + private async Task ShouldGetReportDetails() + { + var reports = await DefaultApi.ReportsClient().GetAllReports(_query); + + reports.ShouldNotBeNull(); + if (!reports.Data.IsNullOrEmpty()) + { + var reportDetails = reports.Data[0]; + var detailsResponse = await DefaultApi.ReportsClient().GetReportDetails(reportDetails.Id); + + detailsResponse.ShouldNotBeNull(); + detailsResponse.Id.ShouldBe(reportDetails.Id); + detailsResponse.CreatedOn.ShouldBe(reportDetails.CreatedOn); + detailsResponse.Type.ShouldBe(reportDetails.Type); + detailsResponse.Account.ClientId.ShouldBe(reportDetails.Account.ClientId); + detailsResponse.Account.EntityId.ShouldBe(reportDetails.Account.EntityId); + detailsResponse.From.ShouldBe(reportDetails.From); + detailsResponse.To.ShouldBe(reportDetails.To); + } + } + } +} diff --git a/test/CheckoutSdkTest/SandboxTestFixture.cs b/test/CheckoutSdkTest/SandboxTestFixture.cs index a52eec08..28d8b6f1 100644 --- a/test/CheckoutSdkTest/SandboxTestFixture.cs +++ b/test/CheckoutSdkTest/SandboxTestFixture.cs @@ -1,148 +1,148 @@ -using Checkout.Common; -using Microsoft.Extensions.Logging; -using Newtonsoft.Json.Linq; -using NLog.Extensions.Logging; -using Shouldly; -using System; -using System.Linq; -using System.Threading.Tasks; -using Xunit.Sdk; - -namespace Checkout -{ - public abstract class SandboxTestFixture - { - protected readonly Previous.ICheckoutApi PreviousApi; - protected readonly ICheckoutApi DefaultApi; - private readonly ILogger _log; - private const int TryMaxAttempts = 10; - - protected SandboxTestFixture(PlatformType platformType) - { - var logFactory = new NLogLoggerFactory(); - _log = logFactory.CreateLogger(typeof(SandboxTestFixture)); - switch (platformType) - { - case PlatformType.Previous: - PreviousApi = CheckoutSdk.Builder() - .Previous() - .StaticKeys() - .PublicKey(System.Environment.GetEnvironmentVariable("CHECKOUT_PREVIOUS_PUBLIC_KEY")) - .SecretKey(System.Environment.GetEnvironmentVariable("CHECKOUT_PREVIOUS_SECRET_KEY")) - .Environment(Environment.Sandbox) - .LogProvider(logFactory) - .HttpClientFactory(new DefaultHttpClientFactory()) - .Build(); - break; - - case PlatformType.Default: - DefaultApi = CheckoutSdk.Builder().StaticKeys() - .PublicKey(System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_PUBLIC_KEY")) - .SecretKey(System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_SECRET_KEY")) - .Environment(Environment.Sandbox) - .LogProvider(logFactory) - .Build(); - break; - - case PlatformType.DefaultOAuth: - DefaultApi = CheckoutSdk.Builder().OAuth() - .ClientCredentials( - System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_OAUTH_CLIENT_ID"), - System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET")) - .Scopes(OAuthScope.Files, OAuthScope.Flow, OAuthScope.Fx, OAuthScope.Gateway, - OAuthScope.Marketplace, OAuthScope.SessionsApp, OAuthScope.SessionsBrowser, - OAuthScope.Vault, OAuthScope.PayoutsBankDetails, OAuthScope.TransfersCreate, - OAuthScope.TransfersView, OAuthScope.BalancesView) - .Environment(Environment.Sandbox) - .LogProvider(logFactory) - .Build(); - break; - - default: - throw new ArgumentOutOfRangeException(nameof(platformType), platformType, null); - } - } - - protected static string GenerateRandomEmail() - { - return $"{Guid.NewGuid()}@checkout-sdk-net.com"; - } - - protected async Task Retriable(Func> func, Predicate predicate = null) - { - var attempts = 1; - while (attempts <= TryMaxAttempts) - { - try - { - T t = await func.Invoke(); - predicate?.Invoke(t).ShouldBeTrue(); - return t; - } - catch (Exception ex) - { - _log.LogWarning( - @"Request/Predicate failed with error '{Error}' - retry {CurrentAttempt}/{MaxAttempts}", - ex.Message, attempts, TryMaxAttempts); - } - - attempts++; - await Task.Delay(2500); - } - - throw new XunitException("Max attempts reached!"); - } - - protected async Task CheckErrorItem(Func> func, string errorItem) - { - try - { - T t = await func.Invoke(); - } - catch (CheckoutApiException ex) - { - ((JArray)ex.ErrorDetails["error_codes"]).ToList().ShouldContain(errorItem); - } - } - - protected static async Task AssertNotFound(Task task) - { - try - { - await task; - } - catch (Exception ex) - { - ex.ShouldNotBeNull(); - ex.ShouldBeAssignableTo(typeof(CheckoutApiException)); - ex.Message.ShouldBe("The API response status code (404) does not indicate success."); - } - } - - protected static Phone GetPhone() - { - return new Phone { CountryCode = "1", Number = "4155552671" }; - } - - protected static Address GetAddress() - { - return new Address - { - AddressLine1 = "CheckoutSdk.com", - AddressLine2 = "90 Tottenham Court Road", - City = "London", - State = "London", - Zip = "W1T 4TJ", - Country = CountryCode.GB - }; - } - - protected static AccountHolder GetAccountHolder() - { - return new AccountHolder - { - FirstName = "John", LastName = "Doe", Phone = GetPhone(), BillingAddress = GetAddress() - }; - } - } +using Checkout.Common; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json.Linq; +using NLog.Extensions.Logging; +using Shouldly; +using System; +using System.Linq; +using System.Threading.Tasks; +using Xunit.Sdk; + +namespace Checkout +{ + public abstract class SandboxTestFixture + { + protected readonly Previous.ICheckoutApi PreviousApi; + protected readonly ICheckoutApi DefaultApi; + private readonly ILogger _log; + private const int TryMaxAttempts = 10; + + protected SandboxTestFixture(PlatformType platformType) + { + var logFactory = new NLogLoggerFactory(); + _log = logFactory.CreateLogger(typeof(SandboxTestFixture)); + switch (platformType) + { + case PlatformType.Previous: + PreviousApi = CheckoutSdk.Builder() + .Previous() + .StaticKeys() + .PublicKey(System.Environment.GetEnvironmentVariable("CHECKOUT_PREVIOUS_PUBLIC_KEY")) + .SecretKey(System.Environment.GetEnvironmentVariable("CHECKOUT_PREVIOUS_SECRET_KEY")) + .Environment(Environment.Sandbox) + .LogProvider(logFactory) + .HttpClientFactory(new DefaultHttpClientFactory()) + .Build(); + break; + + case PlatformType.Default: + DefaultApi = CheckoutSdk.Builder().StaticKeys() + .PublicKey(System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_PUBLIC_KEY")) + .SecretKey(System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_SECRET_KEY")) + .Environment(Environment.Sandbox) + .LogProvider(logFactory) + .Build(); + break; + + case PlatformType.DefaultOAuth: + DefaultApi = CheckoutSdk.Builder().OAuth() + .ClientCredentials( + System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_OAUTH_CLIENT_ID"), + System.Environment.GetEnvironmentVariable("CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET")) + .Scopes(OAuthScope.Files, OAuthScope.Flow, OAuthScope.Fx, OAuthScope.Gateway, + OAuthScope.Marketplace, OAuthScope.SessionsApp, OAuthScope.SessionsBrowser, + OAuthScope.Vault, OAuthScope.PayoutsBankDetails, OAuthScope.TransfersCreate, + OAuthScope.TransfersView, OAuthScope.BalancesView, OAuthScope.Reporting) + .Environment(Environment.Sandbox) + .LogProvider(logFactory) + .Build(); + break; + + default: + throw new ArgumentOutOfRangeException(nameof(platformType), platformType, null); + } + } + + protected static string GenerateRandomEmail() + { + return $"{Guid.NewGuid()}@checkout-sdk-net.com"; + } + + protected async Task Retriable(Func> func, Predicate predicate = null) + { + var attempts = 1; + while (attempts <= TryMaxAttempts) + { + try + { + T t = await func.Invoke(); + predicate?.Invoke(t).ShouldBeTrue(); + return t; + } + catch (Exception ex) + { + _log.LogWarning( + @"Request/Predicate failed with error '{Error}' - retry {CurrentAttempt}/{MaxAttempts}", + ex.Message, attempts, TryMaxAttempts); + } + + attempts++; + await Task.Delay(2500); + } + + throw new XunitException("Max attempts reached!"); + } + + protected async Task CheckErrorItem(Func> func, string errorItem) + { + try + { + T t = await func.Invoke(); + } + catch (CheckoutApiException ex) + { + ((JArray)ex.ErrorDetails["error_codes"]).ToList().ShouldContain(errorItem); + } + } + + protected static async Task AssertNotFound(Task task) + { + try + { + await task; + } + catch (Exception ex) + { + ex.ShouldNotBeNull(); + ex.ShouldBeAssignableTo(typeof(CheckoutApiException)); + ex.Message.ShouldBe("The API response status code (404) does not indicate success."); + } + } + + protected static Phone GetPhone() + { + return new Phone { CountryCode = "1", Number = "4155552671" }; + } + + protected static Address GetAddress() + { + return new Address + { + AddressLine1 = "CheckoutSdk.com", + AddressLine2 = "90 Tottenham Court Road", + City = "London", + State = "London", + Zip = "W1T 4TJ", + Country = CountryCode.GB + }; + } + + protected static AccountHolder GetAccountHolder() + { + return new AccountHolder + { + FirstName = "John", LastName = "Doe", Phone = GetPhone(), BillingAddress = GetAddress() + }; + } + } } \ No newline at end of file