public override bool Execute(OrderTaskContext context)
        {
            bool result = true;

            foreach (Orders.OrderTransaction p in context.MTApp.OrderServices.Transactions.FindForOrder(context.Order.bvin))
            {
                List <Orders.OrderTransaction> transactions = context.MTApp.OrderServices.Transactions.FindForOrder(context.Order.bvin);

                if (p.Action == MerchantTribe.Payment.ActionType.CreditCardInfo ||
                    p.Action == MerchantTribe.Payment.ActionType.CreditCardHold)
                {
                    // if we already have an auth or charge on the card, skip
                    if (p.HasSuccessfulLinkedAction(MerchantTribe.Payment.ActionType.CreditCardCharge, transactions) ||
                        p.HasSuccessfulLinkedAction(MerchantTribe.Payment.ActionType.CreditCardHold, transactions))
                    {
                        continue;
                    }

                    try
                    {
                        MerchantTribe.Payment.Transaction t = context.Order.GetEmptyTransaction();
                        t.Card   = p.CreditCard;
                        t.Amount = p.Amount;

                        if (p.Action == MerchantTribe.Payment.ActionType.CreditCardHold)
                        {
                            t.Action = MerchantTribe.Payment.ActionType.CreditCardCapture;
                        }
                        else
                        {
                            t.Action = MerchantTribe.Payment.ActionType.CreditCardCharge;
                        }

                        MerchantTribe.Payment.Method proc = context.MTApp.CurrentRequestContext.CurrentStore.Settings.PaymentCurrentCreditCardProcessor();
                        proc.ProcessTransaction(t);

                        Orders.OrderTransaction ot = new Orders.OrderTransaction(t);
                        ot.LinkedToTransaction = p.IdAsString;

                        context.MTApp.OrderServices.AddPaymentTransactionToOrder(context.Order, ot, context.MTApp);

                        if (t.Result.Succeeded == false)
                        {
                            result = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        context.Errors.Add(new WorkflowMessage("Exception During Complete Credit Card", ex.Message + ex.StackTrace, false));
                    }
                }

                Orders.OrderPaymentStatus previousPaymentStatus = context.Order.PaymentStatus;
                context.MTApp.OrderServices.EvaluatePaymentStatus(context.Order);
                context.Inputs.Add("bvsoftware", "PreviousPaymentStatus", previousPaymentStatus.ToString());
                BusinessRules.Workflow.RunByName(context, WorkflowNames.PaymentChanged);
            }

            return(result);
        }
Exemplo n.º 2
0
        public bool Void(MerchantTribe.Payment.Transaction t, MerchantTribeApplication app)
        {
            PayPalAPI ppAPI = Utilities.PaypalExpressUtilities.GetPaypalAPI(app.CurrentStore);

            try
            {
                if (t.PreviousTransactionNumber != null)
                {
                    DoVoidResponseType voidResponse = ppAPI.DoVoid(t.PreviousTransactionNumber,
                                                                   "Transaction Voided");
                    if ((voidResponse.Ack == AckCodeType.Success) || (voidResponse.Ack == AckCodeType.SuccessWithWarning))
                    {
                        t.Result.Succeeded = true;
                        t.Result.Messages.Add(new MerchantTribe.Payment.Message("PayPal Express Payment Voided Successfully.", "OK", MerchantTribe.Payment.MessageType.Information));
                        return(true);
                    }
                    else
                    {
                        t.Result.Succeeded = false;
                        t.Result.Messages.Add(new MerchantTribe.Payment.Message("Paypal Express Payment Void Failed.", "", MerchantTribe.Payment.MessageType.Error));
                        foreach (ErrorType ppError in voidResponse.Errors)
                        {
                            t.Result.Messages.Add(new MerchantTribe.Payment.Message(ppError.LongMessage, ppError.ErrorCode, MerchantTribe.Payment.MessageType.Error));
                        }
                        return(false);
                    }
                }
            }
            finally
            {
                ppAPI = null;
            }
            return(false);
        }
Exemplo n.º 3
0
        public bool RecordPaymentTransaction(MerchantTribe.Payment.Transaction t, Orders.Order o)
        {
            OrderTransaction ot = new OrderTransaction(t);

            ot.OrderId = o.bvin;
            ot.StoreId = o.StoreId;
            return(Create(ot));
        }
Exemplo n.º 4
0
        public bool Charge(MerchantTribe.Payment.Transaction t, MerchantTribeApplication app)
        {
            PayPalAPI ppAPI = Utilities.PaypalExpressUtilities.GetPaypalAPI(app.CurrentStore);

            try {
                string OrderNumber = t.MerchantInvoiceNumber + System.Guid.NewGuid().ToString();

                DoExpressCheckoutPaymentResponseType paymentResponse;
                //there was no authorization so we just need to do a direct sale
                paymentResponse = ppAPI.DoExpressCheckoutPayment(t.PreviousTransactionNumber,
                                                                 t.PreviousTransactionAuthCode,
                                                                 string.Format("{0:N}", t.Amount),
                                                                 PaymentActionCodeType.Sale,
                                                                 PayPalAPI.GetCurrencyCodeType(app.CurrentStore.Settings.PayPal.Currency),
                                                                 OrderNumber);

                if ((paymentResponse.Ack == AckCodeType.Success) || (paymentResponse.Ack == AckCodeType.SuccessWithWarning))
                {
                    t.Result.ReferenceNumber = paymentResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.TransactionID;

                    if (paymentResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.PaymentStatus == PaymentStatusCodeType.Completed)
                    {
                        t.Result.Succeeded = true;
                        t.Result.Messages.Add(new MerchantTribe.Payment.Message("PayPal Express Payment Charged Successfully.", "OK", MerchantTribe.Payment.MessageType.Information));
                        return(true);
                    }
                    else if (paymentResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.PaymentStatus == PaymentStatusCodeType.Pending)
                    {
                        t.Result.Succeeded               = true;
                        t.Result.ResponseCode            = "PENDING";
                        t.Result.ResponseCodeDescription = "PayPal Express Payment PENDING";
                        t.Result.Messages.Add(new MerchantTribe.Payment.Message("Paypal Express Payment PENDING.", "OK", MerchantTribe.Payment.MessageType.Information));
                        return(true);
                    }
                    else
                    {
                        t.Result.Succeeded = false;
                        t.Result.Messages.Add(new MerchantTribe.Payment.Message("An error occurred while trying to charge your PayPal payment.", "", MerchantTribe.Payment.MessageType.Error));
                        return(false);
                    }
                }
                else
                {
                    t.Result.Succeeded = false;
                    t.Result.Messages.Add(new MerchantTribe.Payment.Message("Paypal Express Payment Charge Failed.", "", MerchantTribe.Payment.MessageType.Error));
                    foreach (ErrorType ppError in paymentResponse.Errors)
                    {
                        t.Result.Messages.Add(new MerchantTribe.Payment.Message(ppError.LongMessage, ppError.ErrorCode, MerchantTribe.Payment.MessageType.Error));
                    }
                    return(false);
                }
            }
            finally
            {
                ppAPI = null;
            }
        }
Exemplo n.º 5
0
        public Transaction ChargeCardForInvoice(Invoice inv, MerchantTribe.Payment.Method method)
        {
            Transaction t = new Transaction();

            t.Action = MerchantTribe.Payment.ActionType.CreditCardCharge;

            if (inv != null)
            {
                BillingAccount account = Accounts.FindById(inv.AccountId);
                if (account != null)
                {
                    if (!account.HasValidCreditCard(DateTime.Now))
                    {
                        t.Messages += "Billing Account does not have a valid credit card on file.";
                    }
                    else
                    {
                        t.AccountId        = inv.AccountId;
                        t.InvoiceReference = inv.Id.ToString();

                        MerchantTribe.Payment.Transaction payTrans = new MerchantTribe.Payment.Transaction();
                        payTrans.Action = MerchantTribe.Payment.ActionType.CreditCardCharge;
                        payTrans.Amount = inv.TotalGrand();
                        payTrans.Card   = account.CreditCard;
                        payTrans.Customer.PostalCode   = account.BillingZipCode;
                        payTrans.MerchantDescription   = "BV Software";
                        payTrans.MerchantInvoiceNumber = inv.Id.ToString();

                        method.ProcessTransaction(payTrans);

                        t.PopulateFromPaymentTransaction(payTrans);
                    }
                }
                else
                {
                    t.Messages += "Billing Account could not be located";
                }
            }
            else
            {
                t.Messages += "Invoice was null.";
            }

            t = Transactions.CreateAndLoad(t);

            return(t);
        }
Exemplo n.º 6
0
        public bool Authorize(MerchantTribe.Payment.Transaction t, MerchantTribeApplication app)
        {
            PayPalAPI ppAPI = Utilities.PaypalExpressUtilities.GetPaypalAPI(app.CurrentStore);

            try
            {
                DoExpressCheckoutPaymentResponseType paymentResponse;
                if (t.PreviousTransactionNumber != null)
                {
                    paymentResponse = ppAPI.DoExpressCheckoutPayment(t.PreviousTransactionNumber,
                                                                     t.PreviousTransactionAuthCode,
                                                                     string.Format("{0:N}", t.Amount),
                                                                     PaymentActionCodeType.Order,
                                                                     PayPalAPI.GetCurrencyCodeType(app.CurrentStore.Settings.PayPal.Currency),
                                                                     t.MerchantInvoiceNumber + System.Guid.NewGuid().ToString());

                    if ((paymentResponse.Ack == AckCodeType.Success) || (paymentResponse.Ack == AckCodeType.SuccessWithWarning))
                    {
                        t.Result.Succeeded               = true;
                        t.Result.ReferenceNumber         = paymentResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.TransactionID;
                        t.Result.ResponseCode            = "OK";
                        t.Result.ResponseCodeDescription = "PayPal Express Payment Authorized Successfully.";
                        return(true);
                    }
                    else
                    {
                        t.Result.Succeeded = false;
                        t.Result.Messages.Add(new MerchantTribe.Payment.Message("PayPal Express Payment Authorization Failed.", "", MerchantTribe.Payment.MessageType.Error));
                        foreach (ErrorType ppError in paymentResponse.Errors)
                        {
                            t.Result.Messages.Add(new MerchantTribe.Payment.Message(ppError.LongMessage, ppError.ErrorCode, MerchantTribe.Payment.MessageType.Error));
                        }
                        return(false);
                    }
                }
            }
            finally
            {
                ppAPI = null;
            }

            return(false);
        }
Exemplo n.º 7
0
        public bool Refund(MerchantTribe.Payment.Transaction t, MerchantTribeApplication app)
        {
            PayPalAPI ppAPI = Utilities.PaypalExpressUtilities.GetPaypalAPI(app.CurrentStore);

            try {
                if (t.PreviousTransactionNumber != null)
                {
                    string refundType = string.Empty;
                    //per paypal's request, the refund type should always be set to partial
                    refundType = "Partial";
                    RefundTransactionResponseType refundResponse
                        = ppAPI.RefundTransaction(t.PreviousTransactionNumber,
                                                  refundType, string.Format("{0:N}", t.Amount));
                    if ((refundResponse.Ack == AckCodeType.Success) || (refundResponse.Ack == AckCodeType.SuccessWithWarning))
                    {
                        t.Result.Succeeded = true;
                        t.Result.Messages.Add(new MerchantTribe.Payment.Message("PayPal Express Payment Refunded Successfully.", "OK", MerchantTribe.Payment.MessageType.Information));
                        return(true);
                    }
                    else
                    {
                        t.Result.Succeeded = false;
                        t.Result.Messages.Add(new MerchantTribe.Payment.Message("Paypal Express Payment Refund Failed.", "", MerchantTribe.Payment.MessageType.Error));
                        foreach (ErrorType ppError in refundResponse.Errors)
                        {
                            t.Result.Messages.Add(new MerchantTribe.Payment.Message(ppError.LongMessage, ppError.ErrorCode, MerchantTribe.Payment.MessageType.Error));
                        }
                        return(false);
                    }
                }
            }
            finally
            {
                ppAPI = null;
            }

            return(false);
        }
Exemplo 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));
 }
Exemplo n.º 9
0
        public override bool Execute(OrderTaskContext context)
        {
            bool result = true;

            if (context.MTApp.OrderServices.PaymentSummary(context.Order).AmountDue > 0)
            {
                foreach (Orders.OrderTransaction p in context.MTApp.OrderServices.Transactions.FindForOrder(context.Order.bvin))
                {
                    List <Orders.OrderTransaction> transactions = context.MTApp.OrderServices.Transactions.FindForOrder(context.Order.bvin);

                    if (p.Action == MerchantTribe.Payment.ActionType.CreditCardInfo)
                    {
                        // if we already have an auth or charge on the card, skip
                        if (p.HasSuccessfulLinkedAction(MerchantTribe.Payment.ActionType.CreditCardCharge, transactions) ||
                            p.HasSuccessfulLinkedAction(MerchantTribe.Payment.ActionType.CreditCardHold, transactions))
                        {
                            Orders.OrderNote note = new Orders.OrderNote();
                            note.IsPublic = false;
                            note.Note     = "Skipping receive for credit card info because auth or charge already exists. Transaction " + p.Id;
                            context.Order.Notes.Add(note);
                            continue;
                        }

                        try
                        {
                            MerchantTribe.Payment.Transaction t = context.Order.GetEmptyTransaction();
                            t.Card   = p.CreditCard;
                            t.Amount = p.Amount;

                            if (context.MTApp.CurrentRequestContext.CurrentStore.Settings.PaymentCreditCardAuthorizeOnly == true)
                            {
                                t.Action = MerchantTribe.Payment.ActionType.CreditCardHold;
                            }
                            else
                            {
                                t.Action = MerchantTribe.Payment.ActionType.CreditCardCharge;
                            }

                            MerchantTribe.Payment.Method proc = context.MTApp.CurrentRequestContext.CurrentStore.Settings.PaymentCurrentCreditCardProcessor();
                            proc.ProcessTransaction(t);

                            Orders.OrderTransaction ot = new Orders.OrderTransaction(t);
                            ot.LinkedToTransaction = p.IdAsString;
                            context.MTApp.OrderServices.AddPaymentTransactionToOrder(context.Order, ot, context.MTApp);

                            if (t.Result.Succeeded == false)
                            {
                                result = false;
                            }
                        }
                        catch (Exception ex)
                        {
                            context.Errors.Add(new WorkflowMessage("Exception During Receive Credit Card", ex.Message + ex.StackTrace, false));
                            Orders.OrderNote note = new Orders.OrderNote();
                            note.IsPublic = false;
                            note.Note     = "EXCEPTION: " + ex.Message + " | " + ex.StackTrace;
                            context.Order.Notes.Add(note);
                        }
                    }
                }

                // Evaluate Payment Status After Receiving Payments
                Orders.OrderPaymentStatus previousPaymentStatus = context.Order.PaymentStatus;
                context.MTApp.OrderServices.EvaluatePaymentStatus(context.Order);
                context.Inputs.Add("bvsoftware", "PreviousPaymentStatus", previousPaymentStatus.ToString());
                BusinessRules.Workflow.RunByName(context, WorkflowNames.PaymentChanged);
            }
            else
            {
                Orders.OrderNote note = new Orders.OrderNote();
                note.IsPublic = false;
                note.Note     = "Amount due was less than zero. Skipping receive credit cards";
                context.Order.Notes.Add(note);
            }



            if (result == false)
            {
                // Add Error
                bool throwErrors = false;
                throwErrors = context.MTApp.CurrentRequestContext.CurrentStore.Settings.RejectFailedCreditCardOrdersAutomatically;
                if (throwErrors == true)
                {
                    if (result == false)
                    {
                        string errorString = string.Empty; // this.SettingsManager.GetSetting("CustomerErrorMessage");
                        if (errorString == string.Empty)
                        {
                            errorString = "An error occured while attempting to process your credit card. Please check your payment information and try again";
                        }
                        context.Errors.Add(new WorkflowMessage("Receive Card Failed", errorString, true));
                    }
                }
                else
                {
                    // Hide Error
                    result = true;
                }

                // Failure Status Code
                bool SetStatus = false;
                SetStatus = true; // this.SettingsManager.GetBooleanSetting("SetStatusOnFail");
                if (SetStatus == true)
                {
                    string failCode          = Orders.OrderStatusCode.OnHold;
                    Orders.OrderStatusCode c = Orders.OrderStatusCode.FindByBvin(failCode);
                    if (c != null)
                    {
                        context.Order.StatusCode = c.Bvin;
                        context.Order.StatusName = c.StatusName;
                    }
                }
            }
            return(result);
        }
Exemplo n.º 10
0
        public bool Capture(MerchantTribe.Payment.Transaction t, MerchantTribeApplication app)
        {
            PayPalAPI ppAPI = Utilities.PaypalExpressUtilities.GetPaypalAPI(app.CurrentStore);

            try
            {
                string OrderNumber = t.MerchantInvoiceNumber + System.Guid.NewGuid().ToString();

                DoCaptureResponseType captureResponse = ppAPI.DoCapture(t.PreviousTransactionNumber,
                                                                        "Thank you for your payment.",
                                                                        string.Format("{0:N}", t.Amount),
                                                                        PayPalAPI.GetCurrencyCodeType(app.CurrentStore.Settings.PayPal.Currency),
                                                                        OrderNumber);

                if ((captureResponse.Ack == AckCodeType.Success) || (captureResponse.Ack == AckCodeType.SuccessWithWarning))
                {
                    t.Result.ReferenceNumber = captureResponse.DoCaptureResponseDetails.PaymentInfo.TransactionID;

                    if (captureResponse.DoCaptureResponseDetails.PaymentInfo.PaymentStatus == PaymentStatusCodeType.Pending)
                    {
                        t.Result.Succeeded               = true;
                        t.Result.ResponseCode            = "PENDING";
                        t.Result.ResponseCodeDescription = "PayPal Express Payment PENDING";
                        t.Result.Messages.Add(new MerchantTribe.Payment.Message("Paypal Express Payment PENDING.", "OK", MerchantTribe.Payment.MessageType.Information));
                        return(true);
                    }
                    else if (captureResponse.DoCaptureResponseDetails.PaymentInfo.PaymentStatus == PaymentStatusCodeType.InProgress)
                    {
                        t.Result.Succeeded               = true;
                        t.Result.ResponseCode            = "PENDING";
                        t.Result.ResponseCodeDescription = "PayPal Express Payment IN PROGRESS";
                        t.Result.Messages.Add(new MerchantTribe.Payment.Message("Paypal Express Payment PENDING. In Progress.", "OK", MerchantTribe.Payment.MessageType.Information));
                        return(true);
                    }
                    else if (captureResponse.DoCaptureResponseDetails.PaymentInfo.PaymentStatus == PaymentStatusCodeType.None)
                    {
                        t.Result.Succeeded               = true;
                        t.Result.ResponseCode            = "PENDING";
                        t.Result.ResponseCodeDescription = "PayPal Express Payment: No Status Yet";
                        t.Result.Messages.Add(new MerchantTribe.Payment.Message("Paypal Express Payment PENDING. No Status Yet.", "OK", MerchantTribe.Payment.MessageType.Information));
                        return(true);
                    }
                    else if (captureResponse.DoCaptureResponseDetails.PaymentInfo.PaymentStatus == PaymentStatusCodeType.Processed)
                    {
                        t.Result.Succeeded               = true;
                        t.Result.ResponseCode            = "PENDING";
                        t.Result.ResponseCodeDescription = "PayPal Express Payment PENDING";
                        t.Result.Messages.Add(new MerchantTribe.Payment.Message("Paypal Express Payment PENDING.", "OK", MerchantTribe.Payment.MessageType.Information));
                        return(true);
                    }
                    else if (captureResponse.DoCaptureResponseDetails.PaymentInfo.PaymentStatus == PaymentStatusCodeType.Completed)
                    {
                        t.Result.Succeeded = true;
                        t.Result.Messages.Add(new MerchantTribe.Payment.Message("PayPal Express Payment Captured Successfully.", "OK", MerchantTribe.Payment.MessageType.Information));
                        return(true);
                    }
                    else
                    {
                        t.Result.Succeeded = false;
                        t.Result.Messages.Add(new MerchantTribe.Payment.Message("An error occurred while trying to capture your PayPal payment.", "", MerchantTribe.Payment.MessageType.Error));
                        return(false);
                    }
                }
                else
                {
                    t.Result.Succeeded = false;
                    t.Result.Messages.Add(new MerchantTribe.Payment.Message("Paypal Express Payment Charge Failed.", "", MerchantTribe.Payment.MessageType.Error));
                    foreach (ErrorType ppError in captureResponse.Errors)
                    {
                        t.Result.Messages.Add(new MerchantTribe.Payment.Message(ppError.LongMessage, ppError.ErrorCode, MerchantTribe.Payment.MessageType.Error));
                    }
                    return(false);
                }
            }
            finally
            {
                ppAPI = null;
            }
        }
Exemplo n.º 11
0
        // Payments
        public MerchantTribe.Payment.Transaction GetEmptyTransaction()
        {
            MerchantTribe.Payment.Transaction t = new MerchantTribe.Payment.Transaction();

            t.Customer.City = this.BillingAddress.City;
            t.Customer.Company = this.BillingAddress.Company;
            t.Customer.Country = this.BillingAddress.CountryName;
            t.Customer.Email = this.UserEmail;
            t.Customer.FirstName = this.BillingAddress.FirstName;
            t.Customer.LastName = this.BillingAddress.LastName;
            t.Customer.Phone = this.BillingAddress.Phone;
            t.Customer.PostalCode = this.BillingAddress.PostalCode;
            t.Customer.Region = this.BillingAddress.RegionName;
            t.Customer.Street = this.BillingAddress.Line1;

            t.Customer.ShipCity = this.ShippingAddress.City;
            t.Customer.ShipCompany = this.ShippingAddress.Company;
            t.Customer.ShipCountry = this.ShippingAddress.CountryName;
            t.Customer.ShipFirstName = this.ShippingAddress.FirstName;
            t.Customer.ShipLastName = this.ShippingAddress.LastName;
            t.Customer.ShipPhone = this.ShippingAddress.Phone;
            t.Customer.ShipPostalCode = this.ShippingAddress.PostalCode;
            t.Customer.ShipRegion = this.ShippingAddress.RegionName;
            t.Customer.ShipStreet = this.ShippingAddress.Line1;

            t.MerchantDescription = "Order " + this.OrderNumber;
            t.MerchantInvoiceNumber = this.OrderNumber;

            return t;
        }
Exemplo n.º 12
0
        public Transaction ChargeCardForInvoice(Invoice inv, MerchantTribe.Payment.Method method)
        {
            Transaction t = new Transaction();
            t.Action = MerchantTribe.Payment.ActionType.CreditCardCharge;

            if (inv != null)
            {

                BillingAccount account = Accounts.FindById(inv.AccountId);
                if (account != null)
                {
                    if (!account.HasValidCreditCard(DateTime.Now))
                    {
                        t.Messages += "Billing Account does not have a valid credit card on file.";
                    }
                    else
                    {

                        t.AccountId = inv.AccountId;
                        t.InvoiceReference = inv.Id.ToString();

                        MerchantTribe.Payment.Transaction payTrans = new MerchantTribe.Payment.Transaction();
                        payTrans.Action = MerchantTribe.Payment.ActionType.CreditCardCharge;
                        payTrans.Amount = inv.TotalGrand();
                        payTrans.Card = account.CreditCard;
                        payTrans.Customer.PostalCode = account.BillingZipCode;
                        payTrans.MerchantDescription = "BV Software";
                        payTrans.MerchantInvoiceNumber = inv.Id.ToString();

                        method.ProcessTransaction(payTrans);

                        t.PopulateFromPaymentTransaction(payTrans);
                    }
                }
                else
                {
                    t.Messages += "Billing Account could not be located";
                }

            }
            else
            {
                t.Messages += "Invoice was null.";
            }

            t = Transactions.CreateAndLoad(t);

            return t;
        }