Skip to content

Commit

Permalink
Merge remote-tracking branch 'github_origin/ThreeOne' into github_san…
Browse files Browse the repository at this point in the history
…dbox_threeone
  • Loading branch information
spiridon-alexandru committed Jun 11, 2012
2 parents 4b71853 + 11fb9b5 commit 0aefbfa
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 83 deletions.
2 changes: 2 additions & 0 deletions examples/cpp/PurchaseExample/ApplicationController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @brief The controller that handles all purchase related
* The controller is responsible for updating the UI with all
* purchase events.
* @author Emma Tresanszki
*/

#include <maapi.h>
Expand All @@ -43,6 +44,7 @@ mMainScreen(NULL)

// Set Android public key.
PurchaseManager::getInstance()->setPublicKey(DEVELOPER_PUBLIC_KEY);
PurchaseManager::getInstance()->setStoreURL(sAppStoreSandboxURL);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion examples/cpp/PurchaseExample/ApplicationController.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @brief The controller that handles all purchase related
* The controller is responsible for updating the UI with all
* purchase events.
* @author Emma Tresanszki
*/

#ifndef APPLICATIONCONTROLLER_H_
Expand All @@ -33,7 +34,6 @@
#include <Purchase/Purchase.h>
#include <Purchase/PurchaseListener.h>
#include <Purchase/PurchaseManager.h>
#include <Purchase/PurchaseManagerListener.h>
#include <Purchase/Receipt.h>

using namespace NativeUI;
Expand Down
2 changes: 1 addition & 1 deletion examples/cpp/PurchaseExample/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ MA 02110-1301, USA.
*
* It is a basic example that demonstrates how to purchase
* a product and how to get the receipt for it.
* @author Emma Tresanszki
*/

#include <ma.h> // Syscalls
#include <MAUtil/String.h> // C++ String class
#include <MAUtil/Moblet.h> // Moblet class
#include <conprint.h> // lprintfln for logging

#include <NativeUI/Widget.h>
#include <NativeUI/Widgets.h>// Include all widgets
Expand Down
27 changes: 21 additions & 6 deletions examples/cpp/PurchaseExample/MainScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
* - "Buy" section with a buy button and a list of available items for sale.
* - "History" section with a list of purchased items.
* For each purchased item there is a Receipt button.
* When the Receipt button is pressed a dialog/new screen shows the receipt details.
* When the Receipt button is pressed a dialog shows the receipt details.
* @author Emma Tresanszki
*/

#include <conprint.h>
Expand All @@ -34,11 +35,12 @@
#include <mastdlib.h>
#include <matime.h>

#include <Purchase/Purchase.h>

#include "Util.h"
#include "MainScreen.h"

#define BREAKLINE_HEIGHT 10
#define ANDROID_PRODUCT_TYPE_PURCHASED "android.test.purchased"
#define IOS_PRODUCT_TYPE_1 "com.mosync.purchase2.consumable"
#define IOS_PRODUCT_TYPE_2 "com.mosync.purchase2.nonconsumable"

Expand Down Expand Up @@ -189,9 +191,19 @@ void MainScreen::productPurchased(MAUtil::String productId)
mBuyButton->setEnabled(true);

ListViewItem* item = new ListViewItem();
item->setText(productId);
item->setFontColor(ITEMS_COLOR);
mPurchasedItemsList->addChild(item);

// Search the productId among the product list,
// and only display the product name.
for (int i=0; i < mProductIdList.size(); i++)
{
if ( strcmp(mProductIdList[i].c_str(), productId.c_str()) == 0 )
{
item->setText(mProductNamesList[i]);
break;
}
}
}

/**
Expand Down Expand Up @@ -303,12 +315,15 @@ void MainScreen::createProductIdList()
* If you want to run the example for your own product ids,
* add them to the mProductIdList list.
*/
mProductIdList.add(ANDROID_PRODUCT_TYPE_PURCHASED);
mProductIdList.add(sGooglePlayPurchasedProductId);
mProductNamesList.add("Test product");
}
else
{
mProductIdList.add(IOS_PRODUCT_TYPE_1);
mProductNamesList.add("Consumable product");
mProductIdList.add(IOS_PRODUCT_TYPE_2);
mProductNamesList.add("Non-consumable product");
}
}

Expand All @@ -332,15 +347,15 @@ void MainScreen::createMainLayout()
buyLayout->addChild(info);

// Add the list of available items for sale along with check boxes.
for (int i=0; i < mProductIdList.size(); i++)
for (int i=0; i < mProductNamesList.size(); i++)
{
HorizontalLayout* itemLayout = new HorizontalLayout();
itemLayout->wrapContentVertically();
CheckBox* itemCheckBox = new CheckBox();
itemLayout->addChild(itemCheckBox);
mItemsCheckBoxes.add(itemCheckBox);
Label* itemId = new Label();
itemId->setText(mProductIdList[i]);
itemId->setText(mProductNamesList[i]);
itemId->setFontColor(ITEMS_COLOR);
itemLayout->addChild(itemId);
buyLayout->addChild(itemLayout);
Expand Down
21 changes: 9 additions & 12 deletions examples/cpp/PurchaseExample/MainScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ MA 02110-1301, USA.
* - "History" section with a list of purchased items.
* For each purchased item there is a Receipt button.
* When the Receipt button is pressed a dialog/new screen shows the receipt details.
* @author Emma Tresanszki
*/

#ifndef MAINSCREEN_H_
Expand Down Expand Up @@ -123,15 +124,6 @@ class MainScreen:
*/
virtual void buttonClicked(Widget* button);

// /**
// * This method is called when a list view item is clicked.
// * @param listView The list view object that generated the event.
// * @param listViewItem The ListViewItem object that was clicked.
// */
// void listViewItemClicked(
// ListView* listView,
// ListViewItem* listViewItem);

/**
* This method is called when the state of the check box was changed
* by the user.
Expand All @@ -158,10 +150,16 @@ class MainScreen:
*/
void createReceiptDialog();
private:
// List of purchases.
//MAUtil::Vector<Purchase*> mPurchases;

/**
* The productIds of the available items, exactly as they are
* going to be send to the server in the purchase request.
*/
MAUtil::Vector<MAUtil::String> mProductIdList;
/**
* The product names of the available items, user readable.
*/
MAUtil::Vector<MAUtil::String> mProductNamesList;
/**
* Main layout.
*/
Expand All @@ -185,5 +183,4 @@ class MainScreen:
Button* mReceiptOkButton;
};


#endif /* MAINSCREEN_H_ */
8 changes: 0 additions & 8 deletions examples/cpp/PurchaseExample/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ MA 02110-1301, USA.
* Utility functions for the application.
*/


#define IOS_PRODUCT_TYPE_1 "com.mosync.purchase2.consumable"
// This test app can be purchased multiple times.
#define ANDROID_PRODUCT_TYPE_PURCHASED "android.test.purchased"
#define ANDROID_PRODUCT_TYPE_CANCELLED "android.test.canceled"
#define ANDROID_PRODUCT_TYPE_UNAVAILABLE "android.test.item_unavailable"
#define IOS_PRODUCT_TYPE_2 "com.mosync.purchase2.nonconsumable"

#include "Util.h"


Expand Down
37 changes: 36 additions & 1 deletion libs/Purchase/Purchase.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,42 @@ namespace IAP
class PurchaseManager;

/**
*\brief The Purchase class wraps a product that can be buyed and also all
* GooglePlay reserved productID for testing static in-app billing response
* as if a purchase was made.
* (testing purpose).
*/
const MAUtil::String sGooglePlayPurchasedProductId = "android.test.purchased";

/**
* GooglePlay reserved productID for testing static in-app billing response
* as if a refund was received.
* When you make an in-app billing request with this product ID, Google Play
* responds as though the purchase was refunded.
* (testing purpose).
*/
const MAUtil::String sGooglePlayRefundedProductId = "android.test.refunded";

/**
* GooglePlay reserved productID for testing static in-app billing response
* as if an unavailable product tried to be purchased.
* When you make an in-app billing request with this product ID, Google Play
* responds as though the item being purchased was not listed in your
* application's product list.
* (testing purpose).
*/
const MAUtil::String sGooglePlayItemUnavailableProductId = "android.test.item_unavailable";

/**
* GooglePlay reserved productID for testing static in-app billing response
* as if a purchase was canceled.
* When you make an in-app billing request with this product ID Google Play
* responds as though the purchase was canceled.
* (testing purpose).
*/
const MAUtil::String sGooglePlayCanceledPurchaseProductId = "android.test.canceled";

/**
*\brief The Purchase class wraps a product that can be bought and also all
* the details of the transaction(such as the receipt).
*/
class Purchase
Expand Down
9 changes: 6 additions & 3 deletions libs/Purchase/PurchaseManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,13 @@ namespace IAP
* @param developerPublicKey Base64-encoded public key, that can be found
* on the Google Play publisher account page, under Licensing & In-app
* Billing panel in Edit Profile.
*/
void PurchaseManager::setPublicKey(const MAUtil::String& developerPublicKey)
* @return One of the next result codes:
* - MA_PURCHASE_RES_OK if the key was set.
* - MA_PURCHASE_RES_MALFORMED_PUBLIC_KEY if the key is invalid.
*/
int PurchaseManager::setPublicKey(const MAUtil::String& developerPublicKey)
{
maPurchaseSetPublicKey(developerPublicKey.c_str());
return maPurchaseSetPublicKey(developerPublicKey.c_str());
}

/**
Expand Down
7 changes: 5 additions & 2 deletions libs/Purchase/PurchaseManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ namespace IAP
* @param developerPublicKey Base64-encoded public key, that can be found
* on the Google Play publisher account page, under Licensing & In-app
* Billing panel in Edit Profile.
*/
void setPublicKey(const MAUtil::String& developerPublicKey);
* @return One of the next result codes:
* - MA_PURCHASE_RES_OK if the key was set.
* - MA_PURCHASE_RES_MALFORMED_PUBLIC_KEY if the key is invalid.
*/
int setPublicKey(const MAUtil::String& developerPublicKey);

/**
* Set the store URL used for verifying the receipt on iOS platform.
Expand Down
6 changes: 3 additions & 3 deletions runtimes/cpp/platforms/android/IOCtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3409,18 +3409,18 @@ namespace Base
{
jstring jstrKey = jNIEnv->NewStringUTF(developerKey);
jclass cls = jNIEnv->GetObjectClass(jThis);
jmethodID methodID = jNIEnv->GetMethodID(cls, "maPurchaseSetPublicKey", "(Ljava/lang/String;)V");
jmethodID methodID = jNIEnv->GetMethodID(cls, "maPurchaseSetPublicKey", "(Ljava/lang/String;)I");
if (methodID == 0)
{
return 0;
}

jNIEnv->CallVoidMethod(jThis, methodID, jstrKey);
int result = jNIEnv->CallIntMethod(jThis, methodID, jstrKey);

jNIEnv->DeleteLocalRef(cls);
jNIEnv->DeleteLocalRef(jstrKey);

return 1;
return result;
}

int _maPurchaseRequest(MAHandle productHandle, int quantity, JNIEnv* jNIEnv, jobject jThis)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,17 @@ public void maPurchaseCreate(final int productHandle, final String productID)
* Internal function for the maPurchaseSetPublicKey system call.
*
* @param developerPublicKey
* @return MA_PURCHASE_RES_MALFORMED_PUBLIC_KEY or MA_PURCHASE_RES_OK.
*/
public void maPurchaseSetPublicKey(String developerPublicKey)
public int maPurchaseSetPublicKey(String developerPublicKey)
{
panicIfBillingPermissionIsNotSet();
if ( mPurchaseManager != null )
{
mPurchaseManager.setKey(developerPublicKey);
return mPurchaseManager.setKey(developerPublicKey);
}
Log.e("@@MoSync","maPurchaseSetPublicKey error: not available");
return MA_PURCHASE_RES_UNAVAILABLE;
}

/**
Expand Down Expand Up @@ -226,11 +229,8 @@ public int maPurchaseGetName(int productHandle, int memBuffer, int memBufSize)

return result.length( );
}
else
{
Log.e("@@MoSync","maPurchaseGetName error: not available");
return MA_PURCHASE_RES_UNAVAILABLE;
}
Log.e("@@MoSync","maPurchaseGetName error: not available");
return MA_PURCHASE_RES_UNAVAILABLE;
}

/**
Expand Down Expand Up @@ -284,11 +284,8 @@ public int maPurchaseGetField(

return result.length( );
}
else
{
Log.e("@@MoSync","maPurchaseGetField error: not available");
return MA_PURCHASE_RES_UNAVAILABLE;
}
Log.e("@@MoSync","maPurchaseGetField error: not available");
return MA_PURCHASE_RES_UNAVAILABLE;
}

/**
Expand Down Expand Up @@ -336,17 +333,13 @@ public void maPurchaseVerifyReceipt(int handle)
*/
public int maPurchaseDestroy(int handle)
{
// panicIfBillingPermissionIsNotSet();
panicIfBillingPermissionIsNotSet();
if (mPurchaseManager != null)
{
return mPurchaseManager.destroyPurchase(handle);

}
else
{
Log.e("@@MoSync","maPurchaseDestroy error: not available");
return MA_PURCHASE_RES_UNAVAILABLE;
}
Log.e("@@MoSync","maPurchaseDestroy error: not available");
return MA_PURCHASE_RES_UNAVAILABLE;
}
/************************ Class members ************************/

Expand Down
Loading

0 comments on commit 0aefbfa

Please sign in to comment.