public AddPaymentProfileResult AddPaymentProfile(AddPaymentProfileParameter parameter) { UserProfileDto userProfileDto = SiteContext.Current.UserProfileDto; if (userProfileDto == null) { return(this.CreateErrorServiceResult <AddPaymentProfileResult>(SubCode.Forbidden, MessageProvider.Current.Forbidden)); } UserProfile userProfile = this.UnitOfWork.GetRepository <UserProfile>().Get(userProfileDto.Id); IPaymentGateway paymentGateway = this.GetPaymentGateway(); if (!paymentGateway.SupportsStoredPaymentProfiles) { return(this.CreateErrorServiceResult <AddPaymentProfileResult>(SubCode.NotSupported, string.Format(MessageProvider.Current.Not_Supported, "Stored Payment Profiles"))); } GetBillToResult billToResult = this.GetBillTo(parameter.BillToId); if (billToResult.ResultCode != ResultCode.Success) { return(this.CreateErrorServiceResult <AddPaymentProfileResult>(billToResult.SubCode, billToResult.Message)); } Customer billTo = billToResult.BillTo; StorePaymentProfileResult storePaymentProfileResult = paymentGateway.StorePaymentProfile(new StorePaymentProfileParameter() { CustomerProfileId = userProfile.GetProperty("StoredCustomerProfileId", string.Empty), CustomerNumber = billTo.CustomerNumber, CurrencyCode = parameter.CurrencyCode, BillToAddress = CreateCreditCardAddress(billTo), CreditCard = parameter.CreditCard }); if (!storePaymentProfileResult.Success) { return(this.CreateErrorServiceResult <AddPaymentProfileResult>(SubCode.StorePaymentProfileFailed, string.Join(Environment.NewLine, storePaymentProfileResult.ResponseMessages))); } userProfile.SetProperty("StoredCustomerProfileId", storePaymentProfileResult.CustomerProfileId); GetStoredPaymentProfileResult getStoredPaymentProfileResult = paymentGateway.GetStoredPaymentProfile(new GetStoredPaymentProfileParameter() { CustomerNumber = billTo.CustomerNumber, CustomerProfileId = storePaymentProfileResult.CustomerProfileId, PaymentProfileId = storePaymentProfileResult.PaymentProfileId }); if (getStoredPaymentProfileResult.Success) { this.AddUserPaymentProfile(userProfile, new UserPaymentProfile() { CardIdentifier = getStoredPaymentProfileResult.PaymentProfile.PaymentProfileId, Description = parameter.CreditCard.CardHolderName,//BUSA-462 : Ability to save Credit Cards (in CenPos) and offer it to users. CardType = parameter.CreditCard.CardType, MaskedCardNumber = getStoredPaymentProfileResult.PaymentProfile.MaskedCardNumber, ExpirationDate = getStoredPaymentProfileResult.PaymentProfile.Expiration }); } return(new AddPaymentProfileResult()); }