인앱 구매 데모
인앱 상품 구매를 시연하는 완전한 모바일 애플리케이션입니다.
참고: Qt 구매 모듈은 Qt 6.0에서 제거된 모듈 중 하나이며, 이 예제에는 Qt를 사용하여 일반 마켓플레이스와 통합하는 방법에 대한 가이드로서 코드가 포함되어 있습니다.
이 데모는 무엇인가요?
이 데모는 고전적인 단어 맞추기 게임인 Hangman을 기반으로 한 모바일 게임 애플리케이션으로, 데모의 내부 상점을 통해 모음을 구매할 수 있습니다. 게임에서는 추측해야 할 단어의 글자를 나타내는 대시 행이 표시됩니다. 주어진 단어에 나오는 올바른 글자를 맞추면 해당 글자가 단어의 해당 대시 위에 배치됩니다. 단어의 모든 글자를 맞히거나 언제든지 단어 전체를 정확하게 맞히면 게임이 종료되고 승리하게 됩니다. 추측이 틀린 경우 매달린 막대 그림의 한 요소가 그려집니다. 그림이 완성되면 더 이상 추측할 수 없게 되고 패배합니다.
이 데모는 Android 및 iOS 플랫폼용 Qt 애플리케이션 내에서 인앱 제품을 제공하는 방법을 보여줍니다. 데모에서 인앱 구매 기능을 테스트하려면 먼저 애플리케이션과 해당 제품을 외부 스토어에 등록해야 합니다. 이 방법에 대한 소개는 각각 Google Play 및 App Store용 가이드를 참조하세요.
타사 앱 스토어
인앱 제품은 애플리케이션에서 조회하거나 구매하기 전에 대상 스토어에 등록해야 합니다. 각 스토어에서 제품에 동일한 식별자를 사용하면 제품 조회 및 구매를 위한 코드가 간소화되므로 동일한 식별자를 사용하는 것이 좋습니다.
데모 작동 방식
이 데모는 인앱 제품에 대한 정보에 액세스하고 해당 제품에 대한 구매를 요청하기 위해 QML 유형을 등록하는 QML 애플리케이션입니다. 이는 대상 플랫폼의 외부 스토어에 등록됩니다.
인앱 구매는 먼저 스토어 개체를 추가하여 애플리케이션에 추가됩니다. 데모에서 스토어 객체는 애플리케이션 시작 시 로드되는 MainView 컴포넌트에 의해 생성됩니다.
Store { id: iapStore }
이 데모에서는 사용 가능한 인앱 제품 구매를 위한 스토어를 표시하는 구성 요소를 정의합니다. 이러한 제품은 먼저 위에서 만든 스토어 객체를 MainView에 등록해야 합니다. 사용 가능한 제품은 두 가지가 있는데, 첫 번째는 소모품 유형입니다.
Product { id: product100Vowels store: iapStore type: Product.Consumable identifier: "qt.io.demo.hangman.100vowels" onPurchaseSucceeded: { console.log(identifier + " purchase successful"); //Add 100 Vowels applicationData.vowelsAvailable += 100; transaction.finalize(); pageStack.pop(); } onPurchaseFailed: { console.log(identifier + " purchase failed"); console.log("reason: " + transaction.failureReason === Transaction.CanceledByUser ? "Canceled" : transaction.errorString); transaction.finalize(); } }
이 소모성 상품은 게임에서 단어를 맞출 때 사용할 수 있는 100개의 모음을 추가로 제공합니다. 성공적으로 구매하면 100개의 추가 모음을 포함하도록 애플리케이션의 상태를 업데이트합니다. 그런 다음 트랜잭션 객체에서 finalize()를 호출하여 소모품이 제공되었음을 플랫폼 스토어에 확인합니다.
두 번째 제품은 향후 모음을 영구적으로 잠금 해제할 수 있는 비소모성 유형입니다. 구매 시 애플리케이션 상태를 업데이트하는 것 외에도 최종 사용자가 사용하는 다른 기기에서 이 구매를 복원할 수 있는 방법을 제공해야 합니다. 이 경우 onPurchaseRestored에 대한 시그널 핸들러를 생성합니다.
Product { id: productUnlockVowels type: Product.Unlockable store: iapStore identifier: "qt.io.demo.hangman.unlockvowels" onPurchaseSucceeded: { console.log(identifier + " purchase successful"); applicationData.vowelsUnlocked = true; transaction.finalize(); pageStack.pop(); } onPurchaseFailed: { console.log(identifier + " purchase failed"); console.log("reason: " + transaction.failureReason === Transaction.CanceledByUser ? "Canceled" : transaction.errorString); transaction.finalize(); } onPurchaseRestored: { console.log(identifier + " purchase restored"); applicationData.vowelsUnlocked = true; console.log("timestamp: " + transaction.timestamp); transaction.finalize(); pageStack.pop(); } }
데모에서는 제품을 등록하는 것 외에도 등록된 제품을 실제로 구매할 수 있는 인터페이스도 제공합니다. 이 데모는 구매 상호 작용을 표시하고 처리하기 위해 StoreItem
이라는 사용자 지정 컴포넌트를 정의합니다.
Product { id: productUnlockVowels type: Product.Unlockable store: iapStore identifier: "qt.io.demo.hangman.unlockvowels" onPurchaseSucceeded: { console.log(identifier + " purchase successful"); applicationData.vowelsUnlocked = true; transaction.finalize(); pageStack.pop(); } onPurchaseFailed: { console.log(identifier + " purchase failed"); console.log("reason: " + transaction.failureReason === Transaction.CanceledByUser ? "Canceled" : transaction.errorString); transaction.finalize(); } onPurchaseRestored: { console.log(identifier + " purchase restored"); applicationData.vowelsUnlocked = true; console.log("timestamp: " + transaction.timestamp); transaction.finalize(); pageStack.pop(); } }
StoreItem 컴포넌트는 플랫폼의 스토어에서 쿼리한 제품 데이터를 표시하고, 사용자가 제품을 클릭하면 해당 제품의 구매() 메서드를 호출합니다.
Text { id: titleText text: product.title font.bold: true anchors.right: priceText.left anchors.rightMargin: topLevel.globalMargin anchors.top: parent.top anchors.topMargin: topLevel.globalMargin anchors.left: parent.left anchors.leftMargin: topLevel.globalMargin } Text { id: descriptionText text: product.description anchors.right: priceText.left anchors.rightMargin: topLevel.globalMargin anchors.left: parent.left anchors.leftMargin: topLevel.globalMargin anchors.top: titleText.bottom anchors.topMargin: topLevel.globalMargin / 2 wrapMode: Text.WordWrap } Text { id: priceText text: product.price anchors.right: parent.right anchors.rightMargin: topLevel.globalMargin anchors.verticalCenter: parent.verticalCenter } MouseArea { anchors.fill: parent onClicked: { pendingRect.visible = true; spinBox.visible = true; statusText.text = "Purchasing..."; storeItem.state = "PURCHASING"; product.purchase(); } onPressed: { storeItem.state = "PRESSED"; } onReleased: { storeItem.state = "NORMAL"; } }
Android와 iOS는 기본 클래스를 사용합니다. 베이스 클래스에서 안드로이드와 iOS용 파생 클래스가 있습니다:
인앱 구매
인앱 구매는 애플리케이션에서 수익을 창출하는 방법입니다. 이러한 구매는 애플리케이션 내부에서 이루어지며 콘텐츠 잠금 해제부터 가상 아이템까지 모든 것이 포함될 수 있습니다. 이 데모에서는 인앱 구매에 시스템 API를 사용하므로 구매 프로세스가 사용자에게 더 친숙하고 플랫폼에 이미 저장된 정보(예: 신용 카드 정보)를 사용하여 구매 프로세스를 간소화할 수 있습니다.
라이선스 및 속성
Android에 데모를 배포하는 것과 관련하여 자세한 내용은 Android GNU C++ 런타임 라이선스를 참조하세요.
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.