Example #1
0
        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());
        }
        public StorePaymentProfileResult StorePaymentProfile(StorePaymentProfileParameter parameter)
        {
            AddRecurringSaleInformationRequest addRecurringSaleInformationRequest = new AddRecurringSaleInformationRequest()
            {
                UserId     = this.UserId,
                MerchantId = this.MerchantId,
                Password   = this.Password,
                CardNumber = parameter.CreditCard.CardNumber
            };
            int    expirationMonth = parameter.CreditCard.ExpirationMonth;
            string str             = expirationMonth.ToString("00");

            expirationMonth = parameter.CreditCard.ExpirationYear;
            addRecurringSaleInformationRequest.CardExpirationDate     = string.Concat(str, expirationMonth.ToString().Substring(2));
            addRecurringSaleInformationRequest.NameOnCard             = parameter.CreditCard.CardHolderName;
            addRecurringSaleInformationRequest.CardLastFourDigit      = parameter.CreditCard.CardNumber.Substring(parameter.CreditCard.CardNumber.Length - 4);
            addRecurringSaleInformationRequest.CustomerZipCode        = parameter.BillToAddress.PostalCode;
            addRecurringSaleInformationRequest.CustomerEmail          = parameter.BillToAddress.Email;
            addRecurringSaleInformationRequest.CustomerBillingAddress = parameter.BillToAddress.Address1;
            addRecurringSaleInformationRequest.CustomerCode           = parameter.CustomerNumber;
            /*AddRecurringSaleInformationResponse reply = (new AdministrationClient()).AddRecurringSaleInformation(addRecurringSaleInformationRequest); */// since RecurringAuth already gives tokenId
            StorePaymentProfileResult result = new StorePaymentProfileResult()
            {
                Success = true // reply.Result == 0
            };

            if (!result.Success)
            {
                //result.ResponseMessages.Add(string.Format("Transaction Failed: {0}", reply.Message));
            }
            else
            {
                result.CustomerProfileId = "Cenpos";
                result.PaymentProfileId  = this.recurringToken; //reply.Message.Substring(reply.Message.Length - 8);//this.recurringToken;
            }
            return(result);
        }