Added Payment One APK demonstration sample

This commit is contained in:
Timo Reunanen 2014-02-20 11:48:47 +02:00
Родитель 2c38018e50
Коммит 085e79804f
19 изменённых файлов: 1148 добавлений и 0 удалений

8
.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,8 @@
.gradle
build/
.idea/
*.ipr
*.iws
*.iml
out/
local.properties

5
PaymentOneAPK/.classpath Normal file
Просмотреть файл

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/>
</classpath>

33
PaymentOneAPK/.project Normal file
Просмотреть файл

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PaymentOneAPK</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>

Просмотреть файл

@ -0,0 +1,4 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.source=1.6

Просмотреть файл

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nokia.example.paymentoneapk"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="com.android.vending.BILLING"/>
<uses-permission android:name="com.nokia.payment.BILLING"/>
<application android:label="@string/app_name"
android:icon="@drawable/niap_samples_icon"
android:allowBackup="false"
>
<activity android:name=".PaymentOneAPKActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

40
PaymentOneAPK/License.txt Executable file
Просмотреть файл

@ -0,0 +1,40 @@
Copyright © 2014 Nokia Corporation. All rights reserved.
Nokia, Nokia Developer, and HERE are trademarks and/or registered trademarks of
Nokia Corporation. Other product and company names mentioned herein may be
trademarks or trade names of their respective owners.
License
Subject to the conditions below, you may use, copy, modify and/or merge copies
of this software and associated content and documentation files (the “Software”)
to test, develop, publish, distribute, sub-license and/or sell new software
derived from or incorporating the Software, solely in connection with Nokia
devices. Some of the documentation, content and/or software maybe licensed under
open source software or other licenses. To the extent such documentation,
content and/or software are included, licenses and/or other terms and conditions
shall apply in addition and/or instead of this notice. The exact terms of the
licenses, disclaimers, acknowledgements and notices are reproduced in the
materials provided, or in other obvious locations. No other license to any other
intellectual property rights is granted herein.
This file, unmodified, shall be included with all copies or substantial portions
of the Software that are distributed in source code form.
The Software cannot constitute the primary value of any new software derived
from or incorporating the Software.
Any person dealing with the Software shall not misrepresent the source of the
Software.
Disclaimer
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, QUALITY AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES (INCLUDING,
WITHOUT LIMITATION, DIRECT, SPECIAL, INDIRECT, PUNITIVE, CONSEQUENTIAL,
EXEMPLARY AND/ OR INCIDENTAL 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.
Nokia Corporation retains the right to make changes to this document at any
time, without notice.

27
PaymentOneAPK/README.md Normal file
Просмотреть файл

@ -0,0 +1,27 @@
Payment One APK
===============
Simple demonstration application to show how to have Nokia IAP and Google IAB in same application
Building with Eclipse
---------------------
1. Import project
2. Clean build
3. Run
Building with Gradle wrapper
----------------------------
###### Linux & OS X
```
$ ./gradlew installDebug
```
###### Windows
```
C:\PaymentOneAPK> gradlew installDebug
```

Просмотреть файл

@ -0,0 +1,49 @@
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 16
buildToolsVersion "18.1.1"
buildTypes {
release {
runProguard false
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}

Двоичные данные
PaymentOneAPK/gradle/wrapper/gradle-wrapper.jar поставляемый Normal file

Двоичный файл не отображается.

6
PaymentOneAPK/gradle/wrapper/gradle-wrapper.properties поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.9-all.zip

164
PaymentOneAPK/gradlew поставляемый Executable file
Просмотреть файл

@ -0,0 +1,164 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >&-
APP_HOME="`pwd -P`"
cd "$SAVED" >&-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

90
PaymentOneAPK/gradlew.bat поставляемый Normal file
Просмотреть файл

@ -0,0 +1,90 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

Двоичные данные
PaymentOneAPK/res/drawable-hdpi/niap_samples_icon.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 9.5 KiB

Просмотреть файл

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2014 Nokia Corporation and/or its subsidiary(-ies).
See the license text file delivered with this project for more information.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Simple demo to demonstrate how to use Google IAB and Nokia IAP in same APK"
android:id="@+id/textView" android:layout_gravity="center_horizontal" android:paddingLeft="32dp"
android:paddingRight="32dp" android:layout_marginTop="32dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Buy"
android:id="@+id/buy" android:layout_gravity="center_horizontal" android:layout_marginTop="32dp"
android:layout_marginBottom="32dp"/>
</LinearLayout>

Просмотреть файл

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2014 Nokia Corporation and/or its subsidiary(-ies).
See the license text file delivered with this project for more information.
-->
<resources>
<string name="app_name">Payment One APK</string>
</resources>

Просмотреть файл

@ -0,0 +1,144 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.vending.billing;
import android.os.Bundle;
/**
* InAppBillingService is the service that provides in-app billing version 3 and beyond.
* This service provides the following features:
* 1. Provides a new API to get details of in-app items published for the app including
* price, type, title and description.
* 2. The purchase flow is synchronous and purchase information is available immediately
* after it completes.
* 3. Purchase information of in-app purchases is maintained within the Google Play system
* till the purchase is consumed.
* 4. An API to consume a purchase of an inapp item. All purchases of one-time
* in-app items are consumable and thereafter can be purchased again.
* 5. An API to get current purchases of the user immediately. This will not contain any
* consumed purchases.
*
* All calls will give a response code with the following possible values
* RESULT_OK = 0 - success
* RESULT_USER_CANCELED = 1 - user pressed back or canceled a dialog
* RESULT_BILLING_UNAVAILABLE = 3 - this billing API version is not supported for the type requested
* RESULT_ITEM_UNAVAILABLE = 4 - requested SKU is not available for purchase
* RESULT_DEVELOPER_ERROR = 5 - invalid arguments provided to the API
* RESULT_ERROR = 6 - Fatal error during the API action
* RESULT_ITEM_ALREADY_OWNED = 7 - Failure to purchase since item is already owned
* RESULT_ITEM_NOT_OWNED = 8 - Failure to consume since item is not owned
*/
interface IInAppBillingService {
/**
* Checks support for the requested billing API version, package and in-app type.
* Minimum API version supported by this interface is 3.
* @param apiVersion the billing version which the app is using
* @param packageName the package name of the calling app
* @param type type of the in-app item being purchased "inapp" for one-time purchases
* and "subs" for subscription.
* @return RESULT_OK(0) on success, corresponding result code on failures
*/
int isBillingSupported(int apiVersion, String packageName, String type);
/**
* Provides details of a list of SKUs
* Given a list of SKUs of a valid type in the skusBundle, this returns a bundle
* with a list JSON strings containing the productId, price, title and description.
* This API can be called with a maximum of 20 SKUs.
* @param apiVersion billing API version that the Third-party is using
* @param packageName the package name of the calling app
* @param skusBundle bundle containing a StringArrayList of SKUs with key "ITEM_ID_LIST"
* @return Bundle containing the following key-value pairs
* "RESPONSE_CODE" with int value, RESULT_OK(0) if success, other response codes on
* failure as listed above.
* "DETAILS_LIST" with a StringArrayList containing purchase information
* in JSON format similar to:
* '{ "productId" : "exampleSku", "type" : "inapp", "price" : "$5.00",
* "title : "Example Title", "description" : "This is an example description" }'
*/
Bundle getSkuDetails(int apiVersion, String packageName, String type, in Bundle skusBundle);
/**
* Returns a pending intent to launch the purchase flow for an in-app item by providing a SKU,
* the type, a unique purchase token and an optional developer payload.
* @param apiVersion billing API version that the app is using
* @param packageName package name of the calling app
* @param sku the SKU of the in-app item as published in the developer console
* @param type the type of the in-app item ("inapp" for one-time purchases
* and "subs" for subscription).
* @param developerPayload optional argument to be sent back with the purchase information
* @return Bundle containing the following key-value pairs
* "RESPONSE_CODE" with int value, RESULT_OK(0) if success, other response codes on
* failure as listed above.
* "BUY_INTENT" - PendingIntent to start the purchase flow
*
* The Pending intent should be launched with startIntentSenderForResult. When purchase flow
* has completed, the onActivityResult() will give a resultCode of OK or CANCELED.
* If the purchase is successful, the result data will contain the following key-value pairs
* "RESPONSE_CODE" with int value, RESULT_OK(0) if success, other response codes on
* failure as listed above.
* "INAPP_PURCHASE_DATA" - String in JSON format similar to
* '{"orderId":"12999763169054705758.1371079406387615",
* "packageName":"com.example.app",
* "productId":"exampleSku",
* "purchaseTime":1345678900000,
* "purchaseToken" : "122333444455555",
* "developerPayload":"example developer payload" }'
* "INAPP_DATA_SIGNATURE" - String containing the signature of the purchase data that
* was signed with the private key of the developer
* TODO: change this to app-specific keys.
*/
Bundle getBuyIntent(int apiVersion, String packageName, String sku, String type,
String developerPayload);
/**
* Returns the current SKUs owned by the user of the type and package name specified along with
* purchase information and a signature of the data to be validated.
* This will return all SKUs that have been purchased in V3 and managed items purchased using
* V1 and V2 that have not been consumed.
* @param apiVersion billing API version that the app is using
* @param packageName package name of the calling app
* @param type the type of the in-app items being requested
* ("inapp" for one-time purchases and "subs" for subscription).
* @param continuationToken to be set as null for the first call, if the number of owned
* skus are too many, a continuationToken is returned in the response bundle.
* This method can be called again with the continuation token to get the next set of
* owned skus.
* @return Bundle containing the following key-value pairs
* "RESPONSE_CODE" with int value, RESULT_OK(0) if success, other response codes on
* failure as listed above.
* "INAPP_PURCHASE_ITEM_LIST" - StringArrayList containing the list of SKUs
* "INAPP_PURCHASE_DATA_LIST" - StringArrayList containing the purchase information
* "INAPP_DATA_SIGNATURE_LIST"- StringArrayList containing the signatures
* of the purchase information
* "INAPP_CONTINUATION_TOKEN" - String containing a continuation token for the
* next set of in-app purchases. Only set if the
* user has more owned skus than the current list.
*/
Bundle getPurchases(int apiVersion, String packageName, String type, String continuationToken);
/**
* Consume the last purchase of the given SKU. This will result in this item being removed
* from all subsequent responses to getPurchases() and allow re-purchase of this item.
* @param apiVersion billing API version that the app is using
* @param packageName package name of the calling app
* @param purchaseToken token in the purchase information JSON that identifies the purchase
* to be consumed
* @return 0 if consumption succeeded. Appropriate error values for failures.
*/
int consumePurchase(int apiVersion, String packageName, String purchaseToken);
}

Просмотреть файл

@ -0,0 +1,242 @@
/**
* Copyright (c) 2014 Nokia Corporation and/or its subsidiary(-ies).
* See the license text file delivered with this project for more information.
*/
package com.nokia.example.paymentoneapk;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.*;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.android.vending.billing.IInAppBillingService;
import com.nokia.payment.iap.aidl.INokiaIAPService;
import java.util.ArrayList;
public class PaymentOneAPKActivity extends Activity {
private static final String TAG = PaymentOneAPKActivity.class.getCanonicalName();
private final PaymentOneAPKService mService = new PaymentOneAPKService();
private final ArrayList<String> productSkus = new ArrayList<String>(10);
private Button buyButton;
@Override
public void onCreate(final Bundle savedInstanceState) {
Log.d(TAG, "com.nokia.IABinAll.MyActivity.onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
buyButton = (Button) findViewById(R.id.buy);
buyButton.setEnabled(false);
buyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
launchPurchase("android.test.purchased", "inapp", 1234, "");
}
});
final Intent intent = mService.getServiceIntent(this);
bindService(intent, serviceConn, Context.BIND_AUTO_CREATE);
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "com.nokia.example.paymentoneapk.PaymentOneActivity.onActivityResult");
Log.d(TAG, "requestCode = " + requestCode);
Log.d(TAG, "resultCode = " + resultCode);
Toast.makeText(this, "Item purchased", 1500).show();
consumeTestProduct();
}
@Override
protected void onDestroy() {
super.onDestroy();
}
private void mapProductsSkus() {
productSkus.add("android.test.purchased");
Bundle productMappings = new Bundle();
productMappings.putString("1023608", "android.test.purchased");
try {
mService.mapProducts(3, getPackageName(), productMappings);
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void launchPurchase(final String sku, final String itemType, final int requestCode,
final String extraData) {
Log.d(TAG, "com.nokia.example.paymentoneapk.PaymentOneActivity.launchPurchase");
try {
final Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(), sku, itemType, extraData);
final int response = buyIntentBundle.getInt("RESPONSE_CODE");
if (response != 0) {
Log.e(TAG, "error while buying. response=" + response);
toastMessage("Got an error while buying: " + response);
return;
}
final PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
Log.d(TAG, "pendingIntent = " + pendingIntent);
startIntentSenderForResult(
pendingIntent.getIntentSender(), requestCode, new Intent(), 0, 0, 0
);
} catch (final RemoteException e) {
e.printStackTrace();
toastMessage("Got an exception while guying");
} catch (final IntentSender.SendIntentException e) {
e.printStackTrace();
toastMessage("Got an exception while guying");
}
}
public void consumeTestProduct() {
Log.d(TAG, "com.nokia.example.paymentoneapk.PaymentOneActivity.consumeProduct");
new Thread(new Runnable() {
@Override
public void run() {
try {
mService.consumePurchase(
3, getPackageName(), "inapp:" + getPackageName() + ":android.test.purchased"
);
} catch (RemoteException e) {
Log.e(TAG, "error while consuming", e);
toastMessage("Got an exception while consuming");
return;
}
toastMessage("Item consumed");
}
}).start();
}
private void checkIfBillingIsSupported() {
Log.d(TAG, "com.nokia.example.paymentoneapk.PaymentOneActivity.checkIfBillingIsSupported");
new Thread(new Runnable() {
@Override
public void run() {
try {
int result = mService.isBillingSupported(3, getPackageName(), "inapp");
if (result != 0) {
toastMessage("Billing is not supported.");
Log.d(TAG, "result = " + result);
return;
}
buyButton.setEnabled(true);
queryProductDetails();
} catch (RemoteException e) {
Log.e(TAG, "error while isBillingSupported", e);
toastMessage("Got an exception while consuming");
}
}
}).start();
}
private void queryProductDetails() {
Log.d(TAG, "com.nokia.example.paymentoneapk.PaymentOneActivity.queryProductDetails");
final Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", productSkus);
new Thread(new Runnable() {
@Override
public void run() {
final Bundle skuDetails;
try {
skuDetails = mService.getSkuDetails(3, getPackageName(), "inapp", querySkus);
} catch (final RemoteException e) {
Log.e(TAG, "query error", e);
return;
}
final int response = skuDetails.getInt("RESPONSE_CODE");
Log.d(TAG, "response = " + response);
if (response != 0) {
toastMessage("Got invalid response while doing query: " + response);
return;
}
final ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");
for (final String resp : responseList) {
Log.d(TAG, "resp = " + resp);
}
toastMessage("Item query done");
}
}).start();
}
protected void toastMessage(final String message) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(PaymentOneAPKActivity.this, message, 1500).show();
}
});
}
final ServiceConnection serviceConn = new ServiceConnection() {
@Override
public void onServiceConnected(final ComponentName name, final IBinder service) {
Log.d(TAG, "com.nokia.example.paymentoneapk.PaymentOneActivity.onServiceConnected");
mService.setService(PaymentOneAPKActivity.this, service);
mapProductsSkus();
checkIfBillingIsSupported();
}
@Override
public void onServiceDisconnected(final ComponentName name) {
}
};
}

Просмотреть файл

@ -0,0 +1,135 @@
/**
* Copyright (c) 2014 Nokia Corporation and/or its subsidiary(-ies).
* See the license text file delivered with this project for more information.
*/
package com.nokia.example.paymentoneapk;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import com.android.vending.billing.IInAppBillingService;
import com.nokia.payment.iap.aidl.INokiaIAPService;
import java.util.List;
@SuppressWarnings("StaticNonFinalField")
public class PaymentOneAPKService {
public static final String NOKIA_NIAP = "com.nokia.payment.iapenabler";
private static final String TAG = PaymentOneAPKService.class.getCanonicalName();
private IInAppBillingService googleIABService = null;
private INokiaIAPService nokiaIAPService = null;
private static boolean isNokiaIAPValueCached = false;
private static boolean isNokiaIAPInstalled = false;
private boolean useGoogleBilling = false;
public static boolean isNokiaNIAPAvailable(final Context context) {
if (isNokiaIAPValueCached) {
return isNokiaIAPInstalled;
}
final PackageManager packageManager = context.getPackageManager();
final List<PackageInfo> allPackages = packageManager.getInstalledPackages(0);
isNokiaIAPValueCached = true;
for (final PackageInfo packageInfo : allPackages) {
if (NOKIA_NIAP.equals(packageInfo.packageName)) {
Log.d(TAG, "Nokia IAP found");
isNokiaIAPInstalled = true;
return true;
}
}
isNokiaIAPInstalled = false;
return false;
}
public int isBillingSupported(final int apiVersion, final String packageName, final String type)
throws RemoteException {
return useGoogleBilling
? googleIABService.isBillingSupported(apiVersion, packageName, type)
: nokiaIAPService.isBillingSupported(apiVersion, packageName, type);
}
public Bundle getBuyIntent(final int apiVersion, final String packageName, final String sku,
final String type, final String developerPayload) throws RemoteException {
return useGoogleBilling
? googleIABService.getBuyIntent(apiVersion, packageName, sku, type, developerPayload)
: nokiaIAPService.getBuyIntent(apiVersion, packageName, sku, type, developerPayload);
}
public Bundle getSkuDetails(final int apiVersion, final String packageName, final String type,
final Bundle skusBundle) throws RemoteException {
return useGoogleBilling
? googleIABService.getSkuDetails(apiVersion, packageName, type, skusBundle)
: nokiaIAPService.getProductDetails(apiVersion, packageName, type, skusBundle);
}
public int consumePurchase(final int apiVersion, final String packageName, final String purchaseToken)
throws RemoteException {
return useGoogleBilling
? googleIABService.consumePurchase(apiVersion, packageName, purchaseToken)
: nokiaIAPService.consumePurchase(apiVersion, packageName, null, purchaseToken);
}
public void mapProducts(final int apiVersion, final String packageName, final Bundle productMap)
throws RemoteException {
if (!useGoogleBilling) {
nokiaIAPService.setProductMappings(apiVersion, packageName, productMap);
}
}
public void useGoogleIAB(final IInAppBillingService service) {
useGoogleBilling = true;
googleIABService = service;
}
public void useNokiaIAP(final INokiaIAPService service) {
useGoogleBilling = false;
nokiaIAPService = service;
}
public void setService(final Context context, final IBinder service) {
if (PaymentOneAPKService.isNokiaNIAPAvailable(context)) {
useNokiaIAP(INokiaIAPService.Stub.asInterface(service));
} else {
useGoogleIAB(IInAppBillingService.Stub.asInterface(service));
}
}
public Intent getServiceIntent(final Context context) {
return PaymentOneAPKService.isNokiaNIAPAvailable(context)
? new Intent("com.nokia.payment.iapenabler.InAppBillingService.BIND")
: new Intent("com.android.vending.billing.InAppBillingService.BIND");
}
}

Просмотреть файл

@ -0,0 +1,140 @@
/*
Copyright (C) 2013 Nokia Corporation. All rights reserved.
*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
*
http://www.apache.org/licenses/LICENSE-2.0
*
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.nokia.payment.iap.aidl;
import android.os.Bundle;
/**
* All calls will give a response code with the following possible values<br/><br/>
* RESULT_OK = 0 - success<br/>
* RESULT_USER_CANCELED = 1 - user pressed back or canceled a dialog<br/>
* RESULT_BILLING_UNAVAILABLE = 3 - this billing API version is not supported for the type requested or billing is otherwise impossible<br/>
* RESULT_ITEM_UNAVAILABLE = 4 - requested ProductID is not available for purchase<br/>
* RESULT_DEVELOPER_ERROR = 5 - invalid arguments provided to the API<br/>
* RESULT_ERROR = 6 - Fatal error during the API action<br/>
* RESULT_ITEM_ALREADY_OWNED = 7 - Failure to purchase since item is already owned<br/>
* RESULT_ITEM_NOT_OWNED = 8 - Failure to consume since item is not owned<br/>
* RESULT_NO_SIM = 9 - Billing is not available because there is no SIM card inserted<br/>
*<br/>
* Only supported itemtype, other values result in RESULT_DEVELOPER_ERROR<br/>
* ITEM_TYPE_INAPP = "inapp";<br/>
*/
interface INokiaIAPService {
/**
* Checks support for the requested billing API version, package and in-app type.
* @param apiVersion the billing version which the app is using
* @param packageName the package name of the calling app
@param type must always be "inapp"
* @return RESULT_OK(0) on success, corresponding result code on failures
*/
int isBillingSupported(int apiVersion, String packageName, String type );
/**
* Provides details of a list of products<br/>
* Given a list of Productids of a valid type in the productBundle, this returns a bundle
* with a list JSON strings containing the productId, price, title and description.
* This API can be called with a maximum of 20 Productids.
* @param apiVersion billing API version that the Third-party is using
* @param packageName the package name of the calling app
* @param type must always be "inapp"
* @param productBundle bundle containing a StringArrayList of Productids with key "ITEM_ID_LIST", when setProductMappings has been called this parameter can be null
* @return Bundle containing the following key-value pairs<br/>
* "RESPONSE_CODE" with int value, RESULT_OK(0) if success, other response codes on
* failure as listed above.<br/>
* "DETAILS_LIST" with a StringArrayList containing purchase information
* in JSON format similar to:<br/>
<br/>
* '{ "productId" : "1264321", "isvalid", true, "title" : "Product title",<br/>
* "shortdescription" : "Short description of the product", <br/>
* "description" : "Longer description of the product", "priceValue" : "3.00",<br/>
* "price" : "$3.00", "currency", "USD",<br/>
* "purchaseToken" : "ZXlKMlpYSWlPaUl4TGpBaUxDSjBlRzVKWkNJNklrNVFRVmxmVkVWVFZGOVVXRTVmTVRFeE1TSXNJbkJ5YjJSSlpDSTZJakV3TWpNMk1qUWlmUT09",<br/>
* "taxesincluded": true, "restorable" : true, "type" : "inapp" }'<br/><br/>
* or if requested productId is not valid then<br/>
* ''{ "productId" : "invalidproductid", "isvalid", false }'<br/>
*/
Bundle getProductDetails(int apiVersion, String packageName, String type, in Bundle productBundle);
/**
* Returns a pending intent to launch the purchase flow for an in-app item by providing a ProductID,
* the type, a unique purchase token and an optional developer payload.
* @param apiVersion billing API version that the app is using
* @param packageName package name of the calling app
* @param productId the ProductID of the in-app item as published in the developer console or as mapped through setProductMappings
* @param type must always be "inapp"
* @param developerPayload optional argument to be sent back with the purchase information
* @return Bundle containing the following key-value pairs<br/><br/>
* "RESPONSE_CODE" with int value, RESULT_OK(0) if success, other response codes on
* failure as listed above.<br/>
* "BUY_INTENT" - PendingIntent to start the purchase flow
*
* The Pending intent should be launched with startIntentSenderForResult. When purchase flow
* has completed, the onActivityResult() will give a resultCode of OK or CANCELED.<br/><br/>
* If the purchase is successful, the result data will contain the following key-value pairs<br/><br/>
* "RESPONSE_CODE" with int value, RESULT_OK(0) if success, other response codes on
* failure as listed above.<br/>
* "INAPP_PURCHASE_DATA" - String in JSON format similar to<br/><br/>
* '{"orderId":"X393XDAFFDAFAD",<br/>
* "packageName":"com.your.app",<br/>
* "productId":"1264321",<br/>
* "purchaseToken" : "ZXlKMlpYSWlPaUl4TGpBaUxDSjBlRzVKWkNJNklrNVFRVmxmVkVWVFZGOVVXRTVmTVRFeE1TSXNJbkJ5YjJSSlpDSTZJakV3TWpNMk1qUWlmUT09",<br/>
* "developerPayload":"" }'<br/><br/>
* "INAPP_DATA_SIGNATURE" - currently empty string<br/>
*/
Bundle getBuyIntent(int apiVersion, String packageName, String productID, String type,
String developerPayload);
/**
* Returns the current products associated with current imei
* @param apiVersion billing API version that the app is using
* @param packageName package name of the calling app
* @param type must always be "inapp"
* @param productBundle bundle containing a StringArrayList of Productids with key "ITEM_ID_LIST", when setProductMappings has been called this parameter can be null
* @param continuationToken - currently ignored
* @return Bundle containing the following key-value pairs<br/>
* "RESPONSE_CODE" with int value, RESULT_OK(0) if success, other response codes on
* failure as listed above.<br/>
* "INAPP_PURCHASE_ITEM_LIST" - StringArrayList containing the list of owned products<br/>
* "INAPP_PURCHASE_DATA_LIST" - StringArrayList containing for each owned product json string
* similar to following (please note that delveloperPayload field is currently empty):<br/><br/>
* { "productId":"1264321",<br/>
* "purchaseToken" : "ZXlKMlpYSWlPaUl4TGpBaUxDSjBlRzVKWkNJNklrNVFRVmxmVkVWVFZGOVVXRTVmTVRFeE1TSXNJbkJ5YjJSSlpDSTZJakV3TWpNMk1qUWlmUT09",<br/>
* "developerPayload":"" }<br/>
*/
Bundle getPurchases(int apiVersion, String packageName, String type, in Bundle productBundle, String continuationToken );
/**
* Consume the last purchase of the given product. This will result in this item being removed
* from all subsequent responses to getPurchases() and allow re-purchase of this item.
* @param apiVersion billing API version that the app is using
* @param packageName package name of the calling app
* @param productId productId of purchase to be consumed, this argument can be empty or null
* @param purchaseToken token in the purchase information JSON that identifies the purchase
* to be consumed
* @return 0 if consumption succeeded. Appropriate error values for failures.
*/
int consumePurchase(int apiVersion, String packageName, String productId, String purchaseToken);
/**
* Set mapping between nokia productid-s and application internal productid-s
* @param apiVersion billing API version that the app is using
* @param packageName package name of the calling app
* @param mappingsBundle - bundle containing mapping as key, value pairs where key is Nokia productid and value is calling applications internal id
*/
int setProductMappings( int apiVersion, String packageName, in Bundle mappingsBundle );
}