public static RecurlyList<Invoice> List(Invoice.InvoiceState state)
 {
     return new InvoiceList(Invoice.UrlPrefix + "?state=" + state.ToString().EnumNameToTransportCase());
 }
        /// <summary>
        /// Create an Invoice if there are outstanding charges on an account. If there are no outstanding
        /// charges, null is returned.
        /// </summary>
        /// <param name="accountCode">Account code</param>
        /// <returns></returns>
        public static Invoice Create(string accountCode)
        {
            var invoice = new Invoice();

            var statusCode = Client.Instance.PerformRequest(Client.HttpRequestMethod.Post,
                "/accounts/" + Uri.EscapeUriString(accountCode) + Invoice.UrlPrefix,
                invoice.ReadXml);

            return (int)statusCode == ValidationException.HttpStatusCode ? null : invoice;
        }
        /// <summary>
        /// Look up an Invoice.
        /// </summary>
        /// <param name="invoiceNumber">Invoice Number</param>
        /// <returns></returns>
        public static Invoice Get(int invoiceNumber)
        {
            var invoice = new Invoice();

            var statusCode = Client.Instance.PerformRequest(Client.HttpRequestMethod.Get,
                Invoice.UrlPrefix + invoiceNumber,
                invoice.ReadXml);

            return statusCode == HttpStatusCode.NotFound ? null : invoice;
        }
 public bool Equals(Invoice invoice)
 {
     return Uuid == invoice.Uuid;
 }
        public Invoice Refund(IEnumerable<Adjustment> adjustments, bool prorate = false, int quantity = 0)
        {
            var refunds = new RefundList(adjustments, prorate, quantity);
            var invoice = new Invoice();

            var response = Client.Instance.PerformRequest(Client.HttpRequestMethod.Post,
                UrlPrefix + InvoiceNumber + "/refund",
                refunds.WriteXml,
                invoice.ReadXml);

            if (HttpStatusCode.Created == response || HttpStatusCode.OK == response)
                return invoice;
            else
                return null;
        }
        public Invoice RefundAmount(int amountInCents, RefundOrderPriority refundPriority = RefundOrderPriority.Credit)
        {
            var refundInvoice = new Invoice();
            var refund = new OpenAmountRefund(amountInCents, refundPriority);

            var response = Client.Instance.PerformRequest(Client.HttpRequestMethod.Post,
                memberUrl() + "/refund",
                refund.WriteXml,
                refundInvoice.ReadXml);

            if (HttpStatusCode.Created == response || HttpStatusCode.OK == response)
                return refundInvoice;
            else
                return null;
        }
        /// <summary>
        /// Previews a new invoice for the pending charges on an account
        /// </summary>
        public Invoice PreviewInvoicePendingCharges()
        {
            var i = new Invoice();
            Client.Instance.PerformRequest(Client.HttpRequestMethod.Post,
                UrlPrefix + Uri.EscapeUriString(AccountCode) + "/invoices/preview",
                i.ReadXml);

            return i;
        }
 public bool Equals(Invoice invoice)
 {
     return(Uuid == invoice.Uuid);
 }
        internal override void ReadXml(XmlTextReader reader)
        {
            _saved = true;

            string href;

            while (reader.Read())
            {
                if (reader.Name == "subscription" && reader.NodeType == XmlNodeType.EndElement)
                    break;

                if (reader.NodeType != XmlNodeType.Element) continue;

                DateTime dateVal;
                Int32 billingCycles;

                switch (reader.Name)
                {
                    case "account":
                        href = reader.GetAttribute("href");
                        if (null != href)
                            _accountCode = Uri.UnescapeDataString(href.Substring(href.LastIndexOf("/") + 1));
                        break;

                    case "plan":
                        ReadPlanXml(reader);
                        break;

                    case "uuid":
                        Uuid = reader.ReadElementContentAsString();
                        break;

                    case "state":
                        State = reader.ReadElementContentAsString().ParseAsEnum<SubscriptionState>();
                        break;

                    case "unit_amount_in_cents":
                        UnitAmountInCents = reader.ReadElementContentAsInt();
                        break;

                    case "currency":
                        Currency = reader.ReadElementContentAsString();
                        break;

                    case "quantity":
                        Quantity = reader.ReadElementContentAsInt();
                        break;

                    case "activated_at":
                        if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                            ActivatedAt = dateVal;
                        break;

                    case "canceled_at":
                        if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                            CanceledAt = dateVal;
                        break;

                    case "expires_at":
                        if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                            ExpiresAt = dateVal;
                        break;

                    case "current_period_started_at":
                        if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                            CurrentPeriodStartedAt = dateVal;
                        break;

                    case "current_period_ends_at":
                        if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                            CurrentPeriodEndsAt = dateVal;
                        break;

                    case "trial_started_at":
                        if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                            TrialPeriodStartedAt = dateVal;
                        break;

                    case "trial_ends_at":
                        if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                            _trialPeriodEndsAt = dateVal;
                        break;

                    case "bank_account_authorized_at":
                        if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                            BankAccountAuthorizedAt = dateVal;
                        break;

                    case "subscription_add_ons":
                        // overwrite existing list with what came back from Recurly
                        AddOns = new SubscriptionAddOnList(this);
                        AddOns.ReadXml(reader);
                        break;

                    case "invoice":
                        href = reader.GetAttribute("href");
                        if (!href.IsNullOrEmpty())
                            _invoiceNumber = Uri.UnescapeDataString(href.Substring(href.LastIndexOf("/") + 1));
                        else
                            InvoicePreview = new Invoice(reader);
                        break;

                    case "pending_subscription":
                        PendingSubscription = new Subscription { IsPendingSubscription = true };
                        PendingSubscription.ReadPendingSubscription(reader);
                        // TODO test all returned properties are read
                        break;

                    case "collection_method":
                        CollectionMethod = reader.ReadElementContentAsString();
                        break;

                    case "net_terms":
                        NetTerms = reader.ReadElementContentAsInt();
                        break;

                    case "po_number":
                        PoNumber = reader.ReadElementContentAsString();
                        break;

                    case "total_billing_cycles":
                        if (Int32.TryParse(reader.ReadElementContentAsString(), out billingCycles))
                            TotalBillingCycles = billingCycles;
                        break;
                        
                    case "remaining_billing_cycles":
                        if (Int32.TryParse(reader.ReadElementContentAsString(), out billingCycles))
                            RemainingBillingCycles = billingCycles;
                        break;

                    case "tax_in_cents":
                        TaxInCents = reader.ReadElementContentAsInt();
                        break;

                    case "tax_type":
                        TaxType = reader.ReadElementContentAsString();
                        break;

                    case "tax_rate":
                        TaxRate = reader.ReadElementContentAsDecimal();
                        break;

                    case "customer_notes":
                        CustomerNotes = reader.ReadElementContentAsString();
                        break;

                    case "terms_and_conditions":
                        TermsAndConditions = reader.ReadElementContentAsString();
                        break;

                    case "vat_reverse_charge_notes":
                        VatReverseChargeNotes = reader.ReadElementContentAsString();
                        break;

                    case "address":
                        Address = new Address(reader);
                        break;
                }
            }
        }
Exemple #10
0
        internal override void ReadXml(XmlTextReader reader)
        {
            _saved = true;

            string href;

            while (reader.Read())
            {
                if (reader.Name == "subscription" && reader.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }

                if (reader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                DateTime dateVal;
                Int32    billingCycles;
                Int32    pauseCycles;

                switch (reader.Name)
                {
                case "account":
                    href = reader.GetAttribute("href");
                    if (null != href)
                    {
                        _accountCode = Uri.UnescapeDataString(href.Substring(href.LastIndexOf("/") + 1));
                    }
                    break;

                case "plan":
                    ReadPlanXml(reader);
                    break;

                case "uuid":
                    Uuid = reader.ReadElementContentAsString();
                    break;

                case "state":
                    State = reader.ReadElementContentAsString().ParseAsEnum <SubscriptionState>();
                    break;

                case "unit_amount_in_cents":
                    UnitAmountInCents = reader.ReadElementContentAsInt();
                    break;

                case "currency":
                    Currency = reader.ReadElementContentAsString();
                    break;

                case "quantity":
                    Quantity = reader.ReadElementContentAsInt();
                    break;

                case "activated_at":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                    {
                        ActivatedAt = dateVal;
                    }
                    break;

                case "canceled_at":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                    {
                        CanceledAt = dateVal;
                    }
                    break;

                case "expires_at":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                    {
                        ExpiresAt = dateVal;
                    }
                    break;

                case "updated_at":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                    {
                        UpdatedAt = dateVal;
                    }
                    ;
                    break;

                case "current_period_started_at":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                    {
                        CurrentPeriodStartedAt = dateVal;
                    }
                    break;

                case "current_period_ends_at":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                    {
                        CurrentPeriodEndsAt = dateVal;
                    }
                    break;

                case "trial_started_at":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                    {
                        TrialPeriodStartedAt = dateVal;
                    }
                    break;

                case "trial_ends_at":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                    {
                        _trialPeriodEndsAt = dateVal;
                    }
                    break;

                case "bank_account_authorized_at":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                    {
                        BankAccountAuthorizedAt = dateVal;
                    }
                    break;

                case "subscription_add_ons":
                    // overwrite existing list with what came back from Recurly
                    AddOns = new SubscriptionAddOnList(this);
                    AddOns.ReadXml(reader);
                    break;

                case "custom_fields":
                    CustomFields = new List <CustomField>();
                    while (reader.Read())
                    {
                        if (reader.Name == "custom_fields" && reader.NodeType == XmlNodeType.EndElement)
                        {
                            break;
                        }

                        if (reader.NodeType == XmlNodeType.Element && reader.Name == "custom_field")
                        {
                            CustomFields.Add(new CustomField(reader));
                        }
                    }
                    break;

                case "invoice":
                    href = reader.GetAttribute("href");
                    if (!href.IsNullOrEmpty())
                    {
                        _invoiceNumber = Uri.UnescapeDataString(href.Substring(href.LastIndexOf("/") + 1));
                    }
                    else
                    {
                        InvoicePreview = new Invoice(reader);
                    }
                    break;

                case "invoice_collection":
                    InvoiceCollection = new InvoiceCollection(reader);
                    break;

                case "pending_subscription":
                    PendingSubscription = new Subscription {
                        IsPendingSubscription = true
                    };
                    PendingSubscription.ReadPendingSubscription(reader);
                    // TODO test all returned properties are read
                    break;

                case "collection_method":
                    CollectionMethod = reader.ReadElementContentAsString();
                    break;

                case "net_terms":
                    NetTerms = reader.ReadElementContentAsInt();
                    break;

                case "po_number":
                    PoNumber = reader.ReadElementContentAsString();
                    break;

                case "total_billing_cycles":
                    if (Int32.TryParse(reader.ReadElementContentAsString(), out billingCycles))
                    {
                        TotalBillingCycles = billingCycles;
                    }
                    break;

                case "remaining_billing_cycles":
                    if (Int32.TryParse(reader.ReadElementContentAsString(), out billingCycles))
                    {
                        RemainingBillingCycles = billingCycles;
                    }
                    break;

                case "remaining_pause_cycles":
                    if (Int32.TryParse(reader.ReadElementContentAsString(), out pauseCycles))
                    {
                        RemainingPauseCycles = pauseCycles;
                    }
                    break;

                case "tax_in_cents":
                    TaxInCents = reader.ReadElementContentAsInt();
                    break;

                case "tax_type":
                    TaxType = reader.ReadElementContentAsString();
                    break;

                case "tax_rate":
                    TaxRate = reader.ReadElementContentAsDecimal();
                    break;

                case "customer_notes":
                    CustomerNotes = reader.ReadElementContentAsString();
                    break;

                case "terms_and_conditions":
                    TermsAndConditions = reader.ReadElementContentAsString();
                    break;

                case "vat_reverse_charge_notes":
                    VatReverseChargeNotes = reader.ReadElementContentAsString();
                    break;

                case "address":
                    Address = new Address(reader);
                    break;

                case "started_with_gift":
                    StartedWithGiftCard = reader.ReadElementContentAsBoolean();
                    break;

                case "converted_at":
                    DateTime date;
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out date))
                    {
                        ConvertedAt = date;
                    }
                    break;

                case "no_billing_info_reason":
                    NoBillingInfoReason = reader.ReadElementContentAsString();
                    break;

                case "imported_trial":
                    ImportedTrial = reader.ReadElementContentAsBoolean();
                    break;

                case "revenue_schedule_type":
                    var revenueScheduleType = reader.ReadElementContentAsString();
                    if (!revenueScheduleType.IsNullOrEmpty())
                    {
                        RevenueScheduleType = revenueScheduleType.ParseAsEnum <Adjustment.RevenueSchedule>();
                    }
                    break;

                case "auto_renew":
                    bool b;
                    if (bool.TryParse(reader.ReadElementContentAsString(), out b))
                    {
                        AutoRenew = b;
                    }
                    break;

                case "renewal_billing_cycles":
                    int i;
                    if (int.TryParse(reader.ReadElementContentAsString(), out i))
                    {
                        RenewalBillingCycles = i;
                    }
                    break;

                case "current_term_started_at":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                    {
                        CurrentTermStartedAt = dateVal;
                    }
                    break;

                case "current_term_ends_at":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                    {
                        CurrentTermEndsAt = dateVal;
                    }
                    break;

                case "first_bill_date":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                    {
                        FirstBillDate = dateVal;
                    }
                    break;

                case "next_bill_date":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                    {
                        NextBillDate = dateVal;
                    }
                    break;
                }
            }
        }
Exemple #11
0
        /// <summary>
        /// Look up an Invoice.
        /// </summary>
        /// <param name="invoiceNumber">Invoice Number</param>
        /// <returns></returns>
        public static Invoice Get(int invoiceNumber)
        {
            Invoice invoice = new Invoice();

            HttpStatusCode statusCode = Client.PerformRequest(Client.HttpRequestMethod.Get,
                UrlPrefix + invoiceNumber.ToString(),
                new Client.ReadXmlDelegate(invoice.ReadXml));

            if (statusCode == HttpStatusCode.NotFound)
                return null;

            return invoice;
        }
Exemple #12
0
        /// <summary>
        /// Create an Invoice if there are outstanding charges on an account. If there are no outstanding
        /// charges, null is returned.
        /// </summary>
        /// <param name="accountCode">Account code</param>
        /// <returns></returns>
        public static Invoice Create(string accountCode)
        {
            Invoice invoice = new Invoice();

            HttpStatusCode statusCode = Client.PerformRequest(Client.HttpRequestMethod.Post,
                "/accounts/" + System.Uri.EscapeUriString(accountCode) + UrlPrefix,
                new Client.ReadXmlDelegate(invoice.ReadXml));

            if ((int)statusCode == ValidationException.HttpStatusCode)
                return null;

            return invoice;
        }
Exemple #13
0
        /// <summary>
        /// Posts pending charges on an account
        /// </summary>
        public Invoice InvoicePendingCharges()
        {
            Invoice i = new Invoice();
            Client.PerformRequest(Client.HttpRequestMethod.Post,
                UrlPrefix + System.Uri.EscapeUriString(this.AccountCode) + "/invoices"
               , new Client.ReadXmlDelegate(i.ReadXml));

            return i;
        }
 internal OpenAmountRefund(int amountInCents, Invoice.RefundOrderPriority refundPriority = Invoice.RefundOrderPriority.Credit)
 {
     AmountInCents = amountInCents;
     RefundPriority = refundPriority;
 }