Context class for the sale. Holds the payment necessary details.
        public Task <PaymentResponseContext> ProcessSaleAsync(PaymentRequestContext paymentRequest)
        {
            if (paymentRequest == null)
            {
                throw new ArgumentNullException("paymentRequest");
            }

            //validate the PaymentRequestContext instance comming in
            ICollection <ValidationResult> ctxValResults = validatePaymentRequestContext(paymentRequest);

            if (ctxValResults.Any())
            {
                var invalidPaymentResponseCtx = new PaymentResponseContext {
                    ResponseCode      = PaymentResponseCode.InvalidPaymentRequestContext,
                    ValidationResults = ctxValResults
                };

                return(TaskHelpers.FromResult(invalidPaymentResponseCtx));
            }

            //PaymentRequestContext instance is valid. Continue.
            var paymentServiceDescriptor = createPaymentServiceDescriptor(paymentRequest);
            var requestXML = seserializePaymentRequest(paymentServiceDescriptor);

            return(processPaymentRequest(requestXML));
        }
        //private helpers
        private ICollection <ValidationResult> validatePaymentRequestContext(
            PaymentRequestContext paymentRequest)
        {
            if (paymentRequest == null)
            {
                throw new ArgumentNullException("paymentRequest");
            }

            ValidationContext validationContext =
                new ValidationContext(paymentRequest, null, null);

            var valResults = new Collection <ValidationResult>();

            Validator.TryValidateObject(paymentRequest, validationContext, valResults, true);

            return(valResults);
        }
 private PaymentServiceDescriptor createPaymentServiceDescriptor(PaymentRequestContext paymentRequest)
 {
     return(new PaymentServiceDescriptor {
         ModeString = _mode.ToString(),
         Version = _version,
         Terminal = new Terminal {
             MerchantID = _merchantId,
             ID = _terminalId,
             ProvUserID = _provisionUserId,
             UserID = _userId,
             HashData = PaymentUtility.GenerateHASHedData(
                 _terminalId,
                 paymentRequest.CreditCardNumber.ToString(),
                 PaymentUtility.EncodeDecimalPaymentAmount(
                     paymentRequest.PaymentAmount
                     ),
                 _terminalPassword
                 )
         },
         Customer = new Customer {
             EmailAddress = paymentRequest.CustomerEmail,
             IPAddress = paymentRequest.IpAddress
         },
         Card = new Card {
             Number = paymentRequest.CreditCardNumber.ToString(),
             ExpireDate = PaymentUtility.EncodeExpireDate(
                 paymentRequest.CCExpireDateMonth, paymentRequest.CCExpireDateYear
                 ),
             //TODO: This is a temp fix. Make this better.
             CVV2 = (paymentRequest.CVV2.ToString().Length < 3) ? string.Format("0{0}", paymentRequest.CVV2.ToString()) : paymentRequest.CVV2.ToString()
         },
         Transaction = new TransactionRequest {
             CardholderPresentCodeDigit = _cardholderPresentCode.GetHashCode(),
             AmountString = PaymentUtility.EncodeDecimalPaymentAmount(paymentRequest.PaymentAmount),
             CurrencyCodeDigit = paymentRequest.CurrencyCode.GetHashCode(),
             Type = OperationType.Sales.ToString().ToLower(),
             InstallmentCnt = string.Empty
         },
         Order = new OrderRequest {
             GroupID = string.Empty,
             OrderID = string.Empty
         }
     });
 }
        public Task<PaymentResponseContext> ProcessSaleAsync(PaymentRequestContext paymentRequest)
        {
            if (paymentRequest == null)
                throw new ArgumentNullException("paymentRequest");

            //validate the PaymentRequestContext instance comming in
            ICollection<ValidationResult> ctxValResults = validatePaymentRequestContext(paymentRequest);
            if (ctxValResults.Any()) {

                var invalidPaymentResponseCtx = new PaymentResponseContext {

                    ResponseCode = PaymentResponseCode.InvalidPaymentRequestContext,
                    ValidationResults = ctxValResults
                };

                return TaskHelpers.FromResult(invalidPaymentResponseCtx);
            }

            //PaymentRequestContext instance is valid. Continue.
            var paymentServiceDescriptor = createPaymentServiceDescriptor(paymentRequest);
            var requestXML = seserializePaymentRequest(paymentServiceDescriptor);

            return processPaymentRequest(requestXML);
        }
        //private helpers
        private ICollection<ValidationResult> validatePaymentRequestContext(
            PaymentRequestContext paymentRequest)
        {
            if (paymentRequest == null)
                throw new ArgumentNullException("paymentRequest");

            ValidationContext validationContext =
                new ValidationContext(paymentRequest, null, null);

            var valResults = new Collection<ValidationResult>();
            Validator.TryValidateObject(paymentRequest, validationContext, valResults, true);

            return valResults;
        }
        private PaymentServiceDescriptor createPaymentServiceDescriptor(PaymentRequestContext paymentRequest)
        {
            return new PaymentServiceDescriptor {

                ModeString = _mode.ToString(),
                Version = _version,
                Terminal = new Terminal {
                    MerchantID = _merchantId,
                    ID = _terminalId,
                    ProvUserID = _provisionUserId,
                    UserID = _userId,
                    HashData = PaymentUtility.GenerateHASHedData(
                        _terminalId,
                        paymentRequest.CreditCardNumber.ToString(),
                        PaymentUtility.EncodeDecimalPaymentAmount(
                            paymentRequest.PaymentAmount
                        ),
                        _terminalPassword
                    )
                },
                Customer = new Customer {
                    EmailAddress = paymentRequest.CustomerEmail,
                    IPAddress = paymentRequest.IpAddress
                },
                Card = new Card {
                    Number = paymentRequest.CreditCardNumber.ToString(),
                    ExpireDate = PaymentUtility.EncodeExpireDate(
                        paymentRequest.CCExpireDateMonth, paymentRequest.CCExpireDateYear
                    ),
                    //TODO: This is a temp fix. Make this better.
                    CVV2 = (paymentRequest.CVV2.ToString().Length < 3) ? string.Format("0{0}", paymentRequest.CVV2.ToString()) : paymentRequest.CVV2.ToString()
                },
                Transaction = new TransactionRequest {
                    CardholderPresentCodeDigit = _cardholderPresentCode.GetHashCode(),
                    AmountString = PaymentUtility.EncodeDecimalPaymentAmount(paymentRequest.PaymentAmount),
                    CurrencyCodeDigit = paymentRequest.CurrencyCode.GetHashCode(),
                    Type = OperationType.Sales.ToString().ToLower(),
                    InstallmentCnt = string.Empty
                },
                Order = new OrderRequest {
                    GroupID = string.Empty,
                    OrderID = string.Empty
                }
            };
        }