-
Notifications
You must be signed in to change notification settings - Fork 0
Update CyberSource to 10.11.2 #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
226215f
Refactored CyberSource provider.
StanislavSmetaninSSM 587a111
Fix CyberSource request compatibility issues from review
StanislavSmetaninSSM 3fdb36f
Code review fixes:
StanislavSmetaninSSM 0cca7a3
Code-review fixes
dw-sha da447c9
More code-review fixes
dw-sha b8ad58b
Merge branch 'main' into ssm/22845-refactor_cybersource_provider
dw-sha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| using Dynamicweb.Core.Helpers; | ||
| using Dynamicweb.Ecommerce.Orders; | ||
| using System; | ||
| using System.Globalization; | ||
| using System.IO; | ||
|
|
||
| namespace Dynamicweb.Ecommerce.CheckoutHandlers.CyberSource.Helpers; | ||
|
|
||
| internal static class Helper | ||
| { | ||
| public static string GetCertificateFilePath(string certificateFile) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(certificateFile)) | ||
| return string.Empty; | ||
|
|
||
| string path = FilePathHelper.GetAbsolutePath(certificateFile); | ||
| if (File.Exists(path)) | ||
| return path; | ||
|
|
||
| return string.Empty; | ||
| } | ||
|
|
||
| public static string GetCustomerLastName(Order order, string customerName) | ||
| { | ||
| string lastName = order.CustomerSurname; | ||
| int delimeterPosition = customerName.IndexOf(' '); | ||
| if (string.IsNullOrWhiteSpace(lastName)) | ||
| lastName = delimeterPosition > -1 ? customerName.Substring(delimeterPosition + 1) : customerName; | ||
|
|
||
| return lastName; | ||
| } | ||
|
|
||
| public static string GetCustomerFirstName(Order order, string customerName) | ||
| { | ||
| string firstName = order.CustomerFirstName; | ||
| int delimeterPosition = customerName.IndexOf(' '); | ||
| if (string.IsNullOrWhiteSpace(firstName)) | ||
| firstName = delimeterPosition > -1 ? customerName.Substring(0, delimeterPosition) : customerName; | ||
|
|
||
| return firstName; | ||
| } | ||
|
|
||
| public static string GetTransactionAmount(Order order) | ||
| { | ||
| int decimals = order.Currency.Rounding is null || string.IsNullOrEmpty(order.Currency.Rounding.Id) | ||
| ? 2 | ||
| : order.Currency.Rounding.Decimals; | ||
|
|
||
| string amountFormat = decimals > 0 | ||
| ? "0." + new string('0', decimals) | ||
| : "0"; | ||
|
|
||
| string amount = Math.Round(order.Price.Price, decimals).ToString(amountFormat, CultureInfo.InvariantCulture); | ||
|
|
||
| return amount; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Collections.Specialized; | ||
| using System.Security.Cryptography; | ||
|
|
||
| namespace Dynamicweb.Ecommerce.CheckoutHandlers.CyberSource.Helpers; | ||
|
|
||
| internal static class SecurityHelper | ||
| { | ||
| /// <summary> | ||
| /// | ||
| /// </summary> | ||
| /// <param name="publicKey"></param> | ||
| /// <param name="secretKey"></param> | ||
| /// <param name="signature"></param> | ||
| /// <returns></returns> | ||
| /// <remarks>ToDo: Params property hasn't been defined in new Dynamicweb.Context class.</remarks> | ||
| public static bool ValidateResponseSignation(string publicKey, string secretKey, out string signature) | ||
| { | ||
| var parameters = Context.Current.Request.Params; | ||
| return ValidateResponseSignation(parameters, publicKey, secretKey, out signature); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Validates transaction signature | ||
| /// </summary> | ||
| /// <param name="parameters">Transaction parameters</param> | ||
| /// <param name="publicKey">public key</param> | ||
| /// <param name="secretKey">secret key</param> | ||
| /// <param name="signature">signature</param> | ||
| /// <returns>Boolean result of validating transaction signature</returns> | ||
| public static bool ValidateResponseSignation(NameValueCollection parameters, string publicKey, string secretKey, out string signature) | ||
| { | ||
| signature = string.Empty; | ||
| if (parameters is null) | ||
| return false; | ||
|
|
||
| string transactionSignature = parameters["signature"]; | ||
| string signedFieldNamesValue = parameters["signed_field_names"]; | ||
|
|
||
| if (string.IsNullOrEmpty(transactionSignature) || string.IsNullOrEmpty(signedFieldNamesValue)) | ||
| return false; | ||
|
|
||
| string[] signedFieldNames = signedFieldNamesValue.Split(','); | ||
|
|
||
| var dataToSign = new List<string>(); | ||
| foreach (string signedFieldName in signedFieldNames) | ||
| { | ||
| dataToSign.Add(signedFieldName + "=" + parameters[signedFieldName]); | ||
| } | ||
| signature = Sign(string.Join(",", dataToSign), secretKey).Replace("\n", string.Empty); | ||
|
|
||
| return string.Equals(transactionSignature, signature, StringComparison.Ordinal); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Signs parameters with secret key | ||
| /// </summary> | ||
| /// <param name="parameters">set of key value pairs</param> | ||
| /// <param name="secretKey">key that is used for encryption</param> | ||
| /// <returns>Encrypted string</returns> | ||
| public static string Sign(Dictionary<string, string> parameters, string secretKey) | ||
| { | ||
| return Sign(BuildSignation(parameters), secretKey); | ||
| } | ||
|
|
||
| private static string Sign(string data, string secretKey) | ||
| { | ||
| var encoding = new System.Text.UTF8Encoding(); | ||
| var keyBytes = encoding.GetBytes(secretKey); | ||
|
|
||
| using (var hmacsha256 = new HMACSHA256(keyBytes)) | ||
| { | ||
| var messageBytes = encoding.GetBytes(data); | ||
| return Convert.ToBase64String(hmacsha256.ComputeHash(messageBytes)); | ||
| } | ||
| } | ||
|
|
||
| private static string BuildSignation(IDictionary<string, string> parameters) | ||
| { | ||
| var signedFieldNames = parameters["signed_field_names"].Split(','); | ||
| var dataToSign = new List<string>(); | ||
|
|
||
| foreach (string signedFieldName in signedFieldNames) | ||
| { | ||
| dataToSign.Add(signedFieldName + "=" + parameters[signedFieldName]); | ||
| } | ||
|
|
||
| return string.Join(",", dataToSign); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| using Dynamicweb.Ecommerce.CheckoutHandlers.CyberSource.Models.Request.Common; | ||
| using System.Runtime.Serialization; | ||
|
|
||
| namespace Dynamicweb.Ecommerce.CheckoutHandlers.CyberSource.Models.Request; | ||
|
|
||
| /// <summary> | ||
| /// Request to capture the payment | ||
| /// See: https://developer.cybersource.com/api-reference-assets/index.html#payments_capture_capture-a-payment | ||
| /// </summary> | ||
| [DataContract] | ||
| internal sealed class CaptureRequestData | ||
| { | ||
| [DataMember(Name = "clientReferenceInformation")] | ||
| public ClientReferenceInformation ClientReferenceInformation { get; set; } | ||
|
|
||
| [DataMember(Name = "orderInformation")] | ||
| public OrderInformation OrderInformation { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| using System.Runtime.Serialization; | ||
|
|
||
| namespace Dynamicweb.Ecommerce.CheckoutHandlers.CyberSource.Models.Request.Common; | ||
|
|
||
| [DataContract] | ||
| internal sealed class AmountDetails | ||
| { | ||
| /// <summary> | ||
| /// Grand total for the order. This value cannot be negative. You can include a decimal point (.), but no other special characters. | ||
| /// CyberSource truncates the amount to the correct number of decimal places. | ||
| /// </summary> | ||
| [DataMember(Name = "totalAmount")] | ||
| public string TotalAmount { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Currency used for the order. Use the three-character ISO Standard Currency Codes. | ||
| /// </summary> | ||
| [DataMember(Name = "currency")] | ||
| public string Currency { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| using System.Runtime.Serialization; | ||
|
|
||
| namespace Dynamicweb.Ecommerce.CheckoutHandlers.CyberSource.Models.Request.Common; | ||
|
|
||
| [DataContract] | ||
| internal sealed class BillTo | ||
| { | ||
| /// <summary> | ||
| /// Customer’s first name. This name must be the same as the name on the card. | ||
| /// </summary> | ||
| [DataMember(Name = "firstName")] | ||
| public string FirstName { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Customer’s last name. This name must be the same as the name on the card. | ||
| /// </summary> | ||
| [DataMember(Name = "lastName")] | ||
| public string LastName { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Payment card billing street address as it appears on the credit card issuer’s records. | ||
| /// </summary> | ||
| [DataMember(Name = "address1")] | ||
| public string Address1 { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Payment card billing city. | ||
| /// </summary> | ||
| [DataMember(Name = "locality")] | ||
| public string Locality { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// State or province of the billing address. Use the State, Province, and Territory Codes for the United States and Canada. | ||
| /// </summary> | ||
| [DataMember(Name = "administrativeArea")] | ||
| public string AdministrativeArea { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Postal code for the billing address. The postal code must consist of 5 to 9 digits. | ||
| /// When the billing country is the U.S., the 9-digit postal code must follow this format: | ||
| /// [5 digits][dash][4 digits] | ||
| /// Example 12345-6789 | ||
| /// When the billing country is Canada, the 6-digit postal code must follow this format: | ||
| /// [alpha][numeric][alpha][space][numeric][alpha][numeric] | ||
| /// Example A1B 2C3 | ||
| /// </summary> | ||
| [DataMember(Name = "postalCode")] | ||
| public string PostalCode { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Payment card billing country. Use the two-character ISO Standard Country Codes. | ||
| /// </summary> | ||
| [DataMember(Name = "country")] | ||
| public string Country { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Customer's email address, including the full domain name. | ||
| /// </summary> | ||
| [DataMember(Name = "email")] | ||
| public string Email { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Customer’s phone number. | ||
| /// It is recommended that you include the country code when the order is from outside the U.S. | ||
| /// </summary> | ||
| [DataMember(Name = "phoneNumber")] | ||
| public string PhoneNumber { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| using System.Runtime.Serialization; | ||
|
|
||
| namespace Dynamicweb.Ecommerce.CheckoutHandlers.CyberSource.Models.Request.Common; | ||
|
|
||
| [DataContract] | ||
| internal sealed class ClientReferenceInformation | ||
| { | ||
| /// <summary> | ||
| /// Merchant-generated order reference or tracking number. It is recommended that you send a unique value for each transaction so that you can perform meaningful searches for the transaction. | ||
| /// </summary> | ||
| [DataMember(Name = "code")] | ||
| public string Code { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using System.Runtime.Serialization; | ||
|
|
||
| namespace Dynamicweb.Ecommerce.CheckoutHandlers.CyberSource.Models.Request.Common; | ||
|
|
||
| [DataContract] | ||
| internal sealed class LegacyToken | ||
| { | ||
| /// <summary> | ||
| /// Unique identifier for the legacy Secure Storage token used in the transaction. | ||
| /// When you include this value in your request, many of the fields that are normally required for an authorization or credit become optional. | ||
| /// </summary> | ||
| [DataMember(Name = "id")] | ||
| public string Id { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| using System.Runtime.Serialization; | ||
|
|
||
| namespace Dynamicweb.Ecommerce.CheckoutHandlers.CyberSource.Models.Request.Common; | ||
|
|
||
| [DataContract] | ||
| internal sealed class OrderInformation | ||
| { | ||
| [DataMember(Name = "amountDetails")] | ||
| public AmountDetails AmountDetails { get; set; } | ||
|
|
||
| [DataMember(Name = "billTo", EmitDefaultValue = false)] | ||
| public BillTo BillTo { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| using System.Runtime.Serialization; | ||
|
|
||
| namespace Dynamicweb.Ecommerce.CheckoutHandlers.CyberSource.Models.Request.Common; | ||
|
|
||
| [DataContract] | ||
| internal sealed class PaymentInformation | ||
| { | ||
| [DataMember(Name = "legacyToken")] | ||
| public LegacyToken LegacyToken { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| using System.Collections.Generic; | ||
| using System.Runtime.Serialization; | ||
|
|
||
| namespace Dynamicweb.Ecommerce.CheckoutHandlers.CyberSource.Models.Request.Error; | ||
|
|
||
| [DataContract] | ||
| internal sealed class CybersourceError | ||
| { | ||
| [DataMember(Name = "submitTimeUtc")] | ||
| public string SubmitTimeUtc { get; set; } | ||
|
|
||
|
StanislavSmetaninSSM marked this conversation as resolved.
|
||
| [DataMember(Name = "status")] | ||
| public string Status { get; set; } | ||
|
|
||
| [DataMember(Name = "reason")] | ||
| public string Reason { get; set; } | ||
|
|
||
| [DataMember(Name = "message")] | ||
| public string Message { get; set; } | ||
|
|
||
| [DataMember(Name = "details")] | ||
| public IEnumerable<ErrorDetail> Details { get; set; } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| using System.Runtime.Serialization; | ||
|
|
||
| namespace Dynamicweb.Ecommerce.CheckoutHandlers.CyberSource.Models.Request.Error; | ||
|
|
||
| [DataContract] | ||
| internal sealed class ErrorDetail | ||
| { | ||
| [DataMember(Name = "field")] | ||
| public string Field { get; set; } | ||
|
|
||
| [DataMember(Name = "reason")] | ||
| public string Reason { get; set; } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.