決済にStripeを使いたいのですが
Functionsへデプロイ時にエラー発生して上手く行きません
webのfunctionsのコンソールのログは以下となっています(一部抜粋)
"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status": {"code":3,"message":"Function failed on loading user code. This is likely due to a bug in the user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging. Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation."},"authenticationInfo":
↑こちらのエラーメッセージ↓の解決策を読みましたが私のレベルでは何をどうすれば解決できるのか分かりませんでした
Cloud Logging のログ: 「Function to failed on user code.This is likely due to a bug in the user code.」
デプロイしたい関数
index.ts
index.ts
1import * as functions from 'firebase-functions'; 2 3const stripe = require('stripe')(functions.config().stripe.token); 4 5// MARK: - Create stripe customer and return customerId to your app 6exports.createStripeCustomer = functions.https.onCall(async (data, context) => { 7 const email = data.email; 8 const customer = await stripe.customers.create({email: email}); 9 const customerId = customer.id; 10 return { customerId: customerId } 11}); 12 13 14 15// MARK: - Create one time token for stripe 16exports.createStripeEphemeralKeys = functions.https.onCall((data, context) => { 17 const customerId = data.customerId; 18 const stripe_version = data.stripe_version; 19 return stripe.ephemeralKeys 20 .create({ 21 customer: customerId, 22 stripe_version: stripe_version 23 }) 24}); 25 26// MARK: - create Stripe charge 27exports.createStripeCharge = functions.https.onCall((data, context) => { 28 const customer = data.customerId; 29 const source = data.sourceId; 30 const amount = data.amount; 31 32 return stripe.charges.create({ 33 customer: customer, 34 source: source, 35 amount: amount, 36 currency: "jpy", 37 }) 38});
原因と解決方法が分かる方がおられたらご教授頂きたいです。
よろしくいお願いします。
あなたの回答
tips
プレビュー