diff --git a/src/Parbad/src/Gateway/Melli/Internal/MelliHelper.cs b/src/Parbad/src/Gateway/Melli/Internal/MelliHelper.cs
index 2286f3ab..37aa765d 100644
--- a/src/Parbad/src/Gateway/Melli/Internal/MelliHelper.cs
+++ b/src/Parbad/src/Gateway/Melli/Internal/MelliHelper.cs
@@ -18,6 +18,7 @@ internal static class MelliHelper
{
private const int SuccessCode = 0;
private const int DuplicateTrackingNumberCode = 1011;
+ public const string CumulativeAccountsKey="MultiplexingData";
public static object CreateRequestData(Invoice invoice, MelliGatewayAccount account, IMelliGatewayCrypto crypto)
{
@@ -25,15 +26,42 @@ public static object CreateRequestData(Invoice invoice, MelliGatewayAccount acco
var signedData = crypto.Encrypt(account.TerminalKey, data);
- return CreateRequestObject(
+ if (invoice.Properties == null || !invoice.Properties.ContainsKey(CumulativeAccountsKey))
+ {
+ return CreateRequestObject(
+ account.TerminalId,
+ account.MerchantId,
+ invoice.Amount,
+ signedData,
+ invoice.CallbackUrl,
+ invoice.TrackingNumber);
+
+ }
+
+ var melliCumulativeAccount = (MelliCumulativeAccount)invoice.Properties[CumulativeAccountsKey];
+ return CreateRequestMultiplexingDataObject(
account.TerminalId,
account.MerchantId,
invoice.Amount,
signedData,
invoice.CallbackUrl,
- invoice.TrackingNumber);
+ invoice.TrackingNumber,
+ melliCumulativeAccount);
+ }
+ private static object CreateRequestMultiplexingDataObject(string terminalId, string merchantId, long amount, string signedData, string callbackUrl, long orderId, MelliCumulativeAccount melliCumulativeAccount)
+ {
+ return new
+ {
+ TerminalId = terminalId,
+ MerchantId = merchantId,
+ Amount = amount,
+ SignData = signedData,
+ ReturnUrl = callbackUrl,
+ LocalDateTime = DateTime.Now,
+ OrderId = orderId.ToString(),
+ MultiplexingData=melliCumulativeAccount
+ };
}
-
public static PaymentRequestResult CreateRequestResult(
MelliApiRequestResult result,
HttpContext httpContext,
diff --git a/src/Parbad/src/Gateway/Melli/MelliCumulativeAccount.cs b/src/Parbad/src/Gateway/Melli/MelliCumulativeAccount.cs
new file mode 100644
index 00000000..36d09648
--- /dev/null
+++ b/src/Parbad/src/Gateway/Melli/MelliCumulativeAccount.cs
@@ -0,0 +1,42 @@
+using System.Collections.Generic;
+
+namespace Parbad.Gateway.Melli;
+
+public class MelliCumulativeAccount
+{
+ public enum Types
+ {
+ ///
+ /// تسهیم با ارسال مبلغ
+ ///
+ Amount,
+
+ ///
+ /// تسهیم با ارسال درصد
+ ///
+ Percentage
+ }
+
+ public class MultiplexingRow
+ {
+ ///
+ /// ردیف یا شماره شبای حساب
+ ///
+ public string IbanNumber { get; set; }
+
+ ///
+ /// مبلغ یا درصد
+ ///
+ public int Value { get; set; }
+ }
+
+ ///
+ /// نوع تسهیم
+ ///
+ public Types Type { get; set; }
+
+ ///
+ /// مقدار تسهیم
+ ///
+ public List MultiplexingRows { get; set; }
+}
\ No newline at end of file
diff --git a/src/Parbad/src/Gateway/Melli/MelliGatewayBuilderExtensions.cs b/src/Parbad/src/Gateway/Melli/MelliGatewayBuilderExtensions.cs
index 0d7d6fe8..731f5b20 100644
--- a/src/Parbad/src/Gateway/Melli/MelliGatewayBuilderExtensions.cs
+++ b/src/Parbad/src/Gateway/Melli/MelliGatewayBuilderExtensions.cs
@@ -5,6 +5,7 @@
using Microsoft.Extensions.DependencyInjection;
using Parbad.Gateway.Melli.Internal;
using Parbad.GatewayBuilders;
+using Parbad.InvoiceBuilder;
namespace Parbad.Gateway.Melli
{
@@ -53,5 +54,23 @@ public static IGatewayConfigurationBuilder WithOptions(
return builder;
}
+
+ ///
+ /// اضافه کردن اطلاعات تسهیم بانک سداد ملی به درخواست
+ ///
+ ///
+ public static IInvoiceBuilder AddMelliCumulativeAccounts(this IInvoiceBuilder builder, MelliCumulativeAccount data)
+ {
+ if (data == null) throw new ArgumentNullException(nameof(data));
+ if (data.MultiplexingRows==null || data.MultiplexingRows.Count==0) throw new ArgumentNullException(nameof(data.MultiplexingRows));
+
+ builder.ChangeProperties(properties =>
+ {
+ properties[MelliHelper.CumulativeAccountsKey] = data;
+ });
+
+ return builder;
+ }
+
}
}