Пример #1
0
        private static JObject ToDto(PaypalPayer payer)
        {
            if (payer == null)
            {
                throw new ArgumentNullException(nameof(payer));
            }

            var jObj          = new JObject();
            var payerInfo     = new JObject();
            var paymentMethod = string.Empty;

            switch (payer.PaymentMethod)
            {
            case PaypalPaymentMethods.CreditCard:
                paymentMethod = "credit_card";
                break;

            case PaypalPaymentMethods.Paypal:
                paymentMethod = "paypal";
                break;
            }

            payerInfo.Add("email", payer.Email);
            // payerInfo.Add("first_name", payer.FirstName);
            // payerInfo.Add("last_name", payer.LastName);
            // payerInfo.Add("middle_name", payer.MiddleName);
            // TODO : Continue
            jObj.Add("payment_method", paymentMethod);
            jObj.Add("payer_info", payerInfo);
            return(jObj);
        }
Пример #2
0
        private static PaypalPayer ToPayerModel(JObject jObj)
        {
            if (jObj == null)
            {
                throw new ArgumentNullException(nameof(jObj));
            }

            var result        = new PaypalPayer();
            var paymentMethod = jObj.Value <string>("payment_method");

            if (paymentMethod == "credit_card")
            {
                result.PaymentMethod = PaypalPaymentMethods.CreditCard;
            }
            else if (paymentMethod == "paypal")
            {
                result.PaymentMethod = PaypalPaymentMethods.Paypal;
            }

            var payerInfo = jObj.GetValue("payer_info") as JObject;

            if (payerInfo != null)
            {
                result.Email      = payerInfo.Value <string>("email");
                result.FirstName  = payerInfo.Value <string>("first_name");
                result.MiddleName = payerInfo.Value <string>("middle_name");
                result.LastName   = payerInfo.Value <string>("last_name");
                result.Suffix     = payerInfo.Value <string>("suffix");
                result.PayerId    = payerInfo.Value <string>("payer_id");
            }

            return(result);
        }
Пример #3
0
        protected void btnNextStep_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    PayPalExpressPaymentProcessor payPalExpress = new PayPalExpressPaymentProcessor();
                    string      token = CommonHelper.QueryString("token");
                    PaypalPayer payer = payPalExpress.GetExpressCheckout(token);
                    if (string.IsNullOrEmpty(payer.PayerID))
                    {
                        throw new NopException("Payer ID is not set");
                    }

                    PaymentInfo paymentInfo = new PaymentInfo();

                    PaymentMethod paypalExpressPaymentMethod = PaymentMethodManager.GetPaymentMethodBySystemKeyword("PayPalExpress");

                    paymentInfo.PaymentMethodId  = paypalExpressPaymentMethod.PaymentMethodId;
                    paymentInfo.BillingAddress   = NopContext.Current.User.BillingAddress;
                    paymentInfo.ShippingAddress  = NopContext.Current.User.ShippingAddress;
                    paymentInfo.PaypalPayerId    = payer.PayerID;
                    paymentInfo.PaypalToken      = token;
                    paymentInfo.CustomerLanguage = NopContext.Current.WorkingLanguage;
                    paymentInfo.CustomerCurrency = NopContext.Current.WorkingCurrency;

                    int    orderId = 0;
                    string result  = OrderManager.PlaceOrder(paymentInfo, NopContext.Current.User, out orderId);

                    Order order = OrderManager.GetOrderById(orderId);
                    if (!String.IsNullOrEmpty(result))
                    {
                        lConfirmOrderError.Text = Server.HtmlEncode(result);
                        btnNextStep.Visible     = false;
                        return;
                    }
                    else
                    {
                        PaymentManager.PostProcessPayment(order);
                    }
                    Response.Redirect("~/checkoutcompleted.aspx");
                }
                catch (Exception exc)
                {
                    LogManager.InsertLog(LogTypeEnum.OrderError, exc.Message, exc);
                    lConfirmOrderError.Text = Server.HtmlEncode(exc.ToString());
                    btnNextStep.Visible     = false;
                }
            }
        }