Answer the question
In order to leave comments, you need to log in
Why does it give an error when making a POST request to Yukassa via API?
Greetings! In React Native(expo) I'm trying to create an API payment in uCheckout, but I get the error "[Unhandled promise rejection: TypeError: Network request failed]". Although, the same request in Postman returns a response with data. I would be grateful for help. I've been stuck on this for a week now...
Page and request code.
import React, { useEffect, useState } from "react";
import { StyleSheet, Text, View, StatusBar, Button } from "react-native";
export default function Rate() {
const [data, setData] = useState([]);
async function pay() {
fetch("https://api.yookassa.ru/v3/payments", {
method: "POST",
headers: {
Authorization:
"Basic " +
"OD***********Rlc3RfYnc3*********************M05pdmhGRGw4Skx**********************",
idempotenceKey: "6f2cc4b0-e9ae-4108-90e9-c3b6722b02ad",
},
body: JSON.stringify({
id: "35964144-1e6b-4d20-92e8-591752aecea6",
amount: {
value: "120.00",
currency: "RUB",
},
description: "Заказ №7200",
payment_method_data: {
type: "bank_card",
card: {
number: "5555555555554477",
expiry_month: "07",
expiry_year: "2023",
csc: "123",
cardholder: "Dev",
},
},
confirmation: {
type: "redirect",
return_url: "https://www.google.com/",
},
test: "true",
}),
})
.then((res) => res.json())
.then((data) => setpayData(data));
}
return (
<View style={styles.container}>
<Text>текст</Text>
<Button title="Click" onPress={() => pay()} />
<StatusBar />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});
Answer the question
In order to leave comments, you need to log in
use sdk if you can't copy request without errors
curl https://api.yookassa.ru/v3/payments \
-X POST \
-u <Идентификатор магазина>:<Секретный ключ> \
-H 'Idempotence-Key: <Ключ идемпотентности>' \
-H 'Content-Type: application/json' \
-d '{
"amount": {
"value": "2.00",
"currency": "RUB"
},
"payment_method_data": {
"type": "bank_card"
},
"confirmation": {
"type": "redirect",
"return_url": "https://www.merchant-website.com/return_url"
},
"description": "Заказ №72"
}'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question