godotengine / godot-google-play-billing

Godot Android plugin for the Google Play Billing library
MIT License
138 stars 39 forks source link

Add response data to README #20

Open bitwes opened 3 years ago

bitwes commented 3 years ago

I ended up creating a mock store which I plan to make available after I've vetted it. In doing so I created a bunch of constants and dictionaries to help create and process test responses. I'm not 100% sure if it's all correct but this information would be very helpful in the README.

# Use with queryPurchases and querySkuDetails
var SKU_TYPE = {
    INAPP = "inapp",
    SUBS = "subs"
}

# (Android) Purchase.PurchaseState
# (Godot) make_purchase_repsone -> purchase_state
var PURCHASE_STATE  = {
    PENDING  = 2,
    PURCHASED = 1,
    UNSPECIFIED_STATE = 0
}

# (Android) BillingClient.BillingResponseCode
# (Godot) purchase_error signal -> response_code
#         This is also the response_code for all error signals.
var BILLING_RESPONSE_CODE = {
    # Billing API version is not supported for the type requested.
    BILLING_UNAVAILABLE = 3,
    # Invalid arguments provided to the API.
    DEVELOPER_ERROR = 5,
    # Fatal error during the API action.
    ERROR = 6,
    # Requested feature is not supported by Play Store on the current device.
    FEATURE_NOT_SUPPORTED = -2,
    # Failure to purchase since item is already owned.
    ITEM_ALREADY_OWNED = 7,
    # Failure to consume since item is not owned.
    ITEM_NOT_OWNED = 8,
    # Requested product is not available for purchase.
    ITEM_UNAVAILABLE = 4,
    # Success.
    OK = 0,
    # Play Store service is not connected now - potentially transient state.
    SERVICE_DISCONNECTED = -1,
    # The request has reached the maximum timeout before Google Play responds.
    SERVICE_TIMEOUT =  -3,
    # Network connection is down.
    SERVICE_UNAVAILABLE = 2,
    # User pressed back or canceled a dialog.
    USER_CANCELED = 1
}

# Array of these is sent with the sku_details_query_completed
# signal.
var SkuDetailsResponse = {
    "description":"",
    "free_trial_period":"",
    "icon_url":"",
    "introductory_price":"",
    "introductory_price_amount_micros": -1,
    "introductory_price_cycles": -1,
    "introductory_price_period": "",
    "original_price":"",
    "original_price_amount_micros": -1,
    "price":"",
    "price_amount_micros":-1,
    "price_currency_code":"",
    "sku":"",
    "subscription_period": "",
    "title":"",
    "type":""
}

# queryPurchases contains an array of these in the "purchases"
# key and an array of these is sent with the purchases_updated
# signal.
var PurchaseResponse = {
    "is_acknowledged":false,
    "is_auto_renewing":false,
    "order_id":"",
    "package_name":"",
    "purchase_state":-1, # PURCHASE_STATE
    "purchase_time":-1,
    "purchase_token":"",
    "signature":"",
    "sku":""
}

var QueryPurchaseResponse = {
    # 0 = OK, 1 = error.  response_code and debug_message will  be
    # added when an error occurs.
    "status": -1,
    "purchases":[], # array of PurchaseResponse
    "response_code":"", # only exists when status =  1
    "debug_message":"" # only exists when status =  1
}

Also, this is the best starting point I found for understanding how to use the API, which would be useful information for first timers. https://developer.android.com/google/play/billing/integrate

Valeryn4 commented 3 years ago

We really need this!