diff --git a/samples/PaymentGateways/SipayIntegrationSampleConsoleApp/Program.cs b/samples/PaymentGateways/SipayIntegrationSampleConsoleApp/Program.cs index 8b62270..a31629d 100644 --- a/samples/PaymentGateways/SipayIntegrationSampleConsoleApp/Program.cs +++ b/samples/PaymentGateways/SipayIntegrationSampleConsoleApp/Program.cs @@ -19,12 +19,12 @@ )); // Non secure payment -var nonSecurePaymentResponse = await sipayPaymentIntegration.NonSecurePaymentAsync(new NonSecurePaymentRequestModel( +var nonSecurePaymentModel = new NonSecurePaymentRequestModel( ccHolderName: "John Doe", - ccNo: "123456", + ccNo: "4508034508034509", expiryMonth: 12, - expiryYear: 2022, - cvv: 123, + expiryYear: 2026, + cvv: 000, currencyCode: "TRY", installmentsNumber: 1, invoiceId: 1, @@ -32,13 +32,13 @@ name: "John", surname: "Doe", total: 100, - items: "items", cancelUrl: "https://cancelUrl.com", returnUrl: "https://returnUrl.com", - hashKey: "hashKey", ip: "", orderType: 0 -)); +); +nonSecurePaymentModel.AddItem(new NonSecurePaymentItemRequestModel("name", "100", 1, "desc")); +var nonSecurePaymentResponse = await sipayPaymentIntegration.NonSecurePaymentAsync(nonSecurePaymentModel); // Secure payment // 1. Get secure payment hmtl content and show to user @@ -58,7 +58,6 @@ items: "items", cancelUrl: "https://cancelUrl.com", returnUrl: "https://returnUrl.com", - hashKey: "hashKey", orderType: 0, recurringPaymentNumber: 0, recurringPaymentCycle: "", @@ -75,14 +74,12 @@ var securePaymentChargeRequest = await sipayPaymentIntegration.SecurePaymentChargeAsync(new SecurePaymentChargeRequestModel( invoiceId: "1", orderId: "1", - status: "1", - hashKey: "")); + status: "1")); // Cancel payment var cancelResponse = await sipayPaymentIntegration.CancelAsync(new CancellationRequestModel( invoiceId: "", - hashKey: "", refundTransactionId: "", refundWebhookKey: "" )); @@ -91,7 +88,6 @@ var refundResponse = await sipayPaymentIntegration.RefundAsync(new RefundRequestModel( invoiceId: "", amount: 100, - hashKey: "", refundTransactionId: "", refundWebhookKey: "" )); \ No newline at end of file diff --git a/src/Integration.Hub/IntegrationBase.cs b/src/Integration.Hub/IntegrationBase.cs index fb81986..4a995b5 100644 --- a/src/Integration.Hub/IntegrationBase.cs +++ b/src/Integration.Hub/IntegrationBase.cs @@ -65,7 +65,6 @@ public async Task InvokeRequestAsync(Func(responseAsString, _options)!; } - public async Task InvokeRequestAsync(Func> httpRequest, TRequest requestModel) where TRequest : IRequestModel { diff --git a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/CancellationRequestModel.cs b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/CancellationRequestModel.cs index 3a53e8d..90e85f8 100644 --- a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/CancellationRequestModel.cs +++ b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/CancellationRequestModel.cs @@ -2,10 +2,9 @@ namespace Integration.PaymentGateways.Sipay.Infrastructure.PaymentIntegration.Models.Response; public class CancellationRequestModel : IRequestModel { - public CancellationRequestModel(string invoiceId, string hashKey, string refundTransactionId, string? refundWebhookKey = null) + public CancellationRequestModel(string invoiceId, string refundTransactionId, string? refundWebhookKey = null) { InvoiceId = invoiceId; - HashKey = hashKey; RefundTransactionId = refundTransactionId; RefundWebhookKey = refundWebhookKey; } @@ -17,4 +16,20 @@ public CancellationRequestModel(string invoiceId, string hashKey, string refundT public string HashKey { get; set; } public string RefundTransactionId { get; set; } public string? RefundWebhookKey { get; set; } + + public CancellationRequestModel SetMerchantKey(string merchantKey) + { + MerchantKey = merchantKey; + return this; + } + public CancellationRequestModel SetAppSecret(string appSecret) + { + AppSecret = appSecret; + return this; + } + public CancellationRequestModel SetAppId(string appId) + { + AppId = appId; + return this; + } } \ No newline at end of file diff --git a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/CheckInstallmentRequestModel.cs b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/CheckInstallmentRequestModel.cs index b736e87..2f0e042 100644 --- a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/CheckInstallmentRequestModel.cs +++ b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/CheckInstallmentRequestModel.cs @@ -20,4 +20,9 @@ public CheckInstallmentRequestModel(string creditCard, double amount, string cur public string? CommissionBy { get; set; } public bool? IsRecurring { get; set; } public bool? Is2d { get; set; } + public CheckInstallmentRequestModel SetMerchantKey(string merchantKey) + { + MerchantKey = merchantKey; + return this; + } } \ No newline at end of file diff --git a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/NonSecurePaymentRequestModel.cs b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/NonSecurePaymentRequestModel.cs index ea45ce8..12ebbe9 100644 --- a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/NonSecurePaymentRequestModel.cs +++ b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/NonSecurePaymentRequestModel.cs @@ -1,10 +1,11 @@ using Integration.Hub; +using Integration.PaymentGateways.Sipay.Infrastructure.PaymentIntegration.Helpers; namespace Integration.PaymentGateways.Sipay.Infrastructure.PaymentIntegration.Models.Request; public class NonSecurePaymentRequestModel : IRequestModel { - public NonSecurePaymentRequestModel(string ccHolderName, string ccNo, int expiryMonth, int expiryYear, int cvv, string currencyCode, int installmentsNumber, int invoiceId, string invoiceDescription, string name, string surname, int total, string items, string cancelUrl, string returnUrl, string hashKey, string ip, int orderType) + public NonSecurePaymentRequestModel(string ccHolderName, string ccNo, int expiryMonth, int expiryYear, int cvv, string currencyCode, int installmentsNumber, int invoiceId, string invoiceDescription, string name, string surname, int total, string cancelUrl, string returnUrl, string ip, int orderType) { CCHolderName = ccHolderName; CCNo = ccNo; @@ -18,14 +19,36 @@ public NonSecurePaymentRequestModel(string ccHolderName, string ccNo, int expiry Name = name; Surname = surname; Total = total; - Items = items; CancelUrl = cancelUrl; ReturnUrl = returnUrl; - HashKey = hashKey; Ip = ip; OrderType = orderType; } + public NonSecurePaymentRequestModel AddItem(NonSecurePaymentItemRequestModel nonSecurePaymentItemRequestModel) + { + Items.Add(nonSecurePaymentItemRequestModel); + return this; + } + + public NonSecurePaymentRequestModel AddItems(List nonSecurePaymentItemRequestModels) + { + Items.AddRange(nonSecurePaymentItemRequestModels); + return this; + } + + public NonSecurePaymentRequestModel SetMerchantKey(string merchantKey) + { + MerchantKey = merchantKey; + return this; + } + + public NonSecurePaymentRequestModel SetHashKey(string appSecret) + { + HashKey = HashHelper.GenerateHashKey(Total.ToString(), InstallmentsNumber.ToString(), CurrencyCode, MerchantKey, InvoiceId.ToString(), appSecret); + return this; + } + public string CCHolderName { get; set; } public string CCNo { get; set; } public int ExpiryMonth { get; set; } @@ -39,7 +62,7 @@ public NonSecurePaymentRequestModel(string ccHolderName, string ccNo, int expiry public string Surname { get; set; } public int Total { get; set; } public string MerchantKey { get; set; } - public string Items { get; set; } + public List Items { get; set; } = new(); public string CancelUrl { get; set; } public string ReturnUrl { get; set; } public string HashKey { get; set; } @@ -64,4 +87,20 @@ public NonSecurePaymentRequestModel(string ccHolderName, string ccNo, int expiry public string RecurringPaymentCycle { get; set; } public string RecurringPaymentInterval { get; set; } public string RecurringWebHookKey { get; set; } -} \ No newline at end of file +} + +public class NonSecurePaymentItemRequestModel : IRequestModel +{ + public NonSecurePaymentItemRequestModel(string name, string price, int quantity, string? description = null) + { + Name = name; + Price = price; + Quantity = quantity; + Description = description; + } + + public string Name { get; set; } + public string Price { get; set; } + public int Quantity { get; set; } + public string? Description { get; set; } +} diff --git a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/RefundRequestModel.cs b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/RefundRequestModel.cs index 21d0e11..2ba053a 100644 --- a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/RefundRequestModel.cs +++ b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/RefundRequestModel.cs @@ -2,11 +2,10 @@ namespace Integration.PaymentGateways.Sipay.Infrastructure.PaymentIntegration.Models.Response; public class RefundRequestModel : IRequestModel { - public RefundRequestModel(string invoiceId, double amount, string hashKey, string refundTransactionId, string? refundWebhookKey = null) + public RefundRequestModel(string invoiceId, double amount, string refundTransactionId, string? refundWebhookKey = null) { InvoiceId = invoiceId; Amount = amount; - HashKey = hashKey; RefundTransactionId = refundTransactionId; RefundWebhookKey = refundWebhookKey; } @@ -19,4 +18,21 @@ public RefundRequestModel(string invoiceId, double amount, string hashKey, strin public string HashKey { get; set; } public string RefundTransactionId { get; set; } public string? RefundWebhookKey { get; set; } + + + public RefundRequestModel SetMerchantKey(string merchantKey) + { + MerchantKey = merchantKey; + return this; + } + public RefundRequestModel SetAppSecret(string appSecret) + { + AppSecret = appSecret; + return this; + } + public RefundRequestModel SetAppId(string appId) + { + AppId = appId; + return this; + } } \ No newline at end of file diff --git a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/SecurePaymentChargeRequestModel.cs b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/SecurePaymentChargeRequestModel.cs index f93e906..84c59d3 100644 --- a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/SecurePaymentChargeRequestModel.cs +++ b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/SecurePaymentChargeRequestModel.cs @@ -3,17 +3,20 @@ namespace Integration.PaymentGateways.Sipay.Infrastructure.PaymentIntegration.Models.Request; public class SecurePaymentChargeRequestModel : IRequestModel { - public SecurePaymentChargeRequestModel(string invoiceId, string orderId, string status, string hashKey) + public SecurePaymentChargeRequestModel(string invoiceId, string orderId, string status) { InvoiceId = invoiceId; OrderId = orderId; Status = status; - HashKey = hashKey; } - public string MerchantKey { get; set; } public string InvoiceId { get; set; } public string OrderId { get; set; } public string Status { get; set; } public string HashKey { get; set; } + public SecurePaymentChargeRequestModel SetMerchantKey(string merchantKey) + { + MerchantKey = merchantKey; + return this; + } } \ No newline at end of file diff --git a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/SecurePaymentInitialRequestModel.cs b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/SecurePaymentInitialRequestModel.cs index 04947a2..3b9000a 100644 --- a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/SecurePaymentInitialRequestModel.cs +++ b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Request/SecurePaymentInitialRequestModel.cs @@ -1,8 +1,10 @@ +using System.Reflection.Metadata; using Integration.Hub; +using Integration.PaymentGateways.Sipay.Infrastructure.PaymentIntegration.Helpers; namespace Integration.PaymentGateways.Sipay.Infrastructure.PaymentIntegration.Models.Request; public class SecurePaymentInitialRequestModel : IRequestModel { - public SecurePaymentInitialRequestModel(string ccHolderName, string ccNo, int expiryMonth, int expiryYear, int cvv, string currencyCode, int installmentsNumber, string invoiceId, string invoiceDescription, string name, string surname, double total, string items, string cancelUrl, string returnUrl, string hashKey, int orderType, int recurringPaymentNumber, string recurringPaymentCycle, string recurringPaymentInterval, string recurringWebHookKey, int maturityPeriod, int paymentFrequency) + public SecurePaymentInitialRequestModel(string ccHolderName, string ccNo, int expiryMonth, int expiryYear, int cvv, string currencyCode, int installmentsNumber, string invoiceId, string invoiceDescription, string name, string surname, double total, string items, string cancelUrl, string returnUrl, int orderType, int recurringPaymentNumber, string recurringPaymentCycle, string recurringPaymentInterval, string recurringWebHookKey, int maturityPeriod, int paymentFrequency) { CCHolderName = ccHolderName; CCNo = ccNo; @@ -19,7 +21,6 @@ public SecurePaymentInitialRequestModel(string ccHolderName, string ccNo, int ex Items = items; CancelUrl = cancelUrl; ReturnUrl = returnUrl; - HashKey = hashKey; OrderType = orderType; RecurringPaymentNumber = recurringPaymentNumber; RecurringPaymentCycle = recurringPaymentCycle; @@ -70,4 +71,16 @@ public SecurePaymentInitialRequestModel(string ccHolderName, string ccNo, int ex public string? SaleWebHookKey { get; set; } public string? PaymentCompletedBy { get; set; } public string? ResponseMethod { get; set; } + + public SecurePaymentInitialRequestModel SetHashKey(string appSecret) + { + HashKey = HashHelper.GenerateHashKey(Total.ToString(), InstallmentsNumber.ToString(), CurrencyCode, MerchantKey, InvoiceId, appSecret); + return this; + } + + public SecurePaymentInitialRequestModel SetMerchantKey(string merchantKey) + { + MerchantKey = merchantKey; + return this; + } } \ No newline at end of file diff --git a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Response/CheckInstallmentResponseModel.cs b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Response/CheckInstallmentResponseModel.cs index 39d9df6..7fff715 100644 --- a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Response/CheckInstallmentResponseModel.cs +++ b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Response/CheckInstallmentResponseModel.cs @@ -15,5 +15,5 @@ public class CheckInstallmentResponseModel : IResponseModel public string AmountToBePaid { get; set; } public string CurrencyCode { get; set; } public int CurrencyId { get; set; } - public string Title { get; set; } + //public string Title { get; set; }//Sipay has problem. This prop can be both string and int } \ No newline at end of file diff --git a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Response/NonSecurePaymentResponseModel.cs b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Response/NonSecurePaymentResponseModel.cs index 038386c..f6eec8c 100644 --- a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Response/NonSecurePaymentResponseModel.cs +++ b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/Models/Response/NonSecurePaymentResponseModel.cs @@ -4,10 +4,10 @@ public class NonSecurePaymentResponseModel : IResponseModel { public int Status { get; set; } public string OrderNo { get; set; } - public int InvoiceId { get; set; } + public string InvoiceId { get; set; } public int StatusCode { get; set; } public string StatusDescription { get; set; } - public string PaymentMethod { get; set; } + public int PaymentMethod { get; set; } public string TransactionType { get; set; } public int ErrorCode { get; set; } public string Error { get; set; } diff --git a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/SipayPaymentIntegration.cs b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/SipayPaymentIntegration.cs index 0c44fc6..51e187e 100644 --- a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/SipayPaymentIntegration.cs +++ b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/PaymentIntegration/SipayPaymentIntegration.cs @@ -34,7 +34,7 @@ public async Task SetTokenAsync() /// public async Task>> CheckInstallmentsAsync(CheckInstallmentRequestModel checkInstallmentRequestModel) { - checkInstallmentRequestModel.MerchantKey = _merchantKey; + checkInstallmentRequestModel.SetMerchantKey(_merchantKey); return await InvokeRequestAsync>>((client, requestBody) => client.PostAsync(GetCheckInstallmentsUrl(), requestBody), checkInstallmentRequestModel); } @@ -45,7 +45,8 @@ public async Task>> C /// public async Task> NonSecurePaymentAsync(NonSecurePaymentRequestModel nonSecurePaymentRequestModel) { - nonSecurePaymentRequestModel.MerchantKey = _merchantKey; + nonSecurePaymentRequestModel.SetMerchantKey(_merchantKey); + nonSecurePaymentRequestModel.SetHashKey(_appSecret); return await InvokeRequestAsync>((client, requestBody) => client.PostAsync(GetNonSecurePaymentUrl(), requestBody), nonSecurePaymentRequestModel); } @@ -56,15 +57,8 @@ public async Task> NonSecu /// public string SecurePaymentInitial(SecurePaymentInitialRequestModel securePaymentInitialRequestModel) { - securePaymentInitialRequestModel.MerchantKey = _merchantKey; - - //Generate hashkey - var hashKey = HashHelper.GenerateHashKey(securePaymentInitialRequestModel.Total.ToString(), securePaymentInitialRequestModel.InstallmentsNumber.ToString(), securePaymentInitialRequestModel.CurrencyCode, securePaymentInitialRequestModel.MerchantKey, securePaymentInitialRequestModel.InvoiceId, _appSecret); - - //Add hash key to dto - securePaymentInitialRequestModel.HashKey = hashKey; - - //Generate template + securePaymentInitialRequestModel.SetMerchantKey(_merchantKey); + securePaymentInitialRequestModel.SetHashKey(_appSecret); var template = HTMLHelper.GenerateTemplate("3ds-payment-form", "Resources/HTML", securePaymentInitialRequestModel); return template; } @@ -76,8 +70,7 @@ public string SecurePaymentInitial(SecurePaymentInitialRequestModel securePaymen /// public async Task> SecurePaymentChargeAsync(SecurePaymentChargeRequestModel securePaymentChargeRequestModel) { - securePaymentChargeRequestModel.MerchantKey = _merchantKey; - + securePaymentChargeRequestModel.SetMerchantKey(_merchantKey); return await InvokeRequestAsync>((client, requestBody) => client.PostAsync(GetSecurePaymentChargeUrl(), requestBody), securePaymentChargeRequestModel); } @@ -88,10 +81,9 @@ public async Task> Secu /// public async Task> CancelAsync(CancellationRequestModel cancellationRequestModel) { - cancellationRequestModel.MerchantKey = _merchantKey; - cancellationRequestModel.AppSecret = _appSecret; - cancellationRequestModel.AppId = _appKey; - + cancellationRequestModel.SetMerchantKey(_merchantKey); + cancellationRequestModel.SetAppSecret(_appSecret); + cancellationRequestModel.SetAppId(_appKey); return await InvokeRequestAsync>((client, requestBody) => client.PostAsync(GetCancelUrl(), requestBody), cancellationRequestModel); } @@ -102,10 +94,9 @@ public async Task> CancelAsync /// public async Task> RefundAsync(RefundRequestModel refundRequestModel) { - refundRequestModel.MerchantKey = _merchantKey; - refundRequestModel.AppSecret = _appSecret; - refundRequestModel.AppId = _appKey; - + refundRequestModel.SetMerchantKey(_merchantKey); + refundRequestModel.SetAppSecret(_appSecret); + refundRequestModel.SetAppId(_appKey); return await InvokeRequestAsync>((client, requestBody) => client.PostAsync(GetRefundUrl(), requestBody), refundRequestModel); } } \ No newline at end of file diff --git a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/SipayIntegrationBase.cs b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/SipayIntegrationBase.cs index 8405e36..562c20a 100644 --- a/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/SipayIntegrationBase.cs +++ b/src/PaymentGateways/Integration.PaymentGateways.Sipay/Infrastructure/SipayIntegrationBase.cs @@ -1,4 +1,5 @@ using System.Text.Json; +using System.Text.Json.Serialization; using Integration.Hub; namespace Integration.PaymentGateways.Sipay.Infrastructure.PaymentIntegration; @@ -28,6 +29,7 @@ public SipayIntegrationBase(string merchantKey, string appKey, string appSecret, SetSerializerOptions(new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }); }