public override int GetHashCode()
        {
            int?shippingMethodHashCode = ShippingMethodCode?.GetHashCode();
            int?shippingAmountHashCode = ShippingAmountInCents?.GetHashCode();

            if (shippingMethodHashCode != null && shippingAmountHashCode != null)
            {
                return((int)shippingMethodHashCode ^ (int)shippingAmountHashCode);
            }

            return(0);
        }
Example #2
0
        internal void WriteSubscriptionXml(XmlTextWriter xmlWriter, bool embedded)
        {
            xmlWriter.WriteStartElement("subscription"); // Start: subscription

            xmlWriter.WriteElementString("plan_code", PlanCode);

            if (!embedded)
            {
                // <account> and billing info
                Account.WriteXml(xmlWriter);
                xmlWriter.WriteElementString("currency", Currency);
                xmlWriter.WriteElementString("customer_notes", CustomerNotes);
                xmlWriter.WriteElementString("terms_and_conditions", TermsAndConditions);
                xmlWriter.WriteElementString("vat_reverse_charge_notes", VatReverseChargeNotes);
                xmlWriter.WriteElementString("po_number", PoNumber);
            }

            xmlWriter.WriteIfCollectionHasAny("subscription_add_ons", AddOns);

            xmlWriter.WriteStringIfValid("coupon_code", _couponCode);

            if (_couponCodes != null && _couponCodes.Length != 0)
            {
                xmlWriter.WriteStartElement("coupon_codes");
                foreach (var _coupon_code in _couponCodes)
                {
                    xmlWriter.WriteElementString("coupon_code", _coupon_code);
                }
                xmlWriter.WriteEndElement();
            }

            if (UnitAmountInCents.HasValue)
            {
                xmlWriter.WriteElementString("unit_amount_in_cents", UnitAmountInCents.Value.AsString());
            }

            xmlWriter.WriteElementString("quantity", Quantity.AsString());

            if (TrialPeriodEndsAt.HasValue)
            {
                xmlWriter.WriteElementString("trial_ends_at", TrialPeriodEndsAt.Value.ToString("s"));
            }

            if (BankAccountAuthorizedAt.HasValue)
            {
                xmlWriter.WriteElementString("bank_account_authorized_at", BankAccountAuthorizedAt.Value.ToString("s"));
            }

            if (StartsAt.HasValue)
            {
                xmlWriter.WriteElementString("starts_at", StartsAt.Value.ToString("s"));
            }

            if (TotalBillingCycles.HasValue)
            {
                xmlWriter.WriteElementString("total_billing_cycles", TotalBillingCycles.Value.AsString());
            }

            if (FirstRenewalDate.HasValue)
            {
                xmlWriter.WriteElementString("first_renewal_date", FirstRenewalDate.Value.ToString("s"));
            }

            if (Bulk.HasValue)
            {
                xmlWriter.WriteElementString("bulk", Bulk.ToString().ToLower());
            }

            if (CollectionMethod.Like("manual"))
            {
                xmlWriter.WriteElementString("collection_method", "manual");

                if (NetTerms.HasValue)
                {
                    xmlWriter.WriteElementString("net_terms", NetTerms.Value.AsString());
                }
            }
            else if (CollectionMethod.Like("automatic"))
            {
                xmlWriter.WriteElementString("collection_method", "automatic");
            }

            if (ShippingAddressId.HasValue)
            {
                xmlWriter.WriteElementString("shipping_address_id", ShippingAddressId.Value.ToString());
            }

            if (ImportedTrial.HasValue)
            {
                xmlWriter.WriteElementString("imported_trial", ImportedTrial.Value.ToString().ToLower());
            }

            if (RevenueScheduleType.HasValue)
            {
                xmlWriter.WriteElementString("revenue_schedule_type", RevenueScheduleType.Value.ToString().EnumNameToTransportCase());
            }

            if (RemainingBillingCycles.HasValue)
            {
                xmlWriter.WriteElementString("remaining_billing_cycles", RemainingBillingCycles.Value.AsString());
            }

            if (AutoRenew.HasValue)
            {
                xmlWriter.WriteElementString("auto_renew", AutoRenew.Value.AsString());
            }

            if (RenewalBillingCycles.HasValue)
            {
                xmlWriter.WriteElementString("renewal_billing_cycles", RenewalBillingCycles.Value.AsString());
            }

            xmlWriter.WriteIfCollectionHasAny("custom_fields", CustomFields);

            if (!ShippingMethodCode.IsNullOrEmpty())
            {
                xmlWriter.WriteElementString("shipping_method_code", ShippingMethodCode);
            }

            if (ShippingAmountInCents.HasValue)
            {
                xmlWriter.WriteElementString("shipping_amount_in_cents", ShippingAmountInCents.Value.AsString());
            }

            xmlWriter.WriteEndElement(); // End: subscription
        }