Getting the price and currency for a successful in-app purchase

Is it possible to add to the transaction information of a successful in-app purchase the price and currency?

Currently, all we get is a localized string, for example “$5.99”. 

I could try to separate the price from the sign, but the problem with this is that a $ sign can mean USD, Canadian dollars, Australian dollars, etc. 

I looked into getting this info from the stores after a successful purchase by using the transaction id, but there is no way. 

I need this information because I’m trying to report purchase data to an analytics tool that requires I mention:

  1. the price the user payed

  2. the currency in ISO 4217 format

Which is information we should know after the purchase.

Is it possible to add it to the “transaction” table?

Thanks

I need this information because I’m trying to report purchase data to an analytics tool that requires I mention:

  1. the price the user payed

  2. the currency in ISO 4217 format.

I recommend this plugin

https://store.coronalabs.com/plugin/iap-badger

I don’t see in plugin how to get the currency and price in a format that can help me, plus I would rather keep my current iap implementation using the store plugins. 

Can the Corona team add this missing information to the transaction table?

IAP badger does not solve this problem.

Ok here you go: local store = require( “store” ) local json = require( “json” ) – Transaction listener function local function transactionListener( event ) if not ( event.transaction.state == “failed” ) then – Successful transaction print( json.prettify( event ) ) print( "event.transaction: " … json.prettify( event.transaction ) ) else – Unsuccessful transaction; output error details print( event.transaction.errorType ) print( event.transaction.errorString ) end – Tell the store that the transaction is finished store.finishTransaction( event.transaction ) end store.init( transactionListener ) local function productListener(event) for i = 1,#event.products do print(event.products[i].localizedPrice, event.products[i].price, event.products[i].priceLocale) end end store.loadProducts( {“my id”}, productListener )

Ok, it would be very nice I’m wrong. Do you also have the output of 

for i = 1,#event.products do
print(event.products[i].localizedPrice, event.products[i].price, event.products[i].priceLocale)
end

[quote name=“JoakimGerth” post=“329756” timestamp=“1465497739”]Ok, it would be very nice I’m wrong. Do you also have the output of  [color=#282828][font=Helvetica, Arial, Verdana, sans-serif]for i = 1,#event.products do[/font][/color] [color=#282828][font=Helvetica, Arial, Verdana, sans-serif]print(event.products[i].localizedPrice, event.products[i].price, event.products[i].priceLocale)[/font][/color] [color=#282828][font=Helvetica, Arial, Verdana, sans-serif]end[/font][/color][/quote] ???

Every store has different info in the product list:

* In Google we have a field “priceCurrencyCode”, which is exactly what I need. 

* In Apple there is a field “priceLocale”, but I haven’t been able to test it yet due to mac issues.

* In Amazon, there is no information at all stating the currency of the items.

For the Corona team - Would it be possible to add a currency field to Amazon’s IAP library? 

I think I found a work around, try this

edit: I got all this info from: http://country.io/currency.json

local json = require("json") local currencyDataJson = [==[{"BD": "BDT", "BE": "EUR", "BF": "XOF", "BG": "BGN", "BA": "BAM", "BB": "BBD", "WF": "XPF", "BL": "EUR", "BM": "BMD", "BN": "BND", "BO": "BOB", "BH": "BHD", "BI": "BIF", "BJ": "XOF", "BT": "BTN", "JM": "JMD", "BV": "NOK", "BW": "BWP", "WS": "WST", "BQ": "USD", "BR": "BRL", "BS": "BSD", "JE": "GBP", "BY": "BYR", "BZ": "BZD", "RU": "RUB", "RW": "RWF", "RS": "RSD", "TL": "USD", "RE": "EUR", "TM": "TMT", "TJ": "TJS", "RO": "RON", "TK": "NZD", "GW": "XOF", "GU": "USD", "GT": "GTQ", "GS": "GBP", "GR": "EUR", "GQ": "XAF", "GP": "EUR", "JP": "JPY", "GY": "GYD", "GG": "GBP", "GF": "EUR", "GE": "GEL", "GD": "XCD", "GB": "GBP", "GA": "XAF", "SV": "USD", "GN": "GNF", "GM": "GMD", "GL": "DKK", "GI": "GIP", "GH": "GHS", "OM": "OMR", "TN": "TND", "JO": "JOD", "HR": "HRK", "HT": "HTG", "HU": "HUF", "HK": "HKD", "HN": "HNL", "HM": "AUD", "VE": "VEF", "PR": "USD", "PS": "ILS", "PW": "USD", "PT": "EUR", "SJ": "NOK", "PY": "PYG", "IQ": "IQD", "PA": "PAB", "PF": "XPF", "PG": "PGK", "PE": "PEN", "PK": "PKR", "PH": "PHP", "PN": "NZD", "PL": "PLN", "PM": "EUR", "ZM": "ZMK", "EH": "MAD", "EE": "EUR", "EG": "EGP", "ZA": "ZAR", "EC": "USD", "IT": "EUR", "VN": "VND", "SB": "SBD", "ET": "ETB", "SO": "SOS", "ZW": "ZWL", "SA": "SAR", "ES": "EUR", "ER": "ERN", "ME": "EUR", "MD": "MDL", "MG": "MGA", "MF": "EUR", "MA": "MAD", "MC": "EUR", "UZ": "UZS", "MM": "MMK", "ML": "XOF", "MO": "MOP", "MN": "MNT", "MH": "USD", "MK": "MKD", "MU": "MUR", "MT": "EUR", "MW": "MWK", "MV": "MVR", "MQ": "EUR", "MP": "USD", "MS": "XCD", "MR": "MRO", "IM": "GBP", "UG": "UGX", "TZ": "TZS", "MY": "MYR", "MX": "MXN", "IL": "ILS", "FR": "EUR", "IO": "USD", "SH": "SHP", "FI": "EUR", "FJ": "FJD", "FK": "FKP", "FM": "USD", "FO": "DKK", "NI": "NIO", "NL": "EUR", "NO": "NOK", "NA": "NAD", "VU": "VUV", "NC": "XPF", "NE": "XOF", "NF": "AUD", "NG": "NGN", "NZ": "NZD", "NP": "NPR", "NR": "AUD", "NU": "NZD", "CK": "NZD", "XK": "EUR", "CI": "XOF", "CH": "CHF", "CO": "COP", "CN": "CNY", "CM": "XAF", "CL": "CLP", "CC": "AUD", "CA": "CAD", "CG": "XAF", "CF": "XAF", "CD": "CDF", "CZ": "CZK", "CY": "EUR", "CX": "AUD", "CR": "CRC", "CW": "ANG", "CV": "CVE", "CU": "CUP", "SZ": "SZL", "SY": "SYP", "SX": "ANG", "KG": "KGS", "KE": "KES", "SS": "SSP", "SR": "SRD", "KI": "AUD", "KH": "KHR", "KN": "XCD", "KM": "KMF", "ST": "STD", "SK": "EUR", "KR": "KRW", "SI": "EUR", "KP": "KPW", "KW": "KWD", "SN": "XOF", "SM": "EUR", "SL": "SLL", "SC": "SCR", "KZ": "KZT", "KY": "KYD", "SG": "SGD", "SE": "SEK", "SD": "SDG", "DO": "DOP", "DM": "XCD", "DJ": "DJF", "DK": "DKK", "VG": "USD", "DE": "EUR", "YE": "YER", "DZ": "DZD", "US": "USD", "UY": "UYU", "YT": "EUR", "UM": "USD", "LB": "LBP", "LC": "XCD", "LA": "LAK", "TV": "AUD", "TW": "TWD", "TT": "TTD", "TR": "TRY", "LK": "LKR", "LI": "CHF", "LV": "EUR", "TO": "TOP", "LT": "LTL", "LU": "EUR", "LR": "LRD", "LS": "LSL", "TH": "THB", "TF": "EUR", "TG": "XOF", "TD": "XAF", "TC": "USD", "LY": "LYD", "VA": "EUR", "VC": "XCD", "AE": "AED", "AD": "EUR", "AG": "XCD", "AF": "AFN", "AI": "XCD", "VI": "USD", "IS": "ISK", "IR": "IRR", "AM": "AMD", "AL": "ALL", "AO": "AOA", "AQ": "", "AS": "USD", "AR": "ARS", "AU": "AUD", "AT": "EUR", "AW": "AWG", "IN": "INR", "AX": "EUR", "AZ": "AZN", "IE": "EUR", "ID": "IDR", "UA": "UAH", "QA": "QAR", "MZ": "MZN"}]]==] local currencyData = json.decode( currencyDataJson ) local myLoc =system.getPreference( "locale", "country" ) local myCurrency = currencyData[myLoc] print( myCurrency )

Thanks scottrules44, but your solution with the country locale will not solve my problem.

The currency being charged depends on the credit card that is used by the user, regardless of the user’s country. 

I might live in Ireland, but have an American credit card for mobile games, so I’ll be charged with USD, although my locale is Irish. 

After checking also for iOS, this information can be retrieved by the field “priceLocale” (thanks again scottrules44!). 

It contains a string of the form: “en_IL@currency=ILS”

so a simple match can get it:

local currencyCode = string.match(tostring(product.priceLocale), "currency=(%a%a%a)")

So basically, there is only a problem to get this currency code for the Amazon store , since the product info table only contains the following fields:

I/Corona  ( 7214): type CONSUMABLE

I/Corona  ( 7214): description Gold is good

I/Corona  ( 7214): productIdentifier product.id.of.gold

I/Corona  ( 7214): price $1.99

I/Corona  ( 7214): localizedPrice $1.99

I/Corona  ( 7214): smallIconUrl http://path/to/icon.png

I/Corona  ( 7214): title 20 Gold

Could the “priceLocale” field be added to the product’s information table? That would solve the problem. 

Thanks

I recommend this plugin

https://store.coronalabs.com/plugin/iap-badger

I don’t see in plugin how to get the currency and price in a format that can help me, plus I would rather keep my current iap implementation using the store plugins. 

Can the Corona team add this missing information to the transaction table?

IAP badger does not solve this problem.

Ok here you go: local store = require( “store” ) local json = require( “json” ) – Transaction listener function local function transactionListener( event ) if not ( event.transaction.state == “failed” ) then – Successful transaction print( json.prettify( event ) ) print( "event.transaction: " … json.prettify( event.transaction ) ) else – Unsuccessful transaction; output error details print( event.transaction.errorType ) print( event.transaction.errorString ) end – Tell the store that the transaction is finished store.finishTransaction( event.transaction ) end store.init( transactionListener ) local function productListener(event) for i = 1,#event.products do print(event.products[i].localizedPrice, event.products[i].price, event.products[i].priceLocale) end end store.loadProducts( {“my id”}, productListener )

Ok, it would be very nice I’m wrong. Do you also have the output of 

for i = 1,#event.products do
print(event.products[i].localizedPrice, event.products[i].price, event.products[i].priceLocale)
end

[quote name=“JoakimGerth” post=“329756” timestamp=“1465497739”]Ok, it would be very nice I’m wrong. Do you also have the output of  [color=#282828][font=Helvetica, Arial, Verdana, sans-serif]for i = 1,#event.products do[/font][/color] [color=#282828][font=Helvetica, Arial, Verdana, sans-serif]print(event.products[i].localizedPrice, event.products[i].price, event.products[i].priceLocale)[/font][/color] [color=#282828][font=Helvetica, Arial, Verdana, sans-serif]end[/font][/color][/quote] ???

Every store has different info in the product list:

* In Google we have a field “priceCurrencyCode”, which is exactly what I need. 

* In Apple there is a field “priceLocale”, but I haven’t been able to test it yet due to mac issues.

* In Amazon, there is no information at all stating the currency of the items.

For the Corona team - Would it be possible to add a currency field to Amazon’s IAP library? 

I think I found a work around, try this

edit: I got all this info from: http://country.io/currency.json

local json = require("json") local currencyDataJson = [==[{"BD": "BDT", "BE": "EUR", "BF": "XOF", "BG": "BGN", "BA": "BAM", "BB": "BBD", "WF": "XPF", "BL": "EUR", "BM": "BMD", "BN": "BND", "BO": "BOB", "BH": "BHD", "BI": "BIF", "BJ": "XOF", "BT": "BTN", "JM": "JMD", "BV": "NOK", "BW": "BWP", "WS": "WST", "BQ": "USD", "BR": "BRL", "BS": "BSD", "JE": "GBP", "BY": "BYR", "BZ": "BZD", "RU": "RUB", "RW": "RWF", "RS": "RSD", "TL": "USD", "RE": "EUR", "TM": "TMT", "TJ": "TJS", "RO": "RON", "TK": "NZD", "GW": "XOF", "GU": "USD", "GT": "GTQ", "GS": "GBP", "GR": "EUR", "GQ": "XAF", "GP": "EUR", "JP": "JPY", "GY": "GYD", "GG": "GBP", "GF": "EUR", "GE": "GEL", "GD": "XCD", "GB": "GBP", "GA": "XAF", "SV": "USD", "GN": "GNF", "GM": "GMD", "GL": "DKK", "GI": "GIP", "GH": "GHS", "OM": "OMR", "TN": "TND", "JO": "JOD", "HR": "HRK", "HT": "HTG", "HU": "HUF", "HK": "HKD", "HN": "HNL", "HM": "AUD", "VE": "VEF", "PR": "USD", "PS": "ILS", "PW": "USD", "PT": "EUR", "SJ": "NOK", "PY": "PYG", "IQ": "IQD", "PA": "PAB", "PF": "XPF", "PG": "PGK", "PE": "PEN", "PK": "PKR", "PH": "PHP", "PN": "NZD", "PL": "PLN", "PM": "EUR", "ZM": "ZMK", "EH": "MAD", "EE": "EUR", "EG": "EGP", "ZA": "ZAR", "EC": "USD", "IT": "EUR", "VN": "VND", "SB": "SBD", "ET": "ETB", "SO": "SOS", "ZW": "ZWL", "SA": "SAR", "ES": "EUR", "ER": "ERN", "ME": "EUR", "MD": "MDL", "MG": "MGA", "MF": "EUR", "MA": "MAD", "MC": "EUR", "UZ": "UZS", "MM": "MMK", "ML": "XOF", "MO": "MOP", "MN": "MNT", "MH": "USD", "MK": "MKD", "MU": "MUR", "MT": "EUR", "MW": "MWK", "MV": "MVR", "MQ": "EUR", "MP": "USD", "MS": "XCD", "MR": "MRO", "IM": "GBP", "UG": "UGX", "TZ": "TZS", "MY": "MYR", "MX": "MXN", "IL": "ILS", "FR": "EUR", "IO": "USD", "SH": "SHP", "FI": "EUR", "FJ": "FJD", "FK": "FKP", "FM": "USD", "FO": "DKK", "NI": "NIO", "NL": "EUR", "NO": "NOK", "NA": "NAD", "VU": "VUV", "NC": "XPF", "NE": "XOF", "NF": "AUD", "NG": "NGN", "NZ": "NZD", "NP": "NPR", "NR": "AUD", "NU": "NZD", "CK": "NZD", "XK": "EUR", "CI": "XOF", "CH": "CHF", "CO": "COP", "CN": "CNY", "CM": "XAF", "CL": "CLP", "CC": "AUD", "CA": "CAD", "CG": "XAF", "CF": "XAF", "CD": "CDF", "CZ": "CZK", "CY": "EUR", "CX": "AUD", "CR": "CRC", "CW": "ANG", "CV": "CVE", "CU": "CUP", "SZ": "SZL", "SY": "SYP", "SX": "ANG", "KG": "KGS", "KE": "KES", "SS": "SSP", "SR": "SRD", "KI": "AUD", "KH": "KHR", "KN": "XCD", "KM": "KMF", "ST": "STD", "SK": "EUR", "KR": "KRW", "SI": "EUR", "KP": "KPW", "KW": "KWD", "SN": "XOF", "SM": "EUR", "SL": "SLL", "SC": "SCR", "KZ": "KZT", "KY": "KYD", "SG": "SGD", "SE": "SEK", "SD": "SDG", "DO": "DOP", "DM": "XCD", "DJ": "DJF", "DK": "DKK", "VG": "USD", "DE": "EUR", "YE": "YER", "DZ": "DZD", "US": "USD", "UY": "UYU", "YT": "EUR", "UM": "USD", "LB": "LBP", "LC": "XCD", "LA": "LAK", "TV": "AUD", "TW": "TWD", "TT": "TTD", "TR": "TRY", "LK": "LKR", "LI": "CHF", "LV": "EUR", "TO": "TOP", "LT": "LTL", "LU": "EUR", "LR": "LRD", "LS": "LSL", "TH": "THB", "TF": "EUR", "TG": "XOF", "TD": "XAF", "TC": "USD", "LY": "LYD", "VA": "EUR", "VC": "XCD", "AE": "AED", "AD": "EUR", "AG": "XCD", "AF": "AFN", "AI": "XCD", "VI": "USD", "IS": "ISK", "IR": "IRR", "AM": "AMD", "AL": "ALL", "AO": "AOA", "AQ": "", "AS": "USD", "AR": "ARS", "AU": "AUD", "AT": "EUR", "AW": "AWG", "IN": "INR", "AX": "EUR", "AZ": "AZN", "IE": "EUR", "ID": "IDR", "UA": "UAH", "QA": "QAR", "MZ": "MZN"}]]==] local currencyData = json.decode( currencyDataJson ) local myLoc =system.getPreference( "locale", "country" ) local myCurrency = currencyData[myLoc] print( myCurrency )

Thanks scottrules44, but your solution with the country locale will not solve my problem.

The currency being charged depends on the credit card that is used by the user, regardless of the user’s country. 

I might live in Ireland, but have an American credit card for mobile games, so I’ll be charged with USD, although my locale is Irish. 

After checking also for iOS, this information can be retrieved by the field “priceLocale” (thanks again scottrules44!). 

It contains a string of the form: “en_IL@currency=ILS”

so a simple match can get it:

local currencyCode = string.match(tostring(product.priceLocale), "currency=(%a%a%a)")

So basically, there is only a problem to get this currency code for the Amazon store , since the product info table only contains the following fields:

I/Corona  ( 7214): type CONSUMABLE

I/Corona  ( 7214): description Gold is good

I/Corona  ( 7214): productIdentifier product.id.of.gold

I/Corona  ( 7214): price $1.99

I/Corona  ( 7214): localizedPrice $1.99

I/Corona  ( 7214): smallIconUrl http://path/to/icon.png

I/Corona  ( 7214): title 20 Gold

Could the “priceLocale” field be added to the product’s information table? That would solve the problem. 

Thanks