alitnk / monopay

💳 A node.js package for making payment transactions with different payment gateways
https://monopay.js.org
MIT License
114 stars 19 forks source link

TypeError: hexoid is not a function #63

Open kiarashAlizadeh opened 2 months ago

kiarashAlizadeh commented 2 months ago

سلام وقت بخیر در زمان تغریف درایور این مشکل رو برای من در ترمینال مینویسه و اجازه ادامه فعالیت نمیده: ⨯ TypeError: hexoid is not a function at eval (webpack-internal:///(rsc)/./node_modules/formidable/src/Formidable.js:15:18) at (rsc)/./node_modules/formidable/src/Formidable.js (F:\GitProjects\next-tut.next\server\vendor-chunks\formidable.js:20:1)
at webpack_require (F:\GitProjects\next-tut.next\server\webpack-runtime.js:33:43) at eval (webpack-internal:///(rsc)/./node_modules/formidable/src/index.js:5:20)
at (rsc)/./node_modules/formidable/src/index.js (F:\GitProjects\next-tut.next\server\vendor-chunks\formidable.js:63:1) at
webpack_require
(F:\GitProjects\next-tut.next\server\webpack-runtime.js:33:43) at eval (webpack-internal:///(rsc)/./node_modules/soap/lib/utils.js:5:20) at (rsc)/./node_modules/soap/lib/utils.js (F:\GitProjects\next-tut.next\server\vendor-chunks\soap.js:170:1) at webpack_require (F:\GitProjects\next-tut.next\server\webpack-runtime.js:33:43) at eval (webpack-internal:///(rsc)/./node_modules/soap/lib/http.js:26:15) at (rsc)/./node_modules/soap/lib/http.js (F:\GitProjects\next-tut.next\server\vendor-chunks\soap.js:40:1) at webpack_require (F:\GitProjects\next-tut.next\server\webpack-runtime.js:33:43) at eval (webpack-internal:///(rsc)/./node_modules/soap/lib/client.js:27:14) at (rsc)/./node_modules/soap/lib/client.js (F:\GitProjects\next-tut.next\server\vendor-chunks\soap.js:30:1) at webpack_require (F:\GitProjects\next-tut.next\server\webpack-runtime.js:33:43) at eval (webpack-internal:///(rsc)/./node_modules/soap/lib/soap.js:19:16) at (rsc)/./node_modules/soap/lib/soap.js (F:\GitProjects\next-tut.next\server\vendor-chunks\soap.js:150:1) at webpack_require (F:\GitProjects\next-tut.next\server\webpack-runtime.js:33:43) at eval (webpack-internal:///(rsc)/./node_modules/soap/index.js:3:18) at (rsc)/./node_modules/soap/index.js (F:\GitProjects\next-tut.next\server\vendor-chunks\soap.js:20:1) at webpack_require (F:\GitProjects\next-tut.next\server\webpack-runtime.js:33:43) at eval (webpack-internal:///(rsc)/./node_modules/monopay/dist/drivers/behpardakht/behpardakht.js:4:14) at (rsc)/./node_modules/monopay/dist/drivers/behpardakht/behpardakht.js (F:\GitProjects\next-tut.next\server\vendor-chunks\monopay.js:50:1) at webpack_require (F:\GitProjects\next-tut.next\server\webpack-runtime.js:33:43) at eval (webpack-internal:///(rsc)/./node_modules/monopay/dist/drivers/behpardakht/index.js:19:14) at (rsc)/./node_modules/monopay/dist/drivers/behpardakht/index.js (F:\GitProjects\next-tut.next\server\vendor-chunks\monopay.js:60:1) at webpack_require (F:\GitProjects\next-tut.next\server\webpack-runtime.js:33:43) at eval (webpack-internal:///(rsc)/./node_modules/monopay/dist/drivers.js:4:23)
at (rsc)/./node_modules/monopay/dist/drivers.js (F:\GitProjects\next-tut.next\server\vendor-chunks\monopay.js:30:1) at
webpack_require
(F:\GitProjects\next-tut.next\server\webpack-runtime.js:33:43) at eval (webpack-internal:///(rsc)/./node_modules/monopay/dist/index.js:17:14)
at (rsc)/./node_modules/monopay/dist/index.js (F:\GitProjects\next-tut.next\server\vendor-chunks\monopay.js:420:1) at webpack_require (F:\GitProjects\next-tut.next\server\webpack-runtime.js:33:43) at eval (webpack-internal:///(rsc)/./src/utils/monopayConfig.js:6:65) at (rsc)/./src/utils/monopayConfig.js (F:\GitProjects\next-tut.next\server\app\api\payment\request\route.js:392:1) at webpack_require (F:\GitProjects\next-tut.next\server\webpack-runtime.js:33:43) at eval (webpack-internal:///(rsc)/./src/app/api/payment/request/route.js:8:78)
at (rsc)/./src/app/api/payment/request/route.js (F:\GitProjects\next-tut.next\server\app\api\payment\request\route.js:337:1)
at webpack_require (F:\GitProjects\next-tut.next\server\webpack-runtime.js:33:43) at eval (webpack-internal:///(rsc)/./node_modules/next/dist/build/webpack/loaders/next-app-loader.js?name=app%2Fapi%2Fpayment%2Frequest%2Froute&page=%2Fapi%2Fpayment%2Frequest%2Froute&appPaths=&pagePath=private-next-app-dir%2Fapi%2Fpayment%2Frequest%2Froute.js&appDir=F%3A%5CGitProjects%5Cnext-tut%5Csrc%5Capp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=F%3A%5CGitProjects%5Cnext-tut&isDev=true&tsconfigPath=tsconfig.json&basePath=&assetPrefix=&nextConfigOutput=standalone&preferredRegion=&middlewareConfig=e30%3D!:15:117) at (rsc)/./node_modules/next/dist/build/webpack/loaders/next-app-loader.js?name=app%2Fapi%2Fpayment%2Frequest%2Froute&page=%2Fapi%2Fpayment%2Frequest%2Froute&appPaths=&pagePath=private-next-app-dir%2Fapi%2Fpayment%2Frequest%2Froute.js&appDir=F%3A%5CGitProjects%5Cnext-tut%5Csrc%5Capp&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&rootDir=F%3A%5CGitProjects%5Cnext-tut&isDev=true&tsconfigPath=tsconfig.json&basePath=&assetPrefix=&nextConfigOutput=standalone&preferredRegion=&middlewareConfig=e30%3D! (F:\GitProjects\next-tut.next\server\app\api\payment\request\route.js:315:1) at webpack_require (F:\GitProjects\next-tut.next\server\webpack-runtime.js:33:43) at webpack_exec (F:\GitProjects\next-tut.next\server\app\api\payment\request\route.js:402:39) at F:\GitProjects\next-tut.next\server\app\api\payment\request\route.js:403:1925
at
webpack_require
.X (F:\GitProjects\next-tut.next\server\webpack-runtime.js:237:21) at F:\GitProjects\next-tut.next\server\app\api\payment\request\route.js:403:47
at Object. (F:\GitProjects\next-tut.next\server\app\api\payment\request\route.js:406:3) at Module._compile (node:internal/modules/cjs/loader:1376:14) at Module._extensions..js (node:internal/modules/cjs/loader:1435:10) at Module.load (node:internal/modules/cjs/loader:1207:32) { page: '/api/payment/request' }

Keivan-sf commented 2 months ago

سلام وقت شمام بخیر. یه سری اطلاعات اضافه هم نیاز هست که بتونیم مشکلتون رو حل کنیم. دقیقا با استفاده از کدوم فانکشنالیتی این ارور رو دریافت میکنین؟ تو همون مرحله getPaymentDriver این اتفاق براتون میفته؟ اگر ممکنه snippet کدی که باعث این ارور شده رو بفرستید. طوری که اسم درایوری هم که سعی دارید بسازید توش مشخص باشه

اگر ممکنه ورژنی هم که استفاده میکنید بفرستید

kiarashAlizadeh commented 2 months ago

بله در getPaymentDriver این ارور پیش میاد, ورژن : "monopay": "^2.0.0" این دقیقا api هست که استارت کار برای درگاه پرداخته و توی همین قسمت دارم به این ارور میخورم:

`import { NextResponse } from "next/server"; import connectDB from "@/utils/connectDB"; import Payment from "@/models/Payment"; import User from "@/models/User"; import { getServerSession } from "next-auth"; import { authOptions } from "../../auth/[...nextauth]/route";

export async function POST(request) { await connectDB();

const { amount } = await request.json(); // Get amount from request body

try { const driverName = "zarinpal";

// Get payment driver based on provided driver name
// const driver = getDriver(driverName);

const driver = getPaymentDriver("zarinpal", {
  merchantId: process.env.NEXT_PUBLIC_ZARINPAL_MERCHANT_ID,

});

console.log(driver);

// Request payment from the driver
const paymentInfo = await driver.requestPayment({
  amount,
  callbackUrl: `${process.env.NEXT_PUBLIC_API_URL}/payment/callback`,
});

  } catch (err) {
// Error while processing the payment request
console.log(err);
return NextResponse.json(
  { error: "مشکلی در سرور رخ داده است" },
  { status: 500 },
);

} } `

Keivan-sf commented 2 months ago

این قسمت کدتون مشکل تایپی داره

const driver = getPaymentDriver("zarinpal", {
  merchantId: process.env.NEXT_PUBLIC_ZARINPAL_MERCHANT_ID,
});

متد getPaymentDriver فقط ۱ ورودی دریافت میکنه و خروجیش یک function هست که به اون میتونید merchantId رو پاس بدید. مثال برای درایور Zibal:

const driver = getPaymentDriver('zibal')({
  merchantId: 'merchant-id',
  sandbox: true,
});
kiarashAlizadeh commented 2 months ago

توی داکیومنتتون روش تعریفش رو یک جور دیگه نوشتید: image

در هر صورت بازم با این روشی که گفتین امتحان کردم ولی هنوزم اون ارور TypeError: hexoid is not a function رو میگیرم

Keivan-sf commented 2 months ago

حق با شماست ممنونم. یه issue باز کردم که داکیومنتیشن رو توش درست کنم بنظر میاد از ورژن ۲ به بعد تغییر نداشته.

من این فانکشنالیتی getPaymentDriver رو امتحان میکنم اما به مشکلی بر نمیخورم. فکر میکنم مشکل وقتی که از nextjs یا webpack استفاده میکنید پیش میاد. اگر ممکنه این کد زیر رو تو یه پروژه خام اجرا کنید مطمعن شیم رو سیستم هر دومون بدون مشکل کار میکنه که بعدش ببریم با nextjs مشکل رو بررسی کنیم.

import * as monopay from "monopay";

async function main() {
    const driver = monopay.getPaymentDriver("zarinpal");
    console.log(driver);
}

main();

باید output اش [Function (anonymous)] باشه