Exemplo n.º 1
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)));
        }
        /// <summary>
        /// The invoice will be sent to ZarinPal gateway.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="zarinPalInvoice">Describes an invoice for ZarinPal gateway.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public static IInvoiceBuilder UseZarinPal(this IInvoiceBuilder builder, ZarinPalInvoice zarinPalInvoice)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.AddFormatter(invoice =>
            {
                if (invoice.AdditionalData.ContainsKey(ZarinPalHelper.ZarinPalRequestAdditionalKeyName))
                {
                    invoice.AdditionalData.Remove(ZarinPalHelper.ZarinPalRequestAdditionalKeyName);
                }

                invoice.AdditionalData.Add(ZarinPalHelper.ZarinPalRequestAdditionalKeyName, zarinPalInvoice);
            });

            return(builder.SetGateway(ZarinPalGateway.Name));
        }
Exemplo n.º 3
0
        internal static void SetYekPayRequest(this IInvoiceBuilder builder, YekPayRequest yekPayRequest)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (yekPayRequest == null)
            {
                throw new ArgumentNullException(nameof(yekPayRequest));
            }

            builder.AddFormatter(invoice =>
            {
                if (invoice.AdditionalData.ContainsKey(YekPayRequestKey))
                {
                    invoice.AdditionalData.Remove(YekPayRequestKey);
                }

                invoice.AdditionalData.Add(YekPayRequestKey, yekPayRequest);
            });
        }
Exemplo n.º 4
0
        public async Task Invoice_Formatter_Must_Apply_Value_Correctly()
        {
            const long    expectedTrackingNumber = 1000;
            const decimal expectedAmount         = 1000;
            const string  expectedCallbackUrl    = "http://test.com";
            const string  expectedGateway        = "Gateway";

            _builder.AddFormatter(_ =>
            {
                _.TrackingNumber = expectedTrackingNumber;
                _.Amount         = expectedAmount;
                _.CallbackUrl    = new CallbackUrl(expectedCallbackUrl);
                _.GatewayName    = expectedGateway;
            });

            var invoice = await _builder.BuildAsync();

            Assert.AreEqual(expectedTrackingNumber, invoice.TrackingNumber);
            Assert.AreEqual(expectedAmount, (decimal)invoice.Amount);
            Assert.AreEqual(expectedCallbackUrl, (string)invoice.CallbackUrl);
            Assert.AreEqual(expectedGateway, invoice.GatewayName);
        }
 /// <summary>
 /// Generates a new tracking number randomly in <see cref="long"/> range.
 /// </summary>
 public static IInvoiceBuilder UseAutoRandomTrackingNumber(this IInvoiceBuilder builder) =>
 builder.AddFormatter <AutoRandomTrackingNumber>();