forked from organicmaps/organicmaps
[android] Added purshase failure callback
This commit is contained in:
parent
36da010799
commit
a820cba871
3 changed files with 23 additions and 0 deletions
|
@ -11,4 +11,5 @@ public interface PlayStoreBillingCallback
|
|||
{
|
||||
void onPurchaseDetailsLoaded(@NonNull List<SkuDetails> details);
|
||||
void onPurchaseSuccessful(@NonNull List<Purchase> purchases);
|
||||
void onPurchaseFailure();
|
||||
}
|
||||
|
|
|
@ -63,6 +63,8 @@ class PlayStoreBillingConnection implements BillingConnection,
|
|||
}
|
||||
|
||||
mState = State.DISCONNECTED;
|
||||
if (mListener != null)
|
||||
mListener.onDisconnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -75,5 +77,6 @@ class PlayStoreBillingConnection implements BillingConnection,
|
|||
interface ConnectionListener
|
||||
{
|
||||
void onConnected();
|
||||
void onDisconnected();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,6 +84,7 @@ public class PlayStoreBillingManager implements BillingManager<PlayStoreBillingC
|
|||
task.run();
|
||||
break;
|
||||
case DISCONNECTED:
|
||||
mPendingRequests.add(task);
|
||||
mConnection.open();
|
||||
break;
|
||||
case CLOSED:
|
||||
|
@ -137,9 +138,12 @@ public class PlayStoreBillingManager implements BillingManager<PlayStoreBillingC
|
|||
if (responseCode != BillingResponse.OK || purchases == null || purchases.isEmpty())
|
||||
{
|
||||
LOGGER.e(TAG, "Billing failed. Response code: " + responseCode);
|
||||
if (mCallback != null)
|
||||
mCallback.onPurchaseFailure();
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER.i(TAG, "Purchase process successful. Count of purchases: " + purchases.size());
|
||||
if (mCallback != null)
|
||||
mCallback.onPurchaseSuccessful(purchases);
|
||||
}
|
||||
|
@ -171,6 +175,17 @@ public class PlayStoreBillingManager implements BillingManager<PlayStoreBillingC
|
|||
mPendingRequests.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected()
|
||||
{
|
||||
if (mPendingRequests.isEmpty())
|
||||
return;
|
||||
|
||||
mPendingRequests.clear();
|
||||
if (mCallback != null)
|
||||
mCallback.onPurchaseFailure();
|
||||
}
|
||||
|
||||
private class QueryProductDetailsRequest implements Runnable
|
||||
{
|
||||
@Override
|
||||
|
@ -190,12 +205,16 @@ public class PlayStoreBillingManager implements BillingManager<PlayStoreBillingC
|
|||
if (responseCode != BillingResponse.OK)
|
||||
{
|
||||
LOGGER.w(TAG, "Unsuccessful request");
|
||||
if (mCallback != null)
|
||||
mCallback.onPurchaseFailure();
|
||||
return;
|
||||
}
|
||||
|
||||
if (skuDetails == null || skuDetails.isEmpty())
|
||||
{
|
||||
LOGGER.w(TAG, "Purchase details not found");
|
||||
if (mCallback != null)
|
||||
mCallback.onPurchaseFailure();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue