I'm attempting to send an API request to the Stripe API from a cloud firebase function using an HTTP POST method.
The parameters required must be in a format known as 'x-www-form-urlencoded'.
const httpOptions = {
headers: new Headers({
Authorization: 'Bearer sk_test_***',
'Content-Type': 'application/x-www-form-urlencoded'
})
};
const params = 'amount=' + payment_intent.amount + '¤cy=' + payment_intent.currency;
const CHARGE_URL = 'https://api.stripe.com/v1/payment_intents';
try {
const snapshot: any = await Http.post(CHARGE_URL, params, httpOptions).toPromise();
const intent: any = {
id: snapshot.id,
client_secret: snapshot.client_secret
};
await customerClassService.savePaymentIntent(requestId, intent);
resp.status(200)
.send(await Promise.all(intent));
} catch (e) {
console.error(e);
resp.status(400)
.send('An error occurred and will be resolved as soon as possible.');
}
Unfortunately, I am encountering difficulties with this setup. Can anyone offer assistance?