我正在使用Stripe在我的iOS Swift应用和Firebase Cloud Functions中为后端处理付款。我使用位于此处的Stripe的Example项目设置了一个示例应用程序:
Stripe iOS Standard Integration
当我加载CheckoutView时,我收到错误400响应。我认为问题出在我在CheckoutViewController中设置的backendURL(使用上面示例的链接进行自定义):
// 2) Next, optionally, to have this demo save your user's payment details, head to
// https://github.com/stripe/example-ios-backend/tree/v13.0.3, click "Deploy to Heroku", and follow
// the instructions (don't worry, it's free). Replace nil on the line below with your
// Heroku URL (it looks like https://blazing-sunrise-1234.herokuapp.com ).
let backendBaseURL: String? = "https://us-central1-app-1253c.cloudfunctions.net/https-client-donateToUser"
我在Cloud Function日志中收到以下消息:
Request has incorrect Content-Type. application/x-www-form-urlencoded
Invalid request IncomingMessage
Function execution took 498 ms, finished with status code: 400
我尝试使用实际Firebase应用程序的URL(例如:appname123.firebaseapp.com),但返回的是错误404。
任何解决方案的想法将不胜感激。谢谢。
编辑:
由于@psmvac,我修复了后端URL。但是,我现在收到错误The data couldn't be read because it isn't in the correct format
。我相信这是因为我没有云功能来接受临时密钥。到目前为止,这就是我要的内容,为了匹配iOS Stripe示例,还需要什么?我正努力在网上找到任何有关Cloud Function的示例。
export const ephemeral_keys = functions.https.onCall(async (data, context) => {
const stripe_version = data.api_version
stripe.ephemeralKeys.create(data.customer_id,stripe_version)
}
)