Ejemplo n.º 1
0
        public void Setup()
        {
            _services = new ServiceCollection()
                        .BuildServiceProvider();

            _builder = new DefaultInvoiceBuilder(_services);
        }
Ejemplo n.º 2
0
 public VehicleReadySignalHandler(
     IMemory memory,
     IInvoiceBuilder invoiceBuilder)
 {
     _memory         = memory;
     _invoiceBuilder = invoiceBuilder;
 }
Ejemplo n.º 3
0
        public static IInvoiceBuilder AddMellatCumulativeAccounts(this IInvoiceBuilder builder, IEnumerable <MellatCumulativeDynamicAccount> accounts)
        {
            if (accounts == null)
            {
                throw new ArgumentNullException(nameof(accounts));
            }
            if (!accounts.Any())
            {
                throw new ArgumentException("Accounts cannot be an empty collection.", nameof(accounts));
            }

            List <MellatCumulativeDynamicAccount> allAccounts = null;

            builder.ChangeProperties(properties =>
            {
                if (properties.ContainsKey(MellatHelper.CumulativeAccountsKey))
                {
                    allAccounts = (List <MellatCumulativeDynamicAccount>)properties[MellatHelper.CumulativeAccountsKey];
                }
                else
                {
                    allAccounts = new List <MellatCumulativeDynamicAccount>();

                    properties.Add(MellatHelper.CumulativeAccountsKey, allAccounts);
                }

                allAccounts.AddRange(accounts);
            });

            return(builder);
        }
Ejemplo n.º 4
0
 public static IInvoiceBuilder AddMellatCumulativeAccount(this IInvoiceBuilder builder, long subServiceId, long amount, long payerId)
 {
     return(AddMellatCumulativeAccounts(builder, new List <MellatCumulativeDynamicAccount>
     {
         new MellatCumulativeDynamicAccount(subServiceId, amount, payerId)
     }));
 }
Ejemplo n.º 5
0
 public static IInvoiceBuilder SetMellatMobileNumber(this IInvoiceBuilder builder, string mobileNumber)
 {
     return(SetMellatAdditionalData(builder, new MellatGatewayAdditionalDataRequest
     {
         MobileNumber = mobileNumber
     }));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds or updates the given dictionary to the properties of the invoice.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="properties"></param>
        public static IInvoiceBuilder AddOrUpdateProperties(this IInvoiceBuilder builder, IDictionary <string, object> properties)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            ChangeProperties(builder, invoiceProperties =>
            {
                foreach (var data in properties)
                {
                    if (invoiceProperties.ContainsKey(data.Key))
                    {
                        invoiceProperties[data.Key] = data.Value;
                    }
                    else
                    {
                        invoiceProperties.Add(data.Key, data.Value);
                    }
                }
            });

            return(builder);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds or updates the given dictionary to the additional data of the invoice.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="additionalData"></param>
        public static IInvoiceBuilder AddOrUpdateAdditionalData(this IInvoiceBuilder builder, IDictionary <string, object> additionalData)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (additionalData == null)
            {
                throw new ArgumentNullException(nameof(additionalData));
            }

            ChangeAdditionalData(builder, invoiceAdditionalData =>
            {
                foreach (var data in additionalData)
                {
                    if (invoiceAdditionalData.ContainsKey(data.Key))
                    {
                        invoiceAdditionalData[data.Key] = data.Value;
                    }
                    else
                    {
                        invoiceAdditionalData.Add(data.Key, data.Value);
                    }
                }
            });

            return(builder);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Contains extra functions for Mellat Gateway.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="configureMellatInvoiceBuilder">Helps to build the extra functions of Mellat Gateway.</param>
        public static IInvoiceBuilder UseMellat(this IInvoiceBuilder builder, Action <IMellatGatewayInvoiceBuilder> configureMellatInvoiceBuilder)
        {
            builder.UseMellat();

            configureMellatInvoiceBuilder(new MellatGatewayInvoiceBuilder(builder));

            return(builder);
        }
        /// <summary>
        /// Sets the type of the gateway which the invoice must be paid in.
        /// </summary>
        /// <typeparam name="TGateway">Type of the gateway.</typeparam>
        /// <param name="builder"></param>
        /// <exception cref="InvalidGatewayTypeException"></exception>
        public static IInvoiceBuilder SetGatewayType <TGateway>(this IInvoiceBuilder builder) where TGateway : IGateway
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.SetGatewayType(typeof(TGateway)));
        }
        /// <summary>
        /// The invoice will be sent to Parbad Virtual gateway.
        /// </summary>
        /// <param name="builder"></param>
        public static IInvoiceBuilder UseParbadVirtual(this IInvoiceBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.UseGateway(ParbadVirtualGateway.Name));
        }
        /// <summary>
        /// The invoice will be sent to Asan Pardakht gateway.
        /// </summary>
        /// <param name="builder"></param>
        public static IInvoiceBuilder UseAsanPardakht(this IInvoiceBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.SetGateway(AsanPardakhtGateway.Name));
        }
        /// <summary>
        /// The invoice will be sent to Pasargad gateway.
        /// </summary>
        /// <param name="builder"></param>
        public static IInvoiceBuilder UsePasargad(this IInvoiceBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.SetGateway(PasargadGateway.Name));
        }
        /// <summary>
        /// Sets the tracking number of invoice.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="trackingNumber">
        /// The tracking number of invoice.
        /// <para>Note: It must be unique for each payment requests.</para>
        /// </param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public static IInvoiceBuilder SetTrackingNumber(this IInvoiceBuilder builder, long trackingNumber)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.SetTrackingNumberProvider(new UserInputTrackingNumberProvider(trackingNumber)));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Sets the gateway name.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="gatewayName"></param>
        /// <exception cref="GatewayNotFoundException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        public static IInvoiceBuilder SetGateway(this IInvoiceBuilder builder, string gatewayName)
        {
            if (gatewayName == null)
            {
                throw new ArgumentNullException(nameof(gatewayName));
            }

            return(AddFormatter(builder, invoice => invoice.GatewayName = gatewayName));
        }
        /// <summary>
        /// Sets the additional data for <see cref="ZibalGateway"/>.
        /// </summary>
        /// <exception cref="ArgumentNullException"></exception>
        public static IInvoiceBuilder SetZibalData(this IInvoiceBuilder builder, ZibalRequestAdditionalData zibalRequest)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.AddOrUpdateProperty(ZibalHelper.ZibalRequestAdditionalKeyName, zibalRequest));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Changes the properties.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="onChange">An action to perform on the properties.</param>
        public static IInvoiceBuilder ChangeProperties(this IInvoiceBuilder builder, Action <IDictionary <string, object> > onChange)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(AddFormatter(builder, invoice => onChange(invoice.Properties)));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Adds the given formatter to the list of formatters.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="formatInvoice"></param>
        public static IInvoiceBuilder AddFormatter(this IInvoiceBuilder builder, Func <Invoice, Task> formatInvoice)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.AddFormatter(new DefaultInvoiceFormatter(formatInvoice)));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// The invoice will be sent to Saman gateway.
        /// </summary>
        /// <param name="builder"></param>
        public static IInvoiceBuilder UseSaman(this IInvoiceBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.UseGateway(SamanGateway.Name));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Sets ZarinPal Gateway data.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="zarinPalInvoice">Describes an invoice for ZarinPal gateway.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public static IInvoiceBuilder SetZarinPalData(this IInvoiceBuilder builder, ZarinPalInvoice zarinPalInvoice)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.AddOrUpdateProperty(ZarinPalHelper.ZarinPalRequestAdditionalKeyName, zarinPalInvoice);

            return(builder);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Enables or disables Saman Mobile gateway.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="enable">If true, the invoice will be sent to Saman Mobile gateway. Otherwise it will be sent to Saman Web gateway.</param>
        public static IInvoiceBuilder EnableSamanMobileGateway(this IInvoiceBuilder builder, bool enable = true)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.AddOrUpdateAdditionalData(SamanHelper.MobileGatewayKey, enable);

            return(builder);
        }
Ejemplo n.º 21
0
        internal static void SetYekPayRequest(IInvoiceBuilder builder, YekPayRequest yekPayRequest)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (yekPayRequest == null)
            {
                throw new ArgumentNullException(nameof(yekPayRequest));
            }

            builder.AddOrUpdateAdditionalData(YekPayRequestKey, yekPayRequest);
        }
        /// <summary>
        /// Sets additional data to the Invoice for <see cref="PayIrGateway"/>.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="data"></param>
        public static IInvoiceBuilder SetPayIrAdditionalData(this IInvoiceBuilder builder, PayIrRequestAdditionalData data)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            return(builder.AddOrUpdateProperty(PayIrHelper.RequestAdditionalDataKey, data));
        }
        /// <summary>
        /// Sets a provider which generates unique tracking numbers for each payment requests.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="factory"></param>
        /// <exception cref="ArgumentNullException"></exception>
        public static IInvoiceBuilder SetTrackingNumberProvider(this IInvoiceBuilder builder, Func <IServiceProvider, ITrackingNumberProvider> factory)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            return(builder.SetTrackingNumberProvider(factory(builder.Services)));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Contains extra functions for Mellat Gateway.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="configureMellatInvoiceBuilder">Helps to build the extra functions of Mellat Gateway.</param>
        public static IInvoiceBuilder UseMellat(this IInvoiceBuilder builder, Action <IMellatGatewayInvoiceBuilder> configureMellatInvoiceBuilder)
        {
            if (configureMellatInvoiceBuilder == null)
            {
                throw new ArgumentNullException(nameof(configureMellatInvoiceBuilder));
            }

            UseMellat(builder);

            configureMellatInvoiceBuilder(new MellatGatewayInvoiceBuilder(builder));

            return(builder);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Sets some additional data for Parsian Gateway.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="additionalData"></param>
        public static IInvoiceBuilder SetParsianAdditionalData(this IInvoiceBuilder builder, ParsianGatewayAdditionalDataRequest additionalData)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (additionalData == null)
            {
                throw new ArgumentNullException(nameof(additionalData));
            }

            builder.AddOrUpdateProperty(AdditionalDataKey, additionalData);

            return(builder);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Sets additional data for <see cref="MellatGateway"/>.
        /// </summary>
        public static IInvoiceBuilder SetMellatAdditionalData(this IInvoiceBuilder builder, MellatGatewayAdditionalDataRequest request)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            builder.AddOrUpdateProperty(MellatHelper.AdditionalDataKey, request);

            return(builder);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Sets the gateway using the given name. The given name must match the values of
        /// <see cref="Gateway"/> enum.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="gatewayName"></param>
        /// <exception cref="GatewayNotFoundException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        public static IInvoiceBuilder UseGateway(this IInvoiceBuilder builder, string gatewayName)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (gatewayName == null)
            {
                throw new ArgumentNullException(nameof(gatewayName));
            }

            var gatewayType = GatewayHelper.FindGatewayTypeByName(gatewayName, throwException: true);

            return(builder.SetGatewayType(gatewayType));
        }
Ejemplo n.º 28
0
        /// <summary>
        /// The invoice will be sent to YekPay gateway.
        /// </summary>
        public static IInvoiceBuilder SetYekPayData(this IInvoiceBuilder builder, YekPayRequest yekPayRequest)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (yekPayRequest == null)
            {
                throw new ArgumentNullException(nameof(yekPayRequest));
            }

            SetYekPayRequest(builder, yekPayRequest);

            return(builder);
        }
        /// <summary>
        /// Uses the given account to communicate with the gateway.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="accountName">Name of the account.</param>
        public static IInvoiceBuilder UseAccount(this IInvoiceBuilder builder, string accountName)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (accountName.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException(nameof(accountName));
            }

            builder.AddAdditionalData(GatewayAccountKeyName, accountName);

            return(builder);
        }
        /// <summary>
        /// Sets the additional data for PayPing Gateway.
        /// </summary>
        public static IInvoiceBuilder SetPayPingData(this IInvoiceBuilder builder, PayPingRequest payPingRequest)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (payPingRequest == null)
            {
                throw new ArgumentNullException(nameof(payPingRequest));
            }

            builder.AddOrUpdateAdditionalData(PayPingRequestKey, payPingRequest);

            return(builder);
        }
 public CongestionChargeCalculator(ICongestionRateStore congestionRateStore, IInvoiceBuilder invoiceBuilder)
 {
     _congestionRateStore = congestionRateStore;
     _invoiceBuilder = invoiceBuilder;
 }