Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #173 from emmaTresanszki/ThreeOne

MOSYNC-2210 maPurchaseSetPublicKey does not return error code
  • Loading branch information...
commit 72874972139e3de9859c61a1e8fbc151a42cba52 2 parents 29b30a5 + b225fc5
Ali Sarrafi authored
View
2  examples/cpp/PurchaseExample/ApplicationController.cpp
@@ -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>
@@ -43,6 +44,7 @@ mMainScreen(NULL)
// Set Android public key.
PurchaseManager::getInstance()->setPublicKey(DEVELOPER_PUBLIC_KEY);
+ PurchaseManager::getInstance()->setStoreURL(sAppStoreSandboxURL);
}
/**
View
2  examples/cpp/PurchaseExample/ApplicationController.h
@@ -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_
@@ -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;
View
2  examples/cpp/PurchaseExample/Main.cpp
@@ -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
View
27 examples/cpp/PurchaseExample/MainScreen.cpp
@@ -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>
@@ -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"
@@ -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;
+ }
+ }
}
/**
@@ -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");
}
}
@@ -332,7 +347,7 @@ 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();
@@ -340,7 +355,7 @@ void MainScreen::createMainLayout()
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);
View
21 examples/cpp/PurchaseExample/MainScreen.h
@@ -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_
@@ -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.
@@ -158,11 +150,17 @@ 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.
*/
VerticalLayout* mMainLayout;
@@ -185,5 +183,4 @@ class MainScreen:
Button* mReceiptOkButton;
};
-
#endif /* MAINSCREEN_H_ */
View
8 examples/cpp/PurchaseExample/Util.cpp
@@ -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"
View
37 libs/Purchase/Purchase.h
@@ -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
View
9 libs/Purchase/PurchaseManager.cpp
@@ -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());
}
/**
View
7 libs/Purchase/PurchaseManager.h
@@ -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.
View
6 runtimes/cpp/platforms/android/IOCtl.cpp
@@ -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)
View
31 ...a/platforms/androidJNI/AndroidProject/src/com/mosync/internal/android/MoSyncPurchase.java
@@ -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;
}
/**
@@ -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;
}
/**
@@ -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;
}
/**
@@ -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 ************************/
View
4 ...ava/platforms/androidJNI/AndroidProject/src/com/mosync/internal/android/MoSyncThread.java
@@ -3714,9 +3714,9 @@ void maPurchaseCreate(final int productHandle, final String productID)
* \param developerKey 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 maPurchaseSetPublicKey(final String developerPublicKey)
+ int maPurchaseSetPublicKey(final String developerPublicKey)
{
- mMoSyncPurchase.maPurchaseSetPublicKey(developerPublicKey);
+ return mMoSyncPurchase.maPurchaseSetPublicKey(developerPublicKey);
}
/**
View
7 ...rms/androidJNI/AndroidProject/src/com/mosync/internal/android/billing/BillingService.java
@@ -46,6 +46,8 @@
import static com.mosync.internal.generated.MAAPI_consts.MA_PURCHASE_STATE_FAILED;
import static com.mosync.internal.generated.MAAPI_consts.MA_PURCHASE_STATE_COMPLETED;
import static com.mosync.internal.generated.MAAPI_consts.MA_PURCHASE_STATE_PRODUCT_REFUNDED;
+import static com.mosync.internal.generated.MAAPI_consts.MA_PURCHASE_RES_MALFORMED_PUBLIC_KEY;
+import static com.mosync.internal.generated.MAAPI_consts.MA_PURCHASE_RES_OK;
import static com.mosync.internal.android.MoSyncHelpers.SYSLOG;
/**
@@ -85,17 +87,20 @@ public void setThread(MoSyncThread thread)
/**
* Compute your public key (that you got from the Android Market publisher site).
* @param developerPublicKey the Base64 encoded key.
+ * @return MA_PURCHASE_RES_MALFORMED_PUBLIC_KEY or MA_PURCHASE_RES_OK.
*/
- public void setPublicKey(final String developerPublicKey)
+ public int setPublicKey(final String developerPublicKey)
{
try
{
mPublicKey = Security.generatePublicKey(developerPublicKey);
mIsPublicKeySet = true;
+ return MA_PURCHASE_RES_OK;
} catch (Exception ex)
{
SYSLOG("maPurchaseSetPublicKey: malformed developerPublicKey");
mPublicKey = null;
+ return MA_PURCHASE_RES_MALFORMED_PUBLIC_KEY;
}
}
View
4 ...ms/androidJNI/AndroidProject/src/com/mosync/internal/android/billing/PurchaseManager.java
@@ -318,9 +318,9 @@ public void verifyReceipt(int handle)
* Generate a PublicKey instance from a string containing the
* Base64-encoded public key.
*/
- public void setKey(final String developerPublicKey)
+ public int setKey(final String developerPublicKey)
{
- mService.setPublicKey(developerPublicKey);
+ return mService.setPublicKey(developerPublicKey);
}
public int destroyPurchase(int handle)
View
11 tools/idl2/purchase.idl
@@ -60,6 +60,11 @@ group PurchaseResultCodes "Purchase Result Codes" {
* contain the given field.
*/
INVALID_FIELD_NAME = -10;
+ /**
+ * \bried returned by the #maPurchaseSetPublicKey() syscall if the encoded public key
+ * is invalid.
+ */
+ MALFORMED_PUBLIC_KEY = -11;
}
} // end of Purchase Result Codes
@@ -399,8 +404,12 @@ group PurchaseFunctions "Purchase Functions" {
*
* \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.
+ *
+ * \returns 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.
*/
- void maPurchaseSetPublicKey(in MAString developerPublicKey);
+ int maPurchaseSetPublicKey(in MAString developerPublicKey);
/**
* Request the user to purchase a product.
Please sign in to comment.
Something went wrong with that request. Please try again.