예제 #1
0
        /// <summary>
        /// Creates an API object, ready to send to AuthNET servers.
        /// </summary>
        /// <returns></returns>
        public customerPaymentProfileExType ToAPI() {
            var result = new customerPaymentProfileExType();
            
            if (null != this.BillingAddress)
            { result.billTo = this.BillingAddress.ToAPIType(); }

            result.customerPaymentProfileId = this.ProfileID;
            
            if (!String.IsNullOrEmpty(this.DriversLicenseNumber)) {
                result.driversLicense = new driversLicenseType();
                result.driversLicense.dateOfBirth = this.DriversLicenseDOB;
                result.driversLicense.number = this.DriversLicenseNumber;
                result.driversLicense.state = this.DriversLicenseState;
            }

            if (this.IsBusiness) {
                result.customerType = customerTypeEnum.business;
            } else {
                result.customerType = customerTypeEnum.individual;
            }
            result.customerTypeSpecified = true;
            
            result.payment = new paymentType();
            if (!String.IsNullOrEmpty(this.CardNumber) && (this.CardNumber.Trim().Length > 0))
            {
                var card = new creditCardType();
                card.cardCode = this.CardCode;
                card.cardNumber = this.CardNumber;
                card.expirationDate = this.CardExpiration;
                result.payment.Item = card;
            }
            else if ((this.eCheckBankAccount != null) && !String.IsNullOrEmpty(this.eCheckBankAccount.accountNumber) && (this.eCheckBankAccount.accountNumber.Trim().Length > 0))
            {
                var bankAccount = new bankAccountType()
                    {
                        accountTypeSpecified = this.eCheckBankAccount.accountTypeSpecified,
                        accountType =(bankAccountTypeEnum)Enum.Parse(typeof(bankAccountTypeEnum), this.eCheckBankAccount.accountType.ToString(), true),
                        routingNumber = this.eCheckBankAccount.routingNumber,
                        accountNumber = this.eCheckBankAccount.accountNumber,
                        nameOnAccount = this.eCheckBankAccount.nameOnAccount,
                        echeckTypeSpecified = this.eCheckBankAccount.echeckTypeSpecified,
                        echeckType = (echeckTypeEnum)Enum.Parse(typeof(echeckTypeEnum), this.eCheckBankAccount.echeckType.ToString(), true),
                        bankName = this.eCheckBankAccount.bankName,
                        checkNumber = this.eCheckBankAccount.checkNumber
                    };
                result.payment.Item = bankAccount;
            }

            if (!String.IsNullOrEmpty(this.TaxID)) {
                result.taxId = this.TaxID;
            }
            return result;
        }
예제 #2
0
        /// <summary>
        /// The Update function won't accept a change to some values - specifically the billing interval. This creates a request
        /// that the API can understand for updates only
        /// </summary>
        /// <returns></returns>
        public ARBSubscriptionType ToUpdateableAPI() {

            var sub = new ARBSubscriptionType();
            sub.name = this.SubscriptionName;

            if (!String.IsNullOrEmpty(this.CardNumber) && (this.CardNumber.Trim().Length > 0))
            {
                DateTime dt;
                if (!CommonFunctions.ParseDateTime(this.CardExpirationYear, this.CardExpirationMonth, 1, out dt))
                {
                    throw new InvalidOperationException("Need a valid CardExpirationMonth and CardExpirationYear to set up this subscription");
                }

                var creditCard = new creditCardType();
                creditCard.cardNumber = this.CardNumber;
                creditCard.expirationDate = dt.ToString("yyyy-MM");//string.Format("{0}-{1}", this.CardExpirationYear, this.CardExpirationMonth);  // required format for API is YYYY-MM
                sub.payment = new paymentType();
                sub.payment.Item = creditCard;
            }

            if ((this.eCheckBankAccount != null) && !String.IsNullOrEmpty(this.eCheckBankAccount.accountNumber) &&
                 (this.eCheckBankAccount.accountNumber.Trim().Length >0))
            {
                var eCheck = new bankAccountType()
                {
                    accountTypeSpecified = eCheckBankAccount.accountTypeSpecified,
                    accountType = (bankAccountTypeEnum)Enum.Parse(typeof(bankAccountTypeEnum), eCheckBankAccount.accountType.ToString(), true),
                    routingNumber = eCheckBankAccount.routingNumber,
                    accountNumber = eCheckBankAccount.accountNumber,
                    nameOnAccount = eCheckBankAccount.nameOnAccount,
                    echeckTypeSpecified = eCheckBankAccount.echeckTypeSpecified,
                    echeckType = (echeckTypeEnum)Enum.Parse(typeof(echeckTypeEnum), eCheckBankAccount.echeckType.ToString(), true),
                    bankName = eCheckBankAccount.bankName,
                    checkNumber = eCheckBankAccount.checkNumber
                };
                sub.payment = new paymentType { Item = eCheck };
            }

            if (this.BillingAddress != null)
                sub.billTo = this.BillingAddress.ToAPINameAddressType();
            if (this.ShippingAddress != null)
                sub.shipTo = this.ShippingAddress.ToAPINameAddressType();

            sub.paymentSchedule = new paymentScheduleType();
            sub.paymentSchedule.totalOccurrences = this.BillingCycles;
            sub.paymentSchedule.totalOccurrencesSpecified = true;

            sub.amount = this.Amount;
            sub.amountSpecified = true;

            sub.customer = new customerType();
            sub.customer.email = this.CustomerEmail;
            sub.customer.id = this.CustomerID;

            sub.order = new orderType();
            sub.order.description = this.Description;
            sub.order.invoiceNumber = this.Invoice;
                                                        
            return sub;

        }
예제 #3
0
        /// <summary>
        /// This is mostly for internal processing needs - it takes the SubscriptionRequest and turns it into something the Gateway can serialize.
        /// </summary>
        /// <returns></returns>
        public ARBSubscriptionType ToAPI(){

            var sub = new ARBSubscriptionType();
            sub.name = this.SubscriptionName;

            bool isCard = true;
            StringBuilder sbError = new StringBuilder("");
            bool bError = false;
            if (String.IsNullOrEmpty(this.CardNumber) || (this.CardNumber.Trim().Length == 0))
            {
                if ((null == this.eCheckBankAccount) || String.IsNullOrEmpty(this.eCheckBankAccount.accountNumber) ||
                    (this.eCheckBankAccount.accountNumber.Trim().Length == 0))
                {
                    sbError.Append("Need a credit card number or a bank account number to set up this subscription");
                    bError = true;
                }
                else
                {
                    isCard = false;
                }
            }

            DateTime dt = new DateTime();
            if ( isCard && !CommonFunctions.ParseDateTime(this.CardExpirationYear, this.CardExpirationMonth, 1, out dt))
            {
                sbError.Append("Need a valid CardExpirationMonth and CardExpirationYear to set up this subscription");
                bError = true;
            }

            if (bError)
            {
                throw new InvalidOperationException(sbError.ToString());
            }

            if (isCard)
            {
                var creditCard = new creditCardType();
                creditCard.cardNumber = this.CardNumber;
                creditCard.expirationDate = dt.ToString("yyyy-MM"); // required format for API is YYYY-MM
                sub.payment = new paymentType();
                sub.payment.Item = creditCard;
            }
            else
            {
                var eCheck = new bankAccountType()
                    {
                        accountTypeSpecified = eCheckBankAccount.accountTypeSpecified,
                        accountType = (bankAccountTypeEnum)Enum.Parse(typeof(bankAccountTypeEnum), eCheckBankAccount.accountType.ToString(), true),
                        routingNumber = eCheckBankAccount.routingNumber,
                        accountNumber = eCheckBankAccount.accountNumber,
                        nameOnAccount = eCheckBankAccount.nameOnAccount,
                        echeckTypeSpecified = eCheckBankAccount.echeckTypeSpecified,
                        echeckType = (echeckTypeEnum)Enum.Parse(typeof(echeckTypeEnum), eCheckBankAccount.echeckType.ToString(), true),
                        bankName = eCheckBankAccount.bankName,
                        checkNumber = eCheckBankAccount.checkNumber
                    };
                sub.payment = new paymentType {Item = eCheck};
            }

            if(this.BillingAddress!=null)
                sub.billTo = this.BillingAddress.ToAPINameAddressType();
            if (this.ShippingAddress != null)
                sub.shipTo = this.ShippingAddress.ToAPINameAddressType();

            sub.paymentSchedule = new paymentScheduleType();
            sub.paymentSchedule.startDate = this.StartsOn;
            sub.paymentSchedule.startDateSpecified = true;

            sub.paymentSchedule.totalOccurrences = this.BillingCycles;
            sub.paymentSchedule.totalOccurrencesSpecified = true;

            // free 1 month trial
            if (this.TrialBillingCycles > 0) {
                sub.paymentSchedule.trialOccurrences = this.TrialBillingCycles;
                sub.paymentSchedule.trialOccurrencesSpecified = true;
            }

            if (this.TrialAmount > 0) {
                sub.trialAmount = this.TrialAmount;
                sub.trialAmountSpecified = true;
            }

            sub.amount = this.Amount;
            sub.amountSpecified = true;

            sub.paymentSchedule.interval = new paymentScheduleTypeInterval();
            sub.paymentSchedule.interval.length = this.BillingInterval;
            
            if (this.BillingIntervalUnits == BillingIntervalUnits.Months) {
                sub.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.months;
            } else {
                sub.paymentSchedule.interval.unit = ARBSubscriptionUnitEnum.days;
            }
            sub.customer = new customerType();
            sub.customer.email = this.CustomerEmail;

            sub.order = new orderType();
            sub.order.description = this.Description;
            sub.order.invoiceNumber = this.Invoice;

            sub.customer.id = this.CustomerID;

            return sub;

        }
        /// <summary>
        /// Adds a bank account profile to the user and returns the profile ID
        /// </summary>
        /// <returns></returns>
        public string AddECheckBankAccount(string profileID, BankAccount bankAccount, Address billToAddress)
        {
            var req = new createCustomerPaymentProfileRequest();

            req.customerProfileId = profileID;
            req.paymentProfile = new customerPaymentProfileType();
            req.paymentProfile.payment = new paymentType();

            var bankAcct = new bankAccountType()
                {
                    accountTypeSpecified = bankAccount.accountTypeSpecified,
                    accountType = (bankAccountTypeEnum)Enum.Parse(typeof(bankAccountTypeEnum), bankAccount.accountType.ToString(), true),
                    routingNumber = bankAccount.routingNumber,
                    accountNumber = bankAccount.accountNumber,
                    nameOnAccount = bankAccount.nameOnAccount,
                    bankName = bankAccount.bankName,
                    echeckTypeSpecified = bankAccount.echeckTypeSpecified,
                    echeckType = (echeckTypeEnum)Enum.Parse(typeof(echeckTypeEnum), bankAccount.echeckType.ToString(), true)
                };
 
            req.paymentProfile.payment.Item = bankAcct;

            if (billToAddress != null)
                req.paymentProfile.billTo = billToAddress.ToAPIType();

            req.validationModeSpecified = true;
            req.validationMode = this._mode;

            var response = (createCustomerPaymentProfileResponse) _gateway.Send(req);

            return response.customerPaymentProfileId;
        }