Esempio n. 1
0
        public bool AddPaymentTransactionToOrder(Order o, OrderTransaction t, MerchantTribeApplication app)
        {
            // Save Order First if no bvin
            Orders.Upsert(o);

            t.OrderId     = o.bvin;
            t.OrderNumber = o.OrderNumber;
            t.StoreId     = o.StoreId;

            if (Transactions.Create(t))
            {
                OrderPaymentStatus previous = o.PaymentStatus;
                EvaluatePaymentStatus(o);
                OnPaymentChanged(previous, o, app);
                return(Orders.Update(o));
            }

            return(false);
        }
        // Create or Update
        public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata)
        {
            string data = string.Empty;
            string bvin = FirstParameter(parameters);
            ApiResponse<OrderTransactionDTO> response = new ApiResponse<OrderTransactionDTO>();

            OrderTransactionDTO postedItem = null;
            try
            {
                postedItem = MerchantTribe.Web.Json.ObjectFromJson<OrderTransactionDTO>(postdata);
            }
            catch (Exception ex)
            {
                response.Errors.Add(new ApiError("EXCEPTION", ex.Message));
                return MerchantTribe.Web.Json.ObjectToJson(response);
            }

            OrderTransaction item = new OrderTransaction();            
            item.FromDto(postedItem);
            
            OrderTransaction existing = MTApp.OrderServices.Transactions.Find(item.Id);
            if (existing == null || item.IdAsString == "00000000-0000-0000-0000-000000000000")
            {
                item.StoreId = MTApp.CurrentStore.Id;
                item.Id = System.Guid.NewGuid();
                MTApp.OrderServices.Transactions.Create(item);
            }            
            else
            {
                item.StoreId = MTApp.CurrentStore.Id;
                MTApp.OrderServices.Transactions.Update(item);
            }
            OrderTransaction resultItem = MTApp.OrderServices.Transactions.Find(item.Id);
            if (resultItem != null) response.Content = resultItem.ToDto();

            data = MerchantTribe.Web.Json.ObjectToJson(response);
            return data;
        }
 public bool RewardsPointsAddInfo(decimal amount)
 {
     int points = pointsManager.PointsNeededForPurchaseAmount(EnsurePositiveAmount(amount));           
     Transaction t = o.GetEmptyTransaction();
     t.Amount = EnsurePositiveAmount(amount);
     t.Customer.UserId = o.UserID;
     t.RewardPoints = points;
     t.Action = ActionType.RewardPointsInfo;
     OrderTransaction ot = new OrderTransaction(t);
     ot.Success = true;
     return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
 }
        public bool PayPalExpressRefund(OrderTransaction previousTransaction, decimal amount)
        {
            if (previousTransaction == null) return false;

            Transaction t = o.GetEmptyTransaction();
            t.Action = ActionType.PayPalRefund;
            t.Amount = EnsurePositiveAmount(amount);
            t.PreviousTransactionNumber = previousTransaction.RefNum1;
            t.PreviousTransactionAuthCode = previousTransaction.RefNum2;
            OrderTransaction ot = new OrderTransaction(t);

            if (previousTransaction.Action != ActionType.PayPalCapture
                && previousTransaction.Action != ActionType.PayPalCharge
                && previousTransaction.Action != ActionType.PayPalExpressCheckoutInfo)
            {
                ot.Success = false;
                ot.Messages = "Transaction must be PayPal capture or charge type to refund.";
                return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
            }

            Payment.Method.PaypalExpress processor = new Payment.Method.PaypalExpress();
            if (processor != null)
            {
                processor.Refund(t, this.MTApp);
                ot = new OrderTransaction(t);
                ot.LinkedToTransaction = previousTransaction.IdAsString;
            }
            return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
        }
        public bool PayPalExpressVoid(OrderTransaction previousTransaction, decimal amount)
        {
            if (previousTransaction == null) return false;

            Transaction t = o.GetEmptyTransaction();
            t.Action = ActionType.PayPalVoid;
            t.Amount = EnsurePositiveAmount(amount);
            t.PreviousTransactionNumber = previousTransaction.RefNum1;
            t.PreviousTransactionAuthCode = previousTransaction.RefNum2;
            OrderTransaction ot = new OrderTransaction(t);

            if (!previousTransaction.IsVoidable)
            {
                ot.Success = false;
                ot.Messages = "Transaction can not be voided.";
                return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
            }

            Payment.Method.PaypalExpress processor = new Payment.Method.PaypalExpress();  
            if (processor != null)
            {
                processor.Void(t, this.MTApp);
                ot = new OrderTransaction(t);
                ot.LinkedToTransaction = previousTransaction.IdAsString;

                // if the void went through, make sure we mark the previous transaction as voided
                if (t.Result.Succeeded)
                {
                    previousTransaction.Voided = true;
                    svc.Transactions.Update(previousTransaction);
                }
            }
            return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
        }
 // PayPal        
 public bool PayPalExpressAddInfo(decimal amount, string token, string payerId)
 {
     Transaction t = o.GetEmptyTransaction();
     t.Amount = EnsurePositiveAmount(amount);
     t.Action = ActionType.PayPalExpressCheckoutInfo;
     OrderTransaction ot = new OrderTransaction(t);            
     ot.Success = true;
     ot.RefNum1 = token;
     ot.RefNum2 = payerId;
     return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
 }
        public bool PayPalExpressCapture(OrderTransaction holdTransaction, decimal amount)
        {
            if (holdTransaction == null) return false;

            Transaction t = o.GetEmptyTransaction();
            t.Action = ActionType.PayPalCapture;
            t.Amount = EnsurePositiveAmount(amount);
            t.PreviousTransactionNumber = holdTransaction.RefNum1;
            t.PreviousTransactionAuthCode = holdTransaction.RefNum2;
            OrderTransaction ot = new OrderTransaction(t);

            if (holdTransaction.Action != ActionType.PayPalHold)
            {
                ot.Success = false;
                ot.Messages = "Transaction must be PayPal hold type to process.";
                return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
            }

            Payment.Method.PaypalExpress processor = new Payment.Method.PaypalExpress();
            if (processor != null)
            {
                processor.Capture(t, this.MTApp);
                ot = new OrderTransaction(t);
                ot.LinkedToTransaction = holdTransaction.IdAsString;
            }
            return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
        }
Esempio n. 8
0
 public bool AddPaymentTransactionToOrder(Order o, MerchantTribe.Payment.Transaction t, MerchantTribeApplication app)
 {
     Orders.OrderTransaction ot = new OrderTransaction(t);
     return(AddPaymentTransactionToOrder(o, ot, app));
 }
        public bool RewardsPointsRefund(OrderTransaction previousTransaction, decimal amount)
        {
            if (previousTransaction == null) return false;

            Transaction t = o.GetEmptyTransaction();
            t.Action = ActionType.RewardPointsIncrease;
            t.Amount = EnsurePositiveAmount(amount);
            t.RewardPoints = pointsManager.PointsNeededForPurchaseAmount(EnsurePositiveAmount(amount));
            t.Customer.UserId = o.UserID;
            OrderTransaction ot = new OrderTransaction(t);

            if (previousTransaction.Action != ActionType.RewardPointsCapture
                && previousTransaction.Action != ActionType.RewardPointsDecrease
                && previousTransaction.Action != ActionType.RewardPointsInfo)
            {
                ot.Success = false;
                ot.Messages = "Transaction must be Rewards Points capture or charge type to refund.";
                return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
            }

            Payment.RewardPoints processor = new RewardPoints();
            processor.Settings = new RewardPointsSettings(this.MTApp.CurrentStore.Id)
            {
                PointsIssuedPerDollarSpent = pointsManager.PointsToIssueForSpend(1),
                PointsNeededForDollarCredit = pointsManager.PointsNeededForPurchaseAmount(1)
            };
            if (processor != null)
            {
                processor.ProcessTransaction(t);
                ot = new OrderTransaction(t);
                ot.LinkedToTransaction = previousTransaction.IdAsString;
            }
            return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
        }
 // Credit Cards
 public bool CreditCardAddInfo(CardData card, decimal amount)
 {
     Transaction t = o.GetEmptyTransaction();
     t.Amount = EnsurePositiveAmount(amount);
     t.Card = card;
     t.Action = ActionType.CreditCardInfo;
     OrderTransaction ot = new OrderTransaction(t);
     ot.Success = true;
     return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
 }
        public bool CreditCardCharge(OrderTransaction infoTransaction, decimal amount)
        {
            if (infoTransaction == null) return false;

            Transaction t = o.GetEmptyTransaction();
            t.Card = infoTransaction.CreditCard;
            t.Action = ActionType.CreditCardCharge;
            t.Amount = EnsurePositiveAmount(amount);
            OrderTransaction ot = new OrderTransaction(t);

            if (infoTransaction.Action != ActionType.CreditCardInfo)
            {
                ot.Success = false;
                ot.Messages = "Transaction must be CC info type to process.";
                return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
            }

            RequestContext context = this.MTApp.CurrentRequestContext;
            Method processor = context.CurrentStore.Settings.PaymentCurrentCreditCardProcessor();
            if (processor != null)
            {
                processor.ProcessTransaction(t);
                ot = new OrderTransaction(t);
                ot.LinkedToTransaction = infoTransaction.IdAsString;
            }

            return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
        }
        // CompanyAccount
        public bool CompanyAccountAccept(string accountNumber)
        {
            Transaction t = o.GetEmptyTransaction();
            t.CompanyAccountNumber = accountNumber;
            t.Action = ActionType.CompanyAccountAccepted;
            OrderTransaction ot = new OrderTransaction(t);

            OrderTransaction existing = LocateExistingCompanyAccount(accountNumber);
            if (existing == null)
            {
                ot.Success = false;
                ot.Messages = "Could not located the requested Company Account.";
            }
            else
            {

                if (existing.HasSuccessfulLinkedAction(ActionType.CompanyAccountAccepted, svc.Transactions.FindForOrder(o.bvin)))
                {
                    // Fail, already accepted
                    ot.Success = false;
                    ot.Messages = "The requested Company Account has already been accepted.";
                }

                // Succes, receive it, link it to the info transaction
                ot.Amount = EnsurePositiveAmount(existing.Amount);
                ot.LinkedToTransaction = existing.IdAsString;
                ot.Success = true;
            }
            return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
        }
 public bool CompanyAccountAddInfo(string accountNumber, decimal amount)
 {
     Transaction t = o.GetEmptyTransaction();
     t.Amount = EnsurePositiveAmount(amount);
     t.CompanyAccountNumber = accountNumber;
     t.Action = ActionType.CompanyAccountInfo;
     OrderTransaction ot = new OrderTransaction(t);
     ot.Success = true;
     return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
 }
 public bool PurchaseOrderAddInfo(string poNumber, decimal amount)
 {
     Transaction t = o.GetEmptyTransaction();
     t.Amount = EnsurePositiveAmount(amount);
     t.PurchaseOrderNumber = poNumber;
     t.Action = ActionType.PurchaseOrderInfo;
     OrderTransaction ot = new OrderTransaction(t);
     ot.Success = true;
     return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
 }
 public bool CheckReturn(decimal amount, string checkNumber)
 {
     Transaction t = o.GetEmptyTransaction();
     t.Amount = EnsurePositiveAmount(amount);
     t.CheckNumber = checkNumber;
     t.Action = ActionType.CheckReturned;
     OrderTransaction ot = new OrderTransaction(t);
     ot.Success = true;
     return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
 }      
 public bool CashRefund(decimal amount)
 {            
     Transaction t = o.GetEmptyTransaction();
     t.Amount = EnsurePositiveAmount(amount);
     t.Action = ActionType.CashReturned;
     OrderTransaction ot = new OrderTransaction(t);
     ot.Success = true;
     return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
 }
Esempio n. 17
0
 public bool AddPaymentTransactionToOrder(Order o, MerchantTribe.Payment.Transaction t, MerchantTribeApplication app)
 {
     Orders.OrderTransaction ot = new OrderTransaction(t);
     return AddPaymentTransactionToOrder(o, ot, app);
 }
 public void LoadFromPayment(OrderTransaction t)
 {
     LoadFromCardData(t.CreditCard);
 }
Esempio n. 19
0
        public bool AddPaymentTransactionToOrder(Order o, OrderTransaction t, MerchantTribeApplication app)
        {
            // Save Order First if no bvin
            Orders.Upsert(o);            

            t.OrderId = o.bvin;
            t.OrderNumber = o.OrderNumber;
            t.StoreId = o.StoreId;

            if (Transactions.Create(t))
            {
                OrderPaymentStatus previous = o.PaymentStatus;
                EvaluatePaymentStatus(o);
                OnPaymentChanged(previous, o, app);
                return Orders.Update(o);
            }

            return false;
        }
        public bool RewardsPointsUnHold(OrderTransaction holdTransaction, decimal amount)
        {
            if (holdTransaction == null) return false;            

            Transaction t = o.GetEmptyTransaction();
            t.Action = ActionType.RewardPointsUnHold;
            int points = pointsManager.PointsNeededForPurchaseAmount(EnsurePositiveAmount(amount));
            t.RewardPoints = points;
            t.Customer.UserId = o.UserID;
            t.Amount = EnsurePositiveAmount(amount);
            OrderTransaction ot = new OrderTransaction(t);

            if (holdTransaction.Action != ActionType.RewardPointsHold)
            {
                ot.Success = false;
                ot.Messages = "Transaction must be Rewards Points Hold type to process.";
                return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
            }
            
            Payment.RewardPoints processor = new RewardPoints();
            processor.Settings = new RewardPointsSettings(this.MTApp.CurrentStore.Id)
            {
                PointsIssuedPerDollarSpent = pointsManager.PointsToIssueForSpend(1),
                PointsNeededForDollarCredit = pointsManager.PointsNeededForPurchaseAmount(1)
            };

            if (processor != null)
            {
                processor.ProcessTransaction(t);
                ot = new OrderTransaction(t);
                ot.LinkedToTransaction = holdTransaction.IdAsString;

                if (ot.Success)
                {
                    holdTransaction.Voided = true;
                    svc.Transactions.Update(holdTransaction);
                }
            }

            return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
        }
        public bool CreditCardRefund(OrderTransaction previousTransaction, decimal amount)
        {
            if (previousTransaction == null) return false;

            Transaction t = o.GetEmptyTransaction();
            t.Card = previousTransaction.CreditCard;
            t.Action = ActionType.CreditCardRefund;
            t.Amount = EnsurePositiveAmount(amount);
            t.PreviousTransactionNumber = previousTransaction.RefNum1;
            t.PreviousTransactionAuthCode = previousTransaction.RefNum2;
            OrderTransaction ot = new OrderTransaction(t);

            if (previousTransaction.Action != ActionType.CreditCardCapture 
                && previousTransaction.Action != ActionType.CreditCardCharge
                && previousTransaction.Action != ActionType.CreditCardInfo)
            {
                ot.Success = false;
                ot.Messages = "Transaction must be CC capture or charge type to refund.";
                return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
            }

            RequestContext context = this.MTApp.CurrentRequestContext;
            Method processor = context.CurrentStore.Settings.PaymentCurrentCreditCardProcessor();
            if (processor != null)
            {
                processor.ProcessTransaction(t);
                ot = new OrderTransaction(t);
                ot.LinkedToTransaction = previousTransaction.IdAsString;
            }
            return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
        }
 // Offline Payment Info
 public bool OfflinePaymentAddInfo(decimal amount, string description)
 {        
     Transaction t = o.GetEmptyTransaction();
     t.Amount = EnsurePositiveAmount(amount);            
     t.Action = ActionType.OfflinePaymentRequest;
     OrderTransaction ot = new OrderTransaction(t);
     ot.Messages = description;
     ot.Success = true;
     return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
 }
 public void CopyToPayment(OrderTransaction ot)
 {
     ot.CreditCard.ExpirationMonth = ExpirationMonth;
     ot.CreditCard.ExpirationYear = ExpirationYear;
     ot.CreditCard.CardHolderName = CardHolderName;
     if (CardNumber.StartsWith("*") == false)
     {
         ot.CreditCard.CardNumber = CardNumber;
     }
     ot.CreditCard.SecurityCode = SecurityCode;
     //if (ccissuenumber.Text.Trim() != string.Empty) {
     //    ot.CustomPropertySet("bvsoftware", "issuenumber", ccissuenumber.Text);
     //}
 }
        public bool CreditCardVoid(OrderTransaction previousTransaction, decimal amount)
        {
            if (previousTransaction == null) return false;
            
            Transaction t = o.GetEmptyTransaction();
            t.Card = previousTransaction.CreditCard;
            t.Action = ActionType.CreditCardVoid;
            t.Amount = EnsurePositiveAmount(amount);
            t.PreviousTransactionNumber = previousTransaction.RefNum1;
            t.PreviousTransactionAuthCode = previousTransaction.RefNum2;
            OrderTransaction ot = new OrderTransaction(t);

            if (!previousTransaction.IsVoidable)
            {
                ot.Success = false;
                ot.Messages = "Transaction can not be voided.";
                return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
            }

            RequestContext context = this.MTApp.CurrentRequestContext;
            Method processor = context.CurrentStore.Settings.PaymentCurrentCreditCardProcessor();
            if (processor != null)
            {
                processor.ProcessTransaction(t);
                ot = new OrderTransaction(t);
                ot.LinkedToTransaction = previousTransaction.IdAsString;

                // if the void went through, make sure we mark the previous transaction as voided
                if (t.Result.Succeeded)
                {
                    previousTransaction.Voided = true;
                    svc.Transactions.Update(previousTransaction);
                }
            }
            return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
        }