Skip to content

์ฃผ์š” ์ฝ”๋“œ ๐Ÿ“Œ

์†Œ์˜ 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,
    }),
Clone this wiki locally