@monkeyplus/payscope 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/db.d.mts +1 -0
- package/dist/_chunks/lib.mjs +16 -3
- package/dist/server/router.mjs +17 -1
- package/package.json +1 -1
package/dist/_chunks/db.d.mts
CHANGED
|
@@ -1745,6 +1745,7 @@ type Session = typeof sessions.$inferSelect & {
|
|
|
1745
1745
|
type Transaction = typeof transactions.$inferSelect & {
|
|
1746
1746
|
checkout: typeof checkouts.$inferSelect;
|
|
1747
1747
|
session: Session;
|
|
1748
|
+
totalRefundsCount?: number;
|
|
1748
1749
|
};
|
|
1749
1750
|
type Taxe = typeof taxes.$inferSelect & {
|
|
1750
1751
|
type: typeof typeTaxes.$inferSelect;
|
package/dist/_chunks/lib.mjs
CHANGED
|
@@ -410,7 +410,9 @@ function refundPayment({ providers, transaction }) {
|
|
|
410
410
|
});
|
|
411
411
|
const _transaction = await transaction.read(uid);
|
|
412
412
|
assertTransactionProvider(provider, _transaction.provider);
|
|
413
|
-
|
|
413
|
+
const totalRefunds = _transaction?.refund?.totalCount || _transaction.totalRefundsCount;
|
|
414
|
+
console.log("totalRefunds::", totalRefunds);
|
|
415
|
+
if (_transaction.ref && !totalRefunds) {
|
|
414
416
|
const totalAmount = Number(_transaction.checkout.total || 0);
|
|
415
417
|
const requestedAmount = Number(options?.amount || 0);
|
|
416
418
|
const refundAmount = requestedAmount > 0 && requestedAmount < totalAmount ? requestedAmount : totalAmount;
|
|
@@ -431,7 +433,7 @@ function refundPayment({ providers, transaction }) {
|
|
|
431
433
|
payload: details
|
|
432
434
|
};
|
|
433
435
|
} else {
|
|
434
|
-
if (
|
|
436
|
+
if (totalRefunds) return { message: "Esta transacción ya fue reversada" };
|
|
435
437
|
return { message: " Esta transacción no tiene ref" };
|
|
436
438
|
}
|
|
437
439
|
};
|
|
@@ -2800,6 +2802,16 @@ const createPlaceToPay = (options) => {
|
|
|
2800
2802
|
...body
|
|
2801
2803
|
}
|
|
2802
2804
|
});
|
|
2805
|
+
},
|
|
2806
|
+
removeToken: (body) => {
|
|
2807
|
+
const { auth } = getSession();
|
|
2808
|
+
return ofetch(`${endpoint}/api/instrument/invalidate`, {
|
|
2809
|
+
method: "POST",
|
|
2810
|
+
body: {
|
|
2811
|
+
auth,
|
|
2812
|
+
...body
|
|
2813
|
+
}
|
|
2814
|
+
});
|
|
2803
2815
|
}
|
|
2804
2816
|
}
|
|
2805
2817
|
};
|
|
@@ -3045,7 +3057,8 @@ function createGraphql(db) {
|
|
|
3045
3057
|
name: true,
|
|
3046
3058
|
endpoint: true
|
|
3047
3059
|
} } } }
|
|
3048
|
-
}
|
|
3060
|
+
},
|
|
3061
|
+
extras: { totalRefundsCount: (table) => db.$count(refunds, eq(refunds.transactionId, table.id)) }
|
|
3049
3062
|
});
|
|
3050
3063
|
},
|
|
3051
3064
|
findByPk: async (id) => {
|
package/dist/server/router.mjs
CHANGED
|
@@ -939,6 +939,12 @@ function registerPayment(app, db, { path, storeId, providers, preset, providerOp
|
|
|
939
939
|
throw createError({ statusCode: 500 });
|
|
940
940
|
}
|
|
941
941
|
}));
|
|
942
|
+
app.post(path("/refund/:provider"), eventHandler(async (event) => {
|
|
943
|
+
const { payment } = instance;
|
|
944
|
+
const { uid, amount } = await readBody(event);
|
|
945
|
+
const provider = safeParams(event.context.params?.provider || "");
|
|
946
|
+
return await payment.refund(provider, uid, { amount: +(amount || 0) });
|
|
947
|
+
}));
|
|
942
948
|
app.post(path("/verify/:provider"), eventHandler(async (event) => {
|
|
943
949
|
const { payment } = instance;
|
|
944
950
|
const { uid } = await readBody(event);
|
|
@@ -946,12 +952,22 @@ function registerPayment(app, db, { path, storeId, providers, preset, providerOp
|
|
|
946
952
|
const query = getQuery(event);
|
|
947
953
|
return await payment.verify(provider, uid, !!query.override);
|
|
948
954
|
}));
|
|
949
|
-
|
|
955
|
+
const _webhook = eventHandler(async (event) => {
|
|
950
956
|
const { payment } = instance;
|
|
951
957
|
const body = await readBody(event);
|
|
952
958
|
const { reference: uid } = body;
|
|
953
959
|
const provider = safeParams(event.context.params?.provider || "");
|
|
954
960
|
return await payment?.webhook?.(provider, uid, body);
|
|
961
|
+
});
|
|
962
|
+
app.post(path("/webhook/:provider"), _webhook);
|
|
963
|
+
app.post(path("/webhook/dev/:provider"), _webhook);
|
|
964
|
+
app.post(path("/methods/:provider/:method"), eventHandler(async (event) => {
|
|
965
|
+
const { _providers } = instance;
|
|
966
|
+
const body = await readBody(event);
|
|
967
|
+
const provider = safeParams(event.context.params?.provider || "");
|
|
968
|
+
const methodName = safeParams(event.context.params?.method || "");
|
|
969
|
+
const method = _providers[provider].methods[methodName];
|
|
970
|
+
return await method(body);
|
|
955
971
|
}));
|
|
956
972
|
return { graphql };
|
|
957
973
|
}
|