コード例 #1
0
        public async Task Invoice_Must_Have_The_Expected_AdditionalData()
        {
            const string expectedKey   = "key";
            const string expectedValue = "value";

            _builder.AddAdditionalData(expectedKey, expectedValue);

            var invoice = await _builder.BuildAsync();

            Assert.IsNotNull(invoice.AdditionalData);
            Assert.IsTrue(invoice.AdditionalData.ContainsKey(expectedKey));
            Assert.AreEqual(expectedValue, invoice.AdditionalData[expectedKey]);
        }
コード例 #2
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.ChangeAdditionalData(data =>
            {
                if (data.ContainsKey(MellatHelper.CumulativeAccountsKey))
                {
                    allAccounts = (List <MellatCumulativeDynamicAccount>)data[MellatHelper.CumulativeAccountsKey];
                }
                else
                {
                    allAccounts = new List <MellatCumulativeDynamicAccount>();
                }

                allAccounts.AddRange(accounts);
            });

            builder.AddAdditionalData(MellatHelper.CumulativeAccountsKey, allAccounts);

            return(builder);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        /// <summary>
        /// Appends the given dictionary to the additional data of the invoice.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="additionalData"></param>
        public static IInvoiceBuilder AddAdditionalData(this IInvoiceBuilder builder, IDictionary <string, object> additionalData)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (additionalData == null)
            {
                throw new ArgumentNullException(nameof(additionalData));
            }

            foreach (var data in additionalData)
            {
                builder.AddAdditionalData(data.Key, data.Value);
            }

            return(builder);
        }
コード例 #5
0
        public static IInvoiceBuilder AddMellatCumulativeAccounts(this IInvoiceBuilder builder, IList <MellatCumulativeDynamicAccount> accounts)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (accounts == null)
            {
                throw new ArgumentNullException(nameof(accounts));
            }
            if (accounts.Count == 0)
            {
                throw new ArgumentException("accounts cannot be an empty collection.", nameof(accounts));
            }

            IList <MellatCumulativeDynamicAccount> existingAccounts;

            if (builder.AdditionalData.ContainsKey(MellatHelper.CumulativeAccountsKey))
            {
                existingAccounts = (IList <MellatCumulativeDynamicAccount>)builder.AdditionalData[MellatHelper.CumulativeAccountsKey];
            }
            else
            {
                existingAccounts = new List <MellatCumulativeDynamicAccount>();
            }

            foreach (var account in accounts)
            {
                existingAccounts.Add(account);
            }

            builder.AdditionalData.Remove(MellatHelper.CumulativeAccountsKey);
            builder.AddAdditionalData(MellatHelper.CumulativeAccountsKey, existingAccounts);

            builder.UseGateway(Gateway.Mellat);

            return(builder);
        }