Example #1
0
        /// <summary>
        /// Finalizes the sale and performs the redirection.
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <param name="attempt">
        /// The attempt.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        /// <remarks>
        /// This overrides the default behavior to redirect to PayPal
        /// </remarks>
        protected override ActionResult FinalizeSale(CheckoutConfirmationForm model, IPaymentResult attempt)
        {
            if (attempt.Payment.Success)
            {
                CustomerContext.SetValue("invoiceKey", attempt.Invoice.Key.ToString());

                // Trigger the order confirmation notification
                var    billingAddress = attempt.Invoice.GetBillingAddress();
                string contactEmail;
                if (string.IsNullOrEmpty(billingAddress.Email) && !CurrentCustomer.IsAnonymous)
                {
                    contactEmail = ((ICustomer)CurrentCustomer).Email;
                }
                else
                {
                    contactEmail = billingAddress.Email;
                }

                if (!string.IsNullOrEmpty(contactEmail))
                {
                    Notification.Trigger("OrderConfirmation", attempt, new[] { contactEmail });
                }

                return(Redirect(attempt.RedirectUrl));
            }

            throw new NotImplementedException();
        }
 private static void AssertFailWhenResultIsNotSucceed(IPaymentResult result)
 {
     if (!result.IsSucceed)
     {
         Assert.Fail($"Result message: {result.Message}");
     }
 }
 /// <summary>
 /// Raises the Finalizing event.
 /// </summary>
 /// <param name="result">
 /// The result.
 /// </param>
 protected void OnFinalizing(IPaymentResult result)
 {
     if (Finalizing != null)
     {
         Finalizing.RaiseEvent(new CheckoutEventArgs <IPaymentResult>(Context.Customer, result), this);
     }
 }
Example #4
0
 /// <summary>
 /// Ensures ApproveOrderCreation setting.
 /// </summary>
 /// <param name="response">
 /// The response.
 /// </param>
 /// <param name="invoice">
 /// The invoice.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 private bool EnsureApproveOrderCreation(IPaymentResult response, IInvoice invoice)
 {
     if (!response.ApproveOrderCreation)
     {
         return(response.ApproveOrderCreation);
     }
     return(!invoice.ShippableItems().Any() ? response.ApproveOrderCreation : response.ApproveOrderCreation);
 }
Example #5
0
        /// <summary>
        /// Creates an order if approved
        /// </summary>
        /// <param name="result">
        /// The result.
        /// </param>
        private static void CreateOrder(IPaymentResult result)
        {
            if (!result.Payment.Success || !result.ApproveOrderCreation) return;

            // order
            var order = result.Invoice.PrepareOrder(MerchelloContext.Current);

            MerchelloContext.Current.Services.OrderService.Save(order);
        }
Example #6
0
 /// <summary>
 /// The to order confirmation notification.
 /// </summary>
 /// <param name="paymentResult">
 /// The payment result.
 /// </param>
 /// <param name="contacts">
 /// The contacts.
 /// </param>
 /// <returns>
 /// The <see cref="IPaymentResultMonitorModel"/>.
 /// </returns>
 public static IPaymentResultMonitorModel ToOrderConfirmationNotification(this IPaymentResult paymentResult, IEnumerable <string> contacts)
 {
     return(new PaymentResultNotifyModel()
     {
         PaymentSuccess = paymentResult.Payment.Success,
         Payment = paymentResult.Payment.Success ? paymentResult.Payment.Result : null,
         Invoice = paymentResult.Invoice,
         Contacts = contacts.ToArray()
     });
 }
Example #7
0
        /// <summary>
        /// Provides the assertion that the payment is applied to the invoice
        /// </summary>
        /// <param name="response">
        /// The response.
        /// </param>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        private void AssertPaymentApplied(IPaymentResult response, IInvoice invoice)
        {
            // Apply the payment to the invoice if it was not done in the sub class
            var payment = response.Payment.Result;

            if (payment.AppliedPayments(GatewayProviderService).FirstOrDefault(x => x.InvoiceKey == invoice.Key) == null)
            {
                GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, PaymentMethod.Name, payment.Amount);
            }
        }
Example #8
0
        public ActionResult SavePayment(PaymentInformationModel model)
        {
            // has error occurred
            bool error = false;

            // do we raise events
            bool raiseEvents = false;

            // payment attempt result information
            IPaymentResult attempt = null;

            // get payment method
            var paymentMethod = Payment.GetPaymentGatewayMethodByKey(model.PaymentMethodKey).PaymentMethod;

            // get customer, items
            var preparation = base.Basket.SalePreparation();

            // Save the payment method selection
            preparation.SavePaymentMethod(paymentMethod);

            // make sure there is a billing address - it can be empty - it just has to exist
            if (!preparation.IsReadyToInvoice())
            {
                return(RedirectToUmbracoPage(BasketPageId));
            }

            // AuthorizePayment will save the invoice with an Invoice Number.
            attempt = preparation.AuthorizePayment(paymentMethod.Key);

            // if payment isn't successful, grab some information
            if (!attempt.Payment.Success)
            {
                error = true;

                // TBD - Not in Merchello yet
                // Notification.Trigger("OrderConfirmationFailure", attempt, new[] { preparation.GetBillToAddress().Email });

                _log.CreateAuditLogWithKey("Checkout failed - attempt payment failure", preparation.Customer.ExtendedData);
            }
            else
            {
                // trigger the order notification confirmation
                Notification.Trigger("OrderConfirmation", attempt, new[] { preparation.GetBillToAddress().Email });
            }

            // grab final content page
            var receipt = Umbraco.TypedContent(ReceiptId);

            // redirect so that url has invoice number (encrypted) in address bar
            // this feels clunky and unsafe but illustrative all the same
            return
                (Redirect(string.Format("{0}?inv={1}", receipt.Url,
                                        attempt.Invoice.Key.ToString().EncryptWithMachineKey())));
        }
Example #9
0
        /// <summary>
        /// Creates an order if approved
        /// </summary>
        /// <param name="result">
        /// The result.
        /// </param>
        private static void CreateOrder(IPaymentResult result)
        {
            if (!result.Payment.Success || !result.ApproveOrderCreation)
            {
                return;
            }

            // order
            var order = result.Invoice.PrepareOrder(MerchelloContext.Current);

            MerchelloContext.Current.Services.OrderService.Save(order);
        }
Example #10
0
 /// <summary>
 /// The to order confirmation notification.
 /// </summary>
 /// <param name="paymentResult">
 /// The payment result.
 /// </param>
 /// <param name="contacts">
 /// The contacts.
 /// </param>
 /// <param name="shipment">
 /// The shipment.
 /// </param>
 /// <param name="shipMethod">
 /// The ship Method.
 /// </param>
 /// <param name="currencySymbol">
 /// The currency Symbol.
 /// </param>
 /// <returns>
 /// The <see cref="IPaymentResultMonitorModel"/>.
 /// </returns>
 public static IPaymentResultMonitorModel ToOrderConfirmationNotification(this IPaymentResult paymentResult, IEnumerable <string> contacts, IShipment shipment = null, IShipMethod shipMethod = null, string currencySymbol = "")
 {
     return(new PaymentResultNotifyModel()
     {
         PaymentSuccess = paymentResult.Payment.Success,
         Payment = paymentResult.Payment.Success ? paymentResult.Payment.Result : null,
         Invoice = paymentResult.Invoice,
         Contacts = contacts.ToArray(),
         Shipment = shipment,
         ShipMethod = shipMethod,
         CurrencySymbol = currencySymbol,
         ApproveOrderCreation = paymentResult.ApproveOrderCreation
     });
 }
Example #11
0
        /// <summary>
        /// Handles the order confirmation.
        /// </summary>
        /// <param name="model">
        /// The <see cref="ICheckoutPaymentModel"/>.
        /// </param>
        /// <param name="attempt">
        /// The <see cref="IPaymentResult"/>.
        /// </param>
        protected virtual void HandleNotificiation(TPaymentModel model, IPaymentResult attempt)
        {
            if (!attempt.Payment.Success)
            {
                return;
            }

            var billing = attempt.Invoice.GetBillingAddress();

            if (billing.Email.IsNullOrWhiteSpace())
            {
                return;
            }

            Notification.Trigger("OrderConfirmation", attempt, new[] { billing.Email });
        }
        private ActionResult RenderConfirmationThankyou(IPaymentResult attempt)
        {
            if (!attempt.Payment.Success)
            {
                // TODO Notification trigger for bad payment
                // Notific
            }
            else
            {
                // TODO Notify OrderConfirmation
                Basket.Empty();
            }


            //return RedirectToUmbracoPage(ReceiptId);
            var receipt = Umbraco.TypedContent(ReceiptId);

            return
                (Redirect(string.Format("{0}?inv={1}", receipt.Url,
                                        attempt.Invoice.Key.ToString().EncryptWithMachineKey())));
        }
Example #13
0
        private ActionResult RenderConfirmationThankyou(IPaymentResult attempt, string customerEmail)
        {
            if (!attempt.Payment.Success)
            {
                // TODO Notification trigger for bad payment
                // Notific
            }
            else
            {
                Basket.Empty();
                Basket.Save();

                // trigger the order notification confirmation
                Notification.Trigger("OrderConfirmation", attempt, new[] { customerEmail });
            }

            var receipt = Umbraco.TypedContent(GetContentIdByContentName(ReceiptPage));

            return
                (Redirect(string.Format("{0}?inv={1}", receipt.Url,
                                        attempt.Invoice.Key.ToString().EncryptWithMachineKey())));
        }
Example #14
0
        public static void LogInformation(string name, IPaymentResult result)
        {
            var txRefNum = result.Payment.Result.ExtendedData.GetValue(Constants.ExtendedDataKeys.TransactionReferenceNumber);
            var authTransacCode = result.Payment.Result.ExtendedData.GetValue(Constants.ExtendedDataKeys.AuthorizationTransactionCode);
            var avsResult = result.Payment.Result.ExtendedData.GetValue(Constants.ExtendedDataKeys.AvsResult);
            var cvv2Result = result.Payment.Result.ExtendedData.GetValue(Constants.ExtendedDataKeys.Cvv2Result);
            
            Console.WriteLine("TxRefNum:{0}", txRefNum);
            Console.WriteLine("Auth Code:{0}", authTransacCode.Split(',')[0]);
            Console.WriteLine("Response Code:{0}", authTransacCode.Split(',')[1]);
            Console.WriteLine("Approval Status:{0}", authTransacCode.Split(',')[2]);
            Console.WriteLine("avsResult:{0}", avsResult);
            Console.WriteLine("CVV2 Response:{0}", cvv2Result);

            var responseInfo = string.Format("{0}, TxRefNum:{1}, AuthCode:{2}, ResponseCode:{3}, AvsResult:{4}, Cvv2Result:{5}, ApprovalStatus:{6}", name, txRefNum, authTransacCode.Split(',')[0], authTransacCode.Split(',')[1], avsResult, cvv2Result, authTransacCode.Split(',')[2]);

            using (var file = new System.IO.StreamWriter("Certification.csv", true))
            {
                logging.LogMessageToFile(responseInfo,"certification");
                //file.WriteLine(responseInfo);
            }
        }
Example #15
0
        public static void LogInformation(string name, IPaymentResult result)
        {
            var txRefNum        = result.Payment.Result.ExtendedData.GetValue(Constants.ExtendedDataKeys.TransactionReferenceNumber);
            var authTransacCode = result.Payment.Result.ExtendedData.GetValue(Constants.ExtendedDataKeys.AuthorizationTransactionCode);
            var avsResult       = result.Payment.Result.ExtendedData.GetValue(Constants.ExtendedDataKeys.AvsResult);
            var cvv2Result      = result.Payment.Result.ExtendedData.GetValue(Constants.ExtendedDataKeys.Cvv2Result);

            Console.WriteLine("TxRefNum:{0}", txRefNum);
            Console.WriteLine("Auth Code:{0}", authTransacCode.Split(',')[0]);
            Console.WriteLine("Response Code:{0}", authTransacCode.Split(',')[1]);
            Console.WriteLine("Approval Status:{0}", authTransacCode.Split(',')[2]);
            Console.WriteLine("avsResult:{0}", avsResult);
            Console.WriteLine("CVV2 Response:{0}", cvv2Result);

            var responseInfo = string.Format("{0}, TxRefNum:{1}, AuthCode:{2}, ResponseCode:{3}, AvsResult:{4}, Cvv2Result:{5}, ApprovalStatus:{6}", name, txRefNum, authTransacCode.Split(',')[0], authTransacCode.Split(',')[1], avsResult, cvv2Result, authTransacCode.Split(',')[2]);

            using (var file = new System.IO.StreamWriter("Certification.csv", true))
            {
                logging.LogMessageToFile(responseInfo, "certification");
                //file.WriteLine(responseInfo);
            }
        }
        /// <summary>
        /// Finalizes the sale and performs the redirection.
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <param name="attempt">
        /// The attempt.
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        protected virtual ActionResult FinalizeSale(CheckoutConfirmationForm model, IPaymentResult attempt)
        {
            // Trigger the order confirmation notification
            var    billingAddress = attempt.Invoice.GetBillingAddress();
            string contactEmail;

            if (string.IsNullOrEmpty(billingAddress.Email) && !CurrentCustomer.IsAnonymous)
            {
                contactEmail = ((ICustomer)CurrentCustomer).Email;
            }
            else
            {
                contactEmail = billingAddress.Email;
            }

            if (!string.IsNullOrEmpty(contactEmail))
            {
                Notification.Trigger("OrderConfirmation", attempt, new[] { contactEmail });
            }

            return(RedirectToUmbracoPage(model.ReceiptPageId));
        }
Example #17
0
        public CFPaymentScreen(string Stage, string AppId, Dictionary <string, string> InputParams, IPaymentResult result)
        {
            this.Stage       = Stage;
            this.InputParams = InputParams;
            this.AppId       = AppId;
            var htmlSource = new HtmlWebViewSource
            {
                Html = CreateForm()
            };
            var browser = new WebView()
            {
                Source = htmlSource
            };

            browser.Navigating += (sender, e) => {
                if (e.Url.StartsWith("ios-sdk://", System.StringComparison.CurrentCulture))
                {
                    e.Cancel = true;
                    result.onComplete(WebUtility.UrlDecode(e.Url.Substring(30)));
                    Navigation.PopAsync();
                }
            };
            Content = browser;
        }
 private void AssertPaymentApplied(IPaymentResult response, IInvoice invoice)
 {
     // Apply the payment to the invoice if it was not done in the sub class
     var payment = response.Payment.Result;
     if (payment.AppliedPayments(GatewayProviderService).FirstOrDefault(x => x.InvoiceKey == invoice.Key) == null)
     {
         GatewayProviderService.ApplyPaymentToInvoice(payment.Key, invoice.Key, AppliedPaymentType.Debit, PaymentMethod.Name, payment.Amount);
     }
 }
 /// <summary>
 /// Raises the Finalizing event.
 /// </summary>
 /// <param name="result">
 /// The result.
 /// </param>
 protected void OnFinalizing(IPaymentResult result)
 {
     if (Finalizing != null)
     {
         Finalizing.RaiseEvent(new CheckoutEventArgs<IPaymentResult>(Context.Customer, result), this);
     }
 }
Example #20
0
 /// <summary>
 /// The notify extension method for <see cref="IPaymentResult"/>
 /// </summary>
 /// <param name="result">
 /// The result.
 /// </param>
 /// <param name="alias">
 /// The alias.
 /// </param>
 /// <param name="model">
 /// The model.
 /// </param>
 /// <param name="contacts">
 /// The contacts.
 /// </param>
 public static void Notify(this IPaymentResult result, string alias, object model, IEnumerable <string> contacts)
 {
     Notification.Trigger(alias, result, contacts);
 }
 /// <summary>
 /// Allows for overriding the creation of <see cref="ICheckoutPaymentModel"/>.
 /// </summary>
 /// <param name="model">
 /// The <see cref="ICheckoutPaymentModel"/>.
 /// </param>
 /// <param name="customer">
 /// The current customer.
 /// </param>
 /// <param name="paymentMethod">
 /// The <see cref="IPaymentMethod"/>.
 /// </param>
 /// <param name="attempt">
 /// The <see cref="IPaymentResult"/>.
 /// </param>
 /// <returns>
 /// The modified <see cref="ICheckoutPaymentModel"/>.
 /// </returns>
 protected virtual TPaymentModel OnCreate(TPaymentModel model, ICustomerBase customer, IPaymentMethod paymentMethod, IPaymentResult attempt)
 {
     return(model);
 }
Example #22
0
 /// <summary>
 /// To the order shipped notification.
 /// </summary>
 /// <param name="paymentResult">
 /// The payment result.
 /// </param>
 /// <returns>
 /// The <see cref="IPaymentResultMonitorModel"/>.
 /// </returns>
 public static IPaymentResultMonitorModel ToOrderShippedNotification(this IPaymentResult paymentResult)
 {
     return(paymentResult.ToOrderConfirmationNotification(new string[] { }));
 }
Example #23
0
 /// <summary>
 /// The notify extension method for <see cref="IPaymentResult"/>
 /// </summary>
 /// <param name="result">
 /// The <see cref="IPaymentResult"/>
 /// </param>
 /// <param name="alias">
 /// The alias.
 /// </param>
 /// <param name="model">
 /// The model.
 /// </param>
 public static void Notify(this IPaymentResult result, string alias, object model)
 {
     result.Notify(alias, model, new string[] { });
 }
        /// <summary>
        /// Creates a <see cref="ICheckoutPaymentModel"/>.
        /// </summary>
        /// <param name="customer">
        /// The current customer.
        /// </param>
        /// <param name="paymentMethod">
        /// The <see cref="IPaymentMethod"/>.
        /// </param>
        /// <param name="attempt">
        /// The <see cref="IPaymentResult"/>.
        /// </param>
        /// <returns>
        /// The <see cref="ICheckoutPaymentModel"/>.
        /// </returns>
        public TPaymentModel Create(ICustomerBase customer, IPaymentMethod paymentMethod, IPaymentResult attempt)
        {
            var model = Create(customer, paymentMethod);

            model.ViewData.Success    = attempt.Payment.Success;
            model.ViewData.InvoiceKey = attempt.Invoice.Key;
            if (attempt.Payment.Result != null)
            {
                model.ViewData.PaymentKey = attempt.Payment.Result.Key;
            }
            model.ViewData.Exception = attempt.Payment.Exception;
            if (attempt.Payment.Exception != null)
            {
                model.ViewData.Messages = new List <string> {
                    attempt.Payment.Exception.Message
                }
            }
            ;

            return(OnCreate(model, customer, paymentMethod, attempt));
        }
        private ActionResult RenderConfirmationThankyou(IPaymentResult attempt, string customerEmail)
        {
            if (!attempt.Payment.Success)
            {
                // TODO Notification trigger for bad payment
                // Notific
            }
            else
            {                
                Basket.Empty();
                Basket.Save();

                // trigger the order notification confirmation
                Notification.Trigger("OrderConfirmation", attempt, new[] { customerEmail });
            }


            //return RedirectToUmbracoPage(ReceiptId);
            var receipt = Umbraco.TypedContent(ReceiptId);

            return
                Redirect(string.Format("{0}?inv={1}", receipt.Url,
                                       attempt.Invoice.Key.ToString().EncryptWithMachineKey()));

        }
Example #26
0
 /// <summary>
 /// Overrides the creation of the <see cref="BraintreePaymentModel"/>.
 /// </summary>
 /// <param name="model">
 /// The <see cref="BraintreePaymentModel"/>.
 /// </param>
 /// <param name="customer">
 /// The current customer.
 /// </param>
 /// <param name="paymentMethod">
 /// The <see cref="IPaymentMethod"/>.
 /// </param>
 /// <param name="attempt">
 /// The <see cref="IPaymentResult"/>.
 /// </param>
 /// <returns>
 /// The modified <see cref="BraintreePaymentModel"/>.
 /// </returns>
 protected override TPaymentModel OnCreate(TPaymentModel model, ICustomerBase customer, IPaymentMethod paymentMethod, IPaymentResult attempt)
 {
     model.Token     = GetBraintreeToken(customer);
     model.RequireJs = true;
     return(base.OnCreate(model, customer, paymentMethod, attempt));
 }
Example #27
0
 /// <summary>
 /// The notify extension method for <see cref="IPaymentResult"/>
 /// </summary>
 /// <param name="result">
 /// The <see cref="IPaymentResult"/>
 /// </param>
 /// <param name="alias">
 /// The alias.
 /// </param>
 /// <remarks>
 /// This extension is intended for internal emails only.  To use to notify a customer,
 /// use the overloaded version and pass an array of contact addresses.
 /// </remarks>
 public static void Notify(this IPaymentResult result, string alias)
 {
     result.Notify(alias, new string[] { });
 }
 /// <summary>
 /// Ensures ApproveOrderCreation setting.
 /// </summary>
 /// <param name="response">
 /// The response.
 /// </param>
 /// <param name="invoice">
 /// The invoice.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 private bool EnsureApproveOrderCreation(IPaymentResult response, IInvoice invoice)
 {
     if (!response.ApproveOrderCreation) return response.ApproveOrderCreation;
     return !invoice.ShippableItems().Any() ? response.ApproveOrderCreation : response.ApproveOrderCreation;
 }