public override Payment RequestPayment(PaymentRequest paymentRequest)
        {
            IPaymentData paymentData = null;

            if (paymentRequest.Payment == null)
            {
                paymentRequest.Payment = CreatePayment(paymentRequest);
            }

            try
            {
                paymentData = CallInsertOrderWithPayment(paymentRequest);
            }
            // catch (PaymentAmountOutOfRangeExeption)
            catch (GlobalCollectException exception)             //We already logged the error
            {
                // Catch all the exceptions. Not just the PaymentAmountOutOfRangeException.
                // It should never fail by exception. Always decline.
                string status;
                HandleGlobalCollectException(paymentRequest.Payment, exception, out status);
                SetPaymentStatus(paymentRequest.Payment, PaymentStatusCode.Declined, status);

                string declineUrl = paymentRequest.PaymentMethod.DynamicProperty <string>().DeclineUrl;

                RedirectToUrl(declineUrl, paymentRequest.Payment);
            }

            var redirectUrl = paymentData.FormAction;

            HttpContext.Current.Response.Redirect(redirectUrl);

            return(paymentRequest.Payment);
        }
Example #2
0
        public PaymentViewModel(IWindowManager windowManager, IPaymentData paymentData, IClientData clientData)
        {
            DisplayName = "Payment";

            _windowManager = windowManager;
            _paymentData   = paymentData;
            _clientData    = clientData;

            GetClients();
        }
        private void LogPaymentDataReceived(IPaymentData paymentData)
        {
            var message =
                string.Format(
                    "Received payment data from Global Collect: OrderId '{0}', OrderStatus '{1}', FormMethod '{2}', FormAction '{3}'",
                    paymentData.OrderId,
                    paymentData.StatusId,
                    paymentData.FormMethod,
                    paymentData.FormAction);

            _loggingService.Log <GlobalCollectPaymentMethodService>(message);
        }
Example #4
0
        public WorkViewModel(IWindowManager windowManager, IWorkData workData,
                             IClientData clientData, IPaymentData paymentData)
        {
            DisplayName = "Work";

            _windowManager = windowManager;
            _workData      = workData;
            _clientData    = clientData;
            _paymentData   = paymentData;

            GetClients();

            InitializeFormVisibility();
        }
        public override bool Authorize(IPaymentData data)
        {
            //Pre Conditions
            Contract.Requires(data.Customer != null, "Customer required");
            Contract.Requires(data.CardData != null, "CardData Required");
            Contract.Requires(data.CardData.BillingAddress != null, "CardData billing address required");
            Contract.Requires(!String.IsNullOrWhiteSpace(data.CardData.BillingAddress.AddressLine1), "CardData Street Address Required");
            Contract.Requires(!String.IsNullOrWhiteSpace(data.CardData.BillingAddress.City), "CardData City Required");
            Contract.Requires(!String.IsNullOrWhiteSpace(data.CardData.BillingAddress.Country), "CardData country required");
            Contract.Requires(!String.IsNullOrWhiteSpace(data.CardData.BillingAddress.PostalCode), "CardData postal code required");
            Contract.Requires(!String.IsNullOrWhiteSpace(data.CardData.CardNumber), "CardData cardnumber required");
            Contract.Requires(data.CardData.ExpirationMonth > 0, "CardData expiration month required");
            Contract.Requires(data.CardData.ExpirationYear >= System.DateTime.Now.Year, "CardData expiration year must be greater than or equal current year.");
            Contract.Requires(!String.IsNullOrWhiteSpace(data.CardData.CardHolderName), "CardData carholder name required");
            Contract.Requires(!String.IsNullOrWhiteSpace(data.Customer.FirstName), "PaymentData first name required");
            Contract.Requires(!String.IsNullOrWhiteSpace(data.Customer.LastName), "PaymentData last name required");
            Contract.Requires(!String.IsNullOrWhiteSpace(data.CardData.CardHolderFirstName), "PaymentData cardholder first name required");
            Contract.Requires(!String.IsNullOrWhiteSpace(data.CardData.CardHolderLastName), "PaymentData cardholder last name required");
            Contract.Requires(data.Transaction != null, "PaymentData transaction required");
            Contract.Requires(data.Transaction.Amount > 0, "PaymentData transaction amount must be greater than zero");
            //Post Conditions
            Contract.Ensures(data.Transaction.TransactionMessages.Count > 0, "A critical error was encountered left control of authorize without assigning  transaction result messages");

            if (!SupportsAuthorize)
                throw new System.NotSupportedException("Authorize not supported by gateway");
            //If profile exists then the profile id will be returned            
            IGatewayProfile profile = GetOrCreateCustomerProfile(data);
            var customerPaymentProfile = data.MapPaymentDataToCustomerPaymentProfileType();                   
            var paymentProfile = GetOrCreateCustomerPaymentProfile(profile, data);
            var transaction = data.MapPaymentDataToProfileTransAuthCaptureType(long.Parse(paymentProfile.Id), long.Parse(profile.Id));
            var transactionResult = GatewayHelper.CreateProfileTransaction(transaction);
            data.Transaction.TransactionMessages.AddRange(GetTransactionMessage(transactionResult.messages,"createCustomerProfileTransactionResponse"));
           

            
            return transactionResult.messages.resultCode == AuthorizeNet.APICore.messageTypeEnum.Ok;
        }
        IGatewayPaymentProfile GetOrCreateCustomerPaymentProfile(IPaymentData data, long customerProfileId)
        {
            var customerPaymentProfile = data.MapPaymentDataToCustomerPaymentProfileType();            
            IGatewayPaymentProfile result = null;
            try
            {
                var paymentProfileResponse = GatewayHelper.CreateCustomerPaymentProfile(customerPaymentProfile, customerProfileId);
                result = GatewayHelper.GetCustomerPaymentProfile(customerProfileId, long.Parse(paymentProfileResponse.customerPaymentProfileId)).MapCustomerPaymentProfileMaskTypeToGatewayPaymentProfile();

            }
            catch (System.InvalidOperationException ex)
            {
                if (ex.Message == AuthorizeNetGatewayHelper.DUPLICATE_PAYMENT_PROFILE_MESSAGE)
                {
                    var lastFour = data.CardData.CardNumber.Substring(data.CardData.CardNumber.Length - 4);
                    //get the existing profile
                    var paymentProfiles = GatewayHelper.GetCustomerPaymentProfiles(customerProfileId).ToList();
                    var paymentProfile = paymentProfiles.SingleOrDefault(n => n.payment.Item as AuthorizeNet.APICore.creditCardMaskedType != null && ((AuthorizeNet.APICore.creditCardMaskedType)n.payment.Item).cardNumber.Contains(lastFour));
                    result = paymentProfile.MapCustomerPaymentProfileMaskTypeToGatewayPaymentProfile();
                }
            }
            return result;
        }
 IGatewayPaymentProfile GetOrCreateCustomerPaymentProfile(IGatewayProfile gatewayProfile, IPaymentData data)
 {
     IGatewayPaymentProfile result = null;
     if (gatewayProfile.PaymentProfiles != null && gatewayProfile.PaymentProfiles.Count > 0)
     {
         var lastFour = data.CardData.CardNumber.Substring(data.CardData.CardNumber.Length - 4);
         var paymentProfileMatch = gatewayProfile.PaymentProfiles.SingleOrDefault(n => n.PaymentCardData.MaskedCardNumber.Contains(lastFour));
         if (paymentProfileMatch != null)
             result = paymentProfileMatch;
     }
     if (result == null)
     {
         result = GetOrCreateCustomerPaymentProfile(data, long.Parse(gatewayProfile.Id));
     }
     return result;
 }
        public override IGatewayProfile GetOrCreateCustomerProfile(IPaymentData data)
        {

            IGatewayProfile result = new GatewayProfile();            
            AuthorizeNet.APICore.messagesType messages = null;
            var profileId = GatewayHelper.CreateCustomerProfile(data.Customer.EmailAddress, data.Customer.CustomerDescription, out messages);
            result = GatewayHelper.GetCustomerProfile(profileId).MapCustomerProfileToGatewayProfile();          
            data.Transaction.TransactionMessages.AddRange(GetTransactionMessage(messages, "createCustomerProfileRequest"));
            return result;

        }
 public override bool Refund(IPaymentData data)
 {
     //Pre Conditions
     Contract.Requires(data.Transaction != null, "A valid transaction is required for refunds");
     Contract.Requires(data.Transaction.Amount > 0, "A refund requires a transaction amount greater than 0");
     Contract.Requires(!String.IsNullOrWhiteSpace(data.Id), "A refund requires a PaymentProfileId assigned to the Id property of PaymentData");
     Contract.Requires(!String.IsNullOrWhiteSpace(data.Transaction.PreviousTransactionReferenceNumber), "A refund requires a previous transaction number");
     Contract.Requires(data.Customer != null, "A refund requires a Customer");
     Contract.Requires(!String.IsNullOrWhiteSpace(data.Customer.CustomerId), "A refund requires a customer profile id assigned as CustomerId");
     //Post Conditions 
     Contract.Ensures(data.Transaction.TransactionMessages.Count > 0, "A critical error was encountered left control of refund without assigning  transaction result messages");            
     var refundTransactionType = new AuthorizeNet.APICore.profileTransRefundType();
     refundTransactionType.customerProfileId = data.Customer.CustomerId;
     refundTransactionType.customerPaymentProfileId = data.Id;
     refundTransactionType.transId = data.Transaction.PreviousTransactionReferenceNumber;
     refundTransactionType.amount = data.Transaction.Amount;
     var profileTransactionType = new AuthorizeNet.APICore.profileTransactionType();
     profileTransactionType.Item = refundTransactionType;            
     var result = GatewayHelper.CreateProfileTransaction(profileTransactionType);           
     data.Transaction.TransactionMessages.AddRange(GetTransactionMessage(result.messages,"createCustomerProfileTransactionResponse"));
     return result.messages.resultCode == AuthorizeNet.APICore.messageTypeEnum.Ok;
 }
 public abstract IGatewayProfile GetOrCreateCustomerProfile(IPaymentData data);        
Example #11
0
 public abstract bool Charge(IPaymentData data);
Example #12
0
 public abstract bool Refund(IPaymentData data);
Example #13
0
 public abstract bool Capture(IPaymentData data);
Example #14
0
 // These methods do the real work of communicating with 
 // outside services based on the 
 public abstract bool Authorize(IPaymentData data);
Example #15
0
 public PaymentService(IPaymentData paymentData, IAccountData accountData)
 {
     this._paymentsData = paymentData;
     this._accountData  = accountData;
 }
 public override bool Charge(IPaymentData data)
 {
     throw new NotImplementedException();
 }
Example #17
0
 public override bool Void(IPaymentData data)
 {
     if (_CurrentProcessor != null)
     {
         return _CurrentProcessor.Void(data);
     }
     else
     {
         return false;
     }
 }
Example #18
0
 public abstract bool Void(IPaymentData data);
 public override bool Authorize(IPaymentData data)
 {
     throw new NotImplementedException();
 }
 public static IGatewayProfile CreateProfile(IPaymentData data)
 {
     var target = _Container.GetNewProfileCreditCardGateway();
     return target.GetOrCreateCustomerProfile(data);
 }
Example #21
0
 public override bool Authorize(IPaymentData data)
 {
     if (_CurrentProcessor != null)
     {
         return _CurrentProcessor.Authorize(data);
     }
     else
     {
         return false;
     }
 }