Esempio n. 1
0
        public void Donation_ToString_AllFieldsSet()
        {
            var expected = "Donated for: \"" + _targetDonation.Reason +
                           "\" Amount donated: \"" + _targetDonation.Amount +
                           "\" Date donated: \"" + _targetDonation.DonationDate.ToString("dd/MM/yyyy") +
                           "\" Comments: \"" + _targetDonation.Comments + "\"";
            var actual = _targetDonation.ToString();

            Assert.AreEqual(expected, actual);
        }
Esempio n. 2
0
        public void Donation_ToString_NoComment()
        {
            var target = new Donation {
                ID = _id, Reason = _reason, Amount = _amount, DonationDate = _donationDate
            };
            var expected = "Donated for: \"" + target.Reason +
                           "\" Amount donated: \"" + target.Amount +
                           "\" Date donated: \"" + target.DonationDate.ToString("dd/MM/yyyy") + "\"";
            var actual = target.ToString();

            Assert.AreEqual(expected, actual);
        }
        private static async Task <Attachment> BuildReceiptCardAsync(PaymentRecord paymentRecord, Donation donationItem)
        {
            var receiptItems = new List <ReceiptItem>();

            receiptItems.AddRange(paymentRecord.Items.Select <PaymentItem, ReceiptItem>(item =>
            {
                if (donationItem.ToString().Equals(item.Label))
                {
                    return(PaymentDialog.BuildReceiptItem(
                               donationItem.ToString(),
                               donationItem.Description,
                               $"{donationItem.Currency} {donationItem.Amount.ToString("F")}",
                               donationItem.Recipient.ImageUrl));
                }
                else
                {
                    return(PaymentDialog.BuildReceiptItem(
                               item.Label,

                               null,
                               $"{item.Amount.Currency} {item.Amount.Value}",
                               null));
                }
            }));

            var receiptCard = new ReceiptCard
            {
                Title = Resources.RootDialog_Receipt_Title,
                Facts = new List <Fact>
                {
                    new Fact(Resources.RootDialog_Receipt_OrderID, paymentRecord.OrderId.ToString()),
                    new Fact(Resources.RootDialog_Receipt_PaymentMethod, paymentRecord.MethodName)
                },
                Items = receiptItems,
                Tax   = null, // Sales Tax is a displayed line item, leave this blank
                Total = $"{paymentRecord.Total.Amount.Currency} {paymentRecord.Total.Amount.Value}"
            };

            return(receiptCard.ToAttachment());
        }
        public void Add(Donation donation)
        {
            Log.InfoFormat("Entering add function with value {0}", donation.ToString());
            IDbConnection connection = DbUtils.GetConnection();
            {
                Log.Info("DB connection established");
                using (var command = connection.CreateCommand())
                {
                    Log.Info("Creating command");
                    command.CommandText =
                        "insert into Donations(Did, Cid, SumDonated) values (@did, @cid, @sumDonated)";

                    var did = command.CreateParameter();
                    did.ParameterName = "@did";
                    did.Value         = donation.DonorId;
                    command.Parameters.Add(did);

                    var cid = command.CreateParameter();
                    cid.ParameterName = "@cid";
                    cid.Value         = donation.CaseId;
                    command.Parameters.Add(cid);

                    var sumDonated = command.CreateParameter();
                    sumDonated.ParameterName = "@sumDonated";
                    sumDonated.Value         = donation.SumDonated;
                    command.Parameters.Add(sumDonated);

                    int result = command.ExecuteNonQuery();
                    if (result == 0)
                    {
                        Log.InfoFormat("NOT EXECUTED: {0}", command.CommandText);
                    }
                    else
                    {
                        Log.InfoFormat("Executed command: {0}", command.CommandText);
                    }
                }
            }
        }
        private Attachment BuildPaymentCardAsync(string cartId, Donation item)
        {
            var heroCard = new HeroCard
            {
                Title    = item.ToString(),
                Subtitle = $"{item.Currency} {item.Amount.ToString("F")}",
                Text     = item.DonorName,

                /*
                 * Images = new List<CardImage>
                 * {
                 *  new CardImage
                 *  {
                 *      Url = item.Recipient.ImageUrl
                 *  }
                 * },
                 */
                Buttons = new List <CardAction>
                {
                    new CardAction
                    {
                        Title = "Pay",
                        Type  = PaymentRequest.PaymentActionType,
                        Value = BuildPaymentRequest(cartId, item, PaymentService.GetAllowedPaymentMethods())
                    },
                    new CardAction
                    {
                        Title = "Finish",
                        Type  = "postBack",
                        Value = "finish",
                    }
                }
            };

            return(heroCard.ToAttachment());
        }
        private static PaymentRequest BuildPaymentRequest(string cartId, Donation item, MicrosoftPayMethodData methodData)
        {
            return(new PaymentRequest
            {
                Id = cartId,
                Expires = TimeSpan.FromDays(1).ToString(),
                MethodData = new List <PaymentMethodData>
                {
                    methodData.ToPaymentMethodData()
                },
                Details = new PaymentDetails
                {
                    Total = new PaymentItem
                    {
                        Label = Resources.Wallet_Label_Total,
                        Amount = new PaymentCurrencyAmount
                        {
                            Currency = item.Currency,
                            Value = Convert.ToString(item.Amount, CultureInfo.InvariantCulture)
                        },
                        Pending = true
                    },
                    DisplayItems = new List <PaymentItem>
                    {
                        new PaymentItem
                        {
                            Label = item.ToString(),
                            Amount = new PaymentCurrencyAmount
                            {
                                Currency = item.Currency,
                                Value = item.Amount.ToString(CultureInfo.InvariantCulture)
                            }
                        },

                        /*
                         * new PaymentItem
                         * {
                         *  Label = Resources.Wallet_Label_Shipping,
                         *  Amount = new PaymentCurrencyAmount
                         *  {
                         *      Currency = item.Currency,
                         *      Value = "0.00"
                         *  },
                         *  Pending = true
                         * },
                         * new PaymentItem
                         * {
                         *  Label = Resources.Wallet_Label_Tax,
                         *  Amount = new PaymentCurrencyAmount
                         *  {
                         *      Currency = item.Currency,
                         *      Value = "0.00"
                         *  },
                         *  Pending = true
                         * }
                         */
                    }
                },
                Options = new PaymentOptions
                {
                    RequestShipping = false,
                    RequestPayerEmail = true,
                    RequestPayerName = false,
                    RequestPayerPhone = false,
                    //ShippingType = PaymentShippingTypes.Shipping
                }
            });
        }