Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phonegap plugin for the Amazon's In-App Purchasing SDK #97

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Android/AmazonPhonegap/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
16 changes: 16 additions & 0 deletions Android/AmazonPhonegap/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
gen/

# Local configuration file (sdk path, etc)
local.properties
33 changes: 33 additions & 0 deletions Android/AmazonPhonegap/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>AmazonPhonegap</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
51 changes: 51 additions & 0 deletions Android/AmazonPhonegap/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rahulrav.cordova.amazon"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.RECORD_VIDEO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<receiver android:name="com.amazon.inapp.purchasing.ResponseReceiver" >
<intent-filter>
<action
android:name="com.amazon.inapp.purchasing.NOTIFY"
android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY" />
</intent-filter>
</receiver>
</application>

</manifest>
26 changes: 26 additions & 0 deletions Android/AmazonPhonegap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Amazon In-App Purchasing SDK (Phonegap 2.0 Plugin)
==================================================

This project is a Phonegap 2.0 plugin, for the Amazon Appstore for Android's In-App Purchasing SDK.

To get started:

1. Go to developer.amazon.com, and download the In-App purchasing sdk, and the Amazon SDK Tester.
2. adb install -r AmazonSDKTester.apk (the Amazon Appstore SDK Tester)
3. adb push ./assets/amazon.sdktester.json /mnt/sdcard. (Copy the amazon.sdktester.json file in the assets folder to /mnt/sdcard)
4. git clone this project, and build / run it to play with the plugin.

Here is a screenshot representing the purchase flow.

![Purchase flow screenshot](https://github.com/tikurahul/AmazonInAppPurchasing/raw/master/assets/sdk_purchase.png "Screenshot for the purchase flow")

License (The MIT License)
=========================

Copyright (c) 2012 Rahul Ravikumar

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 changes: 32 additions & 0 deletions Android/AmazonPhonegap/assets/amazon.sdktester.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"consumable" : {
"itemType": "CONSUMABLE",
"price": 0.99,
"title": "Consumable Item",
"description": "This item is a consumable item.",
"smallIconUrl": "http://bit.ly/consumable"
},
"entitled" : {
"itemType": "ENTITLED",
"price": 1.99,
"title": "Entitled Item",
"description": "This is an entitled item",
"smallIconUrl": "http://bit.ly/entitled"
},
"subscription.1month" : {
"itemType" : "SUBSCRIPTION",
"price" : 2.99,
"title": "One month Subscription",
"description": "This is a one month subscription",
"smallIconUrl": "http://bit.ly/subscription.1month",
"subscriptionParent": "subscription"
},
"subscription.6month" : {
"itemType" : "SUBSCRIPTION",
"price" : 12.99,
"title": "6 month Subscription",
"description": "This is a six month subscription",
"smallIconUrl": "http://bit.ly/subscription.1month",
"subscriptionParent": "subscription"
}
}
Binary file added Android/AmazonPhonegap/assets/sdk_purchase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions Android/AmazonPhonegap/assets/web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!DOCTYPE html>

<html>

<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1, target-densitydpi=device-dpi'>
<title>Amazon In-App Purchasing Plugin</title>
<!-- Phonegap -->
<script type='text/javascript' src='js/cordova.js'></script>
<!-- jQuery -->
<script type='text/javascript' src='js/jquery-1.7.2.min.js'></script>
<!-- Amazon Appstore Plugin -->
<script type='text/javascript' src='js/amazonInApp.js'></script>
<script type='text/javascript'>
$(document).on('deviceready', function() {

var $status = $('#status');
console.log('Init complete.');
var inAppPurchasing = new AmazonInAppPurchasing();

inAppPurchasing.initialize(function(response) {
console.log('Initializing In App Purchasing SDK');
// check if the sdk is available
var isSdkAvailable = response['isSdkAvailable'];
$status.append('<p>' + JSON.stringify(response) + '</p>');

$('#purchase').click(function(event) {
console.log('Intitating Purchase request');
if(!isSdkAvailable) {
$status.append('<p>Amazon In-App Purchasing SDK is unavailable.</p>');
} else {
// initiate a purchase
inAppPurchasing.purchase('consumable', function(purchaseResponse) {
$status.append('<p>' + JSON.stringify(purchaseResponse) + '</p>');
}, function(errorResponse) {
$status.append('<p>' + JSON.stringify(errorResponse) + '</p>');
});
}
event.preventDefault();
});


});

});
</script>

</head>

<body>
<h3>Amazon Appstore In-App Purchasing</h3>
<p>
Purchase a consumable item. <br/> <br/>
<input id='purchase' type='button' value='Purchase Consumable' /> <br/>
</p>

<div id='status'>
</div>
</body>
</html>
49 changes: 49 additions & 0 deletions Android/AmazonPhonegap/assets/web/js/amazonInApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
;(function(context) {

var AmazonInAppPurchasing = function() {},
serviceName = 'AmazonInAppPurchasing';

/**
Initializes the in-app purchasing SDK.
*/
AmazonInAppPurchasing.prototype.initialize = function (callback, errback) {
cordova.exec(callback, errback, serviceName, 'initialize', []);
};

/**
Gets the logged in user Amazon Customer Id
*/
AmazonInAppPurchasing.prototype.getUserId = function (callback, errback) {
cordova.exec(callback, errback, serviceName, 'userId', []);
};

/**
Gets the item data given a set of skus
*/
// skus = an array of skus
// e.g. [sku1, sku2]
AmazonInAppPurchasing.prototype.getItemData = function (skus, callback, errback) {
cordova.exec(callback, errback, serviceName, 'itemData', [JSON.stringify(skus)]);
};

/**
Purchases a given sku
*/
// sku represents the sku of the item
AmazonInAppPurchasing.prototype.purchase = function (sku, callback, errback) {
cordova.exec(callback, errback, serviceName, 'purchase', [sku]);
};

/**
Gets the purchase updates since the last offset.
*/
// offset represents the last purchase offset
// if you want to get all purchase updates, make the request with offset = null
AmazonInAppPurchasing.prototype.getPurchaseUpdates = function (offset, callback, errback) {
var args = offset ? [offset] : [];
cordova.exec(callback, errback, serviceName, 'purchaseUpdates', args);
};

context.AmazonInAppPurchasing = AmazonInAppPurchasing;

})(this);
Loading