Samsung In-App Purchase v3.0 Programming...

45
Samsung In-App Purchase v3.0 Programming Guide

Transcript of Samsung In-App Purchase v3.0 Programming...

Page 1: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Samsung In-App Purchase v3.0 Programming Guide

Page 2: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 2

Table of Contents

1. Samsung In-App Purchase................................................................................................................................................. 4

1.1 Introduction .................................................................................................................................................................. 4

1.2 Download IAP 3.0 Helper & Sample ................................................................................................................. 6

1.3 IAP 3 Restrictions........................................................................................................................................................ 6

1.4 IAP 3 Development Mode ..................................................................................................................................... 6

1.5 Supported Product Types ....................................................................................................................................... 8

2. IAP 3 Helper Programming ............................................................................................................................................... 8

2.1 Creating a new Android Project .......................................................................................................................... 8

2.2 Adding IAP Helper ..................................................................................................................................................... 9

2.3 Modifying AndroidManifest.xml .......................................................................................................................... 9

2.4 Developing Functions to Link to IAP ............................................................................................................. 11

2.4.1) Purchase ........................................................................................................................................................ 11

2.4.2) Get Inbox List .............................................................................................................................................. 15

2.4.3) Get Cached Inbox List (Supported since IAP 3.0 Helper) ...................................................... 25

2.4.4) Get Item List ................................................................................................................................................ 28

3. IAP 3 Helper Reference .................................................................................................................................................... 31

3.1 SamsungIapHelper .................................................................................................................................................. 31

3.1.1) getInstance( Context, int )..................................................................................................................... 31

3.1.2) (Deprecated) startPayment( String, String, boolean, OnPaymentListener ) ................... 32

3.1.3) startPayment( String, boolean, OnPaymentListener ) ............................................................... 32

3.1.4) (Deprecated) getItemInboxList( String, int, int, String, String, OnGetInboxListener ) 33

3.1.5) getItemInboxList( int, int, String, String, OnGetInboxListener ) ........................................... 33

3.1.6) getItemInboxList( String, OnGetInboxListener ) .......................................................................... 34

3.1.7) (Deprecated) getItemList( String, int, int, String, int, OnGetItemListener ) .................... 34

3.1.8) getItemList( int, int, String, int, OnGetItemListener ) ................................................................ 34

3.2 Result Callback Interface ...................................................................................................................................... 35

3.2.1) onPaymentListener ................................................................................................................................... 35

3.2.2) onGetInboxListener .................................................................................................................................. 36

3.2.3) OnGetItemListener .................................................................................................................................... 36

3.3 Value Object............................................................................................................................................................... 36

3.3.1) PurchaseVo – Purchase Result Information .................................................................................. 36

3.3.2) ItemVo – Product Information ............................................................................................................ 37

3.3.3) InboxVo – Purchased item information .......................................................................................... 38

3.3.4) ErrorVo – Processed Request Result ................................................................................................ 38

3.3.5) VerificationVo – Payment Validity Test Result .............................................................................. 38

3.4 Response Code ......................................................................................................................................................... 39

4. IAP Server-to-Server API Reference ............................................................................................................................ 40

4.1 appsItemVerifyIAPReceipt .................................................................................................................................... 40

Page 3: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 3

Appendix: Deprecated Content ......................................................................................................................................... 42

A.1) startPayment( String, String, boolean, OnPaymentListener ) ................................................... 42

A.2) getItemInboxList( String, int, int, String, String, OnGetInboxListener ) ............................... 42

A.3) getItemList( String, int, int, String, int, OnGetItemListener ) .................................................... 43

Page 4: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 4

1. Samsung In-App Purchase

1.1 Introduction

Samsung In-App Purchase (IAP) allows third party applications to use the Samsung payment service to offer items for sale inside your app. Version 1 linked the payment service to the application using a jar library while version 2 onwards provides the service as an Android package to ensure independence between applications. IAP communicates with third party applications by means of the Android Interface Definition Language (AIDL) beginning with version 2.

This method has numerous advantages, but requires specialized skills in Android to manage various processes, including linking the IAP service, linking Samsung accounts, and running the IAP package validity test.

In order to link more conveniently with IAP, a separate Helper class is provided. The following picture depicts the linking process between a third party application and IAP via the IAP Helper class.

Figure 1: IAP Service Architecture

The third party application simply calls the method of the SamsungIapHelper class and processes the final result. The actual source code for a purchase request in IAP is as follows.

public class PurchaseActivity extends Activity implements OnPaymentListener { private SamsungIapHelper mIapHelper = null; ... protected void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState );

Page 5: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 5

setContentView( R.layout.activity_main ); mIapHelper = SamsungIapHelper.getInstance( this, MODE ); } public void doPurchase( View _view ) { mIapHelper.startPayment(ITEM_ID, true, this ); } @Override public void onPayment( ErrorVo _errorVo, PurchaseVo _purchaseVo ) { // Success or failure of payment is processed here. }

... }

Code 1: IAP Purchase Request

IAP Version 3 is the latest release. The new features in Version 3 are as follows:

1. Supports Auto-Recurring Subscriptions

A non-recurring subscription expires when its period has passed, while auto-recurring subscriptions allow app developers to sell in-app items every month with automated and recurring billing.

2. ItemGroupId (Deprecated) ItemGroupId has been used to separate third party application and is created as 12 digits by GALAXY Apps. But it was difficult to manage each application with ItemGroupId. So ItemGroupId is replaced by PackageName of third party application in IAP Version 3. As a result, ItemGroupId is deprecated in all methods of IAP Helper.

3. Support Custom Item ID For product item ID, 12 digits that are created arbitrarily by GALAXY Apps has been used. But it was not easy to distinguish each item ID, and this item ID was not convenient for managing. Now, IAP Version 3 supports the use of a custom item ID like “GUN”, “machinegun”, “bullet”, and so on.

4. Method to get Cached Inbox List New method to get cached inbox list is added in IAP Version 3. The original method to get inbox list gets all purchased item list by setting index and date as parameters. This new method gets the purchased item list just for specified product item IDs. Also, this new method gets faster response because client caching is supported.

IAP Helper now supports these features. If you’ve used IAP version 2, check for these minor changes:

1. The term "IAP Library" used in IAP Version 2 was changed to "IAP Helper".

2. The package names of IAP Helper and included Sample were changed from "com.sec.android.iap" to "com.samsung.android.sdk.iap".

3. The development environment of the IAP SDK was changed from Eclipse to Android Studio.

Page 6: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 6

1.2 Download IAP 3.0 Helper & Sample

Download the following IAP SDK from the IAP section of the Samsung Developer site:

SamsungInAppPurchaseSDK_v3.x.x.zip

The zipped file includes the sample source code in the table below, which uses the IAP 3.0 Helper.

Number Location Project Description

1 ./Libs AIDL Interface AIDL Interface to link with IAP3.0

2 ./Sample/IAP3Helper IAP3Helper Helper project to link with IAP3.0

(Include AIDL Interface)

3 ./Sample/IAP3Sample IAP3Sample Sample application project using

IAP3Helper

Table 1: SDK components in SamsungInAppPurchaseSDK_v3.x.x.zip

Android Studio 1.1.0 is the standard development environment.

1.3 IAP 3 Restrictions

IAP supports Android API 14 or higher, and will not run properly on older versions. Also, IAP only runs properly on Samsung Electronics devices and will not work with devices from other manufacturers. Aside from these, there are no other restrictions.

1.4 IAP 3 Development Mode

Due to charges that may occur, the IAP payment service is difficult to test. IAP, however, offers three modes to test the service under various conditions.

Mode Value Description

Production Mode 0

This is the mode for production. When releasing your

application, the service must be set to production mode. The

actual payment process occurs only in production mode.

Developer

Test Mode (Success) 1 This test mode always returns successful results.

Developer

Test Mode (Failure) -1 This test mode always returns failed results.

Table 2: Production/Development Modes for IAP Testing

The mode can be set as a parameter when you get an instance with getInstance() of the Helper to purchase an item.

Page 7: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 7

During the development period, it is recommended you test your application sufficiently under various conditions by setting the mode to 1 or -1, which always returns successful or failed results, respectively.

NOTE: Before releasing your application, you must change to production mode. If you release your application in test mode, actual payments will not occur.

Occasionally, applications are released in test mode. In this case, IAP displays the pop-up message that the mode setting is in Developer mode as shown below. If this pop-up appears, please check the mode.

Figure 2: Developer Mode Popup

Page 8: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 8

1.5 Supported Product Types

IAP 3 supports the following product types:

Product Type Description

Consumable If you purchase a product of this type and use it, it is consumed. These products can be repurchased. Example: Consumable products such as bullets in games.

NonConsumable

Once purchased, you can use a product of this type permanently. These products cannot be repurchased. Example: Non-consumable products, such as books, that do not need to be repurchased. Note: Non-consumable product cannot be tested for repurchase. However, repeated testing is available in test mode (1), not in the production mode (0), to repurchase every 10 minutes by initializing the mode.

Non-Recurring Subscription (Short-term)

Once a certain period has passed after a product purchase, these products can be repurchased. Example: Products that can be repurchased after a certain period such as monthly magazines and vouchers with expiration dates.

Auto-Recurring Subscriptions

Auto-Recurring Subscriptions let app developers sell in-app items every month with automated and recurring billing.

All All includes all four types stated above.

Table 3: IAP Product Types

2. IAP 3 Helper Programming

Follow these steps to use the IAP payment service:

1. Create a new Android project.

2. Add the IAP Helper project.

3. Modify AndroidManifest.xml.

4. Develop functionality to link to IAP.

Android Studio 1.1.0 is the development environment used in this guide.

2.1 Creating a new Android Project

In this section you will create a new project for an application that uses IAP.

1. Select File > New Project. The New Android Application screen appears where you can create a new Android application.

2. For this example, the application name is IAP3Sample, and the package name is iap3helper.sample.example. You can choose your own names. After naming, click Next and select API 14 or higher for Minimum SDK.

Page 9: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 9

Caution: Because the application is separated by PackageName instead of ItemGroupID since IAP 3.0, PackageName of the application that has been registered in GALAXY Apps must be specified to test IAP without any errors.

3. And then, click Next again, select Blank Activity, and click Next.

4. Use the default names for the activity name and the layout name, then click Finish to create the new project.

2.2 Adding IAP Helper

Here’s how to add the IAP Helper project to IAP3Sample which you just created:

1. Select IAP3Sample project in the Project Explorer and right-click on IAP3Sample project. Select New > Module.

Select Import Existing Project and click Next and then browse to the IAP3Helper folder in Source Directory and click Finish to add it.

2. Select IAP3Sample project again in the Project Explorer and right-click on IAP3Sample project. Select Open Module Settings to open the Project Structure screen.

You can also open the Project Structure screen by pressing F4.

3. In the Project Structure screen, select IAP3Sample Modules and click the Dependencies tab and then click the + button.

Then you can open up the Choose Modules screen. Select IAP3Helper and click Ok to add it in the Choose Modules screen.

2.3 Modifying AndroidManifest.xml

AndroidManifest privileges and Activity addition, which is introduced in this section, should not be altered. It is best to copy and paste them as needed to prevent changes. They are included as annotations to the AndroidManifest.xml file in the IAP Helper.

2.3.1) Adding Privileges

In order to link to IAP, the com.sec.android.iap.permission.BILLING privilege is required. The android.permission.INTERNET privilege is also needed, as IAP uses network communication. Add privileges to AndroidManifest.xml as follows:

<uses-permission android:name="com.sec.android.iap.permission.BILLING"/> <uses-permission android:name="android.permission.INTERNET"/>

Code 2: Required Manifest Permissions

2.3.2) Adding Activities Included in IAP Helper

IAP Helper communicates with third party applications through transparent activities. Therefore, you must add the three activities below to AndroidManifest.xml.

Page 10: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 10

Activity Name Description

com.samsung.android.sdk.iap.lib.activity.InboxActivity

Activity to request purchased item list

com.samsung.android.sdk.iap.lib.activity.PaymentActivity

Activity to request payment

com.samsung.android.sdk.iap.lib.activity.ItemActivity

Activity to request product item list

Table 4: IAP Activities to Include in the Android Manifest

<activity android:name="com.samsung.android.sdk.iap.lib.activity.InboxActivity" android:theme="@style/Theme.Empty" android:configChanges="orientation|screenSize"/> <activity android:name="com.samsung.android.sdk.iap.lib.activity.PaymentActivity" android:theme="@style/Theme.Empty" android:configChanges="orientation|screenSize"/> <activity android:name="com.samsung.android.sdk.iap.lib.activity.ItemActivity" android:theme="@style/Theme.Empty" android:configChanges="orientation|screenSize"/>

Code 3: IAP Activities in Android Manifest

Caution: Due to the transparency requirements of the three activities, the

activities are set at android:theme=”@style/Theme.Empty.” If you do not select a transparent theme, these activities will conceal your application.

Page 11: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 11

2.4 Developing Functions to Link to IAP

2.4.1) Purchase

To add a purchase button to the layout, add the highlighted code to activity_main.xml. When the purchase button is clicked, it calls the doPurchase method.

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp" > <!-- Purchase Button --> <Button android:id="@+id/btn_purchase_one_item" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/purchase_one_item"

android:onClick="doPurchase"/> </LinearLayout>

Code 4: Code for a Purchase Button

In MainActivity.java, the code to request payment to IAP using the doPurchase method is highlighted in sample Code 5:

public class MainActivity extends Activity implements OnPaymentListener { private static final int MODE = SamsungIapHelper.IAP_MODE_COMMERCIAL;

// Please change the ITEM_ID for your application. // ======================================================================== private static final String ITEM_ID = " Nuclear"; // ======================================================================== private SamsungIapHelper mIapHelper = null; @Override protected void onCreate( Bundle savedInstanceState ) { super.onCreate(savedInstanceState); setContentView( R.layout.activity_main ); mIapHelper = SamsungIapHelper.getInstance( this, MODE ); } public void doPurchase( View _view ) { mIapHelper.startPayment( ITEM_ID, true, this ); } @Override public void onPayment( ErrorVo _errorVo, PurchaseVo _purchaseVo )

Page 12: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 12

{ // Success or failure of payment is processed here. } }

Code 5: Requesting Payment in MainActivity.java

In this code segment, the payment request is sent to IAP in just one line within the doPurchase method. SamsungIapHelper is created in the onCreate method, and the startPayment method is called in the doPurchase method. The third argument in the startPayment method is an OnPaymentListener, which is the interface for the callback onPayment method that receives payment results. Because the activity above implements OnPaymentListener, “this” is inserted as an argument.

The initialization process has been simplified and is now managed within the IAP Helper; only the payment result enters the onPayment interface.

NOTE: startPayment( String,String, Boolean, OnPaymentListener ) has been deprecated.

Instead, use: startPayment( String, boolean, OnPaymentListener ) Method OnPaymentListener Interface

To display the PurchaseVo value when the payment succeeds in the onPayment method, add the following code. If the application can successfully or failed to handle payment is also on the following code.

@Override

public void onPayment( ErrorVo _errorVo, PurchaseVo _purchaseVo ) { AlertDialog.Builder alert = new AlertDialog.Builder( this ); alert.setPositiveButton( android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog, int which ) { dialog.dismiss(); } }); if( _errorVo != null ) { // If Payment is finished Successfully // ================================================================ if( _errorVo.getErrorCode() == SamsungIapHelper.IAP_ERROR_NONE ) { alert.setTitle( _errorVo.getErrorString() ); alert.setMessage( _purchaseVo.dump() );

Page 13: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 13

} // ================================================================ // If Payment is failed // ================================================================ else { alert.setTitle( "ERROR" ); alert.setMessage( _errorVo.getErrorString() ); } // ================================================================ } else { alert.setTitle( "ERROR" ); alert.setMessage( "ErrorVo is null" ); } alert.show(); }

Code 6: Code for displaying PurchaseVo

Page 14: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 14

This is all the coding required to set up purchasing. If you run the code, the Main screen appears.

Test the code by performing these steps:

1. Click Purchase One Item on the Main screen. The Confirm Password screen appears to verify your Samsung account.

2. Enter your password.

3. Click Confirm. The payment method screen, which allows you to select payment options, appears.

4. Select the payment method.

5. Click Buy. The IAP purchase process does the rest.

Figure 3: Purchasing an Item Using IAP

Page 15: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 15

When the payment and purchase are successful, the following confirmation appears:

Figure 4: Payment Confirmation

NOTE: IAP Helper provides Client-to-Server Verification by default to prevent any malicious purchases. For safer transactions, Server-to-Server Verification is a better choice. For more information on Server-to-Server Verification, please refer to 4. IAP Server-to-Server API Reference.

2.4.2) Get Inbox List

To get your purchased item list, you will need the following code. This is similar to the purchase request coding process. Add InboxListActivity to the code, and display the inbox list with ListView.

First, add a button to run InboxListActivity beneath the Purchase One Item button in the layout defined by activity_main.xml layout, and set it to call the doGetInboxList method when clicked.

<!-- InboxList Button --> <Button android:id="@+id/btn_get_inbox_list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="InboxList"

Page 16: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 16

android:onClick="doGetInBoxList" />

Code 7: A Button that Runs InBoxListActvity

Next, implement the doGetInboxList method as shown in the following MainActivity.java. This code sets the required information in the intent and runs InboxListActivity.

public void doGetInBoxList( View _view ) { Date d = new Date(); SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMdd", Locale.getDefault() ); String today = sdf.format( d ); Intent intent = new Intent( MainActivity.this, InboxListActivity.class ); intent.putExtra( "IapMode", MODE ); intent.putExtra( "StartNum", 1 ); intent.putExtra( "EndNum", 15 ); intent.putExtra( "StartDate", "20130101" ); intent.putExtra( "EndDate", today ); startActivity( intent );

}

Code 8: doGetInBoxList Method

When a user clicks the InboxList button, the onCreate method in InboxListActivity saves the values transferred to the intent, and requests the inbox list from IAP based on the transferred values:

public class InboxListActivity extends Activity implements OnGetInboxListener { private int mIapMode = 1; private int mStartNum = 0; private int mEndNum = 0; private String mStartDate = ""; private String mEndDate = ""; private SamsungIapHelper mIapHelper = null; @Override protected void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); Intent intent = getIntent(); if( intent != null && intent.getExtras() != null && intent.getExtras().containsKey( "IapMode" ) && intent.getExtras().containsKey( "StartNum" ) && intent.getExtras().containsKey( "EndNum" ) && intent.getExtras().containsKey( "StartDate" ) && intent.getExtras().containsKey( "EndDate" ) ) {

Page 17: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 17

Code 9: Requesting the Inbox List from IAP

The code may look complicated; however, it is just the code to save the transferred values. In fact, only the two highlighted lines correspond to the request to get the inbox list from IAP. Like the purchase request, the final results are obtained using the onGetItemInbox method in the onGetInboxListener interface. When you run the code, you cannot verify the result’s visibly because there is no code in onGetItemInbox. However, you can verify that your application is actually linked to IAP and that the result is transferred to onGetItemInbox.

NOTE: getItemInboxList( String, int, int, String, String, OnGetInboxListener) has been deprecated.

Instead, use: getItemInboxList( int, int, String, String, OnGetInboxListener ) Method OnPaymentListener Interface Caution: getItemInboxList returns a list of all purchased items regardless of development mode.

Bundle extras = intent.getExtras(); mIapMode = extras.getInt( "IapMode" ); mStartNum = extras.getInt( "StartNum" ); mEndNum = extras.getInt( "EndNum" ); mStartDate = extras.getString( "StartDate" ); mEndDate = extras.getString( "EndDate" ); } else { Toast.makeText( this, R.string.invalid_parameter,

Toast.LENGTH_LONG ).show(); finish(); } mIapHelper = SamsungIapHelper.getInstance( this, mIapMode ); mIapHelper.getItemInboxList( mStartNum, mEndNum, mStartDate, mEndDate, this ); } @Override public void onGetItemInbox ( ErrorVo _errorVo, ArrayList<InboxVo> _inboxList ) {

} }

Page 18: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 18

InboxListActivity must be added to AndroidManifest.xml as follows:

Code 10: Adding InBoxListActivity to AndroidManifest.xml

Next, add data to the Listview in the onGetItemInbox method. First, add the code below to the onCreate method in InboxListActivity. This code offers views in the Activity and initializes the views.

Code 11: Add to the onCreate method in InboxListActivity

The inbox_list_layout.xml file is as shown below.

Code 12: inbox_list_layout.xml

The initView method is as shown here:

<activity android:name=".InboxListActivity" android:label="@string/items_inbox_list" > </activity>

setContentView( R.layout.inbox_list_layout ); initView();

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp" android:orientation="vertical"> <!-- Item Inbox List ListView --> <ListView android:id="@+id/itemInboxList" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:visibility="gone"/> <!-- Item Inbox List NULL --> <TextView android:id="@+id/noDataText" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text=" @string/items_inbox_list_is_empty"/> </LinearLayout>

public void initView() {

Page 19: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 19

Code 13: The InitView Method

Next, add the member parameters below to the InboxListActivity.

Code 14: Member Parameters for InboxListActivity

You can see mInboxListAdapter in the code above. The AdapterView offers a view for each row of the ListView. Further explanation of mInboxListAdapter is beyond the scope of this guide and is not discussed here. InboxListAdapter is as shown below.

mInboxListView = (ListView)findViewById( R.id.itemInboxList ); mNoDataTextView = (TextView)findViewById( R.id.noDataText ); mNoDataTextView.setVisibility( View.GONE ); mInboxListView.setEmptyView( mNoDataTextView ); mInboxListAdapter = new InboxListAdapter( this, R.layout.inbox_row, mInboxList ); mInboxListView.setAdapter( mInboxListAdapter );

}

private ListView mInboxListView = null; private TextView mNoDataTextView = null;

private ArrayList<InboxVo> mInboxList = new ArrayList<InboxVo>(); private InboxListAdapter mInboxListAdapter = null;

public class InboxListAdapter extends ArrayAdapter<InboxVo> { private int mResId = 0; private LayoutInflater mInflater = null; private ArrayList<InboxVo> mItems = null; public InboxListAdapter ( Context _context, int _resId, ArrayList<InboxVo> _items ) { super( _context, _resId, _items ); mResId = _resId; mItems = _items; mInflater = (LayoutInflater)_context.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); } public static class ViewHolder { TextView itemName; TextView itemPriceString; TextView itemType;

Page 20: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 20

TextView paymentId; TextView purchaseDate; TextView expireDate; } @Override public View getView ( final int _position, View _convertView, final ViewGroup _parent ) { final InboxVo vo = mItems.get( _position ); ViewHolder vh; View v = _convertView; if( v == null ) { vh = new ViewHolder(); v = mInflater.inflate( mResId, null ); vh.itemName = (TextView)v.findViewById( R.id.itemName ); vh.itemPriceString = (TextView)v.findViewById( R.id.itemPriceString ); vh.itemType = (TextView)v.findViewById( R.id.itemType ); vh.paymentId = (TextView)v.findViewById( R.id.paymentId ); vh.purchaseDate = (TextView)v.findViewById( R.id.purchaseDate ); vh.expireDate = (TextView)v.findViewById( R.id.expireDate ); v.setTag( vh ); } else { vh = (ViewHolder)v.getTag(); } vh.itemName.setText( vo.getItemName() ); vh.itemPriceString.setText( vo.getItemPriceString() ); String itemType = "Type : "; if( true == "00".equals( vo.getType() ) ) { itemType += "Consumable"; vh.expireDate.setVisibility( View.GONE ); } else if( true == "01".equals( vo.getType() ) ) { itemType += "NonConsumable"; vh.expireDate.setVisibility( View.GONE ); } else if( true == "02".equals( vo.getType() ) ) { itemType += "Subscription"; vh.expireDate.setVisibility( View.VISIBLE ); }

Page 21: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 21

Code 15: InBoxListAdapter

It was mentioned previously that InboxAdapter creates a view for each row of the Listview. The code for the column layout of each view is as shown below. The file name is inbox_row.xml. This file name is transferred as an argument when InboxAdapter is created in the initView method introduced previously.

else if( true == "03".equals( vo.getType() ) ) { itemType += "Auto Recurring Subscription"; vh.expireDate.setVisibility( View.GONE ); } else { itemType += "Unsupported type"; vh.expireDate.setVisibility( View.GONE ); } vh.itemType.setText( itemType ); vh.paymentId.setText( "Payment ID : " + vo.getPaymentId() ); vh.purchaseDate.setText( "Purchase Date : " + vo.getPurchaseDate() ); vh.expireDate.setText( "Expire Date : " + vo.getSubscriptionEndDate() ); return v; } }

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="8dp" android:paddingLeft="12dp" android:paddingRight="12dp" android:paddingTop="8dp" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:id="@+id/itemName" android:layout_width="0dp" android:layout_height="wrap_content" android:lineSpacingExtra="8dp" android:singleLine="true" android:ellipsize="end" android:textSize="14dp" android:textStyle="bold" android:gravity="center_vertical|left" android:layout_weight="1" />

Page 22: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 22

Code 16: Defining List Views in inbox_row.xml

<TextView android:id="@+id/itemPriceString" android:layout_width="wrap_content" android:layout_height="wrap_content" android:lineSpacingExtra="8dp" android:singleLine="true" android:ellipsize="end" android:textSize="14dp" android:textStyle="bold" android:gravity="center_vertical|right" android:layout_marginLeft="10dp" android:layout_weight="0" /> </LinearLayout> <TextView android:id="@+id/itemType" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="end" android:textSize="10dp" android:gravity="center_vertical|left"/> <TextView android:id="@+id/paymentId" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="end" android:textSize="10dp" android:gravity="center_vertical|left"/> <TextView android:id="@+id/purchaseDate" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="end" android:textSize="10dp" android:gravity="center_vertical|left"/> <TextView android:id="@+id/expireDate" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="end" android:textSize="10dp" android:textColor="#FF0000" android:gravity="center_vertical|left"/> </LinearLayout>

Page 23: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 23

Finally, the onGetItemInbox method to handle the result is implemented as shown below.

Code 17: onGetItemInbox Method

The code above adds _inboxList to mInboxList. _inboxList is generated as a result when the Inbox request is processed successfully. It also notifies mInboxListAdapter that data is revised and updates the ListView.

When you run the code, you can see the screen below to verify the inbox list that a user has purchased.

@Override public void onGetItemInbox ( ErrorVo _errorVo, ArrayList<InboxVo> _inboxList ) { if( _errorVo != null && _errorVo.getErrorCode() == SamsungIapHelper.IAP_ERROR_NONE ) { if( _inboxList != null && _inboxList.size() > 0 ) { mInboxList.addAll( _inboxList ); mInboxListAdapter.notifyDataSetChanged(); } } }

Page 24: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 24

Figure 5: InboxList Displayed

Page 25: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 25

2.4.3) Get Cached Inbox List (Supported since IAP 3.0 Helper)

A new method to get the cached inbox list has been added in IAP 3.0 Helper. The method mentioned in the previous section to get inbox list gets all purchased item list by setting index and date as parameters. This new method gets the purchased item list just for specified product item IDs.

This new method gets a much faster response because client caching is supported.

To create an example using this method, add to the InboxListAdapter.java, inbox_list_layout.xml, and inbox_row.xml files that were used in the previous section.

First, add a button to run CachedInboxListActivity beneath the Purchase One Item button in the activity_main.xml layout, and set it to call the doGetCachedInboxList method when clicked.

<!-- Cached InboxList Button --> <Button android:id="@+id/btn_get_cached_inbox_list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/load_cached_items_inbox_list"

android:onClick="doGetCachedInBoxList" />

Code 18: Code for CashedInboxListActivity

Next, specify new items in MainActivity.java as shown below.

private static final String ITEM_IDS = " Nuclear, Claymore, " + " Blockbuster";

Code 19: Adding New Items

Implement the doGetCachedInboxList method as shown below in MainActivity.java. This code sets the required information in the intent and runs CachedInboxListActivity.

public void doGetCachedInBoxList( View _view ) { Intent intent = new Intent( MainActivity.this, CachedInboxListActivity.class ); intent.putExtra( "IapMode", MODE ); intent.putExtra( "ItemIds", ITEM_IDS ); startActivity( intent );

}

Code 20: The doGetChashedInboxList Method

Create CachedInboxListActivity class by adding the following code:

public class CachedInboxListActivity extends Activity

implements OnGetInboxListener

Page 26: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 26

{ private int mIapMode = 1; private String mItemIds = ""; private SamsungIapHelper mIapHelper = null; private ListView mInboxListView = null; private TextView mNoDataTextView = null; private ArrayList<InboxVo> mInboxList = new ArrayList<InboxVo>(); private InboxListAdapter mInboxListAdapter = null; @Override protected void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); setContentView( R.layout.inbox_list_layout ); initView(); Intent intent = getIntent(); if( intent != null && intent.getExtras() != null && intent.getExtras().containsKey( "IapMode" ) && intent.getExtras().containsKey( "ItemIds" ) ) { Bundle extras = intent.getExtras(); mIapMode = extras.getInt( "IapMode" ); mItemIds = extras.getString( "ItemIds" ); } else { Toast.makeText( this, R.string.invalid_parameter, Toast.LENGTH_LONG ).show(); finish(); } mIapHelper = SamsungIapHelper.getInstance( this, mIapMode ); mIapHelper.getItemInboxList( mItemIds, this ); } public void initView() { mInboxListView = (ListView)findViewById( R.id.itemInboxList ); mNoDataTextView = (TextView)findViewById( R.id.noDataText ); mNoDataTextView.setVisibility( View.GONE ); mInboxListView.setEmptyView( mNoDataTextView ); mInboxListAdapter = new InboxListAdapter( this, R.layout.inbox_row, mInboxList ); mInboxListView.setAdapter( mInboxListAdapter );

Page 27: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 27

Code 21: CachedInboxListActivity

The code is almost identical to the previous section, except the parameters of getItemInboxList in the highlighted area are different.

NOTE: getItemInboxList( String, OnGetInboxListener ) Method OnGetInboxListener Interface Caution: getItemInboxList returns a list of all purchased items regardless of development mode.

Finally, add CachedInboxListActivity to AndroidManifest.xml as shown:

Code 22: Adding CachedInboxListActivity to the Android Manifest

} @Override public void onGetItemInbox ( ErrorVo _errorVo, ArrayList<InboxVo> _inboxList ) { if( _errorVo != null && _errorVo.getErrorCode() == SamsungIapHelper.IAP_ERROR_NONE ) { if( _inboxList != null && _inboxList.size() > 0 ) { mInboxList.addAll( _inboxList ); mInboxListAdapter.notifyDataSetChanged(); } } } }

<activity android:name=".CachedInboxListActivity" android:label="@string/cached_items_inbox_list" > </activity>

Page 28: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 28

When you run the code, you can see the following screen. As mentioned earlier, loading inbox list will be faster after first loading because client caching is supported:

Figure 6: Item List

2.4.4) Get Item List

Finally, add the code to get the item list. It is good to display the item list similar to the inbox list in ListView format. In order to remain true to the actual function, it is implemented similar to the purchase request code.

Add a button to get the item list for activity_main.xml as shown below. When this button is clicked, the doGetItemList method is called.

Code 23: Adding a Get Item List Button

Add the code as shown below to the doGetItemList method. You can simply call the

<!-- Get Item List Button --> <Button

android:id="@+id/btn_get_item_list" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/load_item_list"

android:onClick="doGetItemList"/>

Page 29: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 29

getItemList method of SamsungIapHelper.

Code 24: Code to add to doGetItemList

Next, add the OnGetItemListener interface in “implements” of the MainActivity class definition as follows.

Code 25: Adding the OnGetItemListener Interface

Implement the callback onGetItem method in the OnGetItemListener interface. The code below displays the results in AlertDialog when the final results are received.

public void doGetItemList( View _view ) { if( mIapHelper == null ) { mIapHelper = SamsungIapHelper.getInstance( this, MODE ); } mIapHelper.getItemList( 1, 15, "00", MODE, this ); }

public class MainActivity extends Activity

implements OnPaymentListener, OnGetItemListener {

@Override

public void onGetItem( ErrorVo _errorVo, ArrayList<ItemVo> _itemList ) { AlertDialog.Builder alert = new AlertDialog.Builder( this ); alert.setPositiveButton( android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { dialog.dismiss(); } catch( Exception e ) { e.printStackTrace(); } } }); if( _errorVo != null ) { if( _errorVo.getErrorCode() == SamsungIapHelper.IAP_ERROR_NONE ) { alert.setTitle( R.string.item_list ); String message = "";

Page 30: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 30

Code 26: Code for displaying AlertDialog

When you run this example, the item list is displayed in the AlertDialog. An error message will be displayed in the AlertDialog if the code fails to run. As shown below, the item list can be displayed in a list format using the ListView and AdapterView similar to the _inboxList.

for( ItemVo vo : _itemList ) { message += vo.dump() + "\n" + "--------------------------------------" + "\n"; } alert.setMessage( message ); } else { alert.setTitle( R.string.item_list ); alert.setMessage( _errorVo.getErrorString() ); } } else { alert.setTitle( R.string.item_list ); alert.setMessage( "ErrorVo is null" ); } try { alert.show(); } catch( Exception e ) { e.printStackTrace(); } }

Page 31: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 31

Figure 7: Item List from AlertDialog

IAP3Sample downloaded from 1.2 Download IAP 3.0 Helper & Sample includes an example that displays items in a list format using the ListView and AdapterView.

NOTE: getItemList( String, int, int, String, int, OnGetItemListener ) Method has been deprecated.

Instead, use: getItemList( int, int, String, int, OnGetItemListener ) Method OnGetItemListener Interface

3. IAP 3 Helper Reference

3.1 SamsungIapHelper

The IAP Helper provides a total of three methods for purchase, inbox list, and item list. These three methods are embedded in SamsungIapHelper.

3.1.1) getInstance( Context, int )

This method returns the SamsungIapHelper object as a singleton.

Page 32: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 32

Code 27: getInstance

Parameters

Parameter Type Description

_context Context Android Context

_mode int

IAP Development Mode 0: Production Mode 1: Developer Test Mode (Returned results are true every time) -1: Developer Test Mode (Returned results are false every time)

Table 5: getInstance Parameters

Returned Value

SamsungIapHelper

3.1.2) (Deprecated) startPayment( String, String, boolean, OnPaymentListener )

This has been deprecated, instead use 3.1.3) startPayment( String, boolean, OnPaymentListener ). For more information, see A.1) startPayment( String, String, boolean, OnPaymentListener ).

3.1.3) startPayment( String, boolean, OnPaymentListener )

This method requests a purchase and is added to replace deprecated startPayment since IAP 3.0 because itemGroupId has been replaced by PackageName.

Code 28: startPayment

Parameters

Parameter Type Description

_itemId String The product ID value.

_showSuccessDialog boolean If the value is true, the IAP dialog is displayed

public static SamsungIapHelper getInstance( Context _context, int _mode )

public void startPayment ( String _itemId, boolean _showSuccessDialog, OnPaymentListener _onPaymentListener )

Page 33: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 33

after a successful payment. If false, the dialog is not displayed. If false in a third party application, the result must be displayed after a successful payment.

_onPaymentListener onPaymentListener This interface defines the onPayment() callback method that notifies the payment results to third party applications.

Table 6: startPayment Parameters

3.1.4) (Deprecated) getItemInboxList( String, int, int, String, String, OnGetInboxListener )

This is a deprecated method, instead use 3.1.5) getItemInboxList( int, int, String, String, OnGetInboxListener ) For more information, see A.2) getItemInboxList( String, int, int, String, String, OnGetInboxListener ).

3.1.5) getItemInboxList( int, int, String, String, OnGetInboxListener )

This method gets the purchased item list and is added to replace deprecated getItemInBoxList since IAP 3.0 because itemGroupId has been replaced by PackageName.

Code 29: getItemInboxList

Parameters

Parameter Type Description

_startNum int The start number of the requested inbox list. Caution: The start number is 1, not 0.

_endNum int

The end number of the requested inbox list. Caution: The start number is 1, not 0. Example: If _startNum = 1 and _endNum = 15, the inbox list from no. 1 to 15 is requested.

_startDate String The start date of the requested inbox list. Example: “20131031”

_endDate String The end date of the requested inbox list. Example: “20131031”

public void getItemInboxList ( int _startNum, int _endNum, String _startDate, String _endDate, OnGetInboxListener _onGetInboxListener )

Page 34: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 34

_onGetInboxListener onGetInboxListener This interface defines the onGetItemInbox() callback method that transfers the results of the inbox list request to third party applications.

Table 7: getItemInboxList Parameters

3.1.6) getItemInboxList( String, OnGetInboxListener )

This method gets the purchased item list from specified product items and is new since IAP 3.0. This new method gets a much faster response because it supports client caching.

Code 30: getItemInboxList (2)

Parameters

Parameter Type Description

_itemIds String The product IDs. Multiple IDs can be used with a comma between as follows. Example : "000000057507, 000000057508, 000000057509”

_onGetInboxListener onGetInboxListener This interface defines the onGetItemInbox() callback method that transfers the results of the inbox list request to third party applications.

Table 8: getItemInboxList Parameters (2)

3.1.7) (Deprecated) getItemList( String, int, int, String, int, OnGetItemListener )

This has been deprecated, instead use 3.1.8) getItemList( int, int, String, int, OnGetItemListener ). For more information, see

A.3) getItemList( String, int, int, String, int, OnGetItemListener ).

3.1.8) getItemList( int, int, String, int, OnGetItemListener )

This method gets the product item list and is added to replace deprecated getItemList since IAP 3.0 because itemGroupId has been replaced by PackageName.

public void getItemInboxList (

String _itemIds, OnGetInboxListener _onGetInboxListener

)

public void getItemList (

Page 35: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 35

Code 31: getItemList

Parameters

Parameter Type Description

_startNum int The start number of the requested inbox list. Caution: The start number is 1, not 0.

_endNum int

The end number of the requested inbox list. Caution: The start number is 1, not 0. Example: If _startNum = 1 and _endNum = 15, the inbox list from no. 1 to 15 is requested.

_itemType String

Type of Item 00: Consumable (Consumable product) 01: NonConsumable (Nonconsumable product) 02: Subscription (Short-term product) 03: Auto-Recurring Subscriptions Supported type since IAP 3.0 10: All (All types)

_mode int

IAP Development Mode 0: Production Mode 1: Developer Test Mode (Returned result is always success) -1: Developer Test Mode (Returned result is always failure)

_onGetItemListener onGetItemListener This interface defines the onGetItem() callback method that transfers the results of the item list request to 3rd party applications.

Table 9: getItemList Parameters

3.2 Result Callback Interface

3.2.1) onPaymentListener

This interface defines the callback method that is called when an IAP payment is completed.

void onPayment( ErrorVo _errorVo, PurchaseVo _purchaseVo );

Code 32: onPayment

int _startNum, int _endNum, String _itemType, int _mode, OnGetItemListener _onGetItemListener )

Page 36: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 36

Parameters

Parameter Type Description

_errorVo ErrorVo Request results (Refer to 3.3 Value Object) _purchaseVo PurchaseVo Purchase results (Refer to 3.3 Value Object)

Table 10: onPaymentListener Parameters

3.2.2) onGetInboxListener

This is the interface for the callback method that is called when the inbox list request is completed.

void onGetItemInbox( ErrorVo _errorVO, ArrayList<InboxVo> _inboxList );

Code 33: OnGetInBoxListener

Parameters

Parameter Type Description

_errorVo ErrorVo Request results (Refer to 3.3 Value Object) _inboxList ArrayList<InboxVo> Purchased item list (Refer to 3.3 Value Object)

Table 11: OnGetInBoxListener Parameters

3.2.3) OnGetItemListener

This interface defines the callback method that is called when the item list request is completed.

void onGetItem( ErrorVo _errorVo, ArrayList<ItemVo> _itemList );

Code 34: onGetItemListener

Parameters

Parameter Type Description

_errorVo ErrorVo Request results (Refer to 3.3 Value Object) _itemList ArrayList<ItemVo> Item list (Refer to 3.3 Value Object)

Table 12: onGetItemListener Parameters

3.3 Value Object

3.3.1) PurchaseVo – Purchase Result Information

Member Variable Type Description

mItemId String Product ID

mItemName String Product name

mItemPrice Double Product price

Page 37: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 37

Example: 7.99

mItemPriceString String Currency sign + product price Example: €7.99

mCurrencyUnit String Currency sign Example: €, £, $

mCurrencyCode String ISO 4217 Currency code Example: EUR, GBP, USD

mItemDesc String Product description

mItemImageUrl String Product image URL

mItemDownloadUrl String Product download URL

mPaymentId String Payment ID

mPurchaseId String Purchase ID

mPurchaseDate String Purchase date (in millisecond)

mVerifyUrl String IAP server URL to verify that the validity of the

purchase using the mPurchaseId value.

mJsonString String Original JSON String

Table 13: PurchaseVO Purchase Result Info

3.3.2) ItemVo – Product Information

Member Variable Type Description

mItemId String Product ID

mItemName String Product name

mItemPrice Double Product price Example: 7.99

mItemPriceString String Currency sign + product price Example: €7.99

mCurrencyUnit String Currency sign Example: €, £, $

mCurrencyCode String ISO 4217 Currency code Example: EUR, GBP, USD

mItemDesc String Product description

mItemImageUrl String Product image URL

mItemDownloadUrl String Product download URL

mType String

Product type 00: Consumable (Consumable product) 01: NonConsumable (Nonconsumable product) 02: Subscription (Short-term product) 03: Auto-Recurring Subscriptions

mSubscriptionDurationUnit String

If the product type is subscription, this is the unit for the validity period of the product. Available units are YEAR, MONTH, WEEK, and DAY. The units should be in capital letters.

Page 38: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 38

mSubscriptionDurationMultiplier

String

If the product type is subscription, this is the product duration. Combined with mSubscriptionDurationUnit, it is expressed as 1MONTH.

mJsonString String Original JSON String

Table 14: ItemVO Product Info

3.3.3) InboxVo – Purchased item information

Member Variable Type Description

mItemId String Product ID

mItemName String Product name

mItemPrice Double Product price Example: 7.99

mItemPriceString String Currency sign + product price Example: €7.99

mCurrencyUnit String Currency sign Example: €, £, $

mCurrencyCode String ISO 4217 Currency code Example: EUR, GBP, USD

mItemDesc String Product description

mItemImageUrl String Product image URL

mItemDownloadUrl String Product download URL

mType String

Product type 00: Consumable (Consumable product) 01: NonConsumable (Nonconsumable product) 02: Subscription (Short-term product) 03: Auto-Recurring Subscriptions

mPaymentId String Payment ID

mPurchaseId String Purchase ID

mPurchaseDate String Purchased date (in millisecond)

mSubscriptionEndDate String If the product type is subscription, this is the expiration date of the product. This is returned as a long type.

mJsonString String Original JSON String

Table 15: InboxVO Purchased Item Info

3.3.4) ErrorVo – Processed Request Result

Member Variable Type Description

mErrorCode Int Response code ( Refer to 3.4 Response Code )

mErrorString String Error message

mExtraString String Additional information about the results

Table 16: ErrorVO Prcoessed Request Result

Page 39: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 39

3.3.5) VerificationVo – Payment Validity Test Result

Member Variable Type Description

mItemId String Product ID mItemName String Product name

mItemDesc String Product description

mPurchaseDate String Purchase date (in millisecond)

mPaymentId String Payment ID

mPaymentAmount String Total payment amount

mStatus String Validity test result

Table 17: VerificationVo Payment Validity Test Result

3.4 Response Code

Response Code Code Value Description

IAP_ERROR_NONE 0 Success IAP_PAYMENT_IS_CANCELED 1 Payment canceled IAP_ERROR_INITIALIZATION -1000 Failure during IAP initialization

IAP_ERROR_NEED_APP_UPGRADE -1001 IAP upgrade is required IAP_ERROR_COMMON -1002 Error while running IAP

IAP_ERROR_ALREADY_PURCHASED -1003

Error when a non-consumable product is repurchased or a subscription product is repurchased before the product expiration date.

IAP_ERROR_WHILE_RUNNING -1004 Error when payment is requested without bundle information.

IAP_ERROR_PRODUCT_DOES_NOT_EXIST -1005 Error when the requested item list is not available.

IAP_ERROR_CONFIRM_INBOX -1006

If the payment result is not received after requesting payment to the server, the purchased item list should be confirmed because the payment may have occurred successfully. This error message appears in this situation.

IAP_ERROR_ITEM_GROUP_DOES_NOT_EXIST -1007 Error when item group ID does not exist. IAP_ERROR_NETWORK_NOT_AVAILABLE -1008 Error when network is not available. IAP_ERROR_IOEXCEPTION_ERROR -1009 IOException

IAP_ERROR_SOCKET_TIMEOUT -1010 SocketTimeoutException IAP_ERROR_CONNECT_TIMEOUT -1011 ConnectTimeoutException IAP_ERROR_NOT_EXIST_LOCAL_PRICE -1012 The Item is not for sale in the country IAP_ERROR_NOT_AVAILABLE_SHOP -1013 IAP is not serviced in the country

Table 18: Response Codes

Page 40: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 40

Page 41: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 41

4. IAP Server-to-Server API Reference

This section explains server-to-server verification in IAP. IAP allows a third party server to verify the validity of a purchase, which prevents any malicious purchases.

4.1 appsItemVerifyIAPReceipt

verifyUrl (URL to verify the validity of a purchase) in IAP uses the fixed value below.

In IAP, a purchaseId is returned as a part of the results of a purchase request.

In third party client applications, the purchaseId is sent to your server. In your server, you can request the validity of the purchase in the URL format shown below using the verifyUrl and the purchaseId value.

The IAP server sends the results in JSON format as shown below.

4.1.1) When the Purchase Is Valid

Code 35: Valid Puchase Results

verifyUrl : https://iap.samsungapps.com/iap/appsItemVerifyIAPReceipt.as?protocolVersion=2.0

purchaseId : d215d9abcd17b12578a21c0ea7d8821747b64939732a3243b538d8bcae245590

https://iap.samsungapps.com/iap/appsItemVerifyIAPReceipt.as?protocolVersion=2.0&purchaseID=d

215d9abcd17b12578a21c0ea7d8821747b64939732a3243b538d8bcae245590

{ "itemId" : "57515", "paymentId":"ZPMTID20131122GBI0015292", "itemName":"Test Pack", "itemDesc":"IAP Test Item. Best value!", "purchaseDate":"2013-11-22 04:22:36", "paymentAmount":"9.000",

"status":"true", "paymentMethod":"CreditCard", "mode":"REAL", }

Page 42: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 42

4.1.2) When the Purchase Is Not Valid

Code 36: Invalid Purchase Results

4.1.3) Description of Result Values

Name Type Description

itemId String Product ID itemName String Product name itemDesc String Product description paymentId String Payment ID purchaseDate String Purchase date paymentAmount String Total payment amount status String true / false

paymentMethod String

This explains the payment option selected when purchasing a product. Example: CreditCard, MobileMicroPurchase, PrepaidCard, PSMS, CarrierBilling, etc.

mode String This is the development mode selected when purchasing a product. Example: TEST, REAL

Table 19: Result Value Descriptions

{"status":"false"}

Page 43: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 43

Appendix: Deprecated Content

This section contains items that may have been used in IAP versions 1.0 and 2.0, but have been deprecated in IAP 3.0. They are supplied here for reference.

A.1) startPayment( String, String, boolean, OnPaymentListener )

This method requests a purchase.

public void startPayment ( String _itemGroupId, String _itemId, boolean _showSuccessDialog, OnPaymentListener _onPaymentListener )

Parameters

Parameter Type Description

_itemGroupId String

This is the ID value of the group that a product belongs to and is issued through GALAXY Apps. GALAXY Apps issues this ID for each application to link to IAP. This parameter is not used since IAP 3.0 because PackageName of third party application is used instead. This is maintained for backward compatibility.

_itemId String The product ID value

_showSuccessDialog booelan

If the value is true, the IAP dialog is displayed after a successful payment. If false, the dialog is not displayed. If false in a third party application, the result must be displayed after a successful payment.

_onPaymentListener onPaymentListener This interface defines the onPayment() callback method that notifies the payment results to third party applications.

Table A-1

A.2) getItemInboxList( String, int, int, String, String, OnGetInboxListener )

This method gets the purchased item list and is deprecated since IAP 3.0. getItemInboxList( int, int,

String, String, OnGetInboxListener ) method is recommended to use instead of this method.

Page 44: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 44

Parameters

Parameter Type Description

_itemGroupId String

This is the ID value of the group that a product belongs to and is issued through GALAXY Apps. GALAXY Apps issues this ID for each application to link to IAP. This parameter is not used since IAP 3.0 because PackageName of third party application is used instead. This is maintained for backward compatibility.

_startNum int The start number of the requested inbox list. Caution: The start number is 1, not 0.

_endNum int

The end number of the requested inbox list. Caution: The start number is 1, not 0. Example: If _startNum = 1 and _endNum = 15, the inbox list from no. 1 to 15 is requested.

_startDate String The start date of the requested inbox list. Example: “20131031”

_endDate String The end date of the requested inbox list. Example: “20131031”

_onGetInboxListener onGetInboxListener This interface defines the onGetItemInbox() callback method that transfers the results of the inbox list request to third party applications.

Table A-2

A.3) getItemList( String, int, int, String, int, OnGetItemListener ) This method gets the product item list and is deprecated since IAP 3.0. The getItemList( int, int, String, int, OnGetItemListener ) method is recommended to use instead of this method.

public void getItemInboxList ( String _itemGroupId, int _startNum, int _endNum, String _startDate, String _endDate, OnGetInboxListener _onGetInboxListener )

Page 45: Samsung In-App Purchase v3.0 Programming Guidedeveloper.samsung.com/html/...SamsungInAppPurchaseSDK_v3.0.0(… · Samsung In-App Purchase ... Download the following IAP SDK from the

Copyright © Samsung Electronics Co., Ltd. All rights reserved. Page 45

public void getItemList ( String _itemGroupId, int _startNum, int _endNum, String _itemType, int _mode, OnGetItemListener _onGetItemListener )

Parameters

Parameter Type Description

_itemGroupId String

This is the ID value of the group that a product belongs to and is issued through GALAXY Apps. GALAXY Apps issues this ID for each application to link to IAP. This parameter is not used since IAP 3.0 because PackageName of third party application is used instead. This is maintained for backward compatibility.

_startNum int The start number of the requested inbox list. Caution: The start number is 1, not 0.

_endNum int

The end number of the requested inbox list. Caution: The start number is 1, not 0. Example: If _startNum = 1 and _endNum = 15, the inbox list from no. 1 to 15 is requested.

_itemType String

Type of Item 00: Consumable (Consumable product) 01: NonConsumable (Nonconsumable product) 02: Subscription (Short-term product) 03: Auto-Recurring Subscriptions Supported type since IAP 3.0 10: All (All types)

_mode int

IAP Development Mode 0: Production Mode 1: Developer Test Mode (Returned result is always success) -1: Developer Test Mode (Returned result is always failure)

_onGetItemListener

onGetItemListener This interface defines the onGetItem() callback method that transfers the results of the item list request to third party applications.

Table A-3