public PayPalPaymentStatus DoExpressCheckoutPayment(tbl_Orders order, string token, string payerId, string payPalCurrencyCode, string payPalReturnUrl, string payPalCancelUrl, string payPalUser, string payPalPassword, string payPalSignature, string payPalNvpSetExpressUrl, string invoiceID) { string resultToLog; NVPCodec encoder = InitializeEncoder(order); encoder[PayPalConsts.Method] = "DoExpressCheckoutPayment"; encoder[PayPalConsts.Token] = token; encoder[PayPalConsts.PaymentAction] = "Sale"; encoder[PayPalConsts.PayerId] = payerId; encoder[PayPalConsts.CurrencyCode] = payPalCurrencyCode; encoder[PayPalConsts.ReturnUrl] = payPalReturnUrl; encoder[PayPalConsts.CancelUrl] = payPalCancelUrl; encoder[PayPalConsts.User] = payPalUser; encoder[PayPalConsts.Pwd] = payPalPassword; encoder[PayPalConsts.Signature] = payPalSignature; encoder[PayPalConsts.InvoiceID] = invoiceID; string encoded = encoder.Encode(); string result = resultToLog = HttpPost(payPalNvpSetExpressUrl, encoded, 30000); NVPCodec decoder = new NVPCodec(); decoder.Decode(result); PayPalPaymentStatus payPalStatus = new PayPalPaymentStatus(); payPalStatus.TransactionID = decoder[PayPalConsts.TransactionID]; payPalStatus.Token = decoder[PayPalConsts.Token]; payPalStatus.ACK = decoder[PayPalConsts.ACK]; payPalStatus.PaymentStatus = decoder[PayPalConsts.PaymentStatus]; payPalStatus.PendingReason = decoder[PayPalConsts.PendingReason]; payPalStatus.ErrorCode = decoder[PayPalConsts.ErrorCode]; payPalStatus.ErrorMessage = decoder[PayPalConsts.ErrorMessage]; if (payPalStatus.ACK.ToLower() != "success") { ECommerceService.UpdateOrderPaymentStatus(order.OrderID, BL.PaymentStatus.PayPal_DoExpressCheckout_Failure); resultToLog = Server.UrlDecode(resultToLog).Replace("&", Environment.NewLine); Log.Error(String.Format("PayPal payment - DoExpressCheckoutPayment failed: {0}", resultToLog)); } return payPalStatus; }
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; }