コード例 #1
0
        private void StartPaypalCheckout(string properties, int paymentProviderId)
        {
            string[] props = properties.Split(',');
            PaypalApi.UseSandbox = (props.Length == 3 || (props.Length > 3 && Convert.ToBoolean(props[3]) == true));


            PaypalUserCredentials cred = new PaypalUserCredentials(props[0], props[1], props[2]);
            PaypalSetExpressCheckoutParameters param = new PaypalSetExpressCheckoutParameters()
            {
                CancelUrl  = Globals.NavigateURL(this.TabId, "", "action=payment", "provider=" + paymentProviderId.ToString(), "result=cancel"),
                ReturnUrl  = Globals.NavigateURL(this.TabId, "", "action=payment", "provider=" + paymentProviderId.ToString(), "result=success"),
                NoShipping = 1,                                                   // PayPal does not display shipping address fields whatsoever.
                AllowNote  = 0,                                                   // The buyer is unable to enter a note to the merchant.
            };

            PaypalPaymentDetails request = new PaypalPaymentDetails();

            CartInfo cart = Controller.GetCart(PortalId, MainControl.CartId);

            request.Amt          = cart.OrderTotal + cart.AdditionalTotal + cart.OrderTax + cart.AdditionalTax;
            request.TaxAmt       = cart.OrderTax + cart.AdditionalTax;
            request.ItemAmt      = cart.OrderTotal + cart.AdditionalTotal;
            request.InvNum       = cart.CartID.ToString();
            request.CurrencyCode = "EUR";

            List <PaypalPaymentDetailsItem> items = new List <PaypalPaymentDetailsItem>();
            PaypalPaymentDetailsItem        item  = new PaypalPaymentDetailsItem();

            item.Amt  = request.ItemAmt;
            item.Name = String.Format(Localization.GetString("PPCart.Text", this.LocalResourceFile), Controller.GetStoreSettings(PortalId)["VendorName"] ?? "BBStore");
            List <CartProductInfo> products = Controller.GetCartProducts(cart.CartID);

            item.Desc = "";
            foreach (CartProductInfo product in products)
            {
                item.Desc += string.Format("{0} {1}\r\n", (product.Quantity % 1 == 0 ? (int)product.Quantity : product.Quantity), product.Name);
            }
            item.TaxAmt = request.TaxAmt;
            items.Add(item);

            string response = PaypalApi.SetExpressCheckout(cred, request, items, param);

            PaypalCommonResponse ppCommon = new PaypalCommonResponse(response);

            if (ppCommon.Ack == PaypalAckType.Success)
            {
                if (PaypalApi.UseSandbox)
                {
                    Response.Redirect("https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + ppCommon.Token);
                }
                else
                {
                    Response.Redirect("https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + ppCommon.Token);
                }
            }
            else
            {
                string message = "";
                foreach (PaypalError error in ppCommon.Errors)
                {
                    message += String.Format("ErrorNo:{0} Message {1}<br/>\r\n", error.ErrorNo, error.LongMessage);
                }
                MainControl.ErrorText += message;
            }
        }
コード例 #2
0
        private static Order PayPalGenerateOrder(int orderNum)
        {
            // putting sample customer details
            var customer = new Customer(
                firstName: "John",
                lastName: "Doe",
                id: "405050606",
                ordersCount: 4,
                email: "*****@*****.**",
                verifiedEmail: true,
                createdAt: new DateTime(2013, 12, 8, 14, 12, 12, DateTimeKind.Local), // make sure to initialize DateTime with the correct timezone
                notes: "No additional info");

            // putting sample billing details
            var billing = new AddressInformation(
                firstName: "Ben",
                lastName: "Rolling",
                address1: "27 5th avenue",
                city: "Manhattan",
                country: "United States",
                countryCode: "US",
                phone: "5554321234",
                address2: "Appartment 5",
                zipCode: "54545",
                province: "New York",
                provinceCode: "NY",
                company: "IBM",
                fullName: "Ben Philip Rolling");

            var shipping = new AddressInformation(
                firstName: "Luke",
                lastName: "Rolling",
                address1: "4 Bermingham street",
                city: "Cherry Hill",
                country: "United States",
                countryCode: "US",
                phone: "55546665",
                provinceCode: "NJ",
                province: "New Jersey");

            var payments = new PaypalPaymentDetails(
                paymentStatus: "Authorized",
                authorizationId: "AFSDF332432SDF45DS5FD",
                payerEmail: "*****@*****.**",
                payerStatus: "Verified",
                payerAddressStatus: "Unverified",
                protectionEligibility: "Partly Eligibile",
                pendingReason: "Review");

            var lines = new[]
            {
                new ShippingLine(price: 22.22, title: "Mail"),
                new ShippingLine(price: 2, title: "Ship", code: "A22F")
            };

            var items = new[]
            {
                new LineItem(title: "Bag", price: 55.44, quantityPurchased: 1, productId: "48484", sku: "1272727"),
                new LineItem(title: "Monster", price: 22.3, quantityPurchased: 3)
            };

            var discountCodes = new[] { new DiscountCode(moneyDiscountSum: 7, code: "1") };

            var order = new Order(
                merchantOrderId: orderNum.ToString(),
                email: "*****@*****.**",
                customer: customer,
                paymentDetails: payments,
                billingAddress: billing,
                shippingAddress: shipping,
                lineItems: items,
                shippingLines: lines,
                gateway: "authorize_net",
                customerBrowserIp: "165.12.1.1",
                currency: "USD",
                totalPrice: 100.60,
                createdAt: DateTime.Now, // make sure to initialize DateTime with the correct timezone
                updatedAt: DateTime.Now, // make sure to initialize DateTime with the correct timezone
                discountCodes: discountCodes);

            return(order);
        }