提问人:Narayan Maity 提问时间:11/8/2023 更新时间:11/9/2023 访问量:43
在 AWS 中托管后无法启动付款或打开付款网关
Unable to initate payment or open the payment gateway after hosting in AWS
问:
我在 MERN 堆栈中创建了一个基于电子商务的应用程序,后端托管在 AWS EC2 中,前端托管在 Vercel 中。所以我的问题是在 AWS EC2 中托管后端后,我发现我无法打开支付网关。我猜到,也许AWS本身正在阻止支付URL的访问。在chrome浏览器的网络选项卡中,它显示错误。但在 AWS 托管之前,我还尝试了 OnRender 平台在那里托管,它工作正常。504 gateway timeout
strict-origin-when-cross-origin
我在获得超时错误方面所做的事情---- 在AWS中,我将安全组中的出站规则设置为http和https,并且还有入站规则ssh,https和http。但是我仍然无法访问支付网关。我正在使用 Eazebuzz 付款方式。
我正在共享路由和控制器
我的路线是本地视角 http://localhost:5000/api/schemes/:id/initiate_payment
控制器
export const initiatePaymentWithEazebuzz = expressAsyncHandler(async (req, res) => {
const response = await GenSchema.findById({ _id: process.env.GEN_CONFIG_CONFIGURATION_ID });
const scheme = await Scheme.findOne({ "schemeData._id": req.params.id }, { "schemeData.$": 1, status: 1, user: 1 });
if (scheme.status !== "active") {
return res.status(400).json({ error: "This Scheme isn't active anymore. You can't make a payment." });
}
const user = await User.findById(scheme.user);
const amount = scheme.schemeData[0].amount.toFixed(2);
const phone = user.mobile_number.slice(3);
const firstname = user.name.split(" ")[0];
const productinfo = scheme.schemeData[0].month_name;
const email = user.email;
const key = response.eazebuzz_merchant_key;
const salt = response.eazebuzz_salt;
// const key = process.env.EASEBUZZ_KEY;
// const salt = process.env.EAZEBUZZ_SALT;
const txnid = crypto.randomBytes(10).toString("hex");
const hashSequence = generateHashForEazeBuzz({ key, txnid, amount, productinfo, firstname, email, salt });
const url = `${process.env.BASE_URL}/payment_result`;
const formData = {
key,
txnid,
amount,
email,
phone,
firstname,
hash: hashSequence,
productinfo,
furl: url,
surl: url,
};
const eazebuzz_env = process.env.EAZEBUZZ_ENV;
const geturl = (env) => {
let url_link;
if (env === "test") {
url_link = "https://testpay.easebuzz.in/";
} else if (env === "prod") {
url_link = "https://pay.easebuzz.in/";
} else {
url_link = "https://testpay.easebuzz.in/";
}
return url_link;
};
let payment_url = geturl(eazebuzz_env);
let call_url = payment_url + "payment/initiateLink";
const options = {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Accept: "application/json",
},
};
try {
const { data } = await axios.post(call_url, formData, options);
if (data.status === 1) {
await Scheme.findOneAndUpdate(
{ "schemeData._id": req.params.id },
{
$set: {
"schemeData.$.txnid": txnid,
},
}
);
return res.json({ access_url: data.data, key, env: eazebuzz_env });
}
} catch (error) {
return res.json({ message: error.message });
}
});
这是我所做的 NGINX 站点可用性配置,如果需要更改任何事情来启动付款。
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name jewellerymine.jewellerskart.in;
ssl_certificate /etc/nginx/ssl/client-certificate.crt;
ssl_certificate_key /etc/nginx/ssl/private-ssl.key;
location /api {
rewrite ^\/api\/(.*)$ /api/$1 break;
proxy_pass http://localhost:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
答:
2赞
Narayan Maity
11/9/2023
#1
经过一番研究,我找到了解决方案,我发现需要一些参数来激活我的环境变量中的 eazebuzz 支付网关,不幸的是,我忘记将特定变量发送到生产环境,并且我还看到了来自 cors 来源的错误,所以我在我的 cors 设置中添加了 eazebuzz 支付 URL,允许来源,因此问题解决了。
评论