본문 바로가기
웹&앱 개발

react-native-iap을 활용한 인앱결제 구현시 주의점

by choice1219 2024. 10. 8.
반응형

안녕하세요.

VeriLog입니다.

 

오늘은 react-native-iap을 활용한 인앱결제를 구현하기 할 때, 제가 삽질 했던 부분을 공유하고자 합니다.

 

requestPurchase를 할 때, ios의 경우는 sku에 string을 전달하면 되지만,

aos의 경우는 skus에 string[]형태로 전달해야합니다.

(아래 코드 참고)

 

try 
    {
        const result = await requestPurchase(
            Platform.OS === 'ios' ?
            {
                sku: 'v3.everydayQuestItem',
                andDangerouslyFinishTransactionAutomaticallyIOS: false, // requestPurchase 호출 후 자동으로 finishTransaction을 호출할지 여부
            } :
            {
                skus: ['v3.everydayquestitem']
            }
        );
        console.log(result);

         // 2. 결제 완료 후 수동으로 트랜잭션 처리
         const purchase: any = result; // 트랜잭션 결과
         if (purchase) {
             try {
                 const ackResult = await finishTransaction({ purchase }); // 트랜잭션을 명시적으로 완료
                 console.log('Transaction finished:', ackResult);
             } catch (err) {
                 console.error('Error finishing transaction:', err);
             }
         }
    } catch (err) {
        console.error(err);
    }

 

저는 이 부분을 몰라서 몇일을 삽질했는데, 다른 분들은 삽질하지 않으시길 바라며 포스팅 마치겠습니다.

감사합니다.

반응형