Ejemplo n.º 1
0
        protected AdminWS.NumberedOrderRow ConvertNumberedOrderRowBuilderToAdminWSNumberedOrderRow(NumberedOrderRowBuilder norb)
        {
            var nor = new AdminWS.NumberedOrderRow()
            {
                ArticleNumber = norb.GetArticleNumber(),
                Description   = GetDescriptionFromBuilderOrderRow(norb.GetName(), norb.GetDescription()),
                //DiscountAmount = ,
                //DiscountAmountIncludingVat = ,
                DiscountPercent = norb.GetDiscountPercent(),
                //ExtensionData = ,
                NumberOfUnits     = norb.GetQuantity(),
                PriceIncludingVat = norb.GetAmountIncVat().HasValue, // true iff we have set amountIncVat
                PricePerUnit      = (decimal)(norb.GetAmountIncVat() ?? norb.GetAmountExVat()),
                VatPercent        = GetVatPercentFromBuilderOrderRow(norb.GetVatPercent(), norb.GetAmountIncVat(), norb.GetAmountExVat()),
                //DiscountAmount = ,                    // not yet supported
                //DiscountAmountIncludingVat = ,        // not yet supported
                RowNumber = norb.GetRowNumber()
            };

            return(nor);
        }
        public QueryResponse(XmlDocument response) : base(response)
        {
            if (response.SelectSingleNode("/response/transaction") != null)
            {
                TransactionCustomer customer = new TransactionCustomer(
                    AttributeString(response, "/response/transaction/customer", "id"),
                    TextString(response, "/response/transaction/customer/firstname"),
                    TextString(response, "/response/transaction/customer/lastname"),
                    TextString(response, "/response/transaction/customer/initials"),
                    TextString(response, "/response/transaction/customer/fullname"),
                    TextString(response, "/response/transaction/customer/email"),
                    TextString(response, "/response/transaction/customer/ssn"),
                    TextString(response, "/response/transaction/customer/address"),
                    TextString(response, "/response/transaction/customer/address2"),
                    TextString(response, "/response/transaction/customer/city"),
                    TextString(response, "/response/transaction/customer/country"),
                    TextString(response, "/response/transaction/customer/zip"),
                    TextString(response, "/response/transaction/customer/phone"),
                    TextString(response, "/response/transaction/customer/vatnumber"),
                    TextString(response, "/response/transaction/customer/housenumber"),
                    TextString(response, "/response/transaction/customer/companyname")
                    );

                Transaction = new Transaction(
                    TextString(response, "/response/transaction/customerrefno"),
                    TextInt(response, "/response/transaction/merchantid").Value,
                    TextString(response, "/response/transaction/status"),
                    MinorCurrencyToDecimalAmount(TextInt(response, "/response/transaction/amount").Value),
                    TextString(response, "/response/transaction/currency"),
                    MinorCurrencyToDecimalAmount(TextInt(response, "/response/transaction/vat")),
                    MinorCurrencyToDecimalAmount(TextInt(response, "/response/transaction/capturedamount")),
                    MinorCurrencyToDecimalAmount(TextInt(response, "/response/transaction/authorizedamount")),
                    DateTime.Parse(TextString(response, "/response/transaction/created")),
                    TextString(response, "/response/transaction/creditstatus"),
                    MinorCurrencyToDecimalAmount(TextInt(response, "/response/transaction/creditedamount")),
                    TextInt(response, "/response/transaction/merchantresponsecode"),
                    TextString(response, "/response/transaction/paymentmethod"),
                    TextString(response, "/response/transaction/cardtype"),
                    TextString(response, "/response/transaction/callbackurl"),
                    TextString(response, "/response/transaction/subscriptionid"),
                    TextString(response, "/response/transaction/subscriptiontype"),
                    TextString(response, "/response/transaction/eci"),
                    TextString(response, "/response/transaction/mdstatus"),
                    TextString(response, "/response/transaction/expiryyear"),
                    TextString(response, "/response/transaction/expirymonth"),
                    TextString(response, "/response/transaction/ch_name"),
                    TextString(response, "/response/transaction/authcode"),
                    customer
                    );

                var enumerator = response.SelectNodes("/response/transaction/orderrows/row").GetEnumerator();
                var rowNumber  = 1; // NumberedOrderRows are 1-indexed
                while (enumerator.MoveNext())
                {
                    var xmlNode = (XmlNode)enumerator.Current;

                    Transaction.OrderRows.Add(new TransactionOrderRow(
                                                  TextString(xmlNode, "./id"),
                                                  TextString(xmlNode, "./name"),
                                                  MinorCurrencyToDecimalAmount(TextInt(xmlNode, "./amount").Value),
                                                  MinorCurrencyToDecimalAmount(TextInt(xmlNode, "./vat")),
                                                  TextString(xmlNode, "./description"),
                                                  TextDecimal(xmlNode, "./quantity").GetValueOrDefault(1),
                                                  TextString(xmlNode, "./sku"),
                                                  TextString(xmlNode, "./unit")
                                                  ));

                    decimal row_amount      = MinorCurrencyToDecimalAmount(TextInt(xmlNode, "./amount").Value);
                    decimal row_vat         = MinorCurrencyToDecimalAmount(TextInt(xmlNode, "./vat")) ?? 0M;
                    decimal row_amountExVat = (row_amount - row_vat);
                    decimal row_vatPercent  = (row_vat / (row_amountExVat)) * 100;

                    var numberedOrderRow = new NumberedOrderRowBuilder()
                                           .SetRowNumber(rowNumber++)
                                           .SetCreditInvoiceId(null)
                                           .SetInvoiceId(null)
                                           .SetStatus(null)
                                           .SetArticleNumber(TextString(xmlNode, "./sku"))
                                           .SetName(TextString(xmlNode, "./name"))
                                           .SetDescription(TextString(xmlNode, "./description"))
                                           .SetAmountExVat(row_amountExVat)
                                           .SetAmountIncVat(row_amount)
                                           .SetVatPercent(row_vatPercent)
                                           .SetQuantity(TextDecimal(xmlNode, "./quantity").GetValueOrDefault(1))
                                           .SetUnit(TextString(xmlNode, "./unit"))
                                           .SetVatDiscount(0)
                                           .SetDiscountPercent(0)
                    ;
                    Transaction.NumberedOrderRows.Add(numberedOrderRow);
                }
            }
        }
 public UpdateOrderRowsBuilder AddUpdateOrderRow(NumberedOrderRowBuilder numberedOrderRow)
 {
     NumberedOrderRows.Add(numberedOrderRow);
     return(this);
 }