Example #1
0
        /// <summary>
        /// Marks an invoice as failed. This returns a
        /// new invoice collection and does not update the
        /// this invoice object.
        /// </summary>
        /// <returns>New Invoice Collection</returns>
        public InvoiceCollection MarkFailed()
        {
            var collection = new InvoiceCollection();

            Client.Instance.PerformRequest(
                Client.HttpRequestMethod.Put,
                memberUrl() + "/mark_failed",
                collection.ReadXml);
            return(collection);
        }
Example #2
0
        /// <summary>
        /// Use for Adyen HPP transaction requests. Runs validations
        /// but does not run any transactions.
        /// </summary>
        public static InvoiceCollection Pending(Purchase purchase)
        {
            var collection = new InvoiceCollection();

            Client.Instance.PerformRequest(Client.HttpRequestMethod.Post,
                                           UrlPrefix + "pending/",
                                           purchase.WriteXml,
                                           collection.ReadXml);

            return(collection);
        }
Example #3
0
        /// <summary>
        /// Previews a new invoice for the pending charges on an account
        /// </summary>
        public InvoiceCollection PreviewInvoicePendingCharges(Invoice invoice = null)
        {
            invoice = invoice ?? new Invoice();
            var collection = new InvoiceCollection();

            Client.Instance.PerformRequest(Client.HttpRequestMethod.Post,
                                           UrlPrefix + Uri.EscapeDataString(AccountCode) + "/invoices/preview",
                                           invoice.WriteXml,
                                           collection.ReadXml);

            return(collection);
        }
Example #4
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 "gateway_code":
                    GatewayCode = 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;

                case "shipping_method_code":
                    ShippingMethodCode = reader.ReadElementContentAsString();
                    break;

                case "shipping_amount_in_cents":
                    ShippingAmountInCents = reader.ReadElementContentAsInt();
                    break;
                }
            }
        }
 public bool Equals(InvoiceCollection collection)
 {
     return(ChargeInvoice == collection?.ChargeInvoice &&
            CreditInvoices == collection?.CreditInvoices);
 }