コード例 #1
0
        public HttpResponseMessage Get(string cardData)
        {
            CardInput     cartInput     = JsonConvert.DeserializeObject <CardInput>(cardData);
            PayPalRequest payPalRequest = new PayPalRequest(cartInput);

            try
            {
                RequestFlow flow = payPalRequest.GetFlow();
                return(Request.CreateResponse(HttpStatusCode.OK, flow));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, "Fail"));
            }
        }
コード例 #2
0
        public static Token GetToken(PayPalConfig cnf, List <Item> items, bool isSandbox = false)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(!isSandbox ? "https://api-3t.paypal.com/nvp?" : "https://api-3t.sandbox.paypal.com/nvp?");
            PayPalRequest request = new PayPalRequest
            {
                METHOD    = "SetExpressCheckout",
                VERSION   = !isSandbox ? "109.0" : "104.0",
                USER      = cnf.User,
                PWD       = cnf.Password,
                SIGNATURE = cnf.Signature,
                Items     = new Dictionary <string, object>()
            };
            int num = 0;

            foreach (Item item in items)
            {
                request.Items.Add("L_PAYMENTREQUEST_0_NAME" + num, item.Name);
                request.Items.Add("L_PAYMENTREQUEST_0_NUMBER" + num, num);
                request.Items.Add("L_PAYMENTREQUEST_0_QTY" + num, item.Quantity);
                request.Items.Add("L_PAYMENTREQUEST_0_AMT" + num, item.TotalAmount);
                num++;
            }
            request.PAYMENTREQUEST_0_AMT          = items.Sum <Item>(x => x.TotalAmount);
            request.PAYMENTREQUEST_0_CURRENCYCODE = "USD";
            request.RETURNURL = cnf.ReturnUrl + "?guid=" + cnf.guid;
            request.CANCELURL = cnf.CancelUrl + "?guid=" + cnf.guid;
            request.PAYMENTREQUEST_0_PAYMENTACTION = "Sale";
            request.SOLUTIONTYPE = "Sole";
            request.LANDINGPAGE  = "Billing";
            request.BRANDNAME    = cnf.CompanyName;
            builder.Append(QuerystringSerializer.Serialize(request));
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            WebResponse  response = WebRequest.Create(builder.ToString()).GetResponse();
            StreamReader reader1  = new StreamReader(response.GetResponseStream());
            string       s        = reader1.ReadToEnd();

            reader1.Close();
            response.Close();
            return(QuerystringSerializer.Deserialize <Token>(HttpContext.Current.Server.UrlDecode(s), "", false));
        }
コード例 #3
0
        public async Task<PaymentMethodNonce> AuthorizePaypalPaymentAsync(bool requestBillingAgreement, string[] additionalParameters = null, PayPalRequest request = null)
        {
            var actionListener = new PaymentMethodNonceListener();
            try
            {
                AddListener(actionListener);

                PayPal.AuthorizeAccount(this, additionalParameters);

                if (requestBillingAgreement)
                {
                    PayPal.RequestBillingAgreement(this, request??new PayPalRequest());
                }

                return await actionListener.Task();
            }
            finally
            {
                RemoveListener(actionListener);
            }
        }
コード例 #4
0
        public async Task <PaymentMethodNonce> AuthorizePaypalPaymentAsync(bool requestBillingAgreement, string[] additionalParameters = null, PayPalRequest request = null)
        {
            var actionListener = new PaymentMethodNonceListener();

            try
            {
                AddListener(actionListener);

                PayPal.AuthorizeAccount(this, additionalParameters);

                if (requestBillingAgreement)
                {
                    PayPal.RequestBillingAgreement(this, request ?? new PayPalRequest());
                }

                return(await actionListener.Task());
            }
            finally
            {
                RemoveListener(actionListener);
            }
        }