net.robotmedia.billing
Class BillingController

java.lang.Object
  extended by net.robotmedia.billing.BillingController

public class BillingController
extends Object


Nested Class Summary
static class BillingController.BillingStatus
           
static interface BillingController.IConfiguration
          Used to provide on-demand values to the billing controller.
 
Field Summary
static String LOG_TAG
           
 
Constructor Summary
BillingController()
           
 
Method Summary
static BillingController.BillingStatus checkBillingSupported(android.content.Context context)
          Returns the current billing status.
static boolean confirmNotifications(android.content.Context context, String productId)
          Requests to confirm all pending MANUAL notifications for the specified item.
static int countPurchases(android.content.Context context, String productId)
          Returns the number of purchases for the specified item.
protected static void debug(String message)
           
static void dropBillingData(android.content.Context context)
           
static SecretKey getSecretKey(android.content.Context context)
           
static List<Transaction> getTransactions(android.content.Context context)
          Lists all transactions stored locally, including cancellations and refunds.
static List<Transaction> getTransactions(android.content.Context context, String productId)
          Lists all transactions of the specified item, stored locally.
static boolean isDebug()
           
static boolean isPurchased(android.content.Context context, String productId)
          Returns true if the specified item has been registered as purchased in local memory.
protected static void onNotify(android.content.Context context, String notifyId)
          Called when an IN_APP_NOTIFY message is received.
protected static void onPurchaseStateChanged(android.content.Context context, String signedData, String signature)
          Called after the response to a BillingRequest.GetPurchaseInformation request is received.
protected static void onRequestSent(long requestId, net.robotmedia.billing.IBillingRequest request)
          Called after a BillingRequest is sent.
protected static void onResponseCode(long requestId, int responseCode)
          Called after a BillingRequest is sent.
static void registerObserver(IBillingObserver billingObserver)
           
static void requestPurchase(android.content.Context context, String productId)
          Requests the purchase of the specified item.
static void requestPurchase(android.content.Context context, String productId, boolean autoConfirmation)
          Requests the purchase of the specified item with optional automatic confirmation.
static void restoreTransactions(android.content.Context context)
          Requests to restore all transactions.
static void setConfiguration(BillingController.IConfiguration config)
          Sets the configuration instance of the controller.
static void setDebug(boolean debug)
          Sets debug mode.
static void setSignatureValidator(ISignatureValidator validator)
          Sets a custom signature validator.
static void startPurchaseIntent(android.content.Context context, android.app.PendingIntent purchaseIntent, android.content.Intent intent)
          Starts the specified purchase intent with the specified activity.
static void unregisterObserver(IBillingObserver billingObserver)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG_TAG

public static final String LOG_TAG
See Also:
Constant Field Values
Constructor Detail

BillingController

public BillingController()
Method Detail

getSecretKey

@Nonnull
public static SecretKey getSecretKey(@Nonnull
                                             android.content.Context context)
                              throws org.solovyev.common.security.CiphererException
Throws:
org.solovyev.common.security.CiphererException

checkBillingSupported

@Nonnull
public static BillingController.BillingStatus checkBillingSupported(@Nonnull
                                                                            android.content.Context context)
Returns the current billing status. NOTE: current billing status may be not the same as the actual status needs some time to update (but nevertheless it can be used as first approach) This method calls billing service to determine the exact status and notify listeners through IBillingObserver#onCheckBillingSupportedResponse(boolean) method

Parameters:
context - context
Returns:
the current billing status (unknown, supported or unsupported)
See Also:
IBillingObserver.onCheckBillingSupportedResponse(boolean)

confirmNotifications

public static boolean confirmNotifications(@Nonnull
                                           android.content.Context context,
                                           @Nonnull
                                           String productId)
Requests to confirm all pending MANUAL notifications for the specified item.

Parameters:
context - context
productId - id of the item whose purchase must be confirmed.
Returns:
true if pending notifications for this item were found, false otherwise.

countPurchases

public static int countPurchases(@Nonnull
                                 android.content.Context context,
                                 @Nonnull
                                 String productId)
Returns the number of purchases for the specified item. Only transactions with state PURCHASED are counted

Parameters:
context - context
productId - id of the item whose purchases will be counted.
Returns:
number of purchases for the specified item.

debug

protected static void debug(@Nullable
                            String message)

getTransactions

@Nonnull
public static List<Transaction> getTransactions(@Nonnull
                                                        android.content.Context context)
Lists all transactions stored locally, including cancellations and refunds.

Parameters:
context - context
Returns:
list of transactions.

getTransactions

@Nonnull
public static List<Transaction> getTransactions(@Nonnull
                                                        android.content.Context context,
                                                        @Nonnull
                                                        String productId)
Lists all transactions of the specified item, stored locally.

Parameters:
context - context
productId - id of the item whose transactions will be returned.
Returns:
list of transactions.

isPurchased

public static boolean isPurchased(@Nonnull
                                  android.content.Context context,
                                  @Nonnull
                                  String productId)
Returns true if the specified item has been registered as purchased in local memory. Note that if the item was later canceled or refunded this will still return true. Also note that the item might have been purchased in another installation, but not yet registered in this one.

Parameters:
context - context
productId - item id.
Returns:
true if the specified item is purchased, false otherwise.

onNotify

protected static void onNotify(@Nonnull
                               android.content.Context context,
                               @Nonnull
                               String notifyId)
Called when an IN_APP_NOTIFY message is received.

Parameters:
context - context
notifyId - notification id.

onPurchaseStateChanged

protected static void onPurchaseStateChanged(@Nonnull
                                             android.content.Context context,
                                             @Nullable
                                             String signedData,
                                             @Nullable
                                             String signature)
Called after the response to a BillingRequest.GetPurchaseInformation request is received. Registers all transactions in local memory and confirms those who can be confirmed automatically.

Parameters:
context - context
signedData - signed JSON data received from the Market Billing service.
signature - data signature.

onRequestSent

protected static void onRequestSent(long requestId,
                                    @Nonnull
                                    net.robotmedia.billing.IBillingRequest request)
Called after a BillingRequest is sent.

Parameters:
requestId - the id the request.
request - the billing request.

onResponseCode

protected static void onResponseCode(long requestId,
                                     int responseCode)
Called after a BillingRequest is sent.

Parameters:
requestId - the id of the request.
responseCode - the response code.
See Also:
ResponseCode

requestPurchase

public static void requestPurchase(@Nonnull
                                   android.content.Context context,
                                   @Nonnull
                                   String productId)
Requests the purchase of the specified item. The transaction will not be confirmed automatically.

Parameters:
context - context
productId - id of the item to be purchased.
See Also:
requestPurchase(android.content.Context, String, boolean)

requestPurchase

public static void requestPurchase(@Nonnull
                                   android.content.Context context,
                                   @Nonnull
                                   String productId,
                                   boolean autoConfirmation)
Requests the purchase of the specified item with optional automatic confirmation.

Parameters:
context - context
productId - id of the item to be purchased.
autoConfirmation - if true, the transaction will be confirmed automatically. If false, the transaction will have to be confirmed with a call to confirmNotifications(android.content.Context, String).
See Also:
IBillingObserver.onPurchaseIntentOK(String, android.app.PendingIntent)

restoreTransactions

public static void restoreTransactions(@Nonnull
                                       android.content.Context context)
Requests to restore all transactions.

Parameters:
context - context

setConfiguration

public static void setConfiguration(BillingController.IConfiguration config)
Sets the configuration instance of the controller.

Parameters:
config - configuration instance.

setDebug

public static void setDebug(boolean debug)
Sets debug mode.

Parameters:
debug - debug

isDebug

public static boolean isDebug()

setSignatureValidator

public static void setSignatureValidator(ISignatureValidator validator)
Sets a custom signature validator. If no custom signature validator is provided, DefaultSignatureValidator will be used.

Parameters:
validator - signature validator instance.

startPurchaseIntent

public static void startPurchaseIntent(@Nonnull
                                       android.content.Context context,
                                       @Nonnull
                                       android.app.PendingIntent purchaseIntent,
                                       @Nullable
                                       android.content.Intent intent)
Starts the specified purchase intent with the specified activity.

Parameters:
context - context
purchaseIntent - purchase intent.
intent - intent

dropBillingData

public static void dropBillingData(@Nonnull
                                   android.content.Context context)

registerObserver

public static void registerObserver(@Nonnull
                                    IBillingObserver billingObserver)

unregisterObserver

public static void unregisterObserver(@Nonnull
                                      IBillingObserver billingObserver)


Copyright © 2013. All Rights Reserved.