[英]I'm lost trying to setup Node.js for Stripe payment system, boss dropped project on me with dealine
快速背景:我是一名網絡和一般 IT 支持人員,而不是編碼員。 我上一次用 Javascipt 做任何事情是在大約 21 年前,當時我在 HS 並且在我的個人網站上使用翻轉數組作為 GIF 菜單。
所以這周我公司的老板決定接受在線支付。 CEO 的一位 IT 顧問朋友告訴他們使用 Stripe,它很容易在我們的網站上實施,我得到了實施它的任務。
最終它將與我們的 EMR 相關聯,並且 EMR 人員最終會處理那部分。 目前,他們只想要我們的客戶可以輸入他們想要支付的金額的頁面。 是的,我知道我可以讓我的生活更輕松,只需獲取一個 WP 插件,但出於各種原因,我們不想這樣做。
因此,我正在嘗試按照此處的說明作為模板進行操作。
服務器為 CentOS 7 / Node 10.22.1 / PHP 7.3.22 / Apache 2.4.6
所以我遇到的第一個障礙是沒有package.json ,我使用install init
創建一個,但不知道輸入什么值,所以我把它們都保留為默認/空白。
然后當我運行npm install stripe
我得到了這個結果:
npm WARN html@1.0.0 No description
npm WARN html@1.0.0 No repository field.
stripe@8.96.0 updated 1 package and audited 5 packages in 0.82s found 0 vulnerabilities
所以我繼續嘗試運行node stripe.js
並得到這個結果:
/var/www/payment.crisisprepandrecovery.com/html/stripe.js:3
const paymentIntent = await stripe.paymentIntents.create({
^^^^^
SyntaxError: await is only valid in async function
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
所以我沒有正確地做第一部分,代碼實際上有錯誤的語法嗎?
任何和所有的幫助都非常感謝。
嘗試這個:
async function main() {
try {
const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
const paymentIntent = await stripe.paymentIntents.create({
amount: 1477, // $14.77, an easily identifiable amount
currency: 'usd',
});
console.log('Worked! ', paymentIntent.id);
} catch (err) {
console.log('Error! ', err.message);
}
}
main();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.