Beispiel #1
0
        private string SetExpressCheckout(tbl_Orders order, string payPalReturnUrl, string payPalCancelUrl, string payPalUser, string payPalPassword, string payPalSignature, string payPalCurrencyCode, string payPalNvpSetExpressUrl, string payPalHost, string invoiceID, string languageCode)
        {
            string resultToLog;

            NVPCodec encoder = InitializeEncoder(order);

            encoder[PayPalConsts.Method]       = "SetExpressCheckout";
            encoder[PayPalConsts.NoShipping]   = "1";
            encoder[PayPalConsts.ReturnUrl]    = payPalReturnUrl;
            encoder[PayPalConsts.CancelUrl]    = payPalCancelUrl;
            encoder[PayPalConsts.User]         = payPalUser;
            encoder[PayPalConsts.Pwd]          = payPalPassword;
            encoder[PayPalConsts.Signature]    = payPalSignature;
            encoder[PayPalConsts.CurrencyCode] = payPalCurrencyCode;
            encoder[PayPalConsts.InvoiceID]    = invoiceID;

            if (!string.IsNullOrEmpty(languageCode))
            {
                encoder[PayPalConsts.LocaleCode] = languageCode;
            }

            string settings = encoder.GetSettings();

            Log.Info(settings);

            string encoded = encoder.Encode();
            string result  = resultToLog = HttpPost(payPalNvpSetExpressUrl, encoded, 30000);

            NVPCodec decoder = new NVPCodec();

            decoder.Decode(result);

            string token = decoder[PayPalConsts.Token];

            if (decoder[PayPalConsts.ACK].ToLower() == "success" || decoder[PayPalConsts.ACK].ToLower() == "successwithwarning")
            {
                ECommerceService.UpdateOrderPaymentStatus(order.OrderID, BL.PaymentStatus.PayPal_SetExpressCheckout_Success);
                ECommerceService.UpdateOrderSecurityKey(token, order.OrderID);
                return(String.Format("{0}?cmd=_express-checkout&{1}={2}&{3}={4}", payPalHost, PayPalConsts.Token.ToLower(), token, PayPalConsts.Useraction, PayPalConsts.Commit));
            }
            else
            {
                ECommerceService.UpdateOrderPaymentStatus(order.OrderID, BL.PaymentStatus.PayPal_SetExpressCheckout_Failure);
                resultToLog = Server.UrlDecode(resultToLog).Replace("&", Environment.NewLine);
                Log.Error(String.Format("PayPal payment - SetExpressCheckout failed: {0}", resultToLog));
            }

            return(String.Empty);
        }