【发布时间】:2019-02-27 11:26:28
【问题描述】:
我正在尝试使用以下函数与 Stripe API 进行交互 - 它似乎工作正常,因为 key 对象已正确记录在控制台中并按预期显示。
exports.createEphemeralKey = functions.https.onCall((data,context) => {
const stripe_version = data.api_version;
const customerId = data.customer_id;
if (!stripe_version) {
throw new functions.https.HttpsError('missing-stripe-version','The stripe version has not been provided.');
}
if (customerId.length === 0) {
throw new functions.https.HttpsError('missing-customerID','The customer ID has not been provided.');
}
return stripe.ephemeralKeys.create(
{customer: customerId},
{stripe_version: stripe_version}
).then((key) => {
console.log(key);
return key;
}).catch((err) => {
console.log(err);
throw new functions.https.HttpsError('stripe-error', err);
});
});
但是,当我从我的 Swift iOS 应用程序中调用此函数时,result?.data 始终为零。
let funcParams = ["api_version": apiVersion, "customer_id": "......"]
functions.httpsCallable("createEphemeralKey").call(funcParams) { (result, error) in
if let error = error as NSError? {
print(error)
completion(nil,error)
}
if let json = result?.data as? [String: AnyObject] {
print("success")
print(json)
completion(json, nil)
} else {
print("fail")
print(result?.data)
}
}
【问题讨论】:
标签: ios swift firebase stripe-payments google-cloud-functions