The InAppBilling module allows you to access the Android In-App Billing mechanism.
The In-App Billing process using this module is as follows:
First you must call startBillingService(), this initializes the process. Two events are fired from this call: ON_BIND_EVENT and ON_CONNECT_EVENT. Once the ON_CONNECT_EVENT has fired, the module is ready to send requests to the Android Market. There are 5 different request methods:
-checkBillingSupported()
-requestPurchase()
-getPurchaseInformation()
-confirmNotifications()
-restoreTransactions()
Three events can be fired in response to these requests:
RESPONSE_EVENT
PURCHASE_STATE_CHANGED_EVENT
NOTIFY_EVENT.
To use the Signature Verification code included in the module, you must also set the Public Key using
-setPublicKey()
If this is not set, the process will function but will not internally verify any Market responses.
To access this module from JavaScript, you would do the following:
var InAppBilling = require('ti.inappbilling');
Initializes the Billing Service which will be used to send messages to the Android Market. When the Billing Service is bound to the Market Service, an ON_BIND_EVENT e is fired. When the Billing Service connects to the Market service, an ON_CONNECT_EVENT is fired, and the Billing Service can now be used for other requests. This MUST be called before any of the 5 request functions.
Sends a Check Billing Supported request to the Market. This will trigger one synchronous response, a RESPONSE_EVENT. This request will not trigger any asynchronous responses.
Sends a Request Purchase request to the Market, for the specified productId with the specified (optional) developerPayload. This will prompt the Android Market Confirmation window to appear for the specified product. This will trigger one synchronous response, a RESPONSE_EVENT.
This request will also trigger two asynchronous responses: one NOTIFY_EVENT and one RESPONSE_EVENT.
Sends a Get Purchase Information request to market, for the specified String notificationIds. This should be called after an In-App Notify response is recieved, and will request more detailed transaction information. This will trigger one synchronous response, a RESPONSE_EVENT.
This request will also trigger two asynchronous responses: one PURCHASE_STATE_CHANGED_EVENT and one RESPONSE_EVENT.
Sends a Confirm Notifications request to the market, for the specified String notificationIds. This is called to confirm with the Market the delivery of the purchases signified by the notificationIds passed in. This will trigger one synchronous response, a RESPONSE_EVENT.
This request will trigger one asynchronous response, a RESPONSE_EVENT.
Sends a restore Transactions request to the market. This will deliver the user's transaction history for purchases with this application. Should be called only when the application is installed/re-installed. This will trigger one synchronous response, a RESPONSE_EVENT.
This request will also trigger two asynchronous responses: one PURCHASE_STATE_CHANGED_EVENT and one RESPONSE_EVENT.
Sets the key to be used for signature verification (Key is found in Android Market profile information)
Success state in Billing Service binding.
Fail state in Billing Service binding.
Security Exception state in Billing Service binding.
OK message from a Response Code notification.
User Canceled message from a Response Code notification.
User Canceled message from a Response Code notification.
Billing Unavailable message from a Response Code notification.
Item Unavailable message from a Response Code notification.
Developer Error message from a Response Code notification.
Result Error message from a Response Code notification
Success response from signature verification.
Null data response from signature verification (occurs if there is no signed data sent in
Purchase State Changed notification).
Error response from signature verification (occurs if the signature is incorrect and cannot
be verified).
Unknown Nonce response from signature verification (occurs if the nonce returned from the Market
differs from any that have been sent, the message is thus insecure, see Android Documentation).
Public Key null response from signature verification (occurs if setPublicKey has not been called).
Event e is fired when the Billing Service binds with the Market serice, with the property e.result
equal to one of the following:
InAppBilling.SUCCESS
InAppBilling.FAILED
InAppBilling.SECEXCEPTION
Event e is fired when the Billing Service connects to the market. This event has no properties,
but signifies that requests can now be made to the Android Market.
Event e is fired when the module receives an asynchronous IN\_APP\_NOTIFY response from the Market. This event has
one property, e.notifyId. This ID can be used for calls to GetPurchaseInformation and confirmNotifications.
Event e is fired when the module receives an asynchronous PURCHASE\_STATE\_CHANGED response from the market.
This event has 3 properties: first, e.signedData, a JSON String which can be parsed into a JSON object
(see Android documentation: http://developer.android.com/guide/market/billing/billing_reference.html#billing-intents).
Second, e.signature, this can be used to verify the response recieved. If the Public Key has been set,
the module will verify automatically. Third, e.result, a int response with one the following possible values:
InAppBilling.SIGNATURE_VERIFIED
InAppBilling.NULL_DATA
InAppBilling.SIGNATURE_ERROR
InAppBilling.UNKNOWN_NONCE
InAppBilling.PUBLIC\_KEY\_NULL
Event e is fired both from receiving an asynchronous RESPONSE_CODE event and synchronously from each request method.
This event, has 3 properties: first, e.requestId, a double that provides a unique indicator of the response. Second,
e.responseCode, an int response with one of the following possible values:
InAppBilling.RESULT_OK
InAppBilling.RESULT_USER_CANCELED
InAppBilling.RESULT_SERVICE_UNAVAILABLE
InAppBilling.RESULT_BILLING_UNAVAILABLE
InAppBilling.RESULT_ITEM_UNAVAILABLE
InAppBilling.RESULT_DEVELOPER_ERROR
InAppBilling.RESULT_ERROR
Third, e.sync, a boolean value that states whether the event was fired synchronously or not.
See example and Android documentation.
Developed for Appcelerator by Logical Labs Alexander Conway, Logical Labs
View the change log for this module.
Please direct all questions, feedback, and concerns to info@appcelerator.com.
Copyright(c) 2010-2011 by Appcelerator, Inc. All Rights Reserved. Please see the LICENSE file included in the distribution for further details.