def _purchase_check_result(self, item: str, is_ticket_purchase: bool, result: Optional[Dict[str, Any]]) -> None: if result is None: ba.playsound(ba.getsound('error')) ba.screenmessage( ba.Lstr(resource='internal.unavailableNoConnectionText'), color=(1, 0, 0)) else: if is_ticket_purchase: if result['allow']: price = _ba.get_account_misc_read_val( 'price.' + item, None) if (price is None or not isinstance(price, int) or price <= 0): print('Error; got invalid local price of', price, 'for item', item) ba.playsound(ba.getsound('error')) else: ba.playsound(ba.getsound('click01')) _ba.in_game_purchase(item, price) else: if result['reason'] == 'versionTooOld': ba.playsound(ba.getsound('error')) ba.screenmessage(ba.Lstr( resource='getTicketsWindow.versionTooOldText'), color=(1, 0, 0)) else: ba.playsound(ba.getsound('error')) ba.screenmessage(ba.Lstr( resource='getTicketsWindow.unavailableText'), color=(1, 0, 0)) # Real in-app purchase. else: if result['allow']: _ba.purchase(item) else: if result['reason'] == 'versionTooOld': ba.playsound(ba.getsound('error')) ba.screenmessage(ba.Lstr( resource='getTicketsWindow.versionTooOldText'), color=(1, 0, 0)) else: ba.playsound(ba.getsound('error')) ba.screenmessage(ba.Lstr( resource='getTicketsWindow.unavailableText'), color=(1, 0, 0))
def _do_purchase(self, item: str) -> None: if item == 'ad': import datetime # if ads are disabled until some time, error.. next_reward_ad_time = _ba.get_v1_account_misc_read_val_2( 'nextRewardAdTime', None) if next_reward_ad_time is not None: next_reward_ad_time = datetime.datetime.utcfromtimestamp( next_reward_ad_time) now = datetime.datetime.utcnow() if ((next_reward_ad_time is not None and next_reward_ad_time > now) or self._ad_button_greyed): ba.playsound(ba.getsound('error')) ba.screenmessage(ba.Lstr( resource='getTicketsWindow.unavailableTemporarilyText'), color=(1, 0, 0)) elif self._enable_ad_button: _ba.app.ads.show_ad('tickets') else: _ba.purchase(item)
def _purchase(self) -> None: from bastd.ui import getcurrency if self._items == ['pro']: _ba.purchase('pro') else: ticket_count: Optional[int] try: ticket_count = _ba.get_account_ticket_count() except Exception: ticket_count = None if ticket_count is not None and ticket_count < self._price: getcurrency.show_get_tickets_prompt() ba.playsound(ba.getsound('error')) return def do_it() -> None: _ba.in_game_purchase(self._items[0], self._price) ba.playsound(ba.getsound('swish')) do_it()
def _purchase(self) -> None: from ba.internal import get_store_item_name_translated from bastd.ui import getcurrency from bastd.ui import confirm if self._offer['item'] == 'pro': _ba.purchase('pro_sale') elif self._offer['item'] == 'pro_fullprice': _ba.purchase('pro') elif self._is_bundle_sale: # With bundle sales, the price is the name of the IAP. _ba.purchase(self._offer['price']) else: ticket_count: Optional[int] try: ticket_count = _ba.get_account_ticket_count() except Exception: ticket_count = None if (ticket_count is not None and ticket_count < self._offer['price']): getcurrency.show_get_tickets_prompt() ba.playsound(ba.getsound('error')) return def do_it() -> None: _ba.in_game_purchase('offer:' + str(self._offer['id']), self._offer['price']) ba.playsound(ba.getsound('swish')) confirm.ConfirmWindow(ba.Lstr( resource='store.purchaseConfirmText', subs=[('${ITEM}', get_store_item_name_translated(self._offer['item']))]), width=400, height=120, action=do_it, ok_text=ba.Lstr( resource='store.purchaseText', fallback_resource='okText'))