Шукати в цьому блозі

Внутрішньоігрові продажі "плагін iab"


----------------

if not tv then
 pcall(function() require "iab" end)
end
if IAB then
 if android then
  if kindle then
   iab=IAB.new("amazon")
   iab:setProducts({credit50="credit_50",credit100="credit_100",credit500="credit_500",credit1000="credit_1000"})
  else
   iab=IAB.new("google")
   iab:setUp(googleLicence)
   iab:setProducts({credit50="credit50",credit100="credit100",credit500="credit500",credit1000="credit1000"})
  end
 elseif ios then
  iab=IAB.new("ios")
  iab:setProducts({credit50="credit50",credit100="credit100",credit500="credit500",credit1000="credit1000"})
 end
 
 if iab then
  iab:setConsumables({"credit50","credit100","credit500","credit1000"})
  iab:addEventListener(Event.AVAILABLE,function(e)
   print("iab is available")
   iabCheck=false
   iab:requestProducts()
  end)
 
  -- зазвичай тут ми б встановили прапор, що можна робити покупки
                -- в основному ви можете дозволити робити всі файли iap після того, як ця подія викликана
 
  --[[ ЗАПРОС ТОВАРІВ]]--
  --Якщо ця подія викликається, ми отримали перелік продуктів та інформацію про них
  iab:addEventListener(Event.PRODUCTS_COMPLETE,function(e)
   print("Product list completed")
   for i = 1, #e.products do
    local p=e.products[i]
    --id, title, description and price
    print(p.productId,p.title,p.description,p.price)
    if p.productId=="fullgame" then
     iabCheck=true
     iabFullGame=false
    end
    for loop=1,#creditText do
     local c=creditText[loop]
     if p.productId==c[1] then
      c[2]=p.price
      c[3]=true
     end
    end
   end
   iab:restore()
  end)
 
  --Інакше ми не змогли отримати інформацію про товари зараз
  iab:addEventListener(Event.PRODUCTS_ERROR,function(e)
   print(e:getType(),e.error)
  end)
 
  iab:addEventListener(Event.PURCHASE_COMPLETE,function(e)
   -- покупки успішно виконані
--тут вам потрібно перевірити, чи не було раніше збережено квитанцію IDI
-- в тому випадку, якщо покупка ще не була здійснена
-- тоді ви можете розблокувати елемент тут
-- і зберігати квитанцію, імовірно, щоб знати
-- що ви вже надали цей елемент користувачеві
   print("Покупка завершена")
   if remainingCredits<0 then remainingCredits=0 end
   if e.productId=="credit50" then
    remainingCredits+=50
    saveSettings()
   elseif e.productId=="credit100" then
    remainingCredits+=100
    saveSettings()
   elseif e.productId=="credit500" then
    remainingCredits+=500
    saveSettings()
   elseif e.productId=="credit1000" then
    remainingCredits+=1000
    saveSettings()
   elseif e.productId=="fullgame" then
    iabCheck=true
    iabFullGame=true
   end
   print(e:getType(),e.productId,e.receiptId)
  end)
 
  iab:addEventListener(Event.PURCHASE_ERROR,function(e)
    -- не вдалося завершити покупку,
                         --інформувати користувача
   --if e.error=="Unable to buy item (response: 7:Item Already Owned)" then
    iab:isAvailable()
   --end
 --  print(e:getType(),e.error)
  end)
 
  iab:addEventListener(Event.RESTORE_COMPLETE,function(e)
   
--тут вам потрібно перевірити, чи не було раніше збережено квитанцію IDI
-- в тому випадку, якщо покупка ще не була здійснена
-- тоді ви можете розблокувати елемент тут
-- і зберігати квитанцію, імовірно, щоб знати
-- що ви вже надали цей елемент користувачеві
   if iabCheck then
    fullgame=iabFullGame
    saveSettings()
   end
   print("Відновлення завершено")
   --iab:purchase("credit500")
  end)
 
  iab:addEventListener(Event.RESTORE_ERROR,function(e)
   -- відновлення не вдалося завершити,
                        --інформувати користувача
  -- print(e:getType(),e.error)
 
  end)
  iab:isAvailable() 
 --  iab:purchase("credit100")
 else 
  print("Iab постачальник не доступний")
 end
else
 print("Iab недоступний")
end


--------------
зробити покупку так:

if iab then iab:purchase("credit50")