查询商店是否可用
返回不可用的情况:
- 服务建立连接阶段
 
- Play Store 未登录账号
 
- Google Play Services 不可用
 
- 网络故障
 
1 2 3 4
   |  private fun isAvailable(): Boolean {     return Athana.getInstance().iapService.isAvailable() }
 
  | 
1 2 3 4
   |  private boolean isAvailable() {     return Athana.getInstance().getIapService().isAvailable() }
 
  | 
 
查询商品
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
   |  private fun queryProduct(keys: Set<String>) {     Athana.getInstance().queryProducts(         keys = keys,         requestListener = object : AthanaRequestListener<List<IapProduct>> {               override fun onSuccess(data: List<IapProduct>) {                                                 }                override fun onError(error: AthanaError) {                                }         }) }
 
  | 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
   |  private void queryProduct(Set<String> keys) {       Athana.getInstance().queryProducts(           keys,           new AthanaRequestListener<>() {               @Override               public void onSuccess(List<IapProduct> iapProducts) {                                                 }                  @Override               public void onError(@NonNull AthanaError athanaError) {                                }           });   }
 
  | 
 
购买
注意,如需限制一个账号只能购买一次,则需要设置 consumable = false
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
   |  private fun purchase(       product: IapProduct,     customOrderId: Long?,      consumable: Boolean = true  ) {       Athana.getInstance().purchase(           product = product,           clientOrderId = customOrderId,           consumable = consumable,         requestListener = object : AthanaRequestListener<Unit> {               override fun onSuccess(data: Unit) {                                }                  override fun onError(error: AthanaError) {                                }           })   }
 
  | 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
   |  private void purchase(       IapProduct product,       @Nullable Long customOrderId, // 游戏订单号       @Nullable Boolean consumable // 是否可消耗 ) {       Athana.getInstance().purchase(               product,             customOrderId,             null,             consumable,              new AthanaRequestListener<>() {                   @Override                   public void onSuccess(Unit data) {                                        }                      @Override                   public void onError(@NonNull AthanaError athanaError) {                                        }               });   }
 
  | 
 
查询记录
符合以下条件的订单才能够被查询:
1 2 3 4 5 6 7 8 9 10 11 12 13
   |  private fun queryPurchaseHistory() {       Athana.getInstance().iapService.queryPurchaseHistory(           object : StoreRequestListener<List<IapPurchaseDetail>> {               override fun onSuccess(result: List<IapPurchaseDetail>) {                                }                  override fun onError(error: Throwable?) {                                }           })   }
 
  | 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
   |  private void queryPurchaseHistory() {       Athana.getInstance().getIapService().queryPurchaseHistory(new StoreRequestListener<>() {              @Override           public void onResponse(List<IapPurchaseDetail> iapPurchaseDetails) {                        }              @Override           public void onError(@Nullable Throwable throwable) {                        }       });   }
 
  |