public bool Void(Transaction t, HotcakesApplication app) { try { var ppAPI = PaypalExpressUtilities.GetPaypalAPI(app.CurrentStore); if (t.PreviousTransactionNumber != null) { var voidResponse = ppAPI.DoVoid(t.PreviousTransactionNumber, "Transaction Voided"); if (voidResponse.Ack == AckCodeType.Success || voidResponse.Ack == AckCodeType.SuccessWithWarning) { t.Result.Succeeded = true; t.Result.Messages.Add(new Message("PayPal Express Payment Voided Successfully.", "OK", MessageType.Information)); return(true); } t.Result.Succeeded = false; t.Result.Messages.Add(new Message("Paypal Express Payment Void Failed.", string.Empty, MessageType.Error)); foreach (var ppError in voidResponse.Errors) { t.Result.Messages.Add(new Message(ppError.LongMessage, ppError.ErrorCode, MessageType.Error)); } return(false); } } catch (Exception ex) { HandleException(t, ex); } return(false); }
public bool Charge(Transaction t, HotcakesApplication app) { try { var ppAPI = PaypalExpressUtilities.GetPaypalAPI(app.CurrentStore); var OrderNumber = t.MerchantInvoiceNumber + Guid.NewGuid(); DoExpressCheckoutPaymentResponseType paymentResponse; //there was no authorization so we just need to do a direct sale paymentResponse = ppAPI.DoExpressCheckoutPayment(t.PreviousTransactionNumber, t.PreviousTransactionAuthCode, t.Amount.ToString("N", CultureInfo.InvariantCulture), PaymentActionCodeType.Sale, PayPalAPI.GetCurrencyCodeType(app.CurrentStore.Settings.PayPal.Currency), OrderNumber); if (paymentResponse.Ack == AckCodeType.Success || paymentResponse.Ack == AckCodeType.SuccessWithWarning) { var paymentInfo = paymentResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0]; t.Result.ReferenceNumber = paymentInfo.TransactionID; if (paymentInfo.PaymentStatus == PaymentStatusCodeType.Completed) { t.Result.Succeeded = true; t.Result.Messages.Add(new Message("PayPal Express Payment Charged Successfully.", "OK", MessageType.Information)); return(true); } if (paymentInfo.PaymentStatus == PaymentStatusCodeType.Pending) { t.Result.Succeeded = true; t.Result.ResponseCode = "PENDING"; t.Result.ResponseCodeDescription = "PayPal Express Payment PENDING"; t.Result.Messages.Add(new Message("Paypal Express Payment PENDING.", "OK", MessageType.Information)); return(true); } t.Result.Succeeded = false; t.Result.Messages.Add(new Message("An error occurred while trying to charge your PayPal payment.", string.Empty, MessageType.Error)); return(false); } t.Result.Succeeded = false; t.Result.Messages.Add(new Message("Paypal Express Payment Charge Failed.", string.Empty, MessageType.Error)); foreach (var ppError in paymentResponse.Errors) { t.Result.Messages.Add(new Message(ppError.LongMessage, ppError.ErrorCode, MessageType.Error)); } return(false); } catch (Exception ex) { HandleException(t, ex); } return(false); }
private void DisplayPaypalExpressMode(CheckoutViewModel model) { model.PayPalToken = Request.QueryString["token"] ?? string.Empty; model.PayPalPayerId = Request.QueryString["payerId"] ?? string.Empty; if (string.IsNullOrEmpty(model.PayPalToken)) { Redirect(Url.RouteHccUrl(HccRoute.Cart)); } var ppAPI = PaypalExpressUtilities.GetPaypalAPI(HccApp.CurrentStore); var failed = false; GetExpressCheckoutDetailsResponseType ppResponse = null; try { if (!GetExpressCheckoutDetails(ppAPI, ref ppResponse, model)) { failed = true; EventLog.LogEvent("Paypal Express Checkout", "GetExpressCheckoutDetails call failed. Detailed Errors will follow. ", EventLogSeverity.Error); foreach (var ppError in ppResponse.Errors) { EventLog.LogEvent("Paypal error number: " + ppError.ErrorCode, "Paypal Error: '" + ppError.ShortMessage + "' Message: '" + ppError.LongMessage + "' " + " Values passed to GetExpressCheckoutDetails: Token: " + model.PayPalToken, EventLogSeverity.Error); } FlashFailure(Localization.GetString("ErrorOccured")); ViewBag.HideCheckout = true; } } finally { var o = model.CurrentOrder; o.CustomProperties.Add("hcc", "PayerID", Request.QueryString["PayerID"]); if (!failed) { if (ppResponse != null && ppResponse.GetExpressCheckoutDetailsResponseDetails != null && ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo != null) { o.UserEmail = ppResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Payer; if (string.IsNullOrEmpty(o.ShippingAddress.Phone)) { o.ShippingAddress.Phone = ppResponse.GetExpressCheckoutDetailsResponseDetails.ContactPhone ?? string.Empty; } } } HccApp.OrderServices.Orders.Update(o); } }
public bool Authorize(Transaction t, HotcakesApplication app) { try { var ppAPI = PaypalExpressUtilities.GetPaypalAPI(app.CurrentStore); if (t.PreviousTransactionNumber != null) { var OrderNumber = t.MerchantInvoiceNumber + Guid.NewGuid(); PaymentActionCodeType mode = PaymentActionCodeType.Authorization; if (!app.CurrentStore.Settings.PayPal.ExpressAuthorizeOnly) { mode = PaymentActionCodeType.Sale; } var paymentResponse = ppAPI.DoExpressCheckoutPayment(t.PreviousTransactionNumber, t.PreviousTransactionAuthCode, t.Amount.ToString("N", CultureInfo.InvariantCulture), mode, PayPalAPI.GetCurrencyCodeType(app.CurrentStore.Settings.PayPal.Currency), OrderNumber); if (paymentResponse.Ack == AckCodeType.Success || paymentResponse.Ack == AckCodeType.SuccessWithWarning) { var paymentInfo = paymentResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0]; t.Result.Succeeded = true; t.Result.ReferenceNumber = paymentInfo.TransactionID; t.Result.ResponseCode = "OK"; t.Result.ResponseCodeDescription = "PayPal Express Payment Authorized Successfully."; return(true); } t.Result.Succeeded = false; t.Result.Messages.Add(new Message("PayPal Express Payment Authorization Failed.", string.Empty, MessageType.Error)); foreach (var ppError in paymentResponse.Errors) { t.Result.Messages.Add(new Message(ppError.LongMessage, ppError.ErrorCode, MessageType.Error)); } return(false); } } catch (Exception ex) { HandleException(t, ex); } return(false); }
public bool Refund(Transaction t, HotcakesApplication app) { try { var ppAPI = PaypalExpressUtilities.GetPaypalAPI(app.CurrentStore); if (t.PreviousTransactionNumber != null) { var refundType = string.Empty; //per paypal's request, the refund type should always be set to partial refundType = "Partial"; var refundResponse = ppAPI.RefundTransaction( t.PreviousTransactionNumber, refundType, t.Amount.ToString("N", CultureInfo.InvariantCulture), PayPalAPI.GetCurrencyCodeType(app.CurrentStore.Settings.PayPal.Currency)); if (refundResponse.Ack == AckCodeType.Success || refundResponse.Ack == AckCodeType.SuccessWithWarning) { t.Result.Succeeded = true; t.Result.Messages.Add(new Message("PayPal Express Payment Refunded Successfully.", "OK", MessageType.Information)); return(true); } t.Result.Succeeded = false; t.Result.Messages.Add(new Message("Paypal Express Payment Refund Failed.", string.Empty, MessageType.Error)); foreach (var ppError in refundResponse.Errors) { t.Result.Messages.Add(new Message(ppError.LongMessage, ppError.ErrorCode, MessageType.Error)); } return(false); } } catch (Exception ex) { HandleException(t, ex); } return(false); }
public bool Capture(Transaction t, HotcakesApplication app) { try { var ppAPI = PaypalExpressUtilities.GetPaypalAPI(app.CurrentStore); var OrderNumber = t.MerchantInvoiceNumber + Guid.NewGuid(); var captureResponse = ppAPI.DoCapture(t.PreviousTransactionNumber, "Thank you for your payment.", t.Amount.ToString("N", CultureInfo.InvariantCulture), PayPalAPI.GetCurrencyCodeType(app.CurrentStore.Settings.PayPal.Currency), OrderNumber); if (captureResponse.Ack == AckCodeType.Success || captureResponse.Ack == AckCodeType.SuccessWithWarning) { t.Result.ReferenceNumber = captureResponse.DoCaptureResponseDetails.PaymentInfo.TransactionID; if (captureResponse.DoCaptureResponseDetails.PaymentInfo.PaymentStatus == PaymentStatusCodeType.Pending) { t.Result.Succeeded = true; t.Result.ResponseCode = "PENDING"; t.Result.ResponseCodeDescription = "PayPal Express Payment PENDING"; t.Result.Messages.Add(new Message("Paypal Express Payment PENDING.", "OK", MessageType.Information)); return(true); } if (captureResponse.DoCaptureResponseDetails.PaymentInfo.PaymentStatus == PaymentStatusCodeType.InProgress) { t.Result.Succeeded = true; t.Result.ResponseCode = "PENDING"; t.Result.ResponseCodeDescription = "PayPal Express Payment IN PROGRESS"; t.Result.Messages.Add(new Message("Paypal Express Payment PENDING. In Progress.", "OK", MessageType.Information)); return(true); } if (captureResponse.DoCaptureResponseDetails.PaymentInfo.PaymentStatus == PaymentStatusCodeType.None) { t.Result.Succeeded = true; t.Result.ResponseCode = "PENDING"; t.Result.ResponseCodeDescription = "PayPal Express Payment: No Status Yet"; t.Result.Messages.Add(new Message("Paypal Express Payment PENDING. No Status Yet.", "OK", MessageType.Information)); return(true); } if (captureResponse.DoCaptureResponseDetails.PaymentInfo.PaymentStatus == PaymentStatusCodeType.Processed) { t.Result.Succeeded = true; t.Result.ResponseCode = "PENDING"; t.Result.ResponseCodeDescription = "PayPal Express Payment PENDING"; t.Result.Messages.Add(new Message("Paypal Express Payment PENDING.", "OK", MessageType.Information)); return(true); } if (captureResponse.DoCaptureResponseDetails.PaymentInfo.PaymentStatus == PaymentStatusCodeType.Completed) { t.Result.Succeeded = true; t.Result.Messages.Add(new Message("PayPal Express Payment Captured Successfully.", "OK", MessageType.Information)); return(true); } t.Result.Succeeded = false; t.Result.Messages.Add(new Message("An error occurred while trying to capture your PayPal payment.", string.Empty, MessageType.Error)); return(false); } t.Result.Succeeded = false; t.Result.Messages.Add(new Message("Paypal Express Payment Charge Failed.", string.Empty, MessageType.Error)); foreach (var ppError in captureResponse.Errors) { t.Result.Messages.Add(new Message(ppError.LongMessage, ppError.ErrorCode, MessageType.Error)); } return(false); } catch (Exception ex) { HandleException(t, ex); } return(false); }