Esempio n. 1
0
        private void PopulatePaymentDetails(SetExpressCheckoutRequestDetailsType ecDetails)
        {
            var paymentInfo = new PaymentDetailsType();
            var total       = 0.0;
            var currency    = CurrencyCodeType.GBP;
            var address     = new AddressType
            {
                Name            = Checkout.BillingInfo.FirstName + " " + Checkout.BillingInfo.SurName,
                Street1         = Checkout.BillingInfo.FirmName + " " + Checkout.BillingInfo.BuildingName + " " + Checkout.BillingInfo.StreetName,
                CityName        = Checkout.BillingInfo.City,
                StateOrProvince = Checkout.BillingInfo.County,
                PostalCode      = Checkout.BillingInfo.PostCode
            };

            paymentInfo.ShipToAddress = address;

            foreach (var item in Cart)
            {
                var itemInformation = new PaymentDetailsItemType();
                itemInformation.Name     = string.Format("{0}", item.Name);
                itemInformation.Quantity = item.Quantity;
                itemInformation.Amount   = new BasicAmountType(currency, item.UnitPriceInStr);
                total += item.TotalPrice;
                paymentInfo.PaymentDetailsItem.Add(itemInformation);
            }

            var tax = total * 20 / 100;

            paymentInfo.ItemTotal  = new BasicAmountType(currency, total.ToString());
            paymentInfo.OrderTotal = new BasicAmountType(currency, (total + tax).ToString());
            paymentInfo.TaxTotal   = new BasicAmountType(currency, (total * 20 / 100).ToString());
            ecDetails.PaymentDetails.Add(paymentInfo);
        }
Esempio n. 2
0
        public PaymentDetailsItemType CreatePaymentItem(ShoppingCartItem item)
        {
            var product = _productService.GetProductById(item.ProductId);

            if (product is null)
            {
                throw new NopException("Product is not found");
            }

            var productPrice = _taxService.GetProductPrice(product,
                                                           _shoppingCartService.GetUnitPrice(item), false,
                                                           _workContext.CurrentCustomer, out _);

            var currencyCodeType       = _payPalCurrencyCodeParser.GetCurrencyCodeType(_workContext.WorkingCurrency);
            var paymentDetailsItemType = new PaymentDetailsItemType
            {
                Name = product.Name,
                //Description = _productAttributeFormatter.FormatAttributes(item.ProductVariant, item.AttributesXml),
                Amount       = productPrice.GetBasicAmountType(currencyCodeType),
                ItemCategory =
                    product.IsDownload
                        ? ItemCategoryType.Digital
                        : ItemCategoryType.Physical,
                Quantity = item.Quantity.ToString()
            };

            return(paymentDetailsItemType);
        }
        private PaymentDetailsType GetPaymentDetails(IInvoice invoice)
        {
            decimal itemTotal          = 0;
            decimal taxTotal           = 0;
            decimal shippingTotal      = 0;
            var     paymentDetailItems = new List <PaymentDetailsItemType>();

            foreach (var item in invoice.Items)
            {
                switch (item.LineItemType)
                {
                case LineItemType.Tax:
                    taxTotal = item.TotalPrice;
                    break;

                case LineItemType.Shipping:
                    shippingTotal = item.TotalPrice;
                    break;

                case LineItemType.Product:
                    var paymentItem = new PaymentDetailsItemType
                    {
                        Name     = item.Name,
                        ItemURL  = GetWebsiteUrl() + "/all-products/" + item.Sku,
                        Amount   = new BasicAmountType(CurrencyCodeType.USD, item.Price.ToString("0.00")),
                        Quantity = item.Quantity,
                    };
                    paymentDetailItems.Add(paymentItem);
                    itemTotal += item.TotalPrice;
                    break;

                default:
                    throw new Exception("Unsupported item with type: " + item.LineItemType);
                }
            }

            var paymentDetails = new PaymentDetailsType
            {
                PaymentDetailsItem = paymentDetailItems,
                ItemTotal          = new BasicAmountType(CurrencyCodeType.USD, itemTotal.ToString("0.00")),
                TaxTotal           = new BasicAmountType(CurrencyCodeType.USD, taxTotal.ToString("0.00")),
                ShippingTotal      = new BasicAmountType(CurrencyCodeType.USD, shippingTotal.ToString("0.00")),
                OrderTotal         = new BasicAmountType(CurrencyCodeType.USD, (itemTotal + taxTotal + shippingTotal).ToString("0.00")),
                PaymentAction      = PaymentActionCodeType.ORDER,
                SellerDetails      = new SellerDetailsType {
                    PayPalAccountID = _settings.AccountId
                },
                PaymentRequestID = "PaymentRequest",
                //ShipToAddress = shipToAddress,
                NotifyURL = "http://IPNhost"
            };

            return(paymentDetails);
        }
Esempio n. 4
0
        /// <summary>
        /// Builds a <see cref="PaymentDetailsItemType"/>.
        /// </summary>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <param name="factory">
        /// The <see cref="PayPalBasicAmountTypeFactory"/>.
        /// </param>
        /// <param name="isDiscount">
        /// The is discount.
        /// </param>
        /// <returns>
        /// The <see cref="PaymentDetailsItemType"/>.
        /// </returns>
        protected virtual PaymentDetailsItemType BuildGenericPaymentDetailsItemType(ILineItem item, PayPalBasicAmountTypeFactory factory, bool isDiscount)
        {
            var detailsItemType = new PaymentDetailsItemType
            {
                Name     = item.Name,
                ItemURL  = null,
                Amount   = factory.Build(item.Price),
                Quantity = item.Quantity,
            };

            return(detailsItemType);
        }
Esempio n. 5
0
        private void AddProductsToDetails(PaymentDetailsType detailsType)
        {
            _model.ProductItems.ForEach(p =>
            {
                var assignmentDetails = new PaymentDetailsItemType
                {
                    Name         = p.Title,
                    Description  = p.Description,
                    Amount       = new BasicAmountType(_model.CurrencyCodeType, p.Amount.ToString()),
                    Quantity     = 1,
                    ItemCategory = ItemCategoryType.DIGITAL
                };

                detailsType.PaymentDetailsItem.Add(assignmentDetails);
            });
        }
Esempio n. 6
0
        public PaymentDetailsItemType CreatePaymentItem(ShoppingCartItem item)
        {
            decimal taxRate;
            var     productPrice = _taxService.GetProductPrice(item.Product,
                                                               _priceCalculationService.GetUnitPrice(item, true), false,
                                                               _workContext.CurrentCustomer, out taxRate);

            var currencyCodeType       = _payPalCurrencyCodeParser.GetCurrencyCodeType(_workContext.WorkingCurrency);
            var paymentDetailsItemType = new PaymentDetailsItemType
            {
                Name = item.Product.Name,
                //Description = _productAttributeFormatter.FormatAttributes(item.ProductVariant, item.AttributesXml),
                Amount       = productPrice.GetBasicAmountType(currencyCodeType),
                ItemCategory =
                    item.Product.IsDownload
                                                         ? ItemCategoryType.Digital
                                                         : ItemCategoryType.Physical,
                Quantity = item.Quantity.ToString()
            };

            return(paymentDetailsItemType);
        }
Esempio n. 7
0
        /// <summary>
        /// The build product payment details item type.
        /// </summary>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <param name="factory">
        /// The <see cref="PayPalBasicAmountTypeFactory"/>.
        /// </param>
        /// <returns>
        /// The <see cref="PaymentDetailsItemType"/>.
        /// </returns>
        protected virtual PaymentDetailsItemType BuildProductPaymentDetailsItemType(ILineItem item, PayPalBasicAmountTypeFactory factory)
        {
            IProductContent product = null;

            if (_settings.UsesProductContent)
            {
                var productKey = item.ExtendedData.GetProductKey();
                product = _merchello.TypedProductContent(productKey);
            }

            var detailsItemType = new PaymentDetailsItemType
            {
                Name    = item.Name,
                ItemURL = product != null?
                          string.Format("{0}{1}", _settings.WebsiteUrl, product.Url) :
                              null,
                              Amount   = factory.Build(item.Price),
                              Quantity = item.Quantity
            };

            return(detailsItemType);
        }
        private PaymentDetailsItemType[] GetOrderItemsDetails(OrderTaskContext context)
        {
            var currency = PayPalAPI.GetCurrencyCodeType(context.HccApp.CurrentStore.Settings.PayPal.Currency);

            var itemDetails = new List <PaymentDetailsItemType>();

            var itemDetail = new PaymentDetailsItemType();

            itemDetail.Name = context.HccApp.CurrentStore.Settings.FriendlyName;
            var itemsTotalWithoutTax = context.Order.TotalOrderAfterDiscounts;

            if (context.HccApp.CurrentStore.Settings.ApplyVATRules)
            {
                itemsTotalWithoutTax -= context.Order.ItemsTax;
            }
            itemDetail.Amount            = new BasicAmountType();
            itemDetail.Amount.Value      = itemsTotalWithoutTax.ToString("N", CultureInfo.InvariantCulture);
            itemDetail.Amount.currencyID = currency;

            itemDetails.Add(itemDetail);

            return(itemDetails.ToArray());
        }
Esempio n. 9
0
        //private void setKeyResponseObjects(PayPalAPIInterfaceServiceService service, DoReferenceTransactionResponseType response)
        //{
        //    HttpContext CurrContext = new System.Web.HttpContext(); ;
        //    CurrContext.Items.Add("Response_apiName", "DoReferenceTransaction");
        //    CurrContext.Items.Add("Response_redirectURL", null);
        //    CurrContext.Items.Add("Response_requestPayload", service.getLastRequest());
        //    CurrContext.Items.Add("Response_responsePayload", service.getLastResponse());

        //    Dictionary<string, string> responseParams = new Dictionary<string, string>();
        //    responseParams.Add("Correlation Id", response.CorrelationID);
        //    responseParams.Add("API Result", response.Ack.ToString());

        //    if (response.Ack.Equals(AckCodeType.FAILURE) ||
        //        (response.Errors != null && response.Errors.Count > 0))
        //    {
        //        CurrContext.Items.Add("Response_error", response.Errors);
        //    }
        //    else
        //    {
        //        CurrContext.Items.Add("Response_error", null);
        //        DoReferenceTransactionResponseDetailsType transactionDetails = response.DoReferenceTransactionResponseDetails;
        //        responseParams.Add("Transaction ID", transactionDetails.TransactionID);

        //        if (transactionDetails.PaymentInfo != null)
        //        {
        //            responseParams.Add("Payment status", transactionDetails.PaymentInfo.PaymentStatus.ToString());
        //        }

        //        if (transactionDetails.PaymentInfo != null)
        //        {
        //            responseParams.Add("Pending reason", transactionDetails.PaymentInfo.PendingReason.ToString());
        //        }
        //    }
        //    CurrContext.Items.Add("Response_keyResponseObject", responseParams);
        //    Server.Transfer("../APIResponse.aspx");
        //}

        private void populateRequestObject(DoReferenceTransactionRequestType request)
        {
            DoReferenceTransactionRequestDetailsType referenceTransactionDetails = new DoReferenceTransactionRequestDetailsType();

            request.DoReferenceTransactionRequestDetails = referenceTransactionDetails;

            referenceTransactionDetails.ReferenceID   = "61K51535A9986391A";
            referenceTransactionDetails.PaymentAction = PaymentActionCodeType.SALE;


            PaymentDetailsType paymentDetails = new PaymentDetailsType();

            referenceTransactionDetails.PaymentDetails = paymentDetails;

            double orderTotal = 0.0;

            double           itemTotal = 0.0;
            CurrencyCodeType currency  = CurrencyCodeType.USD;

            PaymentDetailsItemType itemDetails = new PaymentDetailsItemType();

            itemDetails.Name = "ItemName";

            itemDetails.Amount = new BasicAmountType(currency, "10");

            itemDetails.Quantity = 2;

            itemDetails.ItemCategory = ItemCategoryType.DIGITAL;
            itemTotal += Convert.ToDouble(itemDetails.Amount.value) * itemDetails.Quantity.Value;

            paymentDetails.PaymentDetailsItem.Add(itemDetails);

            orderTotal += itemTotal;
            paymentDetails.ItemTotal  = new BasicAmountType(currency, itemTotal.ToString());
            paymentDetails.OrderTotal = new BasicAmountType(currency, orderTotal.ToString());
        }
Esempio n. 10
0
        private void PopulateSetExpressCheckoutRequestObject(SetExpressCheckoutRequestType request, User user, Product product, string referrer, int quantity, string billingAgreementText = "")
        {
            const string zero       = "0.00";
            var          orderTotal = 0.0;
            var          itemTotal  = 0.0;

            // Each payment can include requestDetails about multiple items
            // This example shows just one payment item
            if (quantity < 1)
            {
                throw new Exception("Insufficient quantity");
            }
            var itemDetails = new PaymentDetailsItemType {
                Name     = product.Name,
                Amount   = new BasicAmountType(MSKatushaCurrencyCode, product.Amount),
                Quantity = quantity,
                //ItemCategory = ItemCategoryType.PHYSICAL,
                Tax         = new BasicAmountType(MSKatushaCurrencyCode, product.Tax),
                Description = product.Description,
            };

            itemTotal += (Double.Parse(itemDetails.Amount.value) * quantity);

            orderTotal += Double.Parse(itemDetails.Tax.value);
            orderTotal += itemTotal;

            var paymentDetails = new PaymentDetailsType {
                ShippingTotal    = new BasicAmountType(MSKatushaCurrencyCode, zero),
                OrderDescription = MSKatushaorderDescription,
                PaymentAction    = PaymentActionCodeType.SALE,
                ItemTotal        = new BasicAmountType(MSKatushaCurrencyCode, itemTotal.ToString(CultureInfo.InvariantCulture)),
                Custom           = product.FriendlyName + "|" + (referrer ?? ""),
            };

            orderTotal += Double.Parse(paymentDetails.ShippingTotal.value);
            paymentDetails.OrderTotal = new BasicAmountType(MSKatushaCurrencyCode, orderTotal.ToString(CultureInfo.InvariantCulture));
            paymentDetails.PaymentDetailsItem.Add(itemDetails);


            var ecDetails = new SetExpressCheckoutRequestDetailsType {
                ReturnURL       = _settings.ReturnUrl,
                CancelURL       = _settings.CancelUrl,
                BuyerEmail      = user.Email,
                AddressOverride = "0",
                NoShipping      = "1",
                SolutionType    = SolutionTypeType.SOLE,
                BuyerDetails    = new BuyerDetailsType {
                    BuyerId = user.Guid.ToString(), BuyerRegistrationDate = user.CreationDate.ToString("s"), BuyerUserName = user.UserName
                },
                cppHeaderImage = MSKatushaImageUrl,
                BrandName      = MSKatushaBrandName
                                 //PageStyle = pageStyle.Value,
                                 //cppHeaderBorderColor = cppheaderbordercolor.Value,
                                 //cppHeaderBackColor = cppheaderbackcolor.Value,
                                 //cppPayflowColor = cpppayflowcolor.Value,
            };

            ecDetails.PaymentDetails.Add(paymentDetails);

            if (!String.IsNullOrWhiteSpace(billingAgreementText))
            {
                var baType = new BillingAgreementDetailsType(BillingCodeType.MERCHANTINITIATEDBILLINGSINGLEAGREEMENT)
                {
                    BillingAgreementDescription = billingAgreementText
                };
                ecDetails.BillingAgreementDetails.Add(baType);
            }
            request.SetExpressCheckoutRequestDetails = ecDetails;

            /*
             *          //if (insuranceTotal.Value != "" && !double.Parse(insuranceTotal.Value).Equals(0.0)) {
             *          //    paymentDetails.InsuranceTotal = new BasicAmountType(MSKatushaCurrencyCode, zero);
             *          //    paymentDetails.InsuranceOptionOffered = "true";
             *          //    orderTotal += Double.Parse(insuranceTotal.Value);
             *          //}
             *          //if (handlingTotal.Value != "") {
             *          //    paymentDetails.HandlingTotal = new BasicAmountType(MSKatushaCurrencyCode, handlingTotal.Value);
             *          //    orderTotal += Double.Parse(handlingTotal.Value);
             *          //}
             *          //if (taxTotal.Value != "") {
             *          //    paymentDetails.TaxTotal = new BasicAmountType(MSKatushaCurrencyCode, taxTotal.Value);
             *          //    orderTotal += Double.Parse(taxTotal.Value);
             *          //}
             *          //if (shippingName.Value != "" && shippingStreet1.Value != ""
             *          //    && shippingCity.Value != "" && shippingState.Value != ""
             *          //    && shippingCountry.Value != "" && shippingPostalCode.Value != "") {
             *          //    AddressType shipAddress = new AddressType();
             *          //    shipAddress.Name = shippingName.Value;
             *          //    shipAddress.Street1 = shippingStreet1.Value;
             *          //    shipAddress.Street2 = shippingStreet2.Value;
             *          //    shipAddress.CityName = shippingCity.Value;
             *          //    shipAddress.StateOrProvince = shippingState.Value;
             *          //    shipAddress.Country = (CountryCodeType)
             *          //        Enum.Parse(typeof(CountryCodeType), shippingCountry.Value);
             *          //    shipAddress.PostalCode = shippingPostalCode.Value;
             *          //    ecDetails.PaymentDetails[0].ShipToAddress = shipAddress;
             *          //}
             * */
        }
        public ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest)
        {
            var paymentResponse = new ProcessPaymentResult();
            var req             = new SetExpressCheckoutReq();

            req.SetExpressCheckoutRequest = new SetExpressCheckoutRequestType {
                Version = Settings.Version
            };
            var details = new SetExpressCheckoutRequestDetailsType();

            req.SetExpressCheckoutRequest.SetExpressCheckoutRequestDetails = details;

            var currencyCode = (CurrencyCodeType)Utils.GetEnumValueByName(typeof(CurrencyCodeType), processPaymentRequest.CurrencyCode);
            var oPayDetail   = new PaymentDetailsType();

            oPayDetail.OrderTotal            = new BasicAmountType();
            oPayDetail.OrderTotal.Value      = (processPaymentRequest.OrderTotal).ToString("N", new CultureInfo("en-gb"));
            oPayDetail.OrderTotal.currencyID = currencyCode;

            oPayDetail.ShippingMethod = ShippingServiceCodeType.ShippingMethodStandard;

            oPayDetail.ItemTotal                = new BasicAmountType();
            oPayDetail.ItemTotal.Value          = (processPaymentRequest.OrderTotal - processPaymentRequest.Order.ShippingCharge.Raw.WithTax).ToString("N", new CultureInfo("en-gb"));
            oPayDetail.ItemTotal.currencyID     = currencyCode;
            oPayDetail.ShippingMethodSpecified  = true;
            oPayDetail.ShippingTotal            = new BasicAmountType();
            oPayDetail.ShippingTotal.Value      = processPaymentRequest.Order.ShippingCharge.Raw.WithTax.ToString("N", new CultureInfo("en-gb"));
            oPayDetail.ShippingTotal.currencyID = currencyCode;
            oPayDetail.OrderDescription         = "Order Total:" + processPaymentRequest.OrderTotal.ToString();
            oPayDetail.PaymentActionSpecified   = true;
            oPayDetail.PaymentAction            = PaymentActionCodeType.Authorization;


            oPayDetail.InvoiceID = processPaymentRequest.OrderId;

            var oItems = new List <PaymentDetailsItemType>();
            int i      = 1;

            foreach (var itm in processPaymentRequest.Order.Items)
            {
                var oItem = new PaymentDetailsItemType {
                    Number = i.ToString(CultureInfo.InvariantCulture)
                };
                oItem.Name        = itm.StockCode;
                oItem.Description = itm.Name;
                oItem.Amount      = new BasicAmountType();
                decimal itmPrice = itm.Price.Raw.WithTax;
                oItem.Amount.Value      = itmPrice.ToString("N", new CultureInfo("en-gb"));
                oItem.Amount.currencyID = currencyCode;
                oItem.Quantity          = itm.Qty.ToString(CultureInfo.InvariantCulture);
                i = i + 1;
                oItems.Add(oItem);
            }
            if (processPaymentRequest.Order.Discount.Raw.WithTax > 0)
            {
                var odiscountItem = new PaymentDetailsItemType {
                    Number = i.ToString(CultureInfo.InvariantCulture)
                };
                odiscountItem.Name        = "Discount";
                odiscountItem.Description = "Discount";
                odiscountItem.Amount      = new BasicAmountType();
                decimal itmPrice = -processPaymentRequest.Order.Discount.Raw.WithTax;
                odiscountItem.Amount.Value      = itmPrice.ToString("N", new CultureInfo("en-GB"));
                odiscountItem.Amount.currencyID = currencyCode;
                odiscountItem.Quantity          = (1).ToString(CultureInfo.InvariantCulture);
                oItems.Add(odiscountItem);
            }
            if (processPaymentRequest.Order.GrandTotal.Raw.WithTax > processPaymentRequest.OrderTotal)
            {
                var odiscountItem = new PaymentDetailsItemType {
                    Number = i.ToString(CultureInfo.InvariantCulture)
                };
                odiscountItem.Name        = "Paid By Other Source";
                odiscountItem.Description = "Other Source";
                odiscountItem.Amount      = new BasicAmountType();
                decimal itmPrice = -(processPaymentRequest.Order.GrandTotal.Raw.WithTax - processPaymentRequest.OrderTotal);
                odiscountItem.Amount.Value      = itmPrice.ToString("N", new CultureInfo("en-GB"));
                odiscountItem.Amount.currencyID = currencyCode;
                odiscountItem.Quantity          = (1).ToString(CultureInfo.InvariantCulture);
                oItems.Add(odiscountItem);
            }

            oPayDetail.PaymentDetailsItem = oItems.ToArray();

            PaymentDetailsType[] oPayDetails = { oPayDetail };

            details.PaymentDetails = oPayDetails;

            details.ReturnURL = Settings.NotificationUrl + "?oid=" + processPaymentRequest.OrderId + "&payid=" + processPaymentRequest.PaymentId;
            details.CancelURL = Settings.CancelUrl + "/" + processPaymentRequest.BasketId;
            System.Net.ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            var credentials = PaypalSecurityHeader();
            SetExpressCheckoutResponseType response = _paypalService2.SetExpressCheckout(ref credentials, req);

            if (response.Ack == AckCodeType.Success)
            {
                paymentResponse.AuthorizationTransactionUrl = GetPaypalUrl(response.Token);
                paymentResponse.UseAuthUrlToRedirect        = true;
            }
            else
            {
                foreach (var er in response.Errors)
                {
                    paymentResponse.AddError(er.ErrorCode + " : " + er.ShortMessage);
                }
            }
            return(paymentResponse);
        }
Esempio n. 12
0
        private ActionResult Processing_PayPal(int claim, PaymentMode payment)
        {
            if (payment == null)
            {
                throw new System.ArgumentNullException("payment");
            }
            PaymentBeforeProcessingResult beforePaymentResult = BookingProvider.BeforePaymentProcessing(UrlLanguage.CurrentLanguage, payment.paymentparam);

            if (beforePaymentResult == null)
            {
                throw new System.Exception("cannot get payment details");
            }
            if (!beforePaymentResult.success)
            {
                throw new System.Exception("payment details fail");
            }
            System.Collections.Generic.List <PaymentDetailsType> paymentDetails = new System.Collections.Generic.List <PaymentDetailsType>();
            PaymentDetailsType paymentDetail = new PaymentDetailsType();

            paymentDetail.AllowedPaymentMethod = new AllowedPaymentMethodType?(AllowedPaymentMethodType.ANYFUNDINGSOURCE);
            CurrencyCodeType       currency    = (CurrencyCodeType)EnumUtils.GetValue(payment.payrest.currency, typeof(CurrencyCodeType));
            PaymentDetailsItemType paymentItem = new PaymentDetailsItemType();

            paymentItem.Name                 = string.Format(PaymentStrings.ResourceManager.Get("PaymentForOrderFormat"), claim);
            paymentItem.Amount               = new BasicAmountType(new CurrencyCodeType?(currency), payment.payrest.total.ToString("#.00", System.Globalization.NumberFormatInfo.InvariantInfo));
            paymentItem.Quantity             = new int?(1);
            paymentItem.ItemCategory         = new ItemCategoryType?(ItemCategoryType.PHYSICAL);
            paymentItem.Description          = string.Format("Booking #{0}", claim);
            paymentDetail.PaymentDetailsItem = new System.Collections.Generic.List <PaymentDetailsItemType>
            {
                paymentItem
            };
            paymentDetail.PaymentAction = new PaymentActionCodeType?(PaymentActionCodeType.SALE);
            paymentDetail.OrderTotal    = new BasicAmountType(paymentItem.Amount.currencyID, paymentItem.Amount.value);
            paymentDetails.Add(paymentDetail);
            SetExpressCheckoutRequestDetailsType ecDetails = new SetExpressCheckoutRequestDetailsType();

            ecDetails.ReturnURL = new Uri(base.Request.BaseServerAddress(), base.Url.Action("processingresult", new
            {
                id      = "paypal",
                success = true
            })).ToString();
            ecDetails.CancelURL = new Uri(base.Request.BaseServerAddress(), base.Url.Action("processingresult", new
            {
                id      = "paypal",
                success = false
            })).ToString();
            ecDetails.NoShipping     = "1";
            ecDetails.AllowNote      = "0";
            ecDetails.SolutionType   = new SolutionTypeType?(SolutionTypeType.SOLE);
            ecDetails.SurveyEnable   = "0";
            ecDetails.PaymentDetails = paymentDetails;
            ecDetails.InvoiceID      = beforePaymentResult.invoiceNumber;
            SetExpressCheckoutRequestType request = new SetExpressCheckoutRequestType();

            request.Version = "104.0";
            request.SetExpressCheckoutRequestDetails = ecDetails;
            SetExpressCheckoutReq wrapper = new SetExpressCheckoutReq();

            wrapper.SetExpressCheckoutRequest = request;
            System.Collections.Generic.Dictionary <string, string> config = PaymentController.PayPal_CreateConfig();
            PayPalAPIInterfaceServiceService service       = new PayPalAPIInterfaceServiceService(config);
            SetExpressCheckoutResponseType   setECResponse = service.SetExpressCheckout(wrapper);

            System.Collections.Generic.KeyValuePair <string, string> sandboxConfig = config.FirstOrDefault((System.Collections.Generic.KeyValuePair <string, string> m) => m.Key == "mode");
            string sandboxServer = (sandboxConfig.Key != null && sandboxConfig.Value == "sandbox") ? ".sandbox" : "";

            return(base.View("PaymentSystems\\PayPal", new ProcessingContext
            {
                Reservation = BookingProvider.GetReservationState(UrlLanguage.CurrentLanguage, claim),
                PaymentMode = payment,
                BeforePaymentResult = beforePaymentResult,
                RedirectUrl = string.Format("https://www{0}.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={1}", sandboxServer, base.Server.UrlEncode(setECResponse.Token))
            }));

            //  return new RedirectResult(string.Format("https://www{0}.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={1}", sandboxServer, base.Server.UrlEncode(setECResponse.Token)));
        }
Esempio n. 13
0
        private void populateRequestObject(SetExpressCheckoutRequestType request)
        {
            SetExpressCheckoutRequestDetailsType ecDetails = new SetExpressCheckoutRequestDetailsType();

            if (returnUrl.Value != "")
            {
                ecDetails.ReturnURL = returnUrl.Value;
            }
            if (cancelUrl.Value != "")
            {
                ecDetails.CancelURL = cancelUrl.Value;
            }
            if (buyerEmail.Value != "")
            {
                ecDetails.BuyerEmail = buyerEmail.Value;
            }

            //Fix for release
            //NOTE: Setting this field overrides the setting you specified in your Merchant Account Profile
            if (reqConfirmShipping.SelectedIndex != 0)
            {
                ecDetails.ReqConfirmShipping = reqConfirmShipping.SelectedValue;
            }

            if (addressoverride.SelectedIndex != 0)
            {
                ecDetails.AddressOverride = addressoverride.SelectedValue;
            }

            if (noShipping.SelectedIndex != 0)
            {
                ecDetails.NoShipping = noShipping.SelectedValue;
            }
            if (solutionType.SelectedIndex != 0)
            {
                ecDetails.SolutionType = (SolutionTypeType)
                                         Enum.Parse(typeof(SolutionTypeType), solutionType.SelectedValue);
            }

            /* Populate payment requestDetails.
             * SetExpressCheckout allows parallel payments of upto 10 payments.
             * This samples shows just one payment.
             */
            PaymentDetailsType paymentDetails = new PaymentDetailsType();

            ecDetails.PaymentDetails.Add(paymentDetails);
            double           orderTotal = 0.0;
            double           itemTotal  = 0.0;
            CurrencyCodeType currency   = (CurrencyCodeType)
                                          Enum.Parse(typeof(CurrencyCodeType), currencyCode.SelectedValue);

            if (shippingTotal.Value != "")
            {
                paymentDetails.ShippingTotal = new BasicAmountType(currency, shippingTotal.Value);
                orderTotal += Double.Parse(shippingTotal.Value);
            }
            if (insuranceTotal.Value != "" && !double.Parse(insuranceTotal.Value).Equals(0.0))
            {
                paymentDetails.InsuranceTotal         = new BasicAmountType(currency, insuranceTotal.Value);
                paymentDetails.InsuranceOptionOffered = "true";
                orderTotal += Double.Parse(insuranceTotal.Value);
            }
            if (handlingTotal.Value != "")
            {
                paymentDetails.HandlingTotal = new BasicAmountType(currency, handlingTotal.Value);
                orderTotal += Double.Parse(handlingTotal.Value);
            }
            if (taxTotal.Value != "")
            {
                paymentDetails.TaxTotal = new BasicAmountType(currency, taxTotal.Value);
                orderTotal += Double.Parse(taxTotal.Value);
            }
            if (orderDescription.Value != "")
            {
                paymentDetails.OrderDescription = orderDescription.Value;
            }
            paymentDetails.PaymentAction = (PaymentActionCodeType)
                                           Enum.Parse(typeof(PaymentActionCodeType), paymentAction.SelectedValue);

            if (shippingName.Value != "" && shippingStreet1.Value != "" &&
                shippingCity.Value != "" && shippingState.Value != "" &&
                shippingCountry.Value != "" && shippingPostalCode.Value != "")
            {
                AddressType shipAddress = new AddressType();
                shipAddress.Name            = shippingName.Value;
                shipAddress.Street1         = shippingStreet1.Value;
                shipAddress.Street2         = shippingStreet2.Value;
                shipAddress.CityName        = shippingCity.Value;
                shipAddress.StateOrProvince = shippingState.Value;
                shipAddress.Country         = (CountryCodeType)
                                              Enum.Parse(typeof(CountryCodeType), shippingCountry.Value);
                shipAddress.PostalCode = shippingPostalCode.Value;

                //Fix for release
                shipAddress.Phone = shippingPhone.Value;

                ecDetails.PaymentDetails[0].ShipToAddress = shipAddress;
            }

            // Each payment can include requestDetails about multiple items
            // This example shows just one payment item
            if (itemName.Value != null && itemAmount.Value != null && itemQuantity.Value != null)
            {
                PaymentDetailsItemType itemDetails = new PaymentDetailsItemType();
                itemDetails.Name         = itemName.Value;
                itemDetails.Amount       = new BasicAmountType(currency, itemAmount.Value);
                itemDetails.Quantity     = Int32.Parse(itemQuantity.Value);
                itemDetails.ItemCategory = (ItemCategoryType)
                                           Enum.Parse(typeof(ItemCategoryType), itemCategory.SelectedValue);
                itemTotal += Double.Parse(itemDetails.Amount.value) * itemDetails.Quantity.Value;
                if (salesTax.Value != "")
                {
                    itemDetails.Tax = new BasicAmountType(currency, salesTax.Value);
                    orderTotal     += Double.Parse(salesTax.Value);
                }
                if (itemDescription.Value != "")
                {
                    itemDetails.Description = itemDescription.Value;
                }
                paymentDetails.PaymentDetailsItem.Add(itemDetails);
            }

            orderTotal += itemTotal;
            paymentDetails.ItemTotal  = new BasicAmountType(currency, itemTotal.ToString());
            paymentDetails.OrderTotal = new BasicAmountType(currency, orderTotal.ToString());

            // Set Billing agreement (for Reference transactions & Recurring payments)
            if (billingAgreementText.Value != "")
            {
                BillingCodeType billingCodeType = (BillingCodeType)
                                                  Enum.Parse(typeof(BillingCodeType), billingType.SelectedValue);
                BillingAgreementDetailsType baType = new BillingAgreementDetailsType(billingCodeType);
                baType.BillingAgreementDescription = billingAgreementText.Value;
                ecDetails.BillingAgreementDetails.Add(baType);
            }

            //Fix for release
            if (localeCode.SelectedIndex != 0)
            {
                ecDetails.LocaleCode = localeCode.SelectedValue;
            }

            // Set styling attributes for PayPal page
            if (pageStyle.Value != "")
            {
                ecDetails.PageStyle = pageStyle.Value;
            }
            if (cppheaderimage.Value != "")
            {
                ecDetails.cppHeaderImage = cppheaderimage.Value;
            }
            if (cppheaderbordercolor.Value != "")
            {
                ecDetails.cppHeaderBorderColor = cppheaderbordercolor.Value;
            }
            if (cppheaderbackcolor.Value != "")
            {
                ecDetails.cppHeaderBackColor = cppheaderbackcolor.Value;
            }
            if (cpppayflowcolor.Value != "")
            {
                ecDetails.cppPayflowColor = cpppayflowcolor.Value;
            }
            if (brandName.Value != "")
            {
                ecDetails.BrandName = brandName.Value;
            }

            request.SetExpressCheckoutRequestDetails = ecDetails;
        }
Esempio n. 14
0
        public PaymentDetailsType[] GetPaymentDetails(IList <ShoppingCartItem> cart)
        {
            var currencyCode = _payPalCurrencyCodeParser.GetCurrencyCodeType(_workContext.WorkingCurrency);

            decimal orderTotalDiscountAmount;
            List <DiscountForCaching> appliedDiscounts;
            int     redeemedRewardPoints;
            decimal redeemedRewardPointsAmount;
            List <AppliedGiftCard> appliedGiftCards;
            var orderTotalWithDiscount = _payPalCartItemService.GetCartTotal(cart, out orderTotalDiscountAmount,
                                                                             out appliedDiscounts,
                                                                             out redeemedRewardPoints,
                                                                             out redeemedRewardPointsAmount,
                                                                             out appliedGiftCards);

            decimal subTotalWithDiscount;
            decimal subTotalWithoutDiscount;
            List <DiscountForCaching> subTotalAppliedDiscounts;
            decimal subTotalDiscountAmount;
            var     itemTotalWithDiscount = _payPalCartItemService.GetCartItemTotal(cart,
                                                                                    out subTotalDiscountAmount,
                                                                                    out subTotalAppliedDiscounts,
                                                                                    out subTotalWithoutDiscount,
                                                                                    out subTotalWithDiscount);

            var giftCardsAmount = appliedGiftCards.Sum(x => x.AmountCanBeUsed);

            itemTotalWithDiscount = itemTotalWithDiscount - orderTotalDiscountAmount - giftCardsAmount;

            var taxTotal      = _payPalCartItemService.GetTax(cart);
            var shippingTotal = _payPalCartItemService.GetShippingTotal(cart);
            var items         = GetPaymentDetailsItems(cart);

            // checkout attributes
            var customer = cart.GetCustomer();

            if (customer != null)
            {
                var checkoutAttributesXml = customer.GetAttribute <string>(SystemCustomerAttributeNames.CheckoutAttributes, _genericAttributeService, _storeContext.CurrentStore.Id);
                var caValues = _checkoutAttributeParser.ParseCheckoutAttributeValues(checkoutAttributesXml);
                if (caValues != null)
                {
                    foreach (var caValue in caValues)
                    {
                        if (caValue.PriceAdjustment > 0)
                        {
                            var checkoutAttrItem = new PaymentDetailsItemType
                            {
                                Name     = caValue.Name,
                                Amount   = caValue.PriceAdjustment.GetBasicAmountType(currencyCode),
                                Quantity = "1"
                            };
                            items.Add(checkoutAttrItem);
                        }
                    }
                }
            }
            if (orderTotalDiscountAmount > 0 || subTotalDiscountAmount > 0)
            {
                var discountItem = new PaymentDetailsItemType
                {
                    Name   = "Discount",
                    Amount =
                        (-orderTotalDiscountAmount + -subTotalDiscountAmount).GetBasicAmountType(
                            currencyCode),
                    Quantity = "1"
                };

                items.Add(discountItem);
            }

            foreach (var appliedGiftCard in appliedGiftCards)
            {
                var giftCardItem = new PaymentDetailsItemType
                {
                    Name     = string.Format("Gift Card ({0})", appliedGiftCard.GiftCard.GiftCardCouponCode),
                    Amount   = (-appliedGiftCard.AmountCanBeUsed).GetBasicAmountType(currencyCode),
                    Quantity = "1"
                };

                items.Add(giftCardItem);
            }

            return(new[]
            {
                new PaymentDetailsType
                {
                    OrderTotal = orderTotalWithDiscount.GetBasicAmountType(currencyCode),
                    ItemTotal = itemTotalWithDiscount.GetBasicAmountType(currencyCode),
                    TaxTotal = taxTotal.GetBasicAmountType(currencyCode),
                    ShippingTotal = shippingTotal.GetBasicAmountType(currencyCode),
                    PaymentDetailsItem = items.ToArray(),
                    PaymentAction = _payPalExpressCheckoutPaymentSettings.PaymentAction,
                    PaymentActionSpecified = true,
                    ButtonSource = PayPalHelper.BnCode
                }
            });
        }
Esempio n. 15
0
        public Commerce.Common.Transaction DoExpressCheckout(Commerce.Common.Order order, bool AuthOnly)
        {
            //validate that the token is applied to the BillingAddress
            //same with PayerID
            if (String.IsNullOrEmpty(order.BillingAddress.PayPalPayerID))
            {
                throw new Exception("No payer ID set for the BillingAddress of the order");
            }

            if (String.IsNullOrEmpty(order.BillingAddress.PayPalToken))
            {
                throw new Exception("No Token set for the BillingAddress of the order");
            }

            PayPalSvc.DoExpressCheckoutPaymentReq      checkoutRequest = new DoExpressCheckoutPaymentReq();
            DoExpressCheckoutPaymentRequestType        checkoutReqType = new DoExpressCheckoutPaymentRequestType();
            DoExpressCheckoutPaymentRequestDetailsType checkoutDetails = new DoExpressCheckoutPaymentRequestDetailsType();
            PaymentDetailsType paymentDetails = new PaymentDetailsType();

            if (!AuthOnly)
            {
                checkoutDetails.PaymentAction = PaymentActionCodeType.Sale;
            }
            else
            {
                checkoutDetails.PaymentAction = PaymentActionCodeType.Authorization;
            }
            int roundTo = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalDigits;

            checkoutDetails.Token   = order.BillingAddress.PayPalToken;
            checkoutDetails.PayerID = order.BillingAddress.PayPalPayerID;
            checkoutReqType.Version = PayPalServiceUtility.PayPalAPIVersionNumber;
            decimal dTotal = order.OrderTotal;

            paymentDetails.OrderTotal    = GetBasicAmount(RoundIt(dTotal, roundTo));
            paymentDetails.ShippingTotal = this.GetBasicAmount(RoundIt(order.ShippingAmount, roundTo));
            paymentDetails.TaxTotal      = this.GetBasicAmount(RoundIt(order.TaxAmount, roundTo));
            paymentDetails.Custom        = order.OrderNumber;
            paymentDetails.ItemTotal     = GetBasicAmount(RoundIt(order.CalculateSubTotal(), roundTo));
            //paymentDetails.OrderDescription = orderDescription;


            //This tells PayPal that the dashCommerce is making the call. Please leave this
            //as it helps us keep going :):) (not monetarily, just with some love from PayPal).
            paymentDetails.ButtonSource = EC_BN_ID;
            //load up the payment items
            PaymentDetailsItemType item;

            int itemCount = order.Items.Count;

            PaymentDetailsItemType[] items = new PaymentDetailsItemType[itemCount];

            for (int i = 0; i < itemCount; i++)
            {
                item          = new PaymentDetailsItemType();
                item.Name     = order.Items[i].ProductName;
                item.Number   = order.Items[i].Sku;
                item.Quantity = order.Items[i].Quantity.ToString();
                item.Amount   = GetBasicAmount(RoundIt(order.Items[i].PricePaid, roundTo));
                items[i]      = item;
            }
            paymentDetails.PaymentDetailsItem = items;
            checkoutRequest.DoExpressCheckoutPaymentRequest = checkoutReqType;
            checkoutRequest.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails = checkoutDetails;
            checkoutRequest.DoExpressCheckoutPaymentRequest.DoExpressCheckoutPaymentRequestDetails.PaymentDetails = paymentDetails;
            PayPalSvc.DoExpressCheckoutPaymentResponseType response = service2.DoExpressCheckoutPayment(checkoutRequest);

            string errors = this.CheckErrors(response);
            string sOut   = "";

            Commerce.Common.Transaction trans = new Commerce.Common.Transaction();
            if (errors == string.Empty)
            {
                trans.GatewayResponse   = response.Ack.ToString();
                trans.AuthorizationCode = response.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.TransactionID;
            }
            else
            {
                trans.GatewayResponse = errors;
            }

            //return out the transactionID
            return(trans);
        }
Esempio n. 16
0
        private void populateRequestObject(DoReferenceTransactionRequestType request)
        {
            DoReferenceTransactionRequestDetailsType referenceTransactionDetails = new DoReferenceTransactionRequestDetailsType();

            request.DoReferenceTransactionRequestDetails = referenceTransactionDetails;
            referenceTransactionDetails.ReferenceID      = referenceId.Value;
            referenceTransactionDetails.PaymentAction    = (PaymentActionCodeType)
                                                           Enum.Parse(typeof(PaymentActionCodeType), paymentAction.SelectedValue);

            // Populate payment requestDetails.
            PaymentDetailsType paymentDetails = new PaymentDetailsType();

            referenceTransactionDetails.PaymentDetails = paymentDetails;
            double           orderTotal = 0.0;
            double           itemTotal  = 0.0;
            CurrencyCodeType currency   = (CurrencyCodeType)
                                          Enum.Parse(typeof(CurrencyCodeType), currencyCode.SelectedValue);

            if (shippingTotal.Value != "")
            {
                paymentDetails.ShippingTotal = new BasicAmountType(currency, shippingTotal.Value);
                orderTotal += Double.Parse(shippingTotal.Value);
            }
            if (insuranceTotal.Value != "")
            {
                paymentDetails.InsuranceTotal         = new BasicAmountType(currency, insuranceTotal.Value);
                paymentDetails.InsuranceOptionOffered = "true";
                orderTotal += Double.Parse(insuranceTotal.Value);
            }
            if (handlingTotal.Value != "")
            {
                paymentDetails.HandlingTotal = new BasicAmountType(currency, handlingTotal.Value);
                orderTotal += Double.Parse(handlingTotal.Value);
            }
            if (taxTotal.Value != "")
            {
                paymentDetails.TaxTotal = new BasicAmountType(currency, taxTotal.Value);
                orderTotal += Double.Parse(taxTotal.Value);
            }
            if (orderDescription.Value != "")
            {
                paymentDetails.OrderDescription = orderDescription.Value;
            }
            paymentDetails.PaymentAction = (PaymentActionCodeType)
                                           Enum.Parse(typeof(PaymentActionCodeType), paymentAction.SelectedValue);


            // Each payment can include requestDetails about multiple payment items
            // This example shows just one payment item
            if (itemName.Value != null && itemAmount.Value != null && itemQuantity.Value != null)
            {
                PaymentDetailsItemType itemDetails = new PaymentDetailsItemType();
                itemDetails.Name         = itemName.Value;
                itemDetails.Amount       = new BasicAmountType(currency, itemAmount.Value);
                itemDetails.Quantity     = Int32.Parse(itemQuantity.Value);
                itemDetails.ItemCategory = (ItemCategoryType)
                                           Enum.Parse(typeof(ItemCategoryType), itemCategory.SelectedValue);
                itemTotal += Double.Parse(itemDetails.Amount.value) * itemDetails.Quantity.Value;
                if (salesTax.Value != "")
                {
                    itemDetails.Tax = new BasicAmountType(currency, salesTax.Value);
                    orderTotal     += Double.Parse(salesTax.Value);
                }
                if (itemDescription.Value != "")
                {
                    itemDetails.Description = itemDescription.Value;
                }
                paymentDetails.PaymentDetailsItem.Add(itemDetails);
            }
            orderTotal += itemTotal;
            paymentDetails.ItemTotal  = new BasicAmountType(currency, itemTotal.ToString());
            paymentDetails.OrderTotal = new BasicAmountType(currency, orderTotal.ToString());
        }
        public PaymentDetailsType[] GetPaymentDetails(IList <ShoppingCartItem> cart)
        {
            var currencyCode = _payPalCurrencyCodeParser.GetCurrencyCodeType(_workContext.WorkingCurrency);

            var orderTotalWithDiscount = _payPalCartItemService.GetCartTotal(cart, out var orderTotalDiscountAmount,
                                                                             out _,
                                                                             out _,
                                                                             out _,
                                                                             out var appliedGiftCards);

            var itemTotalWithDiscount = _payPalCartItemService.GetCartItemTotal(cart,
                                                                                out var subTotalDiscountAmount,
                                                                                out _,
                                                                                out _,
                                                                                out _);

            var giftCardsAmount = appliedGiftCards.Sum(x => x.AmountCanBeUsed);

            itemTotalWithDiscount = itemTotalWithDiscount - orderTotalDiscountAmount - giftCardsAmount;

            var taxTotal      = _payPalCartItemService.GetTax(cart);
            var shippingTotal = _payPalCartItemService.GetShippingTotal(cart);
            var items         = GetPaymentDetailsItems(cart);

            // checkout attributes
            var customer = _workContext.CurrentCustomer;

            if (customer != null)
            {
                var checkoutAttributesXml = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.CheckoutAttributes, _storeContext.CurrentStore.Id);
                var caValues = _checkoutAttributeParser.ParseCheckoutAttributeValues(checkoutAttributesXml);
                if (caValues != null)
                {
                    foreach (var caValue in caValues)
                    {
                        if (caValue.PriceAdjustment <= 0)
                        {
                            continue;
                        }

                        var checkoutAttrItem = new PaymentDetailsItemType
                        {
                            Name     = caValue.Name,
                            Amount   = caValue.PriceAdjustment.GetBasicAmountType(currencyCode),
                            Quantity = "1"
                        };

                        items.Add(checkoutAttrItem);
                    }
                }
            }

            if (orderTotalDiscountAmount > 0 || subTotalDiscountAmount > 0)
            {
                var discountItem = new PaymentDetailsItemType
                {
                    Name     = "Discount",
                    Amount   = (-orderTotalDiscountAmount + -subTotalDiscountAmount).GetBasicAmountType(currencyCode),
                    Quantity = "1"
                };

                items.Add(discountItem);
            }

            foreach (var appliedGiftCard in appliedGiftCards)
            {
                var giftCardItem = new PaymentDetailsItemType
                {
                    Name     = $"Gift Card ({appliedGiftCard.GiftCard.GiftCardCouponCode})",
                    Amount   = (-appliedGiftCard.AmountCanBeUsed).GetBasicAmountType(currencyCode),
                    Quantity = "1"
                };

                items.Add(giftCardItem);
            }

            return(new[]
            {
                new PaymentDetailsType
                {
                    OrderTotal = orderTotalWithDiscount.GetBasicAmountType(currencyCode),
                    ItemTotal = itemTotalWithDiscount.GetBasicAmountType(currencyCode),
                    TaxTotal = taxTotal.GetBasicAmountType(currencyCode),
                    ShippingTotal = shippingTotal.GetBasicAmountType(currencyCode),
                    PaymentDetailsItem = items.ToArray(),
                    PaymentAction = _payPalExpressCheckoutPaymentSettings.PaymentAction,
                    PaymentActionSpecified = true,
                    ButtonSource = PayPalHelper.BnCode
                }
            });
        }
        public Response PerformRequest(Request request)
        {
            // Create request object
            DoDirectPaymentRequestType paypalRequest = new DoDirectPaymentRequestType();

            DoDirectPaymentRequestDetailsType requestDetails = new DoDirectPaymentRequestDetailsType();

            paypalRequest.DoDirectPaymentRequestDetails = requestDetails;

            // (Optional) How you want to obtain payment. It is one of the following values:
            // * Authorization – This payment is a basic authorization subject to settlement with PayPal Authorization and Capture.
            // * Sale – This is a final sale for which you are requesting payment (default).
            // Note: Order is not allowed for Direct Payment.
            requestDetails.PaymentAction = (PaymentActionCodeType)
                                           Enum.Parse(typeof(PaymentActionCodeType), gatewaySettings.PaymentAction.ToUpper());

            // (Required) Information about the credit card to be charged.
            CreditCardDetailsType creditCard = new CreditCardDetailsType();

            requestDetails.CreditCard = creditCard;
            PayerInfoType payer = new PayerInfoType();
            // (Optional) First and last name of buyer.
            PersonNameType name = new PersonNameType();

            name.FirstName  = request.FirstName;
            name.LastName   = request.LastName;
            payer.PayerName = name;

            // (Required) Details about the owner of the credit card.
            creditCard.CardOwner = payer;

            // (Required) Credit card number.
            creditCard.CreditCardNumber = request.CardNumber;
            // (Optional) Type of credit card. For UK, only Maestro, MasterCard, Discover, and Visa are allowable. For Canada, only MasterCard and Visa are allowable and Interac debit cards are not supported. It is one of the following values:
            // * Visa
            // * MasterCard
            // * Discover
            // * Amex
            // * Maestro: See note.
            // Note: If the credit card type is Maestro, you must set currencyId to GBP. In addition, you must specify either StartMonth and StartYear or IssueNumber.
            creditCard.CreditCardType = (CreditCardTypeType)
                                        Enum.Parse(typeof(CreditCardTypeType), UpdateCreditCardType(request.CardType));
            // Card Verification Value, version 2. Your Merchant Account settings determine whether this field is required. To comply with credit card processing regulations, you must not store this value after a transaction has been completed.
            // Character length and limitations: For Visa, MasterCard, and Discover, the value is exactly 3 digits. For American Express, the value is exactly 4 digits.
            creditCard.CVV2 = request.CardCvv;
            // (Required) Credit card expiration month.
            creditCard.ExpMonth = request.ExpireDate.Month;
            // (Required) Credit card expiration year.
            creditCard.ExpYear = request.ExpireDate.Year;

            requestDetails.PaymentDetails = new PaymentDetailsType();
            // (Optional) Your URL for receiving Instant Payment Notification (IPN) about this transaction. If you do not specify this value in the request, the notification URL from your Merchant Profile is used, if one exists.
            // Important: The notify URL applies only to DoExpressCheckoutPayment. This value is ignored when set in SetExpressCheckout or GetExpressCheckoutDetails.
            //requestDetails.PaymentDetails.NotifyURL = "";

            // (Optional) Buyer's shipping address information.
            AddressType billingAddr = new AddressType();

            billingAddr.Name = request.FirstName + " " + request.LastName;
            // (Required) First street address.
            billingAddr.Street1 = request.Address1;
            // (Optional) Second street address.
            billingAddr.Street2 = request.Address2;
            // (Required) Name of city.
            billingAddr.CityName = request.City;
            // (Required) State or province.
            billingAddr.StateOrProvince = request.State;
            // (Required) Country code.
            billingAddr.Country = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), request.Country);
            // (Required) U.S. ZIP code or other country-specific postal code.
            billingAddr.PostalCode = request.ZipCode;

            // (Optional) Phone number.
            billingAddr.Phone = request.Phone;

            payer.Address = billingAddr;

            AddressType shippingAddr = new AddressType();

            shippingAddr.Name            = request.ShipToFirstName + " " + request.ShipToLastName;
            shippingAddr.Street1         = request.ShipToAddress;
            shippingAddr.CityName        = request.ShipToCity;
            shippingAddr.StateOrProvince = request.ShipToState;
            shippingAddr.PostalCode      = request.ShipToZipCode;
            shippingAddr.Country         = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), request.ShipToCountry);

            requestDetails.PaymentDetails.ShipToAddress = shippingAddr;

            // (Required) The total cost of the transaction to the buyer. If shipping cost and tax charges are known, include them in this value. If not, this value should be the current subtotal of the order. If the transaction includes one or more one-time purchases, this field must be equal to the sum of the purchases. This field must be set to a value greater than 0.
            // Note: You must set the currencyID attribute to one of the 3-character currency codes for any of the supported PayPal currencies.
            CurrencyCodeType currency = (CurrencyCodeType)
                                        Enum.Parse(typeof(CurrencyCodeType), gatewaySettings.CurrencyCode);

            BasicAmountType paymentAmount = new BasicAmountType(currency, request.Amount.ToString("N2"));

            requestDetails.PaymentDetails.OrderTotal    = paymentAmount;
            requestDetails.PaymentDetails.ItemTotal     = new BasicAmountType(currency, Convert.ToDouble(request.SubTotal ?? "0").ToString("N2"));
            requestDetails.PaymentDetails.ShippingTotal = new BasicAmountType(currency, Convert.ToDouble(request.ShippingTotal ?? "0").ToString("N2"));
            requestDetails.PaymentDetails.TaxTotal      = new BasicAmountType(currency, Convert.ToDouble(request.Tax ?? "0").ToString("N2"));

            // add skus
            List <PaymentDetailsItemType> items = new List <PaymentDetailsItemType>();

            foreach (PaymentSku sku in request.SkuItems)
            {
                PaymentDetailsItemType item = new PaymentDetailsItemType();

                item.Amount      = new BasicAmountType(currency, (sku.InitialPrice * sku.Quantity).ToString("N2"));
                item.Quantity    = sku.Quantity;
                item.Name        = sku.Title;
                item.Number      = sku.SkuCode;
                item.Description = sku.LongDescription;

                items.Add(item);
            }

            requestDetails.PaymentDetails.PaymentDetailsItem = items;

            // Invoke the API
            DoDirectPaymentReq wrapper = new DoDirectPaymentReq();

            wrapper.DoDirectPaymentRequest = paypalRequest;
            // Create the PayPalAPIInterfaceServiceService service object to make the API call

            Dictionary <string, string> config = new Dictionary <string, string>();

            // enforce 30000 minimum for timeout specification (30 secs)
            int timeout = 30000;

            timeout = Math.Max(timeout, Convert.ToInt32(gatewaySettings.Timeout ?? "0"));

            config.Add("account0.apiUsername", gatewaySettings.User);
            config.Add("account0.apiPassword", gatewaySettings.Password);
            config.Add("account0.apiSignature", gatewaySettings.Signature);
            config.Add("account0.applicationId", gatewaySettings.AppID);
            config.Add("connectionTimeout", timeout.ToString());
            config.Add("mode", gatewaySettings.Mode);

            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(config);

            // # API call
            // Invoke the DoDirectPayment method in service wrapper object
            DoDirectPaymentResponseType paypalResponse = service.DoDirectPayment(wrapper);

            // Check for API return status
            return(ParseResponse(service, paypalResponse));
        }
Esempio n. 19
0
        private SetExpressCheckoutRequestType populateRequestObject(FinancialGateway financialGateway, PaymentInfo paymentInfo, List <GatewayAccountItem> selectedAccounts)
        {
            SetExpressCheckoutRequestType        request   = new SetExpressCheckoutRequestType();
            SetExpressCheckoutRequestDetailsType ecDetails = new SetExpressCheckoutRequestDetailsType();
            String host      = GlobalAttributesCache.Value("PublicApplicationRoot");
            int    lastSlash = host.LastIndexOf('/');

            host = (lastSlash > -1) ? host.Substring(0, lastSlash) : host;
            if (financialGateway.GetAttributeValue("ReturnPage") != string.Empty)
            {
                PageReference pageReference = new PageReference(financialGateway.GetAttributeValue("ReturnPage"));
                ecDetails.ReturnURL = host + pageReference.BuildUrl();
            }
            if (financialGateway.GetAttributeValue("CancelPage") != string.Empty)
            {
                PageReference pageReference = new PageReference(financialGateway.GetAttributeValue("CancelPage"));
                ecDetails.CancelURL = host + pageReference.BuildUrl();
            }

            /*
             * // (Optional) Email address of the buyer as entered during checkout. PayPal uses this value to pre-fill the PayPal membership sign-up portion on the PayPal pages.
             * if (buyerEmail.Value != string.Empty)
             * {
             *
             * }*/
            ecDetails.BuyerEmail = paymentInfo.Email;

            /* Populate payment requestDetails.
             * SetExpressCheckout allows parallel payments of upto 10 payments.
             * This samples shows just one payment.
             */
            PaymentDetailsType paymentDetails = new PaymentDetailsType();

            ecDetails.PaymentDetails.Add(paymentDetails);
            // (Required) Total cost of the transaction to the buyer. If shipping cost and tax charges are known, include them in this value. If not, this value should be the current sub-total of the order. If the transaction includes one or more one-time purchases, this field must be equal to the sum of the purchases. Set this field to 0 if the transaction does not include a one-time purchase such as when you set up a billing agreement for a recurring payment that is not immediately charged. When the field is set to 0, purchase-specific fields are ignored.
            double orderTotal = 0.0;
            // Sum of cost of all items in this order. For digital goods, this field is required.
            double           itemTotal = Convert.ToDouble(paymentInfo.Amount);
            CurrencyCodeType currency  = CurrencyCodeType.USD;

            //(Optional) Description of items the buyer is purchasing.
            paymentDetails.OrderDescription = "Contribution";

            // We do a authorization then complete the sale in the "Charge" phase
            paymentDetails.PaymentAction = PaymentActionCodeType.AUTHORIZATION;
            foreach (GatewayAccountItem item in selectedAccounts)
            {
                if (item.Amount > 0)
                {
                    PaymentDetailsItemType itemDetails = new PaymentDetailsItemType();

                    itemDetails.Name        = item.Name;
                    itemDetails.Amount      = new BasicAmountType(currency, item.Amount.ToString());
                    itemDetails.Quantity    = 1;
                    itemDetails.Description = item.PublicName;
                    itemDetails.Number      = item.Id.ToString();
                    paymentDetails.PaymentDetailsItem.Add(itemDetails);
                }
            }

            orderTotal += itemTotal;
            paymentDetails.ItemTotal  = new BasicAmountType(currency, itemTotal.ToString());
            paymentDetails.OrderTotal = new BasicAmountType(currency, orderTotal.ToString());

            //(Optional) Your URL for receiving Instant Payment Notification (IPN)
            //about this transaction. If you do not specify this value in the request,
            //the notification URL from your Merchant Profile is used, if one exists.
            //Important:
            //The notify URL applies only to DoExpressCheckoutPayment.
            //This value is ignored when set in SetExpressCheckout or GetExpressCheckoutDetails.
            //Character length and limitations: 2,048 single-byte alphanumeric characters
            paymentDetails.NotifyURL = "";
            // ipnNotificationUrl.Value.Trim();

            //(Optional) Locale of pages displayed by PayPal during Express Checkout.

            /*if (localeCode.SelectedIndex != 0)
             * {
             *  ecDetails.LocaleCode = localeCode.SelectedValue;
             * }
             *
             * // (Optional) Name of the Custom Payment Page Style for payment pages associated with this button or link. It corresponds to the HTML variable page_style for customizing payment pages. It is the same name as the Page Style Name you chose to add or edit the page style in your PayPal Account profile.
             * if (pageStyle.Value != string.Empty)
             * {
             *  ecDetails.PageStyle = pageStyle.Value;
             * }*/
            //(Optional) URL for the image you want to appear at the top left of the payment page. The image has a maximum size of 750 pixels wide by 90 pixels high. PayPal recommends that you provide an image that is stored on a secure (https) server. If you do not specify an image, the business name displays.
            if (financialGateway.GetAttributeValue("PayPalLogoImage") != string.Empty)
            {
                ecDetails.cppHeaderImage = financialGateway.GetAttributeValue("PayPalLogoImage");
            }

            /*// (Optional) Sets the border color around the header of the payment page. The border is a 2-pixel perimeter around the header space, which is 750 pixels wide by 90 pixels high. By default, the color is black.
             * if (cppheaderbordercolor.Value != string.Empty)
             * {
             *  ecDetails.cppHeaderBorderColor = cppheaderbordercolor.Value;
             * }
             * // (Optional) Sets the background color for the header of the payment page. By default, the color is white.
             * if (cppheaderbackcolor.Value != string.Empty)
             * {
             *  ecDetails.cppHeaderBackColor = cppheaderbackcolor.Value;
             * }
             * // (Optional) Sets the background color for the payment page. By default, the color is white.
             * if (cpppayflowcolor.Value != string.Empty)
             * {
             *  ecDetails.cppPayflowColor = cpppayflowcolor.Value;
             * }
             * // (Optional) A label that overrides the business name in the PayPal account on the PayPal hosted checkout pages.
             */
            if (financialGateway.GetAttributeValue("PayPalBrandName") != string.Empty)
            {
                ecDetails.BrandName = financialGateway.GetAttributeValue("PayPalBrandName");
            }

            request.SetExpressCheckoutRequestDetails = ecDetails;

            return(request);
        }
        private void populateRequestObject(DoReferenceTransactionRequestType request, string billingAgreementID, string orderDescription, string itemName, double itemAmount, string serviceDescription)
        {
            DoReferenceTransactionRequestDetailsType referenceTransactionDetails = new DoReferenceTransactionRequestDetailsType();

            request.DoReferenceTransactionRequestDetails = referenceTransactionDetails;
            // (Required) A transaction ID from a previous purchase, such as a credit card charge using the DoDirectPayment API, or a billing agreement ID.
            referenceTransactionDetails.ReferenceID = billingAgreementID;

            // (Optional) How you want to obtain payment. It is one of the following values:
            // * Authorization – This payment is a basic authorization subject to settlement with PayPal Authorization and Capture.
            // * Sale – This is a final sale for which you are requesting payment.
            referenceTransactionDetails.PaymentAction = (PaymentActionCodeType)
                                                        Enum.Parse(typeof(PaymentActionCodeType), "SALE");
            // Populate payment requestDetails.
            PaymentDetailsType paymentDetails = new PaymentDetailsType();

            referenceTransactionDetails.PaymentDetails = paymentDetails;
            // (Required) The total cost of the transaction to the buyer. If shipping cost and tax charges are known, include them in this value. If not, this value should be the current subtotal of the order. If the transaction includes one or more one-time purchases, this field must be equal to the sum of the purchases. Set this field to 0 if the transaction does not include a one-time purchase such as when you set up a billing agreement for a recurring payment that is not immediately charged. When the field is set to 0, purchase-specific fields are ignored.
            // Note: You must set the currencyID attribute to one of the 3-character currency codes for any of the supported PayPal currencies.
            double orderTotal = 0.0;
            // (Optional) Sum of cost of all items in this order.
            // Note: You must set the currencyID attribute to one of the 3-character currency codes for any of the supported PayPal currencies.
            double           itemTotal = 0.0;
            CurrencyCodeType currency  = (CurrencyCodeType)
                                         Enum.Parse(typeof(CurrencyCodeType), "USD");

            // (Optional) Sum of tax for all items in this order.
            // Note: You must set the currencyID attribute to one of the 3-character currency codes for any of the supported PayPal currencies.
            //if (taxTotal.Value != string.Empty)
            //{
            //    paymentDetails.TaxTotal = new BasicAmountType(currency, taxTotal.Value);
            //    orderTotal += Convert.ToDouble(taxTotal.Value);
            //}

            if (orderDescription != string.Empty)
            {
                paymentDetails.OrderDescription = orderDescription;
            }
            // Each payment can include requestDetails about multiple payment items
            // This example shows just one payment item
            var itemQuantity = 1;

            if (itemName != null && itemAmount != null && itemQuantity != null)
            {
                PaymentDetailsItemType itemDetails = new PaymentDetailsItemType();
                // Item name. This field is required when you pass a value for ItemCategory.
                itemDetails.Name = itemName;
                // Cost of item. This field is required when you pass a value for ItemCategory.

                //itemDetails.Amount = new BasicAmountType(currency, itemAmount.ToString());
                itemDetails.Amount = new BasicAmountType(currency, String.Format("{0:0.00}", itemAmount));

                // Item quantity. This field is required when you pass a value forItemCategory.
                itemDetails.Quantity = Convert.ToInt32(itemQuantity);
                // Indicates whether the item is digital or physical. For digital goods, this field is required and you must set it to Digital to get the best rates. It is one of the following values:
                // * Digital
                // * Physical
                // This field is introduced in version 69.0.
                itemDetails.ItemCategory = (ItemCategoryType)
                                           Enum.Parse(typeof(ItemCategoryType), "DIGITAL");
                itemTotal += Convert.ToDouble(itemDetails.Amount.value) * itemDetails.Quantity.Value;
                //if (salesTax.Value != string.Empty)
                //{
                //    itemDetails.Tax = new BasicAmountType(currency, salesTax.Value);
                //    orderTotal += Convert.ToDouble(salesTax.Value);
                //}
                // (Optional) Item description.
                // This field is available since version 53.0.
                if (serviceDescription != string.Empty)
                {
                    itemDetails.Description = serviceDescription;
                }
                paymentDetails.PaymentDetailsItem.Add(itemDetails);
            }
            orderTotal += itemTotal;
            paymentDetails.ItemTotal  = new BasicAmountType(currency, itemTotal.ToString());
            paymentDetails.OrderTotal = new BasicAmountType(currency, orderTotal.ToString());
        }
Esempio n. 21
0
        private PaymentDetailsType CreatePayPalPaymentDetails(IInvoice invoice, ProcessorArgumentCollection args = null)
        {
            string articleBySkuPath = args.GetArticleBySkuPath(_settings.ArticleBySkuPath.IsEmpty() ? null : GetWebsiteUrl() + _settings.ArticleBySkuPath);
            var    currencyCodeType = PayPalCurrency(invoice.CurrencyCode());
            var    currencyDecimals = CurrencyDecimals(currencyCodeType);

            decimal     itemTotal     = 0;
            decimal     taxTotal      = 0;
            decimal     shippingTotal = 0;
            AddressType shipAddress   = null;

            var paymentDetailItems = new List <PaymentDetailsItemType>();

            foreach (var item in invoice.Items)
            {
                if (item.LineItemTfKey == Merchello.Core.Constants.TypeFieldKeys.LineItem.TaxKey)
                {
                    taxTotal = item.TotalPrice;
                }
                else if (item.LineItemTfKey == Merchello.Core.Constants.TypeFieldKeys.LineItem.ShippingKey)
                {
                    shippingTotal = item.TotalPrice;
                    var address = item.ExtendedData.GetAddress(Merchello.Core.AddressType.Shipping);
                    if (address != null)
                    {
                        shipAddress = new AddressType()
                        {
                            Name            = address.Name,
                            Street1         = address.Address1,
                            Street2         = address.Address2,
                            PostalCode      = address.PostalCode,
                            CityName        = address.Locality,
                            StateOrProvince = address.Region,
                            CountryName     = address.Country().Name,
                            Country         = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), address.Country().CountryCode, true),
                            Phone           = address.Phone
                        };
                    }
                }
                else if (item.LineItemTfKey == Merchello.Core.Constants.TypeFieldKeys.LineItem.DiscountKey)
                {
                    var discountItem = new PaymentDetailsItemType
                    {
                        Name     = item.Name,
                        ItemURL  = (articleBySkuPath.IsEmpty() ? null : articleBySkuPath + item.Sku),
                        Amount   = new BasicAmountType(currencyCodeType, PriceToString(item.Price * -1, currencyDecimals)),
                        Quantity = item.Quantity,
                    };
                    paymentDetailItems.Add(discountItem);
                    itemTotal -= item.TotalPrice;
                }
                else
                {
                    var paymentItem = new PaymentDetailsItemType {
                        Name     = item.Name,
                        ItemURL  = (articleBySkuPath.IsEmpty() ? null : articleBySkuPath + item.Sku),
                        Amount   = new BasicAmountType(currencyCodeType, PriceToString(item.Price, currencyDecimals)),
                        Quantity = item.Quantity,
                    };
                    paymentDetailItems.Add(paymentItem);
                    itemTotal += item.TotalPrice;
                }
            }

            var paymentDetails = new PaymentDetailsType
            {
                PaymentDetailsItem = paymentDetailItems,
                ItemTotal          = new BasicAmountType(currencyCodeType, PriceToString(itemTotal, currencyDecimals)),
                TaxTotal           = new BasicAmountType(currencyCodeType, PriceToString(taxTotal, currencyDecimals)),
                ShippingTotal      = new BasicAmountType(currencyCodeType, PriceToString(shippingTotal, currencyDecimals)),
                OrderTotal         = new BasicAmountType(currencyCodeType, PriceToString(invoice.Total, currencyDecimals)),
                PaymentAction      = PaymentActionCodeType.ORDER,
                InvoiceID          = invoice.InvoiceNumberPrefix + invoice.InvoiceNumber.ToString("0"),
                SellerDetails      = new SellerDetailsType {
                    PayPalAccountID = _settings.AccountId
                },
                PaymentRequestID = "PaymentRequest",
                ShipToAddress    = shipAddress,
                NotifyURL        = "http://IPNhost"
            };

            return(paymentDetails);
        }
        /// <summary>
        /// The build product payment details item type.
        /// </summary>
        /// <param name="item">
        /// The item.
        /// </param>        
        /// <param name="factory">
        /// The <see cref="PayPalBasicAmountTypeFactory"/>.
        /// </param>
        /// <returns>
        /// The <see cref="PaymentDetailsItemType"/>.
        /// </returns>
        protected virtual PaymentDetailsItemType BuildProductPaymentDetailsItemType(ILineItem item, PayPalBasicAmountTypeFactory factory)
        {
            IProductContent product = null;
            if (_settings.UsesProductContent)
            {
                var productKey = item.ExtendedData.GetProductKey();
                product = _merchello.TypedProductContent(productKey);
            }

            var detailsItemType = new PaymentDetailsItemType
            {
                Name = item.Name,
                ItemURL = product != null ?
                    string.Format("{0}{1}", _settings.WebsiteUrl, product.Url) :
                    null,
                Amount = factory.Build(item.Price),
                Quantity = item.Quantity
            };

            return detailsItemType;
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpContext CurrContext = HttpContext.Current;

        // Create the SetExpressCheckoutResponseType object
        SetExpressCheckoutResponseType responseSetExpressCheckoutResponseType = new SetExpressCheckoutResponseType();

        try
        {
            // Check if the EC methos is shorcut or mark
            string ecMethod = "";
            if (Request.QueryString["ExpressCheckoutMethod"] != null)
            {
                ecMethod = Request.QueryString["ExpressCheckoutMethod"];
            }
            else if ((string)(Session["ExpressCheckoutMethod"]) != null)
            {
                ecMethod = (string)(Session["ExpressCheckoutMethod"]);
            }
            string item_name     = "";
            string item_id       = "";
            string item_desc     = "";
            string item_quantity = "";
            string item_amount   = "";
            //string tax_amount = "";
            //string shipping_amount = "";
            //string handling_amount = "";
            //string shipping_discount_amount = "";
            //string insurance_amount = "";
            string total_amount  = "";
            string currency_code = "";
            string payment_type  = "";
            string roundedtotal  = "";
            string roundeditmamt = "";

            // From Marck EC Page
            //string shipping_rate = "";
            string first_name  = "";
            string last_name   = "";
            string street1     = "";
            string street2     = "";
            string city        = "";
            string state       = "";
            string postal_code = "";
            string country     = "";
            string phone       = "";
            //Double new_total_rate = 0.00;
            AddressType shipToAddress = new AddressType();
            if (ecMethod != null && ecMethod == "ShorcutExpressCheckout")
            {
                // Get parameters from index page (shorcut express checkout)
                item_name     = Request.Form["item_name"];
                item_id       = Request.Form["item_id"];
                item_desc     = Request.Form["item_desc"];
                item_quantity = Request.Form["item_quantity"];
                item_amount   = Request.Form["item_amount"];

                total_amount            = Request.Form["total_amount"];
                currency_code           = Request.Form["currency_code_type"];
                payment_type            = Request.Form["payment_type"];
                Session["Total_Amount"] = total_amount;

                roundeditmamt = (Math.Round(double.Parse(item_amount), 2)).ToString();
                roundedtotal  = (Math.Round(double.Parse(total_amount), 2)).ToString();
            }
            else if (ecMethod != null && ecMethod == "MarkExpressCheckout")
            {
                // Get parameters from mark ec page
                //shipping_rate = Request.Form["shipping_method"].ToString();

                item_name     = Request.Form["item_name"];
                item_id       = Request.Form["item_id"];
                item_desc     = Request.Form["item_desc"];
                item_quantity = Request.Form["item_quantity"];
                item_amount   = Request.Form["item_amount"];
                //tax_amount = Request.Form["tax_amount"];
                //shipping_amount = Request.Form["shipping_amount"];
                //handling_amount = Request.Form["handling_amount"];
                //shipping_discount_amount = Request.Form["shipping_discount_amount"];
                //insurance_amount = Request.Form["insurance_amount"];
                total_amount  = Request.Form["total_amount"];
                currency_code = Request.Form["currency_code"];
                payment_type  = Request.Form["payment_type"];

                first_name  = Request.Form["FIRST_NAME"];
                last_name   = Request.Form["LAST_NAME"];
                street1     = Request.Form["STREET_1"];
                street2     = Request.Form["STREET_2"];
                city        = Request.Form["CITY"];
                state       = Request.Form["STATE"];
                postal_code = Request.Form["POSTAL_CODE"];
                country     = Request.Form["COUNTRY"];
                phone       = Request.Form["PHONE"];

                roundeditmamt = (Math.Round(double.Parse(item_amount), 2)).ToString();
                roundedtotal  = (Math.Round(double.Parse(total_amount), 2)).ToString();

                // Set the details of new shipping address
                //shipToAddress.Name = first_name + " " + last_name;
                //shipToAddress.Street1 = street1;
                //if (!street2.Equals(""))
                //{
                //    shipToAddress.Street2 = street2;
                //}
                //shipToAddress.CityName = city;
                //shipToAddress.StateOrProvince = state;
                //string countrycode = country;
                //CountryCodeType countryCodeType = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), countrycode, true);
                //shipToAddress.Country = countryCodeType;
                //shipToAddress.PostalCode = postal_code;
                //if (!phone.Equals(""))
                //{
                //    shipToAddress.Phone = phone;
                //}

                //Double total_rate = Convert.ToDouble(total_amount);
                //Double old_shipping_rate = Convert.ToDouble(shipping_amount);
                //Double new_shipping_rate = Convert.ToDouble(shipping_rate);

                // Calculate new order total based on shipping method selected
                //new_total_rate = total_rate - old_shipping_rate + new_shipping_rate;
                //Session["Total_Amount"] = new_total_rate.ToString();
                //total_amount = new_total_rate.ToString();
                //shipping_amount = new_shipping_rate.ToString();
            }

            Session["SellerEmail"] = SellerEmail;
            CurrencyCodeType currencyCode_Type = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), currency_code, true);
            Session["currency_code_type"] = currencyCode_Type;
            PaymentActionCodeType payment_ActionCode_Type = (PaymentActionCodeType)Enum.Parse(typeof(PaymentActionCodeType), payment_type, true);
            Session["payment_action_type"] = payment_ActionCode_Type;
            // SetExpressCheckoutRequestDetailsType object
            SetExpressCheckoutRequestDetailsType setExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
            // (Required) URL to which the buyer's browser is returned after choosing to pay with PayPal.
            setExpressCheckoutRequestDetails.ReturnURL = ReturnUrl;
            //(Required) URL to which the buyer is returned if the buyer does not approve the use of PayPal to pay you
            setExpressCheckoutRequestDetails.CancelURL = CancelUrl;
            // A URL to your logo image. Use a valid graphics format, such as .gif, .jpg, or .png
            setExpressCheckoutRequestDetails.cppLogoImage = LogoUrl;
            // To display the border in your principal identifying color, set the "cppCartBorderColor" parameter to the 6-digit hexadecimal value of that color
            // setExpressCheckoutRequestDetails.cppCartBorderColor = "0000CD";

            //Item details
            PaymentDetailsItemType itemDetails = new PaymentDetailsItemType();
            itemDetails.Name        = item_name;
            itemDetails.Amount      = new BasicAmountType(currencyCode_Type, roundeditmamt);
            itemDetails.Quantity    = Convert.ToInt32(item_quantity);
            itemDetails.Description = item_desc;
            itemDetails.Number      = item_id;

            //Add more items if necessary by using the class 'PaymentDetailsItemType'

            // Payment Information
            List <PaymentDetailsType> paymentDetailsList = new List <PaymentDetailsType>();

            PaymentDetailsType paymentDetails = new PaymentDetailsType();
            paymentDetails.PaymentAction = payment_ActionCode_Type;
            paymentDetails.ItemTotal     = new BasicAmountType(currencyCode_Type, roundeditmamt);//item amount
            //paymentDetails.TaxTotal = new BasicAmountType(currencyCode_Type, tax_amount); //tax amount;
            //paymentDetails.ShippingTotal = new BasicAmountType(currencyCode_Type, shipping_amount); //shipping amount
            //paymentDetails.HandlingTotal = new BasicAmountType(currencyCode_Type, handling_amount); //handling amount
            //paymentDetails.ShippingDiscount = new BasicAmountType(currencyCode_Type, shipping_discount_amount); //shipping discount
            //paymentDetails.InsuranceTotal = new BasicAmountType(currencyCode_Type, insurance_amount); //insurance amount
            paymentDetails.OrderTotal = new BasicAmountType(currencyCode_Type, roundedtotal); // order total amount

            paymentDetails.PaymentDetailsItem.Add(itemDetails);

            // Unique identifier for the merchant.
            SellerDetailsType sellerDetails = new SellerDetailsType();
            sellerDetails.PayPalAccountID = SellerEmail;
            paymentDetails.SellerDetails  = sellerDetails;

            if (ecMethod != null && ecMethod == "MarkExpressCheckout")
            {
                paymentDetails.ShipToAddress = shipToAddress;
            }
            paymentDetailsList.Add(paymentDetails);
            setExpressCheckoutRequestDetails.PaymentDetails = paymentDetailsList;

            // Collect Shipping details if MARK express checkout

            SetExpressCheckoutReq         setExpressCheckout        = new SetExpressCheckoutReq();
            SetExpressCheckoutRequestType setExpressCheckoutRequest = new SetExpressCheckoutRequestType(setExpressCheckoutRequestDetails);
            setExpressCheckout.SetExpressCheckoutRequest = setExpressCheckoutRequest;

            // Create the service wrapper object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService();

            // API call
            // Invoke the SetExpressCheckout method in service wrapper object
            responseSetExpressCheckoutResponseType = service.SetExpressCheckout(setExpressCheckout);

            if (responseSetExpressCheckoutResponseType != null)
            {
                // Response envelope acknowledgement
                string acknowledgement = "SetExpressCheckout API Operation - ";
                acknowledgement += responseSetExpressCheckoutResponseType.Ack.ToString();
                //logger.Debug(acknowledgement + "\n");
                System.Diagnostics.Debug.WriteLine(acknowledgement + "\n");
                // # Success values
                if (responseSetExpressCheckoutResponseType.Ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // # Redirecting to PayPal for authorization
                    // Once you get the "Success" response, needs to authorise the
                    // transaction by making buyer to login into PayPal. For that,
                    // need to construct redirect url using EC token from response.
                    // Express Checkout Token
                    string EcToken = responseSetExpressCheckoutResponseType.Token;
                    //logger.Info("Express Checkout Token : " + EcToken + "\n");
                    System.Diagnostics.Debug.WriteLine("Express Checkout Token : " + EcToken + "\n");
                    // Store the express checkout token in session to be used in GetExpressCheckoutDetails & DoExpressCheckout API operations
                    Session["EcToken"] = EcToken;
                    Response.Redirect(RedirectUrl + HttpUtility.UrlEncode(EcToken), false);
                    Context.ApplicationInstance.CompleteRequest();
                }
                // # Error Values
                else
                {
                    List <ErrorType> errorMessages = responseSetExpressCheckoutResponseType.Errors;
                    string           errorMessage  = "";
                    foreach (ErrorType error in errorMessages)
                    {
                        //logger.Debug("API Error Message : " + error.LongMessage);
                        System.Diagnostics.Debug.WriteLine("API Error Message : " + error.LongMessage + "\n");
                        errorMessage = errorMessage + error.LongMessage;
                    }
                    //Redirect to error page in case of any API errors
                    CurrContext.Items.Add("APIErrorMessage", errorMessage);
                    Server.Transfer("~/Response.aspx");
                }
            }
        }
        catch (System.Exception ex)
        {
            // Log the exception message
            //logger.Debug("Error Message : " + ex.Message);
            System.Diagnostics.Debug.WriteLine("Error Message : " + ex.Message);
        }
    }
        private void populateRequestObject(DoReferenceTransactionRequestType request)
        {
            DoReferenceTransactionRequestDetailsType referenceTransactionDetails = new DoReferenceTransactionRequestDetailsType();

            request.DoReferenceTransactionRequestDetails = referenceTransactionDetails;
            // (Required) A transaction ID from a previous purchase, such as a credit card charge using the DoDirectPayment API, or a billing agreement ID.
            referenceTransactionDetails.ReferenceID = referenceId.Value;
            // (Optional) How you want to obtain payment. It is one of the following values:
            // * Authorization – This payment is a basic authorization subject to settlement with PayPal Authorization and Capture.
            // * Sale – This is a final sale for which you are requesting payment.
            referenceTransactionDetails.PaymentAction = (PaymentActionCodeType)
                                                        Enum.Parse(typeof(PaymentActionCodeType), paymentAction.SelectedValue);

            // Populate payment requestDetails.
            PaymentDetailsType paymentDetails = new PaymentDetailsType();

            referenceTransactionDetails.PaymentDetails = paymentDetails;
            // (Required) The total cost of the transaction to the buyer. If shipping cost and tax charges are known, include them in this value. If not, this value should be the current subtotal of the order. If the transaction includes one or more one-time purchases, this field must be equal to the sum of the purchases. Set this field to 0 if the transaction does not include a one-time purchase such as when you set up a billing agreement for a recurring payment that is not immediately charged. When the field is set to 0, purchase-specific fields are ignored.
            // Note: You must set the currencyID attribute to one of the 3-character currency codes for any of the supported PayPal currencies.
            double orderTotal = 0.0;
            // (Optional) Sum of cost of all items in this order.
            // Note: You must set the currencyID attribute to one of the 3-character currency codes for any of the supported PayPal currencies.
            double           itemTotal = 0.0;
            CurrencyCodeType currency  = (CurrencyCodeType)
                                         Enum.Parse(typeof(CurrencyCodeType), currencyCode.SelectedValue);

            // (Optional) Total shipping costs for this order.
            // Note: You must set the currencyID attribute to one of the 3-character currency codes for any of the supported PayPal currencies.
            if (shippingTotal.Value != string.Empty)
            {
                paymentDetails.ShippingTotal = new BasicAmountType(currency, shippingTotal.Value);
                orderTotal += Convert.ToDouble(shippingTotal.Value);
            }
            // (Optional) Total handling costs for this order.
            // Note: You must set the currencyID attribute to one of the 3-character currency codes for any of the supported PayPal currencies.
            if (handlingTotal.Value != string.Empty)
            {
                paymentDetails.HandlingTotal = new BasicAmountType(currency, handlingTotal.Value);
                orderTotal += Convert.ToDouble(handlingTotal.Value);
            }
            // (Optional) Sum of tax for all items in this order.
            // Note: You must set the currencyID attribute to one of the 3-character currency codes for any of the supported PayPal currencies.
            if (taxTotal.Value != string.Empty)
            {
                paymentDetails.TaxTotal = new BasicAmountType(currency, taxTotal.Value);
                orderTotal += Convert.ToDouble(taxTotal.Value);
            }
            // (Optional) Description of items the buyer is purchasing.
            // Note: The value you specify is available only if the transaction includes a purchase. This field is ignored if you set up a billing agreement for a recurring payment that is not immediately charged.
            if (orderDescription.Value != string.Empty)
            {
                paymentDetails.OrderDescription = orderDescription.Value;
            }

            // Each payment can include requestDetails about multiple payment items
            // This example shows just one payment item
            if (itemName.Value != null && itemAmount.Value != null && itemQuantity.Value != null)
            {
                PaymentDetailsItemType itemDetails = new PaymentDetailsItemType();
                // Item name. This field is required when you pass a value for ItemCategory.
                itemDetails.Name = itemName.Value;
                // Cost of item. This field is required when you pass a value for ItemCategory.
                itemDetails.Amount = new BasicAmountType(currency, itemAmount.Value);
                // Item quantity. This field is required when you pass a value forItemCategory.
                itemDetails.Quantity = Convert.ToInt32(itemQuantity.Value);
                // Indicates whether the item is digital or physical. For digital goods, this field is required and you must set it to Digital to get the best rates. It is one of the following values:
                // * Digital
                // * Physical
                // This field is introduced in version 69.0.
                itemDetails.ItemCategory = (ItemCategoryType)
                                           Enum.Parse(typeof(ItemCategoryType), itemCategory.SelectedValue);
                itemTotal += Convert.ToDouble(itemDetails.Amount.value) * itemDetails.Quantity.Value;
                //if (salesTax.Value != string.Empty)
                //{
                //    itemDetails.Tax = new BasicAmountType(currency, salesTax.Value);
                //    orderTotal += Convert.ToDouble(salesTax.Value);
                //}
                // (Optional) Item description.
                // This field is available since version 53.0.
                if (itemDescription.Value != string.Empty)
                {
                    itemDetails.Description = itemDescription.Value;
                }
                paymentDetails.PaymentDetailsItem.Add(itemDetails);
            }
            orderTotal += itemTotal;
            paymentDetails.ItemTotal  = new BasicAmountType(currency, itemTotal.ToString());
            paymentDetails.OrderTotal = new BasicAmountType(currency, orderTotal.ToString());
            // (Optional) Your URL for receiving Instant Payment Notification (IPN) about this transaction. If you do not specify this value in the request, the notification URL from your Merchant Profile is used, if one exists.
            // Important:
            // The notify URL applies only to DoExpressCheckoutPayment. This value is ignored when set in SetExpressCheckout or GetExpressCheckoutDetails.
            paymentDetails.NotifyURL = ipnNotificationUrl.Value.Trim();
        }
        /// <summary>
        /// Construct the Gets the PayPal payment details from our payment and Cart to pass onto PayPal.
        /// </summary>
        /// <remarks>
        /// The PayPal payment detail can be a bit different from OrderForm because
        /// sometimes cart total calculated by Commerce is different with cart total calculated by PalPal,
        /// though this difference is very small (~0.01 currency).
        /// We adjust this into an additional item to ensure PayPal shows the same total number with Commerce.
        /// We also add the Order discount (if any) as and special item with negative price to PayPal payment detail.
        /// See detail about PayPal structure type in this link https://developer.paypal.com/docs/classic/express-checkout/ec_api_flow/
        /// </remarks>
        /// <param name="payment">The payment to take info (Total, LineItem, ...) from</param>
        /// <param name="orderGroup">The order group (to be InvoiceID to pass to PayPal)</param>
        /// <param name="orderNumber">The order number.</param>
        /// <param name="notifyUrl">The notify Url.</param>
        /// <returns>The PayPal payment detail to pass to API request</returns>
        public PaymentDetailsType GetPaymentDetailsType(IPayment payment, IOrderGroup orderGroup, string orderNumber, string notifyUrl)
        {
            var orderForm          = orderGroup.Forms.First(form => form.Payments.Contains(payment));
            var paymentDetailsType = new PaymentDetailsType();

            paymentDetailsType.ButtonSource = "Episerver_Cart_EC";                                        // (Optional) An identification code for use by third-party applications to identify transactions. Character length and limitations: 32 single-byte alphanumeric characters
            paymentDetailsType.InvoiceID    = orderNumber;                                                // Character length and limitations: 127 single-byte alphanumeric characters
            paymentDetailsType.Custom       = orderGroup.CustomerId + "|" + paymentDetailsType.InvoiceID; // A free-form field for your own use. Character length and limitations: 256 single-byte alphanumeric characters
                                                                                                          // NOTE: paymentDetailsType.OrderDescription = 127 single-byte alphanumeric characters string
                                                                                                          // NOTE: paymentDetailsType.TransactionId = string, provided if you have transactionId in your Commerce system // (Optional) Transaction identification number of the transaction that was created.;

            // (Optional) Your URL for receiving Instant Payment Notification (IPN) about this transaction. If you do not specify this value in the request, the notification URL from your Merchant Profile is used, if one exists.
            // IMPORTANT:The notify URL only applies to DoExpressCheckoutPayment. This value is ignored when set in SetExpressCheckout or GetExpressCheckoutDetails.
            // Character length and limitations: 2,048 single-byte alphanumeric characters
            paymentDetailsType.NotifyURL = notifyUrl;

            var currency      = orderGroup.Currency;
            var totalOrder    = currency.Round(payment.Amount);
            var totalShipping = currency.Round(orderGroup.GetShippingTotal(_orderGroupCalculator).Amount);
            var totalHandling = currency.Round(orderForm.HandlingTotal);
            var totalTax      = currency.Round(orderGroup.GetTaxTotal(_orderGroupCalculator).Amount);
            var lineItemTotal = 0m;

            var paymentDetailItems = new List <PaymentDetailsItemType>();

            foreach (var lineItem in orderForm.GetAllLineItems())
            {
                // recalculate final unit price after all kind of discounts are subtracted from item.ListPrice
                var finalUnitPrice = currency.Round(lineItem.GetExtendedPrice(currency).Amount / lineItem.Quantity);
                lineItemTotal += finalUnitPrice * lineItem.Quantity;

                paymentDetailItems.Add(new PaymentDetailsItemType
                {
                    Name     = lineItem.DisplayName,
                    Number   = lineItem.Code,
                    Quantity = Convert.ToInt32(lineItem.Quantity.ToString("0")),
                    Amount   = ToPayPalAmount(finalUnitPrice, currency)
                });
            }

            // this adjustment also include the gift-card (in sample)
            var orderAdjustment       = totalOrder - totalShipping - totalHandling - totalTax - lineItemTotal;
            var adjustmentForShipping = 0m;

            if (orderAdjustment != 0 || // adjustment for gift card/(order level) promotion case
                lineItemTotal == 0    // in this case, the promotion (or discount) make all lineItemTotal zero, but buyer still have to pay shipping (and/or handling, tax).
                                      // We still need to adjust lineItemTotal for Paypal accepting (need to be greater than zero)
                )
            {
                var paymentDetailItem = new PaymentDetailsItemType
                {
                    Name        = "Order adjustment",
                    Number      = "ORDERADJUSTMENT",
                    Description = "GiftCard, Discount at OrderLevel and/or PayPal-Commerce-calculating difference in cart total",  // Character length and limitations: 127 single-byte characters
                    Quantity    = 1
                };

                var predictLineitemTotal = lineItemTotal + orderAdjustment;
                if (predictLineitemTotal <= 0)
                {
                    // can't overpaid for item. E.g.: total item amount is 68, orderAdjustment is -70, PayPal will refuse ItemTotal = -2
                    // we need to push -2 to shippingTotal or shippingDiscount

                    // HACK: Paypal will not accept an item total of $0, even if there is a shipping fee. The Item total must be at least 1 cent/penny.
                    // We need to take 1 cent/penny from adjustmentForLineItemTotal and push to adjustmentForShipping
                    orderAdjustment       = (-lineItemTotal + 0.01m);     // -68 + 0.01 = -67.99
                    adjustmentForShipping = predictLineitemTotal - 0.01m; // -2 - 0.01 = -2.01
                }
                else
                {
                    // this case means: due to PayPal calculation, buyer need to pay more that what Commerce calculate. Because:
                    // sometimes cart total calculated by Commerce is different with
                    // cart total calculated by PalPal, though this difference is very small (~0.01 currency)
                    // We adjust the items total to make up for that, to ensure PayPal shows the same total number with Commerce
                }

                lineItemTotal += orderAdjustment; // re-adjust the lineItemTotal

                paymentDetailItem.Amount = ToPayPalAmount(orderAdjustment, currency);
                paymentDetailItems.Add(paymentDetailItem);
            }

            if (adjustmentForShipping > 0)
            {
                totalShipping += adjustmentForShipping;
            }
            else
            {
                // Shipping discount for this order. You specify this value as a negative number.
                // NOTE:Character length and limitations: Must not exceed $10,000 USD in any currency.
                // No currency symbol. Regardless of currency, decimal separator must be a period (.), and the optional thousands separator must be a comma (,).
                // Equivalent to nine characters maximum for USD.
                // NOTE:You must set the currencyID attribute to one of the three-character currency codes for any of the supported PayPal currencies.
                paymentDetailsType.ShippingDiscount = ToPayPalAmount(adjustmentForShipping, currency);
            }

            paymentDetailsType.OrderTotal    = ToPayPalAmount(totalOrder, currency);
            paymentDetailsType.ShippingTotal = ToPayPalAmount(totalShipping, currency);
            paymentDetailsType.HandlingTotal = ToPayPalAmount(totalHandling, currency);
            paymentDetailsType.TaxTotal      = ToPayPalAmount(totalTax, currency);
            paymentDetailsType.ItemTotal     = ToPayPalAmount(lineItemTotal, currency);

            paymentDetailsType.PaymentDetailsItem = paymentDetailItems;
            paymentDetailsType.ShipToAddress      = AddressHandling.ToAddressType(orderForm.Shipments.First().ShippingAddress);

            if (orderForm.Shipments.Count > 1)
            {
                // (Optional) The value 1 indicates that this payment is associated with multiple shipping addresses. Character length and limitations: Four single-byte numeric characters.
                paymentDetailsType.MultiShipping = "1";
            }

            return(paymentDetailsType);
        }
Esempio n. 26
0
        public static PayPalResponceModel Pay(string email, CartViewModel cart, string expressCheckoutSuccessUrl, string paymentFailureUrl)
        {
            Dictionary <string, string>      config  = PayPal.Api.ConfigManager.Instance.GetProperties();
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(config);

            SetExpressCheckoutRequestType        setExpressCheckoutReqType = new SetExpressCheckoutRequestType();
            SetExpressCheckoutRequestDetailsType details    = new SetExpressCheckoutRequestDetailsType();
            List <PaymentDetailsType>            payDetails = new List <PaymentDetailsType>();
            PaymentDetailsType paydtl = new PaymentDetailsType();

            paydtl.PaymentAction = PaymentActionCodeType.ORDER;

            BasicAmountType shippingTotal = new BasicAmountType();

            shippingTotal.value      = cart.ShippingCost.ToString();
            shippingTotal.currencyID = CurrencyCodeType.USD;

            decimal itemsTotal = 0.0M;

            List <PaymentDetailsItemType> lineItems = new List <PaymentDetailsItemType>();

            foreach (var cartItem in cart.Items)
            {
                PaymentDetailsItemType item = new PaymentDetailsItemType();
                BasicAmountType        amt  = new BasicAmountType();
                amt.currencyID = CurrencyCodeType.USD;

                amt.value     = "50";
                item.Quantity = cartItem.Count;
                itemsTotal   += 50 * cartItem.Count;

                item.Name   = string.Format("{0} {1} Shirt", cartItem.Project.ShirtColor, cartItem.Project.SizeString);
                item.Amount = amt;

                lineItems.Add(item);
            }

            decimal orderTotal = itemsTotal + cart.ShippingCost;

            paydtl.OrderTotal         = new BasicAmountType(CurrencyCodeType.USD, Convert.ToString(orderTotal));
            paydtl.PaymentDetailsItem = lineItems;

            paydtl.ShippingTotal      = shippingTotal;
            paydtl.PaymentDetailsItem = lineItems;
            payDetails.Add(paydtl);

            details.BuyerEmail     = email;
            details.PaymentDetails = payDetails;
            details.ReturnURL      = expressCheckoutSuccessUrl;
            details.CancelURL      = paymentFailureUrl;

            setExpressCheckoutReqType.SetExpressCheckoutRequestDetails = details;
            SetExpressCheckoutReq expressCheckoutReq = new SetExpressCheckoutReq();

            expressCheckoutReq.SetExpressCheckoutRequest = setExpressCheckoutReqType;
            SetExpressCheckoutResponseType response = null;

            try
            {
                response = service.SetExpressCheckout(expressCheckoutReq);
            }
            catch (Exception ex)
            {
                return(new PayPalResponceModel
                {
                    Success = false,
                    ErrorMessage = ex.Message
                });
            }

            if (!response.Ack.ToString().Trim().ToUpper().Equals(AckCode.FAILURE.ToString()) && !response.Ack.ToString().Trim().ToUpper().Equals(AckCode.FAILUREWITHWARNING.ToString()))
            {
                var redirectUrl = string.Format("{0}_express-checkout&token={1}", config["paypalResultUrl"], response.Token);
                return(new PayPalResponceModel
                {
                    Success = true,
                    RedirectUrl = redirectUrl
                });
            }

            return(new PayPalResponceModel
            {
                Success = false,
                ErrorMessage = string.Join(". ", response.Errors.Select(x => x.LongMessage).ToList())
            });
        }
Esempio n. 27
0
        public void ProcessDirectPayment(PayPalInformation paypalinformation)
        {
            DoDirectPaymentRequestType DoDirectPmtReqType = new DoDirectPaymentRequestType();

            DoDirectPmtReqType.DoDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType();

            // Set payment action
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentAction = PaymentActionCodeType.Sale;

            // Set IP
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.IPAddress = HttpContext.Current.Request.UserHostAddress;

            // Set CreditCard info.
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard = new CreditCardDetailsType();
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CreditCardNumber = paypalinformation.Order.CreditCard.Number;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CreditCardType   = ( CreditCardTypeType )StringToEnum(typeof(CreditCardTypeType), paypalinformation.Order.CreditCard.CardType);

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CVV2     = paypalinformation.Order.CreditCard.SecurityCode;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.ExpMonth = paypalinformation.Order.CreditCard.ExpMonth;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.ExpYear  = paypalinformation.Order.CreditCard.ExpYear;

            // Set the billing address
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner                          = new PayerInfoType();
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName                = new PersonNameType();
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.FirstName      = paypalinformation.Order.EndUser.FirstName;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.LastName       = paypalinformation.Order.EndUser.LastName;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address                  = new AddressType();
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street1          = paypalinformation.Order.CreditCard.Address.AddressLine;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street2          = paypalinformation.Order.CreditCard.Address.AddressLine2;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CityName         = paypalinformation.Order.CreditCard.Address.City;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.StateOrProvince  = paypalinformation.Order.CreditCard.Address.State;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.PostalCode       = paypalinformation.Order.CreditCard.Address.PostalCode;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CountrySpecified = true;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Country          = CountryCodeType.US;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Phone            = paypalinformation.Order.EndUser.ContactInformation.Phone;

            PaymentDetailsItemType[] itemArray = new PaymentDetailsItemType[paypalinformation.Order.OrderDetails.Products.Length];
            PaymentDetailsItemType   items     = null;

            // Loop through all items that were added to the shopping cart.
            for (int i = 0; i < paypalinformation.Order.OrderDetails.Products.Length; i++)
            {
                items                   = new PaymentDetailsItemType();
                items.Amount            = new BasicAmountType();
                items.Amount.Value      = paypalinformation.Order.OrderDetails.Products[i].Price.ToString();
                items.Amount.currencyID = CurrencyCodeType.USD;
                items.Quantity          = paypalinformation.Order.OrderDetails.Products[i].Quantity.ToString();

                //items.Tax						= new BasicAmountType();
                //items.Tax.Value				= CalculationManager.CalcSalesTax( Convert.ToDecimal( items.Amount.Value ) ).ToString();
                //items.Tax.currencyID			= CurrencyCodeType.USD;

                items.Name   = paypalinformation.Order.OrderDetails.Products[i].Name;
                items.Number = paypalinformation.Order.OrderDetails.Products[i].ProductID.ToString();

                itemArray.SetValue(items, i);
            }

            // set payment Details
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails                  = new PaymentDetailsType();
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.Custom           = System.DateTime.Now.ToLongTimeString();
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderDescription = "";

            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.PaymentDetailsItem = new PaymentDetailsItemType[itemArray.Length];
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.PaymentDetailsItem = itemArray;

            for (int ii = 0; ii < itemArray.Length; ii++)
            {
                DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.PaymentDetailsItem.SetValue(itemArray[ii], ii);
            }

            // Order summary.
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal               = new BasicAmountType();
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.currencyID    = CurrencyCodeType.USD;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.Value         = paypalinformation.Order.OrderTotal.ToString();
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal            = new BasicAmountType();
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal.currencyID = CurrencyCodeType.USD;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal.Value      = paypalinformation.Order.ShippingTotal.ToString();
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.TaxTotal             = new BasicAmountType();
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.TaxTotal.currencyID  = CurrencyCodeType.USD;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.TaxTotal.Value       = paypalinformation.Order.Tax.ToString();
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal            = new BasicAmountType();
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal.currencyID = CurrencyCodeType.USD;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal.Value      = paypalinformation.Order.SubTotal.ToString();

            //set ship to address
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress                  = new AddressType();
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Name             = paypalinformation.Order.EndUser.FirstName + " " + paypalinformation.Order.EndUser.LastName;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Street1          = paypalinformation.Order.ShippingAddress.AddressLine;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.CityName         = paypalinformation.Order.ShippingAddress.City;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.StateOrProvince  = paypalinformation.Order.ShippingAddress.State;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.PostalCode       = paypalinformation.Order.ShippingAddress.PostalCode;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.CountrySpecified = true;
            DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Country          = CountryCodeType.US;

            // credentials
            DoDirectPaymentReq DoDPReq = new DoDirectPaymentReq();

            DoDPReq.DoDirectPaymentRequest         = DoDirectPmtReqType;
            DoDPReq.DoDirectPaymentRequest.Version = "2.20";

            try
            {
                //make call return response
                DoDirectPaymentResponseType DPRes = new DoDirectPaymentResponseType();
                DPRes = PPInterface.DoDirectPayment(DoDPReq);
                string errors = CheckForErrors(DPRes);

                if (errors == string.Empty)
                {
                    IsSubmissionSuccess = true;
                    paypalinformation.Order.TransactionID = DPRes.TransactionID;
                }
                else
                {
                    IsSubmissionSuccess = false;
                    SubmissionError     = errors;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 28
0
        public static String MakeECRecurringProfile(ShoppingCart cart, int orderNumber, String payPalToken, String payerID, DateTime nextRecurringShipDate)
        {
            PayPalAPISoapBinding   IPayPalRefund;
            PayPalAPIAASoapBinding IPayPal;

            PayPalController.GetPaypalRequirements(out IPayPalRefund, out IPayPal);
            String result = String.Empty;

            CreateRecurringPaymentsProfileReq                ECRecurringRequest  = new CreateRecurringPaymentsProfileReq();
            CreateRecurringPaymentsProfileRequestType        varECRequest        = new CreateRecurringPaymentsProfileRequestType();
            CreateRecurringPaymentsProfileRequestDetailsType varECRequestDetails = new CreateRecurringPaymentsProfileRequestDetailsType();
            CreateRecurringPaymentsProfileResponseType       ECRecurringResponse = new CreateRecurringPaymentsProfileResponseType();

            //Re-Use the Internal Gateway Recurring Billing logic for calculating how much of the order is recurring
            ShoppingCart cartRecur       = new ShoppingCart(cart.ThisCustomer.SkinID, cart.ThisCustomer, CartTypeEnum.RecurringCart, orderNumber, false);
            Decimal      CartTotalRecur  = Decimal.Round(cartRecur.Total(true), 2, MidpointRounding.AwayFromZero);
            Decimal      RecurringAmount = CartTotalRecur - CommonLogic.IIF(cartRecur.Coupon.CouponType == CouponTypeEnum.GiftCard, CommonLogic.IIF(CartTotalRecur < cartRecur.Coupon.DiscountAmount, CartTotalRecur, cartRecur.Coupon.DiscountAmount), 0);

            DateIntervalTypeEnum ecRecurringIntervalType = cartRecur.CartItems[0].RecurringIntervalType;                //We currently only support 1 interval per recurring order, so grabbing the first as a default should be safe
            int ecRecurringInterval = cartRecur.CartItems[0].RecurringInterval;

            BasicAmountType ecRecurringAmount = new BasicAmountType();

            ecRecurringAmount.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), AppLogic.AppConfig("Localization.StoreCurrency"), true);
            ecRecurringAmount.Value      = RecurringAmount.ToString();

            BillingPeriodDetailsType varECSchedulePaymentDetails = GetECRecurringPeriodDetails(ecRecurringIntervalType, ecRecurringInterval);

            varECSchedulePaymentDetails.Amount = ecRecurringAmount;
            varECSchedulePaymentDetails.TotalBillingCyclesSpecified = false;

            ScheduleDetailsType varECSchedule = new ScheduleDetailsType();

            //Need a better description, but it must match the one sent in StartEC
            varECSchedule.Description                        = "Recurring order created on " + System.DateTime.Now.ToShortDateString() + " from " + AppLogic.AppConfig("StoreName");
            varECSchedule.MaxFailedPayments                  = 0; //Cancel the order if a recurrence fails
            varECSchedule.MaxFailedPaymentsSpecified         = true;
            varECSchedule.AutoBillOutstandingAmount          = AutoBillType.NoAutoBill;
            varECSchedule.AutoBillOutstandingAmountSpecified = true;
            varECSchedule.PaymentPeriod                      = varECSchedulePaymentDetails;

            RecurringPaymentsProfileDetailsType varECProfileDetails = new RecurringPaymentsProfileDetailsType();

            varECProfileDetails.SubscriberName   = cart.ThisCustomer.FirstName + " " + cart.ThisCustomer.LastName;
            varECProfileDetails.BillingStartDate = nextRecurringShipDate;

            varECRequestDetails.ScheduleDetails = varECSchedule;
            varECRequestDetails.Token           = payPalToken;
            varECRequestDetails.RecurringPaymentsProfileDetails = varECProfileDetails;

            if (cart.IsAllDownloadComponents())
            {
                PaymentDetailsItemType varECPaymentDetails = new PaymentDetailsItemType();
                varECPaymentDetails.ItemCategory          = ItemCategoryType.Digital;
                varECPaymentDetails.ItemCategorySpecified = true;

                List <PaymentDetailsItemType> ECPaymentDetailsList = new List <PaymentDetailsItemType>();

                ECPaymentDetailsList.Add(varECPaymentDetails);

                varECRequestDetails.PaymentDetailsItem = ECPaymentDetailsList.ToArray();
            }

            varECRequest.Version = API_VER;
            varECRequest.CreateRecurringPaymentsProfileRequestDetails = varECRequestDetails;

            ECRecurringRequest.CreateRecurringPaymentsProfileRequest = varECRequest;

            ECRecurringResponse = IPayPal.CreateRecurringPaymentsProfile(ECRecurringRequest);

            if (ECRecurringResponse.Ack.ToString().StartsWith("success", StringComparison.InvariantCultureIgnoreCase))
            {
                result = AppLogic.ro_OK;
            }
            else
            {
                if (ECRecurringResponse.Errors != null)
                {
                    bool first = true;
                    for (int ix = 0; ix < ECRecurringResponse.Errors.Length; ix++)
                    {
                        if (!first)
                        {
                            result += ", ";
                        }
                        result += ECRecurringResponse.Errors[ix].LongMessage;
                        first   = false;
                    }
                }
            }

            //Log the transaction
            OrderTransactionCollection ecRecurringOrderTransaction = new OrderTransactionCollection(orderNumber);

            ecRecurringOrderTransaction.AddTransaction("PayPal Express Checkout Recurring Profile Creation",
                                                       ECRecurringRequest.ToString(),
                                                       result,
                                                       payerID,                                                                                                                                                                                       //PNREF = payerID
                                                       (ECRecurringResponse.CreateRecurringPaymentsProfileResponseDetails.ProfileID == null ? "No ProfileID provided" : ECRecurringResponse.CreateRecurringPaymentsProfileResponseDetails.ProfileID), //Code = ProfileID
                                                       AppLogic.ro_PMPayPalExpress,
                                                       null,
                                                       RecurringAmount);

            return(result);
        }
        /// <summary>
        /// Builds a <see cref="PaymentDetailsItemType"/>.
        /// </summary>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <param name="factory">
        /// The <see cref="PayPalBasicAmountTypeFactory"/>.
        /// </param>
        /// <param name="isDiscount">
        /// The is discount.
        /// </param>
        /// <returns>
        /// The <see cref="PaymentDetailsItemType"/>.
        /// </returns>
        protected virtual PaymentDetailsItemType BuildGenericPaymentDetailsItemType(ILineItem item, PayPalBasicAmountTypeFactory factory, bool isDiscount)
        {
            var detailsItemType = new PaymentDetailsItemType
            {
                Name = item.Name,
                ItemURL = null,
                Amount = factory.Build(item.Price),
                Quantity = item.Quantity,
            };

            return detailsItemType;
        }
Esempio n. 30
0
        public string GenerateOrder(List <ItemPayPal> items)
        {
            // Create request object
            SetExpressCheckoutRequestType request = new SetExpressCheckoutRequestType();

            SetExpressCheckoutRequestDetailsType ecDetails = new SetExpressCheckoutRequestDetailsType();



            /* Populate payment requestDetails.
             * SetExpressCheckout allows parallel payments of upto 10 payments.
             * This samples shows just one payment.
             */
            PaymentDetailsType paymentDetails = new PaymentDetailsType();

            ecDetails.PaymentDetails.Add(paymentDetails);
            // (Required) Total cost of the transaction to the buyer. If shipping cost and tax charges are known, include them in this value. If not, this value should be the current sub-total of the order. If the transaction includes one or more one-time purchases, this field must be equal to the sum of the purchases. Set this field to 0 if the transaction does not include a one-time purchase such as when you set up a billing agreement for a recurring payment that is not immediately charged. When the field is set to 0, purchase-specific fields are ignored.
            double orderTotal = 0.0;
            // Sum of cost of all items in this order. For digital goods, this field is required.
            double           itemTotal = 0.0;
            CurrencyCodeType currency  = CurrencyCodeType.MXN;


            //(Optional) Description of items the buyer is purchasing.
            // Note:
            // The value you specify is available only if the transaction includes a purchase.
            // This field is ignored if you set up a billing agreement for a recurring payment
            // that is not immediately charged.
            // Character length and limitations: 127 single-byte alphanumeric characters

            paymentDetails.OrderDescription = "";

            // How you want to obtain payment. When implementing parallel payments,
            // this field is required and must be set to Order.
            // When implementing digital goods, this field is required and must be set to Sale.
            // If the transaction does not include a one-time purchase, this field is ignored.
            // It is one of the following values:
            //   Sale – This is a final sale for which you are requesting payment (default).
            //   Authorization – This payment is a basic authorization subject to settlement with PayPal Authorization and Capture.
            //   Order – This payment is an order authorization subject to settlement with PayPal Authorization and Capture.
            paymentDetails.PaymentAction = PaymentActionCodeType.SALE;

            paymentDetails.ButtonSource = "PTSH";

            foreach (ItemPayPal item in items)
            {
                PaymentDetailsItemType details = new PaymentDetailsItemType()
                {
                    Name     = item.Name,
                    Amount   = new BasicAmountType(currency, ((decimal)item.Price).ToString()),
                    Quantity = item.Quantity
                };

                // Indicates whether an item is digital or physical. For digital goods, this field is required and must be set to Digital. It is one of the following values:
                //   1.Digital
                //   2.Physical
                //  This field is available since version 65.1.
                //itemDetails.ItemCategory = ItemCategoryType.DIGITAL;

                itemTotal += Convert.ToDouble(details.Amount.value) * details.Quantity.Value;

                //(Optional) Item description.
                // Character length and limitations: 127 single-byte characters
                // This field is introduced in version 53.0.

                details.Description = item.Description;

                paymentDetails.PaymentDetailsItem.Add(details);
            }

            orderTotal += itemTotal;
            paymentDetails.ItemTotal  = new BasicAmountType(currency, itemTotal.ToString());
            paymentDetails.OrderTotal = new BasicAmountType(currency, orderTotal.ToString());
            paymentDetails.Custom     = "9998";
            paymentDetails.InvoiceID  = null;

            ecDetails.ReturnURL          = AppSettings.PayPalCallbackOk;
            ecDetails.CancelURL          = AppSettings.PayPalCallbackFail;
            ecDetails.NoShipping         = "1";
            ecDetails.AllowNote          = "0";
            ecDetails.cppCartBorderColor = "0b5ba1";

            // (Optional) URL for the image you want to appear at the top left of the payment page. The image has a maximum size of 750 pixels wide by 90 pixels high. PayPal recommends that you provide an image that is stored on a secure (https) server. If you do not specify an image, the business name displays.
            ecDetails.cppHeaderImage = "";

            request.SetExpressCheckoutRequestDetails = ecDetails;

            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////


            // Invoke the API
            SetExpressCheckoutReq wrapper = new SetExpressCheckoutReq();

            wrapper.SetExpressCheckoutRequest = request;

            System.Net.ServicePointManager.Expect100Continue = false;

            // Configuration map containing signature credentials and other required configuration.
            // For a full list of configuration parameters refer in wiki page
            // [https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters]

            // Create the PayPalAPIInterfaceServiceService service object to make the API call
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(_payPalConfiguration);

            //wrapper.SetExpressCheckoutRequest.Version = "84.0";
            // # API call
            // Invoke the SetExpressCheckout method in service wrapper object
            SetExpressCheckoutResponseType setECResponse = service.SetExpressCheckout(wrapper);

            // Check for API return status

            if (setECResponse.Ack.Equals(AckCodeType.FAILURE) || (setECResponse.Errors != null && setECResponse.Errors.Any()))
            {
                return(string.Empty);
            }
            return(setECResponse.Token);
        }
Esempio n. 31
0
        public override string RecurringBillingCreateSubscription(String SubscriptionDescription, Customer ThisCustomer, Address UseBillingAddress, Address UseShippingAddress, Decimal RecurringAmount, DateTime StartDate, int RecurringInterval, DateIntervalTypeEnum RecurringIntervalType, int OriginalRecurringOrderNumber, string XID, IDictionary <string, string> TransactionContext, out String RecurringSubscriptionID, out String RecurringSubscriptionCommand, out String RecurringSubscriptionResult)
        {
            string result = string.Empty;

            try
            {
                //Re-Use the Internal Gateway Recurring Billing logic for calculating how much of the order is recurring
                ShoppingCart recurringCart = new ShoppingCart(ThisCustomer.SkinID, ThisCustomer, CartTypeEnum.RecurringCart, OriginalRecurringOrderNumber, false);

                CreditCardDetailsType creditCard = new CreditCardDetailsType();

                if (UseBillingAddress.CardNumber != null && UseBillingAddress.CardNumber.Length > 0)
                {
                    creditCard.CreditCardNumber  = UseBillingAddress.CardNumber;
                    creditCard.ExpMonth          = Localization.ParseUSInt(UseBillingAddress.CardExpirationMonth);
                    creditCard.ExpYear           = Localization.ParseUSInt(UseBillingAddress.CardExpirationYear);
                    creditCard.ExpMonthSpecified = true;
                    creditCard.ExpYearSpecified  = true;
                    creditCard.CVV2 = XID;

                    if (UseBillingAddress.CardType == "AmericanExpress")
                    {
                        creditCard.CreditCardType = (CreditCardTypeType)Enum.Parse(typeof(CreditCardTypeType), "Amex", true);
                    }
                    else
                    {
                        creditCard.CreditCardType = (CreditCardTypeType)Enum.Parse(typeof(CreditCardTypeType), UseBillingAddress.CardType, true);
                    }
                    creditCard.CreditCardTypeSpecified = true;
                }
                else
                {
                    creditCard.CreditCardTypeSpecified = false;
                }

                BasicAmountType recurringAmount = new BasicAmountType();
                recurringAmount.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), AppLogic.AppConfig("Localization.StoreCurrency"), true);
                recurringAmount.Value      = RecurringAmount.ToString();

                DateIntervalTypeEnum recurringIntervalType = recurringCart.CartItems[0].RecurringIntervalType;                 //We currently only support 1 interval per recurring order, so grabbing the first as a default should be safe
                int recurringInterval = recurringCart.CartItems[0].RecurringInterval;

                BillingPeriodDetailsType billingPeriodDetails = PayPalController.GetECRecurringPeriodDetails(recurringIntervalType, recurringInterval);
                billingPeriodDetails.Amount = recurringAmount;
                billingPeriodDetails.TotalBillingCyclesSpecified = false;

                ScheduleDetailsType scheduleDetails = new ScheduleDetailsType();
                scheduleDetails.Description                        = string.Format("Recurring order created on {0} from {1}", System.DateTime.Now.ToShortDateString(), AppLogic.AppConfig("StoreName"));
                scheduleDetails.MaxFailedPayments                  = 0;
                scheduleDetails.MaxFailedPaymentsSpecified         = true;
                scheduleDetails.AutoBillOutstandingAmount          = AutoBillType.NoAutoBill;
                scheduleDetails.AutoBillOutstandingAmountSpecified = true;
                scheduleDetails.PaymentPeriod                      = billingPeriodDetails;

                RecurringPaymentsProfileDetailsType profileDetails = new RecurringPaymentsProfileDetailsType();
                profileDetails.SubscriberName   = ThisCustomer.FirstName + " " + ThisCustomer.LastName;
                profileDetails.BillingStartDate = StartDate;

                CreateRecurringPaymentsProfileRequestDetailsType profileRequestDetails = new CreateRecurringPaymentsProfileRequestDetailsType();
                profileRequestDetails.ScheduleDetails = scheduleDetails;
                profileRequestDetails.RecurringPaymentsProfileDetails = profileDetails;
                profileRequestDetails.CreditCard = creditCard;

                if (!(UseBillingAddress.CardNumber != null && UseBillingAddress.CardNumber.Length > 0))
                {
                    profileRequestDetails.Token = XID;
                }

                if (recurringCart.IsAllDownloadComponents())
                {
                    PaymentDetailsItemType paymentDetailsItem = new PaymentDetailsItemType();
                    paymentDetailsItem.ItemCategory          = ItemCategoryType.Digital;
                    paymentDetailsItem.ItemCategorySpecified = true;

                    List <PaymentDetailsItemType> paymentDetailsList = new List <PaymentDetailsItemType>();
                    paymentDetailsList.Add(paymentDetailsItem);

                    profileRequestDetails.PaymentDetailsItem = paymentDetailsList.ToArray();
                }

                CreateRecurringPaymentsProfileRequestType profileRequest = new CreateRecurringPaymentsProfileRequestType();
                profileRequest.Version = API_VER;
                profileRequest.CreateRecurringPaymentsProfileRequestDetails = profileRequestDetails;

                CreateRecurringPaymentsProfileReq request = new CreateRecurringPaymentsProfileReq();
                request.CreateRecurringPaymentsProfileRequest = profileRequest;

                CreateRecurringPaymentsProfileResponseType profileResponse = new CreateRecurringPaymentsProfileResponseType();
                profileResponse = IPayPal.CreateRecurringPaymentsProfile(request);

                if (profileResponse != null && profileResponse.Ack.ToString().StartsWith("success", StringComparison.InvariantCultureIgnoreCase))
                {
                    result = AppLogic.ro_OK;
                }
                else
                {
                    if (profileResponse.Errors != null)
                    {
                        bool first = true;
                        for (int ix = 0; ix < profileResponse.Errors.Length; ix++)
                        {
                            if (!first)
                            {
                                result += ", ";
                            }
                            result += profileResponse.Errors[ix].LongMessage;
                            first   = false;
                        }
                    }
                }

                RecurringSubscriptionID      = (profileResponse.CreateRecurringPaymentsProfileResponseDetails.ProfileID == null ? "No ProfileID provided" : profileResponse.CreateRecurringPaymentsProfileResponseDetails.ProfileID);
                RecurringSubscriptionCommand = string.Empty;
                RecurringSubscriptionResult  = (profileResponse.CreateRecurringPaymentsProfileResponseDetails.DCCProcessorResponse == null ? "No response provided" : profileResponse.CreateRecurringPaymentsProfileResponseDetails.DCCProcessorResponse);

                //Log the transaction
                OrderTransactionCollection ecRecurringOrderTransaction = new OrderTransactionCollection(OriginalRecurringOrderNumber);
                ecRecurringOrderTransaction.AddTransaction("PayPal Express Checkout Recurring Profile Creation",
                                                           request.ToString(),
                                                           result,
                                                           string.Empty,
                                                           (profileResponse.CreateRecurringPaymentsProfileResponseDetails.ProfileID == null ? "No ProfileID provided" : profileResponse.CreateRecurringPaymentsProfileResponseDetails.ProfileID),
                                                           AppLogic.ro_PMPayPalExpress,
                                                           null,
                                                           RecurringAmount);
            }
            catch
            {
                result = "Recurring Profile Creation Failed.";
                RecurringSubscriptionID      = string.Empty;
                RecurringSubscriptionCommand = string.Empty;
                RecurringSubscriptionResult  = result;
            }
            return(result);
        }
Esempio n. 32
0
        private void PopulateRequestObject(SetExpressCheckoutRequestType request, string email, string orderDescription, string billingAgreementText, string LogoURL, string brandName, double itemTotalAmount, string PlanName, double planAmount, string planDescription)
        {
            SetExpressCheckoutRequestDetailsType ecDetails = new SetExpressCheckoutRequestDetailsType();

            ecDetails.ReturnURL = System.Configuration.ConfigurationManager.AppSettings["ReturnUrl"];
            ecDetails.CancelURL = System.Configuration.ConfigurationManager.AppSettings["CancelURL"];

            ecDetails.BuyerEmail = email;
            //Optional get from merchant account ecDetails.ReqConfirmShipping=value;
            //Optional get from paypal  ecDetails.AddressOverride
            //optional ecDetails.NoShipping
            ecDetails.SolutionType = (SolutionTypeType)Enum.Parse(typeof(SolutionTypeType), "SOLE");
            //ecDetails.LandingPage = (LandingPageType)Enum.Parse(typeof(LandingPageType), "BILLING");

            //Adding payment details
            PaymentDetailsType paymentDetails = new PaymentDetailsType();

            ecDetails.PaymentDetails.Add(paymentDetails);

            // (Required) Total cost of the transaction to the buyer.
            //If shipping cost and tax charges are known, include them in this value.
            //If not, this value should be the current sub-total of the order. If the transaction includes one or more one-time purchases,
            //this field must be equal to the sum of the purchases. Set this field to 0 if the transaction does not include a one-time purchase
            //such as when you set up a billing agreement for a recurring payment that is not immediately charged. When the field is set to 0, purchase-specific fields are ignored.

            double orderTotal = 0.0;
            // Sum of cost of all items in this order. For digital goods, this field is required.
            double           itemTotal = 0.0;
            CurrencyCodeType currency  = (CurrencyCodeType)
                                         Enum.Parse(typeof(CurrencyCodeType), "USD");

            // How you want to obtain payment. When implementing parallel payments,
            // this field is required and must be set to Order.
            // When implementing digital goods, this field is required and must be set to Sale.
            // If the transaction does not include a one-time purchase, this field is ignored.
            // It is one of the following values:
            //   Sale – This is a final sale for which you are requesting payment (default).
            //   Authorization – This payment is a basic authorization subject to settlement with PayPal Authorization and Capture.
            //   Order – This payment is an order authorization subject to settlement with PayPal Authorization and Capture.
            paymentDetails.PaymentAction = (PaymentActionCodeType)
                                           Enum.Parse(typeof(PaymentActionCodeType), "SALE");

            // Each payment can include requestDetails about multiple items
            // This example shows just one payment item
            var itemName     = PlanName;
            var itemQuantity = 1;

            if (itemName != null && planAmount != null && itemQuantity != null)
            {
                PaymentDetailsItemType itemDetails = new PaymentDetailsItemType();
                itemDetails.Name = itemName;
                //itemDetails.Amount = new BasicAmountType(currency, planAmount.ToString()); // Comment by nitendra
                itemDetails.Amount = new BasicAmountType(currency, String.Format("{0:0.00}", planAmount)); // Added by nitendra
                // planAmount
                itemDetails.Quantity = Convert.ToInt32(itemQuantity);
                // Indicates whether an item is digital or physical. For digital goods, this field is required and must be set to Digital. It is one of the following values:
                //   1.Digital
                //   2.Physical
                //  This field is available since version 65.1.
                itemDetails.ItemCategory = (ItemCategoryType)
                                           Enum.Parse(typeof(ItemCategoryType), "DIGITAL");
                itemTotal += Convert.ToDouble(itemDetails.Amount.value) * itemDetails.Quantity.Value;
                //(Optional) Item sales tax.
                //    Note: You must set the currencyID attribute to one of
                //    the 3-character currency codes for any of the supported PayPal currencies.
                //    Character length and limitations: Value is a positive number which cannot exceed $10,000 USD in any currency.
                //    It includes no currency symbol. It must have 2 decimal places, the decimal separator must be a period (.),
                //    and the optional thousands separator must be a comma (,).
                //if (salesTax.Value != string.Empty)
                //{
                //    itemDetails.Tax = new BasicAmountType(currency, salesTax.Value);
                //    orderTotal += Convert.ToDouble(salesTax.Value);
                //}
                //(Optional) Item description.
                // Character length and limitations: 127 single-byte characters
                // This field is introduced in version 53.0.
                if (planDescription != string.Empty)
                {
                    itemDetails.Description = planDescription;
                }
                paymentDetails.PaymentDetailsItem.Add(itemDetails);
            }

            // Comment by nitendra
            //orderTotal += itemTotal;
            //paymentDetails.ItemTotal = new BasicAmountType(currency, itemTotal.ToString());
            //paymentDetails.OrderTotal = new BasicAmountType(currency, orderTotal.ToString());

            // Added by nitendra
            orderTotal += itemTotal;
            paymentDetails.ItemTotal  = new BasicAmountType(currency, String.Format("{0:0.00}", itemTotal));
            paymentDetails.OrderTotal = new BasicAmountType(currency, String.Format("{0:0.00}", orderTotal));


            if (billingAgreementText != string.Empty)
            {
                //(Required) Type of billing agreement. For recurring payments,
                //this field must be set to RecurringPayments.
                //In this case, you can specify up to ten billing agreements.
                //Other defined values are not valid.
                //Type of billing agreement for reference transactions.
                //You must have permission from PayPal to use this field.
                //This field must be set to one of the following values:
                //   1. MerchantInitiatedBilling - PayPal creates a billing agreement
                //      for each transaction associated with buyer.You must specify
                //      version 54.0 or higher to use this option.
                //   2. MerchantInitiatedBillingSingleAgreement - PayPal creates a
                //      single billing agreement for all transactions associated with buyer.
                //      Use this value unless you need per-transaction billing agreements.
                //      You must specify version 58.0 or higher to use this option.
                BillingCodeType billingCodeType = (BillingCodeType)
                                                  Enum.Parse(typeof(BillingCodeType), "MERCHANTINITIATEDBILLING");
                BillingAgreementDetailsType baType = new BillingAgreementDetailsType(billingCodeType);
                baType.BillingAgreementDescription = billingAgreementText;
                ecDetails.BillingAgreementDetails.Add(baType);
            }

            //Logo for Website
            // (Optional) URL for the image you want to appear at the top left of the payment page. The image has a maximum size of 750 pixels wide by 90 pixels high. PayPal recommends that you provide an image that is stored on a secure (https) server. If you do not specify an image, the business name displays.
            if (LogoURL != string.Empty)
            {
                ecDetails.cppHeaderImage = LogoURL;
            }

            // (Optional) A label that overrides the business name in the PayPal account on the PayPal hosted checkout pages.
            if (brandName != string.Empty)
            {
                ecDetails.BrandName = brandName;
            }
            request.SetExpressCheckoutRequestDetails = ecDetails;
        }