How to get Google PlayStore country in Adobe Air - air

We are having app that uses Milkmangames native extension for inApp purchases in Android app. The problem is that I can not find out the price and currency of the product user bought. Price from Google comes in localized format which is due to bad implementation at their side I guess. The price can be 5 dolars or 10 kroner, but it is impossible to know whether it is US dollars or Canadian dollars, Swedish kroner or Norway kroner.
Other option that would work for me is getting the market user is using, but I can not seem to find out the way to do it in AIR.

I ran across almost the same issue trying to find a way to get the raw price data and country code so that we could track IAP data better. Apparently there is a long-standing feature request for the native Google IAB extension to support something like this: https://code.google.com/p/marketbilling/issues/detail?id=93
Thankfully, AS3 itself provides an interface to get this information (as does native Android if you have your own ANE experience). Below is a sample in AS3 that should be able to get you what you want based on the information you get from the ANE in the localized price formatting.
var price:String = "$4.99";
var defaultLocaleID:LocaleID = new LocaleID(LocaleID.DEFAULT);
var currencyFormatter:CurrencyFormatter = new CurrencyFormatter(defaultLocaleID.name);
var currencyCode:String = currencyFormatter.currencyISOCode;
var currencySymbol:String = currencyFormatter.currencySymbol;
var priceClean:Number = currencyFormatter.parse(price).value;
trace( "CURRENCY TEST: price: " + price + " | currency code: " + currencyCode + " | symbol: " + currencySymbol + " | priceClean: " + priceClean );
The expected output for myself (in the US) is the below:
CURRENCY TEST: price: $4.99 | currency code: USD | symbol: $ |
priceClean: 4.99
Hope that helps.

Related

Most Recent Coins added to CoinGecko

I am trying to get the most recently added coin added to Coingecko. Any ideas which API to use or how to achieve this.
Ideally I am trying to get this in near realtime.
Thanks
I don't think Coingecko provides a direct API to retrieve recently added coins. For your development purposes, you can definitely try web scraping.
https://www.coingecko.com/en/coins/recently_added
You can read the name of the latest coins directly from https://www.coingecko.com/en/coins/recently_added and then use CoinGecko API to search info by name.
In Python:
import requests
# get all coins listed on CoinGecko
coins = requests.get('https://api.coingecko.com/api/v3/coins/list').json()
# extract the name of the latest coins
r = requests.get('https://www.coingecko.com/it/monete/recently_added')
for line in r.text.splitlines():
if '<td class="py-0 coin-name" data-sort=' in line:
name = line[len('<td class="py-0 coin-name" data-sort=')+1:-2]
print(name)
# then search coin in the list retrieved above
for coin in coins:
if coin['name'] == name:
r = requests.get('https://api.coingecko.com/api/v3/coins/'+coin['id'])
print(r.json())

Coinbase work with ethereum in stead of bitcoin

I am trying to create an ether buy and sell bot on coinbase. They have a truly wonderfull description on their developer page. There is one thing I am missing.
Somehow all functions automatically refer to bitcoin and not to ether. I assume there is a setting to change that in the code but I am not finding or succeeding in this. All examples on their developer page are with bitcoin. For example:
buy_price = client.get_buy_price(currency = 'EUR')
This returns: amount, base and currency. So I noticed I can change the currency. Now I tried to change the base with
buy_price = client.get_buy_price(currency = 'EUR', base = 'ETH')
It still returns BTC (bitcoin) as base.
Hope someone can help me out here.
Try this:
buy_price = client.get_buy_price(currency_pair = 'ETH-USD')
From https://developers.coinbase.com/api/v2#get-exchange-rates
EDIT: the Python API seems not to work. But the raw GET request works, so here's a replacement function for you:
import urllib.request
import json
def myGetBuyPrice(crypto, fiat):
ret = (urllib.request.urlopen("https://api.coinbase.com/v2/prices/"+crypto+"-"+fiat+"/buy").read()).decode("utf-8")
return json.loads(ret)["data"]
print myGetBuyPrice("ETH", "USD")

Hotcakes access variant prices via SingleProductViewModel

From the SingleProductViewModel, what is the best way to access prices for the variants associated with the product? From the documentation page linked above, I see that SingleProductViewModel contains a Product object, but I'm not sure how to use that to get prices of variants. (I can't find a listing of properties for the Product object).
Here is my specific use case: I have a Hotcakes Category Viewer and I'd like each product listed to display the range of prices for all variants of that product, rather than just the price for the main product. For example, a fedora product would display price as "$10 - $30" if the product contained variants with prices of $10, $20, and $30. I happen to be using the "simple" view of the category viewer, so am expecting to implement this in _RenderSingleProductSimple.cshtml, however I'm interested in using this for other category views, too.
Thanks in advance.
From what I've seen, most people will change their viewset to say something like "Starting at [PRICE]" or "As Low As [PRICE]" when there is a variant detected.
If you'd like to show the full range of prices, this can be done too, but you should know that depending on how many products that have variants and how many variants overall in the view, this could result in a negative performance impact on the site. How much impact is seen could range from negligible to undesirable.
The documentation you mentioned includes information about the Item property of the SingleProductViewModel class. This property includes all of the variant information you'd be looking for.
So, what you could do is use the Item.HasVariants property to determine if you need to have a different label. If that returns true, you can then iterate through the Item.Variants property to get all of the prices and find the lowest and highest ones to display.
Thanks #Will Strohl, that is helpful information.
I've put together the following code which seems to be achieving the original aim. Note that I said "variants" in the question, and these are product variants in our implementation, however we are achieving price adjustments for the variants via product options, so the code below looks at Model.Item.Options rather than Model.Item.Variants. Also, regarding price, I ignored user price details that weren't relevant to our implementation, and so used Model.Item.ListPrice rather than Model.UserPrice.DisplayPrice.
<div class="hc-recprice">
#{
string priceToDisplay = "";
if (Model.Item.HasOptions()){
decimal minPrice = Decimal.MaxValue;
decimal maxPrice = Decimal.MinValue;
decimal oiPrice = 0;
Hotcakes.Commerce.Catalog.OptionList options = Model.Item.Options;
foreach (Hotcakes.Commerce.Catalog.Option o in options){
foreach (Hotcakes.Commerce.Catalog.OptionItem oi in o.Items){
oiPrice = Model.Item.ListPrice + oi.PriceAdjustment;
if (oiPrice < minPrice) {
minPrice = oiPrice;
}
if (oiPrice > maxPrice) {
maxPrice = oiPrice;
}
}
}
if(minPrice == maxPrice){
priceToDisplay = string.Format("{0:C0}", minPrice);
} else {
priceToDisplay = string.Format("{0:C0}", minPrice) + " - " + string.Format("{0:C0}", maxPrice);
}
} else {
priceToDisplay = string.Format("{0:C0}", Model.Item.ListPrice);
}
#Html.Raw(priceToDisplay)
}
</div>

Aditionnal price to product in prestashop

I am selling drinks in bottles that have a deposit price. The customer has to pay that amount, but can get it back by bringing the bottles to a supermarket. I would like to show the product price without the deposit in the product pages, but when the user checks out his cart, this amount needs to be added to the cart for each item having a deposit. Here are some extra info:
Not all products have a deposit
The deposit price depends on the product
I managed to add a "deposit" field to the backoffice in the product page:
http://oi57.tinypic.com/6p9s80.jpg
But it seems that changing the whole workflow of the cart check out would be quite a pain. Is there any easy way to achieve this task?
Thanks !
easiest way to do what you want it is using "product attributes combinations" + little code changes, step by step:
create product attribute e.g. "deposit"
add value to it, any,e.g. "yes"
in product create combination with "deposit: yes", set price impact value as you need, e.g. "$10" and set it as default combination
to show on product page price without "deposit" change in themes/themename/js/product.js in function updatePrice() find lines
// Apply combination price impact
// 0 by default, +x if price is inscreased, -x if price is decreased
basePriceWithoutTax = basePriceWithoutTax + +combination.price;
and wrap it into condition:
if( your_attribute_id != combination.attributes[0] ) {
basePriceWithoutTax = basePriceWithoutTax + +combination.price;
}
but in cart you will see full price.
UPD:
I see no good way to do it in template, without core changes, so if you need it (solution also not ideal)
file controllers/front/CategoryController.php (use override) method assignProductList() change code block to next view:
foreach ($this->cat_products as &$product) {
if ($product['id_product_attribute'] && isset($product['product_attribute_minimal_quantity']))
$product['minimal_quantity'] = $product['product_attribute_minimal_quantity'];
$combination = new Combination($product['id_product_attribute']);
$attributes = $combination->getAttributesName($this->context->language->id);
foreach ($attributes as $attribute) {
if(your_attribute_id == $attribute['id_attribute'])
$product['price_tax_exc'] -= $combination->price;
}
}
you will need to repeat it for all lists controllers that you use (and you can do not use foreach but access to array element by index like you already did), in any case solution very project specific, just quick fix, in common case be better use other ways.

PhoneGap + Database How save a result in the database & how use data stock in a page

My uderstanding of Javascript is really limited. I have a simple calculation to make. A B and C are 3 inputs numbers and I need the result D in the database iOS for future use, using Phonegap and jQuery.
[ (A-10) / (200/B) ] + [ (C/10) x ((10xB)/45)] = C
This is my simple javascript
function test(){
a=Number(document.calculator.entree1.value);
b=Number(document.calculator.entree2.value);
c=Number(document.calculator.entree3.value);
d=((a-10)/(200/b))+((c/10)*((10*b)/45))
document.calculator.total.value=Math.round(d);
}
My question is how I could stock this data result Math.round(d); in the phone gap database and use it again in a daily page result?
Thanks.