示例#1
0
        /// <summary>
        /// Card constructor with all available fields.
        /// </summary>
        /// <param name="number">the card number</param>
        /// <param name="expMonth">the expiry month</param>
        /// <param name="expYear">the expiry year</param>
        /// <param name="cvc">the CVC code</param>
        /// <param name="name">the cardholder name</param>
        /// <param name="addressLine1">the first line of the billing address</param>
        /// <param name="addressLine2">the second line of the billing address</param>
        /// <param name="addressCity">the city of the billing address</param>
        /// <param name="addressState">the state of the billing address</param>
        /// <param name="addressZip">the zip code of the billing address</param>
        /// <param name="addressCountry">the country of the billing address</param>
        /// <param name="brand">brand of this card</param>
        /// <param name="last4">last 4 digits of the card</param>
        /// <param name="fingerprint">the card fingerprint</param>
        /// <param name="funding">the funding type of the card</param>
        /// <param name="country">ISO country code of the card itself</param>
        /// <param name="currency">the currency of the card</param>
        /// <param name="id">the cardId</param>
        public Card(
            String number,
            int expMonth,
            int expYear,
            string cvc,
            string name,
            string addressLine1,
            string addressLine2,
            string addressCity,
            string addressState,
            string addressZip,
            string addressCountry,
            string brand,
            string last4,
            string fingerprint,
            string funding,
            string country,
            string currency,
            string id)
        {
            Number         = StripeTextUtils.NullIfBlank(NormalizeCardNumber(number));
            ExpiryMonth    = expMonth;
            ExpiryYear     = expYear;
            CVC            = StripeTextUtils.NullIfBlank(cvc);
            Name           = StripeTextUtils.NullIfBlank(name);
            AddressLine1   = StripeTextUtils.NullIfBlank(addressLine1);
            AddressLine2   = StripeTextUtils.NullIfBlank(addressLine2);
            AddressCity    = StripeTextUtils.NullIfBlank(addressCity);
            AddressState   = StripeTextUtils.NullIfBlank(addressState);
            AddressZip     = StripeTextUtils.NullIfBlank(addressZip);
            AddressCountry = StripeTextUtils.NullIfBlank(addressCountry);
            Brand          = StripeTextUtils.AsCardBrand(brand) == null?GetBrand() : brand;

            Last4 = StripeTextUtils.NullIfBlank(last4) == null?GetLast4() : last4;

            Fingerprint = StripeTextUtils.NullIfBlank(fingerprint);
            Funding     = StripeTextUtils.AsFundingType(funding);
            Country     = StripeTextUtils.NullIfBlank(country);
            Currency    = StripeTextUtils.NullIfBlank(currency);
            Id          = StripeTextUtils.NullIfBlank(id);
        }
        /// <summary>
        /// A utility function to map the fields of a <see cref="Card"/> object into a <see langword="Dictionary"/> we
        /// can use in network communications.
        /// </summary>
        /// <param name="card">the <see cref="Card"/> to be read</param>
        /// <returns>a <see langword="Dictionary"/> containing the appropriate values read from the card</returns>
        public static Dictionary <string, string> HashMapFromCard(Card card)
        {
            var cardParams = new Dictionary <string, string>();

            cardParams["card[number]"]          = StripeTextUtils.NullIfBlank(card.Number);
            cardParams["card[cvc]"]             = StripeTextUtils.NullIfBlank(card.CVC);
            cardParams["card[exp_month]"]       = card.ExpiryMonth.ToString();
            cardParams["card[exp_year]"]        = card.ExpiryYear.ToString();
            cardParams["card[name]"]            = StripeTextUtils.NullIfBlank(card.Name);
            cardParams["card[currency]"]        = StripeTextUtils.NullIfBlank(card.Currency);
            cardParams["card[address_line1]"]   = StripeTextUtils.NullIfBlank(card.AddressLine1);
            cardParams["card[address_line2]"]   = StripeTextUtils.NullIfBlank(card.AddressLine2);
            cardParams["card[address_city]"]    = StripeTextUtils.NullIfBlank(card.AddressCity);
            cardParams["card[address_zip]"]     = StripeTextUtils.NullIfBlank(card.AddressZip);
            cardParams["card[address_state]"]   = StripeTextUtils.NullIfBlank(card.AddressState);
            cardParams["card[address_country]"] = StripeTextUtils.NullIfBlank(card.AddressCountry);

            // Remove all null values; they cause validation errors
            RemoveNullParams(cardParams);

            return(cardParams);
        }