Example #1
0
        public IPaymentResponse DoExpressCheckoutPayment(OrderDetails orderDetails, string payPalToken, string payPalPayerId)
        {
            if (orderDetails == null) throw new ArgumentNullException("orderDetails");
            if (string.IsNullOrWhiteSpace(payPalToken)) throw new ArgumentNullException("payPalToken");
            if (string.IsNullOrWhiteSpace(payPalPayerId)) throw new ArgumentNullException("payPalPayerId");

            var request = _requestBuilder.DoExpressCheckoutPayment(orderDetails, payPalToken, payPalPayerId);
            return doExpressCheckoutPaymentFor(request);
        }
Example #2
0
        public NameValueCollection SetExpressCheckout(OrderDetails orderDetails, string cancelUrl, string confirmationUrl)
        {
            var request = getBaseSetExpressCheckoutRequest(orderDetails.OrderTotal, orderDetails.CurrencyCodeType, cancelUrl, confirmationUrl);
            addOrderDetailsValues(orderDetails, request);

            // SetExpressCheckout specific
            addOptionalValueToRequest("ALLOWNOTE", orderDetails.AllowNote, request);
            addOptionalValueToRequest("BUYEREMAILOPTINENABLE", orderDetails.EnableCustomerMarketingEmailOptIn, request);

            return request;
        }
Example #3
0
        void addOrderDetailsValues(OrderDetails orderDetails, NameValueCollection request)
        {
            addOptionalValueToRequest("NOSHIPPING", (int)orderDetails.DisplayShippingAddress, request);
            addOptionalValueToRequest("PAYMENTREQUEST_0_TAXAMT", orderDetails.TaxTotal, request);
            addOptionalValueToRequest("PAYMENTREQUEST_0_SHIPPINGAMT", orderDetails.ShippingTotal, request);
            addOptionalValueToRequest("PAYMENTREQUEST_0_SHIPDISCAMT", orderDetails.ShippingDiscount, request);
            addOptionalValueToRequest("PAYMENTREQUEST_0_CUSTOM", orderDetails.CustomField, request);
            addOptionalValueToRequest("PAYMENTREQUEST_0_DESC", orderDetails.OrderDescription, request);

            var lineNumber = 0;
            var itemTotal = 0m;
            var recurringNumber = 0;
            if (orderDetails.Items != null)
            {
                foreach (var line in orderDetails.Items)
                {
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_NAME" + lineNumber, line.Name, request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_NUMBER" + lineNumber, line.Number, request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_DESC" + lineNumber, line.Description, request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_AMT" + lineNumber, line.UnitPrice, request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_TAXAMT" + lineNumber, line.Tax, request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_QTY" + lineNumber, line.Quantity, request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_ITEMURL" + lineNumber, line.ItemUrl, request);

                    if (line.IsRecurringPayment)
                    {
                        addOptionalValueToRequest("L_BILLINGTYPE" + recurringNumber, "RecurringPayments", request);
                        addOptionalValueToRequest("L_BILLINGAGREEMENTDESCRIPTION" + recurringNumber, line.Description, request);
                        recurringNumber++;
                    }

                    itemTotal += (line.UnitPrice ?? 0) * (line.Quantity ?? 1);
                    lineNumber++;
                }
            }
            if (orderDetails.Discounts != null)
            {
                foreach (var line in orderDetails.Discounts)
                {
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_NAME" + lineNumber, line.Description, request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_AMT" + lineNumber, line.Amount.AsNegativeValue(), request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_TAXAMT" + lineNumber, line.Tax.AsNegativeValue(), request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_QTY" + lineNumber, line.Quantity, request);

                    itemTotal += line.Amount.AsNegativeValue() * (line.Quantity ?? 1);
                    lineNumber++;
                }
            }

            if (itemTotal > 0)
                addOptionalValueToRequest("PAYMENTREQUEST_0_ITEMAMT", itemTotal, request);
        }
Example #4
0
        public NameValueCollection SetExpressCheckout(OrderDetails orderDetails, string cancelUrl, string confirmationUrl, NameValueCollection optionalFields)
        {
            var request = SetExpressCheckout(orderDetails, cancelUrl, confirmationUrl);

            foreach(string key in optionalFields)
            {
                //Make sure we're not overwriting a field that's already been set
                if(request[key] == null)
                    addOptionalValueToRequest(key, optionalFields[key], request);
            }

            return request;
        }
Example #5
0
        public NameValueCollection DoExpressCheckoutPayment(OrderDetails orderDetails, string payPalToken, string payPalPayerId)
        {
            var request = getQueryWithCredentials();

            request["METHOD"] = "DoExpressCheckoutPayment";
            request["TOKEN"] = payPalToken;
            request["PAYERID"] = payPalPayerId;
            request["PAYMENTREQUEST_0_AMT"] = orderDetails.OrderTotal.AsPayPalFormatString();
            request["PAYMENTREQUEST_0_CURRENCYCODE"] = "GBP";
            request["PAYMENTREQUEST_0_PAYMENTACTION"] = "Sale";

            addOrderDetailsValues(orderDetails, request);

            return request;
        }
Example #6
0
        public PayPalExpressCheckoutToken SetExpressCheckout(OrderDetails orderDetails, string cancelUrl, string confirmationUrl)
        {
            if (orderDetails == null) throw new ArgumentNullException("orderDetails");
            if (string.IsNullOrWhiteSpace(cancelUrl)) throw new ArgumentNullException("cancelUrl");
            if (string.IsNullOrWhiteSpace(confirmationUrl)) throw new ArgumentNullException("confirmationUrl");

            _logger.Log("SetExpressCheckout.Request", orderDetails);

            var request = _requestBuilder.SetExpressCheckout(orderDetails, cancelUrl, confirmationUrl);
            return setExpressCheckoutRequestFor(request);
        }
Example #7
0
        OrderDetails parseOrderDetails(NameValueCollection payPalResponse)
        {
            var orderDetails = new OrderDetails
            {
                OrderTotal = decimal.Parse(payPalResponse["PAYMENTREQUEST_0_AMT"]),
                TaxTotal = parseOptionalDecimalValueFromResponse("PAYMENTREQUEST_0_TAXAMT", payPalResponse),
                ShippingTotal = parseOptionalDecimalValueFromResponse("PAYMENTREQUEST_0_SHIPPINGAMT", payPalResponse),
                ShippingDiscount = parseOptionalDecimalValueFromResponse("PAYMENTREQUEST_0_SHIPDISCAMT", payPalResponse),
                AllowNote = parseOptionalBooleanValueFromResponse("ALLOWNOTE", payPalResponse),
                OrderDescription = parseOptionalStringValueFromResponse("PAYMENTREQUEST_0_DESC", payPalResponse),
                CustomField = payPalResponse["PAYMENTREQUEST_0_CUSTOM"]
            };

            var orderDetailsItems = new Dictionary<int, OrderDetailsItem>();
            var discountDetailses = new Dictionary<int, DiscountDetails>();

            foreach (var key in payPalResponse.AllKeys.Where(x => x.StartsWith("L_PAYMENTREQUEST_0_AMT")).OrderBy(x => x))
            {
                var itemNumber = int.Parse(key.Substring("L_PAYMENTREQUEST_0_AMT".Length));
                var amount = decimal.Parse(payPalResponse[key]);
                var isDiscount = amount < 0;

                if (isDiscount)
                    discountDetailses.Add(itemNumber, new DiscountDetails { Amount = amount });
                else
                    orderDetailsItems.Add(itemNumber, new OrderDetailsItem { UnitPrice = amount });
            }

            parseLineNumbers(payPalResponse, orderDetailsItems);
            parseLineDescritions(payPalResponse, orderDetailsItems);
            parseLineItemUrls(payPalResponse, orderDetailsItems);
            parseLineNames(payPalResponse, orderDetailsItems, discountDetailses);
            parseLineQuantities(payPalResponse, orderDetailsItems, discountDetailses);
            parseLineTaxAmounts(payPalResponse, orderDetailsItems, discountDetailses);

            if (orderDetailsItems.Values.Any())
                orderDetails.Items = orderDetailsItems.Values;
            if (discountDetailses.Values.Any())
                orderDetails.Discounts = discountDetailses.Values;

            return orderDetails;
        }
Example #8
0
        void addOrderDetailsValues(OrderDetails orderDetails, NameValueCollection request)
        {
            addOptionalValueToRequest("PAYMENTREQUEST_0_TAXAMT", orderDetails.TaxTotal, request);
            addOptionalValueToRequest("PAYMENTREQUEST_0_SHIPPINGAMT", orderDetails.ShippingTotal, request);
            addOptionalValueToRequest("PAYMENTREQUEST_0_SHIPDISCAMT", orderDetails.ShippingDiscount, request);
            addOptionalValueToRequest("PAYMENTREQUEST_0_CUSTOM", orderDetails.CustomField, request);
            addOptionalValueToRequest("PAYMENTREQUEST_0_DESC", orderDetails.OrderDescription, request);

            addOptionalValueToRequest("REQCONFIRMSHIPPING", orderDetails.ReqConfirmShipping, request);

            // Add payer information
            addOptionalValueToRequest("NOSHIPPING", (int?)orderDetails.NoShipping, request);
            addOptionalValueToRequest("PAYMENTREQUEST_0_SHIPTONAME", orderDetails.ShipToName, request);
            addOptionalValueToRequest("PAYMENTREQUEST_0_SHIPTOSTREET", orderDetails.ShipToStreet, request);
            addOptionalValueToRequest("PAYMENTREQUEST_0_SHIPTOCITY", orderDetails.ShipToCity, request);
            addOptionalValueToRequest("PAYMENTREQUEST_0_SHIPTOSTATE", orderDetails.ShipToState, request);
            addOptionalValueToRequest("PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE", orderDetails.ShipToCountryCode, request);
            addOptionalValueToRequest("PAYMENTREQUEST_0_SHIPTOZIP", orderDetails.ShipToZip, request);
            // This one isn't documented in all places
            addOptionalValueToRequest("PAYMENTREQUEST_0_EMAIL", orderDetails.Email, request);
            addOptionalValueToRequest("PAYMENTREQUEST_0_SHIPTOPHONENUM", orderDetails.ShipToPhoneNum, request);

            // These are supposed to be deprecated in favor of the above, but my sandbox was ignoring the above
            addOptionalValueToRequest("NO_SHIPPING", (int?)orderDetails.NoShipping, request);
            addOptionalValueToRequest("SHIPTONAME", orderDetails.ShipToName, request);
            addOptionalValueToRequest("SHIPTOSTREET", orderDetails.ShipToStreet, request);
            addOptionalValueToRequest("SHIPTOCITY", orderDetails.ShipToCity, request);
            addOptionalValueToRequest("SHIPTOSTATE", orderDetails.ShipToState, request);
            addOptionalValueToRequest("SHIPTOCOUNTRYCODE", orderDetails.ShipToCountryCode, request);
            addOptionalValueToRequest("SHIPTOZIP", orderDetails.ShipToZip, request);
            // This one isn't documented
            addOptionalValueToRequest("EMAIL", orderDetails.Email, request);
            addOptionalValueToRequest("SHIPTOPHONENUM", orderDetails.ShipToPhoneNum, request);

            var lineNumber = 0;
            var itemTotal = 0m;
            if (orderDetails.Items != null)
            {
                foreach (var line in orderDetails.Items)
                {
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_NAME" + lineNumber, line.Name, request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_NUMBER" + lineNumber, line.Number, request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_DESC" + lineNumber, line.Description, request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_AMT" + lineNumber, line.UnitPrice, request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_TAXAMT" + lineNumber, line.Tax, request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_QTY" + lineNumber, line.Quantity, request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_ITEMURL" + lineNumber, line.ItemUrl, request);

                    itemTotal += (line.UnitPrice ?? 0)*(line.Quantity ?? 1);
                    lineNumber++;
                }
            }
            if (orderDetails.Discounts != null)
            {
                foreach (var line in orderDetails.Discounts)
                {
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_NAME" + lineNumber, line.Description, request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_AMT" + lineNumber, line.Amount.AsNegativeValue(), request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_TAXAMT" + lineNumber, line.Tax.AsNegativeValue(), request);
                    addOptionalValueToRequest("L_PAYMENTREQUEST_0_QTY" + lineNumber, line.Quantity, request);

                    itemTotal += line.Amount.AsNegativeValue()*(line.Quantity ?? 1);
                    lineNumber++;
                }
            }

            if (itemTotal > 0)
                addOptionalValueToRequest("PAYMENTREQUEST_0_ITEMAMT", itemTotal, request);
        }
Example #9
0
        public NameValueCollection SetExpressCheckout(Address shipToAddress,OrderDetails orderDetails, string cancelUrl, string confirmationUrl)
        {
            var request = SetExpressCheckout(orderDetails,cancelUrl,confirmationUrl);
            addAddressValues(shipToAddress, request);

            return request;
        }