Skip to content

Commit

Permalink
Merge pull request #3 from jldelatorre/Issue/ReplacePayPal
Browse files Browse the repository at this point in the history
Created new class for PayPal constants
  • Loading branch information
jldelatorre authored Nov 1, 2022
2 parents 092e7f1 + c2b085b commit 1f582c4
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ public override bool ProcessCheckout(OrderTaskContext context)
EventLog.LogEvent("PayPal Express Checkout", "CartCancelUrl=" + cartCancelUrl, EventLogSeverity.Information);
EventLog.LogEvent("PayPal Express Checkout", "CartReturnUrl=" + cartReturnUrl, EventLogSeverity.Information);

string mode = Constants.PAYMENT_MODE_AUTHORIZE;
string mode = PayPalConstants.PAYMENT_MODE_AUTHORIZE;
if (!context.HccApp.CurrentStore.Settings.PayPal.ExpressAuthorizeOnly)
{
mode = Constants.PAYMENT_MODE_CAPTURE;
mode = PayPalConstants.PAYMENT_MODE_CAPTURE;
}

// Accelerated boarding
if (string.IsNullOrWhiteSpace(context.HccApp.CurrentStore.Settings.PayPal.UserName))
{
mode = Constants.PAYMENT_MODE_CAPTURE;
mode = PayPalConstants.PAYMENT_MODE_CAPTURE;
}

var solutionType = context.HccApp.CurrentStore.Settings.PayPal.RequirePayPalAccount ? SolutionTypeType.Mark : SolutionTypeType.Sole;
Expand Down Expand Up @@ -209,11 +209,11 @@ public override bool ProcessCheckout(OrderTaskContext context)
string urlTemplate;
if (string.Compare(context.HccApp.CurrentStore.Settings.PayPal.Mode, "Live", true) == 0)
{
urlTemplate = Constants.LIVE_URL;
urlTemplate = PayPalConstants.LIVE_URL;
}
else
{
urlTemplate = Constants.SANDBOX_URL;
urlTemplate = PayPalConstants.SANDBOX_URL;
}
HttpContextBase httpContext = new HccHttpContextWrapper(HttpContext.Current);
httpContext.Response.Redirect(string.Format(urlTemplate, expressResponse.Result<Order>().Id), true);
Expand Down
36 changes: 0 additions & 36 deletions Libraries/Hotcakes.Commerce/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,41 +164,5 @@ public class Constants
public const string TAG_IOGPRICECURRENCY = "<meta property=\"og:price:currency\" content=\"{0}\" />";
#endregion

#region PayPal
//Payments Status
public const string PAYMENT_STATUS_COMPLETED = "COMPLETED";
public const string PAYMENT_STATUS_COMPLETED_DESCRIPTION = "PayPal Express Payment Captured Successfully";
public const string PAYMENT_STATUS_Pending = "PENDING";
public const string PAYMENT_STATUS_Pending_DESCRIPTION = "PayPal Express Payment PENDING";
public const string PAYMENT_STATUS_DENIED = "DENIED";
public const string PAYMENT_STATUS_DENIED_DESCRIPTION = "PayPal Express Payment DENIED";
public const string PAYMENT_STATUS_ERROR_DESCRIPTION =
"An error occurred while trying to capture your PayPal payment.";
public const string PAYMENT_CHARGE_ERROR = "An error occurred while trying to charge your PayPal payment.";
public const string PAYMENT_ERROR = "Paypal Express Payment Charge Failed.";

//Payment Authorize
public const string PAYMENT_AUTHORIZE_SUCCESS = "PayPal Express Payment Authorized Successfully.";
public const string PAYMENT_AUTHORIZE_FAILED = "PayPal Express Payment Authorization Failed.";


//Payment Refund
public const string PAYMENT_REFUND_SUCCESS = "PayPal Express Payment Refunded Successfully.";
public const string PAYMENT_REFUND_FAILED = "Paypal Express Payment Refund Failed.";

//Payment Void
public const string PAYMENT_Void_SUCCESS = "PayPal Express Payment Voided Successfully.";
public const string PAYMENT_Void_FAILED = "Paypal Express Payment Void Failed.";


//Payment Mode
public const string PAYMENT_MODE_AUTHORIZE = "AUTHORIZE";
public const string PAYMENT_MODE_CAPTURE = "CAPTURE";

//Template URL
public const string LIVE_URL = "https://www.paypal.com/checkoutnow?token={0}";
public const string SANDBOX_URL = "https://www.sandbox.paypal.com/checkoutnow?token={0}";

#endregion
}
}
42 changes: 42 additions & 0 deletions Libraries/Hotcakes.Commerce/Common/PayPalConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;


namespace Hotcakes.Commerce.Common
{
public class PayPalConstants
{
//Payments Status
public const string PAYMENT_STATUS_COMPLETED = "COMPLETED";
public const string PAYMENT_STATUS_COMPLETED_DESCRIPTION = "PayPal Express Payment Captured Successfully";
public const string PAYMENT_STATUS_Pending = "PENDING";
public const string PAYMENT_STATUS_Pending_DESCRIPTION = "PayPal Express Payment PENDING";
public const string PAYMENT_STATUS_DENIED = "DENIED";
public const string PAYMENT_STATUS_DENIED_DESCRIPTION = "PayPal Express Payment DENIED";
public const string PAYMENT_STATUS_ERROR_DESCRIPTION =
"An error occurred while trying to capture your PayPal payment.";
public const string PAYMENT_CHARGE_ERROR = "An error occurred while trying to charge your PayPal payment.";
public const string PAYMENT_ERROR = "Paypal Express Payment Charge Failed.";

//Payment Authorize
public const string PAYMENT_AUTHORIZE_SUCCESS = "PayPal Express Payment Authorized Successfully.";
public const string PAYMENT_AUTHORIZE_FAILED = "PayPal Express Payment Authorization Failed.";


//Payment Refund
public const string PAYMENT_REFUND_SUCCESS = "PayPal Express Payment Refunded Successfully.";
public const string PAYMENT_REFUND_FAILED = "Paypal Express Payment Refund Failed.";

//Payment Void
public const string PAYMENT_Void_SUCCESS = "PayPal Express Payment Voided Successfully.";
public const string PAYMENT_Void_FAILED = "Paypal Express Payment Void Failed.";


//Payment Mode
public const string PAYMENT_MODE_AUTHORIZE = "AUTHORIZE";
public const string PAYMENT_MODE_CAPTURE = "CAPTURE";

//Template URL
public const string LIVE_URL = "https://www.paypal.com/checkoutnow?token={0}";
public const string SANDBOX_URL = "https://www.sandbox.paypal.com/checkoutnow?token={0}";
}
}
1 change: 1 addition & 0 deletions Libraries/Hotcakes.Commerce/Hotcakes.Commerce.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
<Compile Include="Catalog\ResevationItem.cs" />
<Compile Include="Catalog\ValidateSelectionsResult.cs" />
<Compile Include="Common\Constants.cs" />
<Compile Include="Common\PayPalConstants.cs" />
<Compile Include="Configuration\IConfigurationManager.cs" />
<Compile Include="Configuration\SmtpSettings.cs" />
<Compile Include="Contacts\AffiliatePayment.cs" />
Expand Down
52 changes: 26 additions & 26 deletions Libraries/Hotcakes.Commerce/Payment/Methods/PaypalExpress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ public bool Authorize(Transaction t, HotcakesApplication app)
t.Result.Succeeded = true;
t.Result.ReferenceNumber = paymentInfo.Id;
t.Result.ResponseCode = "OK";
t.Result.ResponseCodeDescription = Constants.PAYMENT_AUTHORIZE_SUCCESS;
t.Result.ResponseCodeDescription = PayPalConstants.PAYMENT_AUTHORIZE_SUCCESS;
return true;
}
t.Result.Succeeded = false;
t.Result.Messages.Add(new Message(Constants.PAYMENT_AUTHORIZE_FAILED, string.Empty,
t.Result.Messages.Add(new Message(PayPalConstants.PAYMENT_AUTHORIZE_FAILED, string.Empty,
MessageType.Error));
return false;
}
Expand Down Expand Up @@ -126,38 +126,38 @@ public bool Capture(Transaction t, HotcakesApplication app)
var capturedInfo = captureResponse.Result<PayPalCheckoutSdk.Payments.Capture>();
t.Result.ReferenceNumber = capturedInfo.Id;

if (capturedInfo.Status == Constants.PAYMENT_STATUS_Pending)
if (capturedInfo.Status == PayPalConstants.PAYMENT_STATUS_Pending)
{
t.Result.Succeeded = true;
t.Result.ResponseCode = Constants.PAYMENT_STATUS_Pending;
t.Result.ResponseCodeDescription = Constants.PAYMENT_STATUS_Pending_DESCRIPTION;
t.Result.Messages.Add(new Message(Constants.PAYMENT_STATUS_Pending_DESCRIPTION, "OK",
t.Result.ResponseCode = PayPalConstants.PAYMENT_STATUS_Pending;
t.Result.ResponseCodeDescription = PayPalConstants.PAYMENT_STATUS_Pending_DESCRIPTION;
t.Result.Messages.Add(new Message(PayPalConstants.PAYMENT_STATUS_Pending_DESCRIPTION, "OK",
MessageType.Information));
return true;
}
if (capturedInfo.Status == Constants.PAYMENT_STATUS_DENIED)
if (capturedInfo.Status == PayPalConstants.PAYMENT_STATUS_DENIED)
{
t.Result.Succeeded = true;
t.Result.ResponseCode = Constants.PAYMENT_STATUS_DENIED;
t.Result.ResponseCodeDescription = Constants.PAYMENT_STATUS_DENIED_DESCRIPTION;
t.Result.Messages.Add(new Message(Constants.PAYMENT_STATUS_DENIED_DESCRIPTION, "OK",
t.Result.ResponseCode = PayPalConstants.PAYMENT_STATUS_DENIED;
t.Result.ResponseCodeDescription = PayPalConstants.PAYMENT_STATUS_DENIED_DESCRIPTION;
t.Result.Messages.Add(new Message(PayPalConstants.PAYMENT_STATUS_DENIED_DESCRIPTION, "OK",
MessageType.Information));
return true;
}
if (capturedInfo.Status == Constants.PAYMENT_STATUS_COMPLETED)
if (capturedInfo.Status == PayPalConstants.PAYMENT_STATUS_COMPLETED)
{
t.Result.Succeeded = true;
t.Result.Messages.Add(new Message(Constants.PAYMENT_STATUS_COMPLETED_DESCRIPTION, "OK",
t.Result.Messages.Add(new Message(PayPalConstants.PAYMENT_STATUS_COMPLETED_DESCRIPTION, "OK",
MessageType.Information));
return true;
}
t.Result.Succeeded = false;
t.Result.Messages.Add(new Message(Constants.PAYMENT_STATUS_ERROR_DESCRIPTION,
t.Result.Messages.Add(new Message(PayPalConstants.PAYMENT_STATUS_ERROR_DESCRIPTION,
string.Empty, MessageType.Error));
return false;
}
t.Result.Succeeded = false;
t.Result.Messages.Add(new Message(Constants.PAYMENT_ERROR, string.Empty,
t.Result.Messages.Add(new Message(PayPalConstants.PAYMENT_ERROR, string.Empty,
MessageType.Error));
return false;
}
Expand Down Expand Up @@ -186,29 +186,29 @@ public bool Charge(Transaction t, HotcakesApplication app)

t.Result.ReferenceNumber = paymentInfo.Id;

if (paymentInfo.Status == Constants.PAYMENT_STATUS_COMPLETED)
if (paymentInfo.Status == PayPalConstants.PAYMENT_STATUS_COMPLETED)
{
t.Result.Succeeded = true;
t.Result.Messages.Add(new Message(Constants.PAYMENT_STATUS_COMPLETED_DESCRIPTION, "OK",
t.Result.Messages.Add(new Message(PayPalConstants.PAYMENT_STATUS_COMPLETED_DESCRIPTION, "OK",
MessageType.Information));
return true;
}
if (paymentInfo.Status == Constants.PAYMENT_STATUS_Pending)
if (paymentInfo.Status == PayPalConstants.PAYMENT_STATUS_Pending)
{
t.Result.Succeeded = true;
t.Result.ResponseCode = Constants.PAYMENT_STATUS_Pending;
t.Result.ResponseCodeDescription = Constants.PAYMENT_STATUS_Pending_DESCRIPTION;
t.Result.Messages.Add(new Message(Constants.PAYMENT_STATUS_Pending_DESCRIPTION, "OK",
t.Result.ResponseCode = PayPalConstants.PAYMENT_STATUS_Pending;
t.Result.ResponseCodeDescription = PayPalConstants.PAYMENT_STATUS_Pending_DESCRIPTION;
t.Result.Messages.Add(new Message(PayPalConstants.PAYMENT_STATUS_Pending_DESCRIPTION, "OK",
MessageType.Information));
return true;
}
t.Result.Succeeded = false;
t.Result.Messages.Add(new Message(Constants.PAYMENT_CHARGE_ERROR,
t.Result.Messages.Add(new Message(PayPalConstants.PAYMENT_CHARGE_ERROR,
string.Empty, MessageType.Error));
return false;
}
t.Result.Succeeded = false;
t.Result.Messages.Add(new Message(Constants.PAYMENT_ERROR, string.Empty,
t.Result.Messages.Add(new Message(PayPalConstants.PAYMENT_ERROR, string.Empty,
MessageType.Error));

return false;
Expand Down Expand Up @@ -238,12 +238,12 @@ public bool Refund(Transaction t, HotcakesApplication app)
if (refundResponse.StatusCode == HttpStatusCode.Created)
{
t.Result.Succeeded = true;
t.Result.Messages.Add(new Message(Constants.PAYMENT_REFUND_SUCCESS, "OK",
t.Result.Messages.Add(new Message(PayPalConstants.PAYMENT_REFUND_SUCCESS, "OK",
MessageType.Information));
return true;
}
t.Result.Succeeded = false;
t.Result.Messages.Add(new Message(Constants.PAYMENT_REFUND_FAILED, string.Empty,
t.Result.Messages.Add(new Message(PayPalConstants.PAYMENT_REFUND_FAILED, string.Empty,
MessageType.Error));
return false;
}
Expand All @@ -267,12 +267,12 @@ public bool Void(Transaction t, HotcakesApplication app)
if (voidResponse.StatusCode == HttpStatusCode.NoContent)
{
t.Result.Succeeded = true;
t.Result.Messages.Add(new Message(Constants.PAYMENT_Void_SUCCESS, "OK",
t.Result.Messages.Add(new Message(PayPalConstants.PAYMENT_Void_SUCCESS, "OK",
MessageType.Information));
return true;
}
t.Result.Succeeded = false;
t.Result.Messages.Add(new Message(Constants.PAYMENT_Void_FAILED, string.Empty,
t.Result.Messages.Add(new Message(PayPalConstants.PAYMENT_Void_FAILED, string.Empty,
MessageType.Error));
return false;
}
Expand Down

0 comments on commit 1f582c4

Please sign in to comment.