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); }
public ActionResult LandingPage() { NameValueCollection variables = Request.QueryString; string token = HttpUtility.UrlEncode(variables[PayPalConsts.Token]); string payerID = HttpUtility.UrlEncode(variables[PayPalConsts.PayerId]); tbl_Orders order = string.IsNullOrEmpty(token) ? null : ECommerceService.GetOrderBySecurityKey(token, DomainID); if (order != null) { ECommerceService.UpdateOrderPaymentStatus(order.OrderID, BL.PaymentStatus.PayPal_LandingPage); } string paymentMessage = string.Empty; string actionName = "PaymentError"; string orderID = (order != null) ? order.OrderID.ToString() : "[unknown]"; if (string.IsNullOrEmpty(payerID)) { paymentMessage = String.Format("PayPal payment canceled for order {0}", orderID); Log.Info(paymentMessage); if (order != null) { ECommerceService.UpdateOrderPaymentStatus(order.OrderID, BL.PaymentStatus.PayPal_LandingPage_PayerUnknown); } return(RedirectToRoute("Website", new { action = "OrderSummary" })); } else { string currencyCode = DomainService.GetSettingsValue(BL.SettingsKey.payPalCurrencyCode, this.DomainID); PayPalPaymentStatus status = DoExpressCheckoutPayment( order, token, payerID, currencyCode, PayPalLandingPageUrl, PayPalLandingPageUrl, DomainService.GetSettingsValue(BL.SettingsKey.payPalUsername, this.DomainID), DomainService.GetSettingsValue(BL.SettingsKey.payPalPassword, this.DomainID), DomainService.GetSettingsValue(BL.SettingsKey.payPalSignature, this.DomainID), PayPalApiUrlNvp, order.OrderID.ToString()); switch (status.ACK.ToUpper()) { case "SUCCESS": case "SUCCESSWITHWARNING": { paymentMessage = String.Format("PayPal payment success, pending status [{0}] ", status.PaymentStatus); Log.Info(paymentMessage); if (order != null) { ECommerceService.UpdateOrderPaymentStatus(order.OrderID, BL.PaymentStatus.Paid, currencyCode); } actionName = "ThankYou"; } break; case "FAILURE": case "FAILUREWITHWARNING": case "WARNING": { paymentMessage = String.Format("PayPal payment failed [{0}] ", status.ErrorMessage); Log.Fatal(paymentMessage); ECommerceService.UpdateOrderPaymentStatus(order.OrderID, BL.PaymentStatus.PayPal_DoExpressCheckout_Failure, currencyCode); } break; default: { paymentMessage = String.Format("PayPal first step unknown result [{0}] ", status.ACK + ": " + status.ErrorMessage); Log.Fatal(paymentMessage); ECommerceService.UpdateOrderPaymentStatus(order.OrderID, BL.PaymentStatus.PayPal_DoExpressCheckout_Unknown, currencyCode); } break; } } return(RedirectToRoute("Website", new { action = actionName, orderID = orderID })); }
public void Cancelled() { this.Status = PayPalPaymentStatus.Cancelled; }
public void Completed(string payerId) { this.PayPalPayerId = payerId; this.Status = PayPalPaymentStatus.Completed; }
public void AddError(PayPalError error) { this.Errors.Add(error); this.Status = PayPalPaymentStatus.Error; }