TapPay v5.24 Update

- Add Cardholder English Name, Email, and phone number
This commit is contained in:
warrenchen 2025-12-10 15:47:19 +09:00
parent 31557c826c
commit ce18a5eb1c
2 changed files with 207 additions and 129 deletions

View File

@ -15,6 +15,7 @@ using Nop.Services.Payments;
using Nop.Services.Plugins; using Nop.Services.Plugins;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Text.RegularExpressions;
namespace Nop.Plugin.Payments.TapPay; namespace Nop.Plugin.Payments.TapPay;
@ -89,10 +90,30 @@ public class TapPayPaymentProcessor : BasePlugin, IPaymentMethod
var customer = await _customerService.GetCustomerByIdAsync(processPaymentRequest.CustomerId); var customer = await _customerService.GetCustomerByIdAsync(processPaymentRequest.CustomerId);
var customerBillingAddress = await _customerService.GetCustomerBillingAddressAsync(customer); 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( var requestBody = JsonSerializer.Serialize(
new { new {
partner_key = _tapPayPaymentSettings.PartnerKey, partner_key = _tapPayPaymentSettings.PartnerKey,
prime = ((Newtonsoft.Json.Linq.JArray)processPaymentRequest.CustomValues["Prime"])[0].ToString(), prime = prime,
amount = (int)processPaymentRequest.OrderTotal, amount = (int)processPaymentRequest.OrderTotal,
merchant_id = _tapPayPaymentSettings.Merchant.ToString(), merchant_id = _tapPayPaymentSettings.Merchant.ToString(),
order_number = processPaymentRequest.OrderGuid.ToString(), order_number = processPaymentRequest.OrderGuid.ToString(),
@ -105,11 +126,13 @@ public class TapPayPaymentProcessor : BasePlugin, IPaymentMethod
}, },
details = "AI Hardware / APP", details = "AI Hardware / APP",
cardholder = new { cardholder = new {
phone_number = customerBillingAddress.PhoneNumber, phone_number = cardholderPhone,
name = customerBillingAddress.LastName + customerBillingAddress.FirstName, phone_number_country_code = string.IsNullOrWhiteSpace(cardholderPhoneCode) ? "886" : cardholderPhoneCode,
email = customerBillingAddress.Email, name_en = cardholderNameEn,
zip_code = customerBillingAddress.ZipPostalCode, name = (customerBillingAddress?.LastName ?? string.Empty) + (customerBillingAddress?.FirstName ?? string.Empty),
address = customerBillingAddress.City + customerBillingAddress.Address1 + customerBillingAddress.Address2, email = cardholderEmail,
zip_code = customerBillingAddress?.ZipPostalCode,
address = (customerBillingAddress?.City ?? string.Empty) + (customerBillingAddress?.Address1 ?? string.Empty) + (customerBillingAddress?.Address2 ?? string.Empty),
member_id = processPaymentRequest.CustomerId.ToString() member_id = processPaymentRequest.CustomerId.ToString()
} }
} }
@ -367,7 +390,11 @@ public class TapPayPaymentProcessor : BasePlugin, IPaymentMethod
public Task<ProcessPaymentRequest> GetPaymentInfoAsync(IFormCollection form) public Task<ProcessPaymentRequest> GetPaymentInfoAsync(IFormCollection form)
{ {
var paymentRequest = new ProcessPaymentRequest(); 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); return Task.FromResult(paymentRequest);
} }

View File

@ -3,8 +3,6 @@
} }
@model Nop.Plugin.Payments.TapPay.Models.PaymentInfoModel @model Nop.Plugin.Payments.TapPay.Models.PaymentInfoModel
@* <!script async src="https://js.tappaysdk.com/tpdirect/v5.1.0"></!script> *@
<input type="hidden" asp-for="AppId" /> <input type="hidden" asp-for="AppId" />
<input type="hidden" asp-for="AppKey" /> <input type="hidden" asp-for="AppKey" />
<input type="hidden" asp-for="ServerType" /> <input type="hidden" asp-for="ServerType" />
@ -35,10 +33,41 @@
<div class="form-control ccv" style="height: 20px"></div> <div class="form-control ccv" style="height: 20px"></div>
</td> </td>
</tr> </tr>
<tr>
<td>
<label>@T("Payment.CardHolderName"):</label>
</td>
<td>
<input type="text" id="CardholderNameEn" name="CardholderNameEn" maxlength="45" placeholder="@T("Payment.CardHolderName")"/>
</td>
</tr>
<tr>
<td>
<label>@T("Payment.CardHolderEmail"):</label>
</td>
<td>
<input type="text" id="CardholderEmail" name="CardholderEmail" maxlength="40" placeholder="@T("Payment.CardHolderEmail")"/>
</td>
</tr>
<tr id="phone_group">
<td>
<label>@T("Payment.CardHolderPhone"):</label>
</td>
<td>
<div style="display: flex">
+<input type="tel" id="CardholderPhoneNumberCountryCode" name="CardholderPhoneNumberCountryCode" minlength="1" maxlength="3" placeholder="886" value="886"/>
<input type="tel" id="CardholderPhoneNumber" name="CardholderPhoneNumber" maxlength="16" placeholder="912345678"/>
</div>
</td>
</tr>
</table> </table>
<script asp-location="Footer"> <script asp-location="Footer">
//$(document).ready(function() {
$.getScript("https://js.tappaysdk.com/tpdirect/v5.1.0", function() { $.ajax({
url: "https://js.tappaysdk.com/sdk/tpdirect/v5.24.0",
dataType: "script",
cache: true,
success: function() {
TPDirect.setupSDK($('#AppId').val(), $('#AppKey').val(), $('#ServerType').val()); TPDirect.setupSDK($('#AppId').val(), $('#AppKey').val(), $('#ServerType').val());
$('.button-1.payment-info-next-step-button').attr('disabled', true); $('.button-1.payment-info-next-step-button').attr('disabled', true);
$('.button-1.payment-info-next-step-button').removeAttr('onclick'); $('.button-1.payment-info-next-step-button').removeAttr('onclick');
@ -90,6 +119,27 @@
placeholder: '後三碼' placeholder: '後三碼'
} }
}, },
@* cardholder: {
name_en: {
element: document.getElementById('name_en'),
placeholder: '持卡人姓名'
},
email: {
element: document.getElementById('email'),
placeholder: 'Email'
},
phone: {
country_code: {
element: document.getElementById('phone_country_code'),
placeholder: '886'
},
number: {
element: document.getElementById('phone_number'),
placeholder: '912345678'
}
}
}, *@
styles: { styles: {
'input': { 'input': {
'color': 'gray' 'color': 'gray'
@ -166,6 +216,7 @@
setNumberFormGroupToNormal('.ccv-group'); setNumberFormGroupToNormal('.ccv-group');
} }
}); });
}
}); });
function setNumberFormGroupToError(selector) { function setNumberFormGroupToError(selector) {