Ad
Firebase Cloud Function Always Returns Null
I'm trying to use the following function to interact with the Stripe API - it seems to work fine as the key
object is logged correctly in the console and appears as expected.
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);
});
});
However, when I call this function from my Swift iOS App, the result?.data
is always nil.
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)
}
}
Ad
Answer
It is probably because you don't return "data that can be JSON encoded" (see the doc). The following should work:
....
).then((key) => {
console.log(key);
return {key: key};
})
....
Ad
source: stackoverflow.com
Related Questions
- → Function Undefined in Axios promise
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Click to navigate on mobile devices
- → Playing Video - Server is not correctly configured - 12939
- → How to allow api access to android or ios app only(laravel)?
- → Axios array map callback
- → Access the Camera and CameraRoll on Android using React Native?
- → Update React [Native] View on Day Change
- → Shopify iOS SDK - issue converting BuyProductVariant to BuyProduct
- → BigCommerce and shopify API
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → React Native - Differences between Android and IOS
- → What is the difference between React Native and React?
Ad