Search code examples
coronasdk

How do I show an in app purchase price in local currency


Just wondering what I need to call to show the price in local currency of my in app purchase. Eg, in Australia I would like to have a button / label that shows $1.29 (tier 1) but if somebody in North America is using the app, it will show $0.99 (tier 1).

This is for iOS.

Thanks in advance.


Solution

  • When you use the store library, you can call the function "loadProducts" to get the available items for sale. Each item entry has a field "localizedPrice" that is a string representing the price according to the user's apple store.

    for example, for ios:

    local productIds = { 
        --array of your product identifiers, as you defined them in iTunes Connect 
    }
    
    local function loadProductsCallback( event )
        local validProducts = event.products
        local invalidProducts = event.invalidProducts
        if validProducts ~= nil then
            for i = 1, #validProducts do
                local currentItem = validProducts[i]
                -- here do what you want with currentItem.localizedPrice 
            end
        end
    end
    
    local store = require("store")
    store.init("apple", storeListener)
    if store.isActive and store.canLoadProducts then
        store.loadProducts(productIds, loadProductsCallback)
    End
    

    You can read more about it in the documentation: http://docs.coronalabs.com/api/library/store/loadProducts.html