game/godot

Gdoot - Android in-app purchases

C/H 2018. 11. 26. 08:30

Android in-app purchases

Godot engine has integrated GooglePaymentsV3 module with which we can implement in-app purchases in our game.
Godot 엔진은 우리 게임에서 인앱 구매를 구현할 수있는 GooglePaymentsV3 모듈을 통합했습니다.

The Godot engine demo project repository has an android-iap example project. It includes a gdscript interface for android IAP.
Godot 엔진 데모 프로젝트 저장소에는 android-iap 예제 프로젝트가 있습니다. 그것은 안드로이드 IAP 용 gdscript 인터페이스를 포함합니다.

Check the repository here https://github.com/godotengine/godot-demo-projects

Find the iap.gd script in
다음 위치에서 iap.gd 스크립트를 찾으십시오.

godot-demo-projects/misc/android_iap

Add it to the Autoload list and name it as IAP so that we can reference it anywhere in the game.
자동로드 목록에 추가하고 IAP로 이름을 지정하여 게임의 어느 곳에서나 참조 할 수있게하십시오.

Getting the product details

When starting our game, we will need to get the item details from Google such as the product price, description and localized price string etc.
Google 게임을 시작할 때 제품 가격, 설명 및 현지화된 가격 문자열 등과 같은 항목 세부 정보를 Google에서 가져와야합니다.

#First listen to the sku details update callback
#먼저 SKU 세부 정보 업데이트 콜백 수신 대기
IAP.connect("sku_details_complete",self,"sku_details_complete")

#Then ask google the details for these items
#그런 다음 Google에이 항목에 대한 세부 정보를 요청하십시오.
IAP.sku_details_query(["pid1","pid2"]) #pid1 and pid2 are our product ids entered in Googleplay dashboard


#This will be called when sku details are retrieved successfully
#sku 세부 정보가 성공적으로 검색 될 때 호출됩니다.
func sku_details_complete():
    print(IAP.sku_details) #This will print the details as JSON format, refer the format in iap.gd
    print(IAP.sku_details["pid1"].price) #print formatted localized price

We can use the IAP details to display the title, price and/or description on our shop scene.
IAP 세부 정보를 사용하여 상점 현장의 제목, 가격 및 / 또는 설명을 표시 할 수 있습니다.

Check if user purchased an item

When starting our game, we can check if the user has purchased any product. YOU SHOULD DO THIS ONLY AFTER 2/3 SECONDS AFTER YOUR GAME IS LOADED. If we do this as the first thing when the game is launched, IAP might not be initialized and our game will crash on start.
게임을 시작할 때 사용자가 제품을 구매했는지 확인할 수 있습니다. 게임을 로드한 후 2/3초 후에 작업을 수행해야합니다. 게임을 시작할때 이 작업을 가장 먼저 수행하면 IAP가 초기화되지 않고 게임이 시작될 때 충돌이 발생할 수 있습니다.

#Add a listener first
IAP.connect("has_purchased",self,"iap_has_purchased")
IAP.request_purchased() #Ask Google for all purchased items

#This will call for each and every user purchased products
func iap_has_purchased(item_name):
    print(item_name) #print the name of purchased items

Google IAP policy says the game should restore the user’s purchases if the user replaces their phone or reinstalls the same app. We can use the above code to check what products the user has purchased and we can make our game respond accordingly.
Google IAP 정책에 따르면 사용자가 휴대 전화를 교체하거나 동일한 앱을 다시 설치하면 게임에서 사용자의 구매를 복원해야한다고합니다. 위의 코드를 사용하여 사용자가 구입한 제품을 확인할 수 있으며 이에 따라 게임을 적절하게 응답 할 수 있습니다.

Simple Purchase

We can put this purchase logic on a product’s buy button.
구매 로직을 제품의 구매 버튼에 넣을 수 있습니다.

#First listen for purchase_success callback
IAP.connect("purchase_success",self,"purchase_success_callback")

#Then call purchase like this
IAP.purchase("pid1") #replace pid1 with your product id
IAP.purchase("pid2") #replace pid2 with your another product id

#This function will be called when the purchase is a success
func purchase_success_callback(item):
    print(item + " has purchased")

We can also implement other signals for the purchase flow and improve the user experience as you needed.
또한 구매 흐름에 대한 다른 신호를 구현하고 필요할 때 사용자 경험을 향상시킬 수 있습니다.

purchase_fail - When the purchase is failed due to any reason
어떤 이유로 구매가 실패한 경우

purchase_cancel - When the user cancels the purchase
사용자가 구매를 취소한 경우

purchase_owned - When the user already bought the product earlier
사용자가 이미 제품을 이전에 구입 한 경우

Consumables and Non-Consumables

There are two types of products - consumables and non-consumables. Consumables are purchased and used, for eg: healing potions which can be purchased again and again. Non-consumables are one time purchases, for eg: Level packs.
제품에는 소모품과 비 소모품이라는 두가지 유형이 있습니다. 소모품은 예를 들어 다음과 같이 구입하여 사용합니다. 여러번 구입할 수있는 치유 물약. 비 소모품은 예를 들어 레벨팩과 같이 한 번 구매합니다.

Google doesn’t have this separation in their dashboard. If our product is a consumable, and if a user has purchased it, it will not be available for purchase until it is consumed. So we should call the consume method for our consumables and don’t call consume for your non-consumables.
Google은 대시 보드에서 이러한 구분을하지 않습니다. 우리 제품이 소모품이고 사용자가 그것을 구입 한 경우, 소비될 때까지는 구입할 수 없습니다. 그래서 우리는 소비재에 대한 소비 방법을 호출해야하며 귀하의 비 소모품에 대해서는 소비를 요구하지 마십시오.

IAP.connect("consume_success",self,"on_consume_success")
IAP.consume("pid")

func on_consume_success(item):
    print(item + " consumed")

If our game has only consumables, we don’t have to do this. We can set it to consume the item automatically after a purchase.
우리 게임에 소모품 만 있다면 우리는 이것을 할 필요가 없습니다. 구매 후 상품을 자동으로 소비하도록 설정할 수 있습니다.

IAP.set_auto_consume(true)

If our game has only non-consumables, we can
게임에 비 소모품 만 있으면

IAP.set_auto_consume(false)

We should set the auto consume value only once when the game starts.
게임이 시작될 때 자동 소비 값을 한 번만 설정해야 합니다.

Testing

If we add a gmail id as a tester in Google dashboard, that tester can purchase items and they will not be charged. Another way to test IAP is using redeem codes generated by us for our game because the purchase flow is the same.
Google 대시 보드에 gmail ID를 테스터로 추가하면 해당 테스터는 항목을 구입할 수 있으며 대금이 청구되지 않습니다. IAP를 테스트하는 또 다른 방법은 구매 흐름이 동일하기 때문에 Google에서 생성 한 코드를 사용하는 것입니다.

Third way of testing is in development side. If we put the product ids as shown below, we will get a static fixed response according to the product id. This is a quick way of testing things before going to the dashboard.
세 번째 테스트 방법은 개발 단계입니다. 아래 그림과 같이 제품 ID를 입력하면 제품 ID에 따라 고정된 고정 응답을 얻게 됩니다. 이는 대시 보드에 가기 전에 테스트하는 빠른 방법입니다.

  • android.test.purchased
  • android.test.canceled
  • android.test.refunded
  • android.test.item_unavailable


"iap" is located in Autoloads. See Project> Project Settings> AutoLoad
"iap"은 Autoloads에 있습니다. 프로젝트> 프로젝트 설정> 자동로드를 참조하십시오.

To enable IAP module
IAP 모듈을 사용하려면

  1. Project> Project Settings
  2. Write [Category: android] / [Property: modules] / [Type: String] and click Add
  3. Click "Android" on left panel
  4. double click on right filed of "modules"
  5. write "org/godotengine/godot/GodotPaymentV3"

To test in-app purchase on android device,
안드로이드 기기에서 인앱 구매를 테스트하려면,

  1. Need to add "com.android.vending.BILLING" permission at Project> Export> Android> User Permissions
    프로젝트> 내보내기> Android> 사용자 권한에서 "com.android.vending.BILLING"권한을 추가해야합니다.
  2. Export APK and upload it as alpha or beta stage to Google Play Developer Console and publish it.
    APK를 내보내고 알파 또는 베타 단계로 Google Play 개발자 콘솔에 업로드하고 게시합니다.
         (It's not publicly available, but you can access it.)
    (공개적으로 사용할 수는 없지만 액세스 할 수 있습니다.)
  3. There should be activated in-app item
    인앱 상품이 활성화되어야합니다.
  4. Any changes on Developer console will take 2 ~ 3 hours to take effect
    개발자 콘솔에서 변경 사항이 적용 되려면 2 ~ 3 시간이 소요됩니다.


반응형

'game > godot' 카테고리의 다른 글

Godot - Console support in Godot  (0) 2018.11.28
Godot - Services for iOS  (0) 2018.11.27
Godot3 - Compiling for Android - Troubleshooting Fail  (0) 2018.11.24
Godot3 - Compiling for Android  (0) 2018.11.23
Godot3 - ConfigFile  (0) 2018.11.21