-
Notifications
You must be signed in to change notification settings - Fork 2
์ฃผ์ ์ฝ๋ ๐
์์ edited this page Dec 24, 2023
·
1 revision
- ๊ฒฐ์ ํ๊ธฐ
kakao pay API์ NHN KCP ์ผ๋ฐ๊ฒฐ์ ๋ฅผ ์ฐ๋ํ์ฌ ์ฌ์ฉํ์ต๋๋ค.
IMP.requesst_pay(param, callback)
ํธ์ถ ํ callback์ผ๋ก ์คํ๋ฉ๋๋ค.
pg
: kakao pay API์ NHN kcp๋ฅผ ์ง์ ํ์์ต๋๋ค.
pay_method : card
function requestPayment(pg: string) {
let paymentData = {
pg: 'kcp',
pay_method: 'card',
merchant_uid: `mid_${new Date().getTime()}`,
name: '์ฃผ๋ฌธ๋ช
:๊ฒฐ์ ํ
์คํธ',
amount: totalCost,
buyer_email: userInfo.email,
buyer_name: userInfo.name,
buyer_tel: deliveryInfo.tel,
buyer_addr: deliveryInfo.mainAddress,
buyer_postcode: '123-456',
};
if (pg === 'kakao') {
paymentData.pg = 'kakaopay';
}
IMP.init('imp38488078');
IMP.request_pay(paymentData, async (response: PaymentResponse) => {
if (response.success) {
console.log('๊ฒฐ์ ์ฑ๊ณต', response);
try {
await handlePurchase();
alert('๊ฒฐ์ ๊ฐ ์๋ฃ๋์์ต๋๋ค.');
} catch (error) {
console.error('๊ฒฐ์ ์ ๋ณด ์ ์ฅ ์คํจ:', error);
}
} else {
console.error('๊ฒฐ์ ์คํจ', response);
}
});
}
- ํ๋งค ์ํ ๋ฑ๋กํ๊ธฐ
์ํ ๋ฐ์ดํฐ ๋ชจ๋ ์ํ๊ฐ ์ ๋ฐ์ดํธํ ์ดํ post method๋ฅผ ์ด์ฉํ์ฌ ๋คํธ์ํฌ๋ก ์ ์กํฉ๋๋ค.
const handleAllChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
const { name, value } = event.target;
if (name === 'price' || name === 'shippingFees') {
const numericValue = parseFloat(value);
setProductData((prev) => ({ ...prev, [name]: numericValue }));
} else {
setProductData((prev) => ({ ...prev, [name]: value }));
}
};
const productAllSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!isValid) {
alert('์์์ด ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค.');
return;
}
try {
const response = await api.createProduct(productData);
setProductData(response.data.item);
alert('ํ๋งค ์ํ ๋ฑ๋ก์ด ์๋ฃ๋์์ต๋๋ค.');
navigate(`/user/${userId}/product-manager`);
} catch (error) {
console.error('API Error:', error);
}
};
createProduct: (productData: any) =>
axiosInstance.post('/seller/products/', {
...initCreateData,
...productData,
mainImages: productData.mainImages,
name: productData.name,
content: productData.content,
}),