/// <summary> /// Initializes a new instance of the <see cref="PaymentProfile"/> class, using the passed-in API type to create the profile. /// </summary> /// <param name="apiType">Type of the API.</param> public PaymentProfile(customerPaymentProfileMaskedType apiType) { if(apiType.billTo!=null) this.BillingAddress = new Address(apiType.billTo); this.ProfileID = apiType.customerPaymentProfileId; if (apiType.driversLicense!=null) { this.DriversLicenseNumber = apiType.driversLicense.number; this.DriversLicenseState = apiType.driversLicense.state; this.DriversLicenseDOB = apiType.driversLicense.dateOfBirth; } if (apiType.customerTypeSpecified) { this.IsBusiness = apiType.customerType == customerTypeEnum.business; } else { this.IsBusiness = false; } if (apiType.payment != null) { if (apiType.payment.Item is creditCardMaskedType) { var card = (creditCardMaskedType) apiType.payment.Item; this.CardType = card.cardType; this.CardNumber = card.cardNumber; this.CardExpiration = card.expirationDate; } else if (apiType.payment.Item is bankAccountMaskedType) { var bankAcct = (bankAccountMaskedType)apiType.payment.Item; this.eCheckBankAccount = new BankAccount() { accountTypeSpecified = bankAcct.accountTypeSpecified, accountType = (BankAccountType)Enum.Parse(typeof(BankAccountType), bankAcct.accountType.ToString(), true), routingNumber = bankAcct.routingNumber, accountNumber = bankAcct.accountNumber, nameOnAccount = bankAcct.nameOnAccount, echeckTypeSpecified = bankAcct.echeckTypeSpecified, echeckType = (EcheckType)Enum.Parse(typeof(EcheckType), bankAcct.echeckType.ToString(), true), bankName = bankAcct.bankName, checkNumber = "" }; } } this.TaxID = apiType.taxId; }
private void SaveECheckToProfile(string routingNumber, string accountNumber, PaymentInfo paymentInfo, Customer customer) { if (accountNumber.StartsWith("X")) return; var foundPaymentProfile = customer.PaymentProfiles.SingleOrDefault(p => p.ProfileID == paymentInfo.AuNetCustPayBankId.ToString()); var bankAccount = new BankAccount { accountType = BankAccountType.Checking, nameOnAccount = customer.Description, accountNumber = accountNumber, routingNumber = routingNumber }; if (foundPaymentProfile == null) { var paymentProfileId = CustomerGateway.AddECheckBankAccount(customer.ProfileID, BankAccountType.Checking, routingNumber, accountNumber, customer.Description); paymentInfo.AuNetCustPayBankId = paymentProfileId.ToInt(); } else { foundPaymentProfile.eCheckBankAccount = bankAccount; var isSaved = CustomerGateway.UpdatePaymentProfile(customer.ProfileID, foundPaymentProfile); if (!isSaved) throw new Exception($"UpdatePaymentProfile failed to save credit card for {paymentInfo.PeopleId}"); } }
/// <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; }