Skip to content

Commit 1dfb399

Browse files
committed
feat(payments): add detailed logging for WeChat mini program order processing and binding token requests
1 parent b4d5571 commit 1dfb399

3 files changed

Lines changed: 99 additions & 0 deletions

File tree

‎apps/web/src/modules/public/events/components/EventRegistrationForm.tsx‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,11 @@ export function EventRegistrationForm({
790790
try {
791791
const ticketTypeId = resolveTicketTypeId();
792792
const clientContext = await buildWechatPaymentClientContext();
793+
console.log("[MINI_BIND_RECOVERY] form:start", {
794+
eventId: event.id,
795+
ticketTypeId,
796+
clientContext,
797+
});
793798
const requestBody = {
794799
ticketTypeId,
795800
quantity: selectedQuantity,
@@ -805,6 +810,10 @@ export function EventRegistrationForm({
805810
clientContext,
806811
};
807812

813+
console.log(
814+
"[MINI_BIND_RECOVERY] form:create-order:request",
815+
requestBody,
816+
);
808817
const response = await fetch(`/api/events/${event.id}/orders`, {
809818
method: "POST",
810819
headers: {
@@ -819,27 +828,58 @@ export function EventRegistrationForm({
819828
defaultRegistrationError,
820829
);
821830
const errorMessage = errorPayload.message;
831+
console.log("[MINI_BIND_RECOVERY] form:create-order:error", {
832+
status: response.status,
833+
errorPayload,
834+
clientContext,
835+
});
822836
const shouldPromptWechatBinding =
823837
errorPayload.code === "WECHAT_OPENID_REQUIRED" ||
824838
errorMessage.toLowerCase().includes("openid");
825839
if (shouldPromptWechatBinding) {
826840
if (clientContext.environmentType === "miniprogram") {
841+
console.log(
842+
"[MINI_BIND_RECOVERY] form:bind-token:request",
843+
);
827844
const bindTokenResponse = await fetch(
828845
"/api/payments/wechat/mini-bind-token",
829846
{ method: "POST" },
830847
);
848+
console.log(
849+
"[MINI_BIND_RECOVERY] form:bind-token:response",
850+
{
851+
status: bindTokenResponse.status,
852+
},
853+
);
831854
if (!bindTokenResponse.ok) {
832855
throw new Error(errorMessage);
833856
}
834857
const bindTokenResult = await bindTokenResponse.json();
858+
console.log(
859+
"[MINI_BIND_RECOVERY] form:bind-token:payload",
860+
bindTokenResult,
861+
);
862+
console.log(
863+
"[MINI_BIND_RECOVERY] form:pending-order:request",
864+
);
835865
const pendingOrderResponse = await fetch(
836866
`/api/events/${event.id}/orders/pending?${buildWechatPaymentClientContextQuery(clientContext)}`,
837867
);
868+
console.log(
869+
"[MINI_BIND_RECOVERY] form:pending-order:response",
870+
{
871+
status: pendingOrderResponse.status,
872+
},
873+
);
838874
if (!pendingOrderResponse.ok) {
839875
throw new Error(errorMessage);
840876
}
841877
const pendingOrderResult =
842878
await pendingOrderResponse.json();
879+
console.log(
880+
"[MINI_BIND_RECOVERY] form:pending-order:payload",
881+
pendingOrderResult,
882+
);
843883
const pendingOrder = pendingOrderResult?.data as
844884
| PaymentOrderData
845885
| undefined;
@@ -851,6 +891,13 @@ export function EventRegistrationForm({
851891
if (!pendingOrder || !requestPaymentParams) {
852892
throw new Error(errorMessage);
853893
}
894+
console.log("[MINI_BIND_RECOVERY] form:open-payment", {
895+
hasBindToken: Boolean(
896+
bindTokenResult.data.bindToken,
897+
),
898+
hasRequestPaymentParams:
899+
Boolean(requestPaymentParams),
900+
});
854901
setPaymentOrder({
855902
...pendingOrder,
856903
payPayload: {

‎apps/web/src/modules/public/events/components/EventRegistrationModal.tsx‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,10 @@ export function EventRegistrationModal({
757757
const performPaidOrder = async () => {
758758
try {
759759
const clientContext = await buildWechatPaymentClientContext();
760+
console.log("[MINI_BIND_RECOVERY] modal:start", {
761+
eventId: event.id,
762+
clientContext,
763+
});
760764
const requestBody = {
761765
ticketTypeId: resolveTicketTypeId(),
762766
quantity: selectedQuantity,
@@ -772,6 +776,10 @@ export function EventRegistrationModal({
772776
clientContext,
773777
};
774778

779+
console.log(
780+
"[MINI_BIND_RECOVERY] modal:create-order:request",
781+
requestBody,
782+
);
775783
const response = await fetch(`/api/events/${event.id}/orders`, {
776784
method: "POST",
777785
headers: {
@@ -786,27 +794,58 @@ export function EventRegistrationModal({
786794
defaultRegistrationError,
787795
);
788796
const errorMessage = errorPayload.message;
797+
console.log("[MINI_BIND_RECOVERY] modal:create-order:error", {
798+
status: response.status,
799+
errorPayload,
800+
clientContext,
801+
});
789802
const shouldPromptWechatBinding =
790803
errorPayload.code === "WECHAT_OPENID_REQUIRED" ||
791804
errorMessage.toLowerCase().includes("openid");
792805
if (shouldPromptWechatBinding) {
793806
if (clientContext.environmentType === "miniprogram") {
807+
console.log(
808+
"[MINI_BIND_RECOVERY] modal:bind-token:request",
809+
);
794810
const bindTokenResponse = await fetch(
795811
"/api/payments/wechat/mini-bind-token",
796812
{ method: "POST" },
797813
);
814+
console.log(
815+
"[MINI_BIND_RECOVERY] modal:bind-token:response",
816+
{
817+
status: bindTokenResponse.status,
818+
},
819+
);
798820
if (!bindTokenResponse.ok) {
799821
throw new Error(errorMessage);
800822
}
801823
const bindTokenResult = await bindTokenResponse.json();
824+
console.log(
825+
"[MINI_BIND_RECOVERY] modal:bind-token:payload",
826+
bindTokenResult,
827+
);
828+
console.log(
829+
"[MINI_BIND_RECOVERY] modal:pending-order:request",
830+
);
802831
const pendingOrderResponse = await fetch(
803832
`/api/events/${event.id}/orders/pending?${buildWechatPaymentClientContextQuery(clientContext)}`,
804833
);
834+
console.log(
835+
"[MINI_BIND_RECOVERY] modal:pending-order:response",
836+
{
837+
status: pendingOrderResponse.status,
838+
},
839+
);
805840
if (!pendingOrderResponse.ok) {
806841
throw new Error(errorMessage);
807842
}
808843
const pendingOrderResult =
809844
await pendingOrderResponse.json();
845+
console.log(
846+
"[MINI_BIND_RECOVERY] modal:pending-order:payload",
847+
pendingOrderResult,
848+
);
810849
const pendingOrder = pendingOrderResult?.data as
811850
| PaymentOrderData
812851
| undefined;
@@ -818,6 +857,13 @@ export function EventRegistrationModal({
818857
if (!pendingOrder || !requestPaymentParams) {
819858
throw new Error(errorMessage);
820859
}
860+
console.log("[MINI_BIND_RECOVERY] modal:open-payment", {
861+
hasBindToken: Boolean(
862+
bindTokenResult.data.bindToken,
863+
),
864+
hasRequestPaymentParams:
865+
Boolean(requestPaymentParams),
866+
});
821867
setPaymentOrder({
822868
...pendingOrder,
823869
payPayload: {

‎apps/web/src/modules/public/events/components/PaymentModal.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ const invokeMiniProgramBridgePay = async (
144144
...params,
145145
baseUrl: window.location.origin,
146146
};
147+
console.log("[MINI_BIND_RECOVERY] payment-modal:navigate", {
148+
hasBindToken: Boolean((payload as { bindToken?: string }).bindToken),
149+
hasBaseUrl: Boolean((payload as { baseUrl?: string }).baseUrl),
150+
hasEventId: Boolean((payload as { eventId?: string }).eventId),
151+
orderNo: (payload as { orderNo?: string }).orderNo,
152+
});
147153

148154
const encodedParams = encodeURIComponent(JSON.stringify(payload));
149155
navigateTo({ url: `/pages/pay/pay?params=${encodedParams}` });

0 commit comments

Comments
 (0)