diff --git a/src/Plugins/Nop.Plugin.Payments.TapPay/TapPayPaymentProcessor.cs b/src/Plugins/Nop.Plugin.Payments.TapPay/TapPayPaymentProcessor.cs index 0965109..add5795 100755 --- a/src/Plugins/Nop.Plugin.Payments.TapPay/TapPayPaymentProcessor.cs +++ b/src/Plugins/Nop.Plugin.Payments.TapPay/TapPayPaymentProcessor.cs @@ -15,6 +15,7 @@ using Nop.Services.Payments; using Nop.Services.Plugins; using System.Text; using System.Text.Json; +using System.Text.RegularExpressions; namespace Nop.Plugin.Payments.TapPay; @@ -89,10 +90,30 @@ public class TapPayPaymentProcessor : BasePlugin, IPaymentMethod var customer = await _customerService.GetCustomerByIdAsync(processPaymentRequest.CustomerId); var customerBillingAddress = await _customerService.GetCustomerBillingAddressAsync(customer); + string GetCustomValue(string key) + { + if (processPaymentRequest.CustomValues.TryGetValue(key, out var value) && value != null) + return value.ToString().Trim(); + + return string.Empty; + } + + var prime = GetCustomValue("Prime"); + if (string.IsNullOrEmpty(prime)) + { + result.AddError("TapPay prime is missing."); + return result; + } + + var cardholderEmail = GetCustomValue("CardholderEmail"); + var cardholderPhone = GetCustomValue("CardholderPhoneNumber"); + var cardholderPhoneCode = GetCustomValue("CardholderPhoneNumberCountryCode"); + var cardholderNameEn = GetCustomValue("CardholderNameEn"); + var requestBody = JsonSerializer.Serialize( new { partner_key = _tapPayPaymentSettings.PartnerKey, - prime = ((Newtonsoft.Json.Linq.JArray)processPaymentRequest.CustomValues["Prime"])[0].ToString(), + prime = prime, amount = (int)processPaymentRequest.OrderTotal, merchant_id = _tapPayPaymentSettings.Merchant.ToString(), order_number = processPaymentRequest.OrderGuid.ToString(), @@ -105,11 +126,13 @@ public class TapPayPaymentProcessor : BasePlugin, IPaymentMethod }, details = "AI Hardware / APP", cardholder = new { - phone_number = customerBillingAddress.PhoneNumber, - name = customerBillingAddress.LastName + customerBillingAddress.FirstName, - email = customerBillingAddress.Email, - zip_code = customerBillingAddress.ZipPostalCode, - address = customerBillingAddress.City + customerBillingAddress.Address1 + customerBillingAddress.Address2, + phone_number = cardholderPhone, + phone_number_country_code = string.IsNullOrWhiteSpace(cardholderPhoneCode) ? "886" : cardholderPhoneCode, + name_en = cardholderNameEn, + name = (customerBillingAddress?.LastName ?? string.Empty) + (customerBillingAddress?.FirstName ?? string.Empty), + email = cardholderEmail, + zip_code = customerBillingAddress?.ZipPostalCode, + address = (customerBillingAddress?.City ?? string.Empty) + (customerBillingAddress?.Address1 ?? string.Empty) + (customerBillingAddress?.Address2 ?? string.Empty), member_id = processPaymentRequest.CustomerId.ToString() } } @@ -367,7 +390,11 @@ public class TapPayPaymentProcessor : BasePlugin, IPaymentMethod public Task GetPaymentInfoAsync(IFormCollection form) { var paymentRequest = new ProcessPaymentRequest(); - paymentRequest.CustomValues.Add("Prime", form["Prime"]); + paymentRequest.CustomValues.Add("Prime", form["Prime"].ToString()); + paymentRequest.CustomValues.Add("CardholderEmail", form["CardholderEmail"].ToString()); + paymentRequest.CustomValues.Add("CardholderPhoneNumber", form["CardholderPhoneNumber"].ToString()); + paymentRequest.CustomValues.Add("CardholderPhoneNumberCountryCode", form["CardholderPhoneNumberCountryCode"].ToString()); + paymentRequest.CustomValues.Add("CardholderNameEn", form["CardholderNameEn"].ToString()); return Task.FromResult(paymentRequest); } @@ -482,4 +509,4 @@ public class TapPayPaymentProcessor : BasePlugin, IPaymentMethod public bool SkipPaymentInfo => false; #endregion -} \ No newline at end of file +} diff --git a/src/Plugins/Nop.Plugin.Payments.TapPay/Views/PaymentInfo.cshtml b/src/Plugins/Nop.Plugin.Payments.TapPay/Views/PaymentInfo.cshtml index a4bd80d..3aff7fd 100755 --- a/src/Plugins/Nop.Plugin.Payments.TapPay/Views/PaymentInfo.cshtml +++ b/src/Plugins/Nop.Plugin.Payments.TapPay/Views/PaymentInfo.cshtml @@ -3,8 +3,6 @@ } @model Nop.Plugin.Payments.TapPay.Models.PaymentInfoModel -@* *@ - @@ -35,137 +33,190 @@
+ + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ +