Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

#259 #260

Merged
merged 3 commits into from
Jul 23, 2014
Merged

#259 #260

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,331 changes: 1,330 additions & 1 deletion library/src/org/onepf/oms/OpenIabHelper.java

Large diffs are not rendered by default.

86 changes: 55 additions & 31 deletions library/src/org/onepf/oms/appstore/nokiaUtils/NokiaStoreHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.util.List;

public class NokiaStoreHelper implements AppstoreInAppBillingService {

//todo why own constants?
public static final int RESULT_OK = 0;
public static final int RESULT_USER_CANCELED = 1;
public static final int RESULT_BILLING_UNAVAILABLE = 3;
Expand All @@ -45,6 +45,8 @@ public class NokiaStoreHelper implements AppstoreInAppBillingService {
public static final int RESULT_ITEM_NOT_OWNED = 8;
public static final int RESULT_NO_SIM = 9;

public static final int RESULT_BAD_RESPONSE = -1002;

private static final String TAG = NokiaStoreHelper.class.getSimpleName();
public static final boolean IS_DEBUG_MODE = false;

Expand Down Expand Up @@ -128,12 +130,18 @@ public void onServiceDisconnected(final ComponentName name) {
"Billing service unavailable on device."));
}

} else {

mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);

}
}
} else {
try {
mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
} catch (SecurityException e) {
logError("Can't bind to the service", e);
if (listener != null) {
listener.onIabSetupFinished(new NokiaResult(RESULT_BILLING_UNAVAILABLE,
"Billing service unavailable on device due to lack of the permission \"com.nokia.payment.BILLING\"."));
}
}
}
}

private Intent getServiceIntent() {
final Intent intent = new Intent(NokiaStore.VENDING_ACTION);
Expand Down Expand Up @@ -180,29 +188,36 @@ public void launchPurchaseFlow(final Activity act, final String sku, final Strin
}

try {
final Bundle buyIntentBundle = mService.getBuyIntent(
3, getPackageName(), sku, IabHelper.ITEM_TYPE_INAPP, extraData
);

logDebug("buyIntentBundle = " + buyIntentBundle);

final int responseCode = buyIntentBundle.getInt("RESPONSE_CODE", 0);
final PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");

if (responseCode == RESULT_OK) {
mRequestCode = requestCode;
mPurchaseListener = listener;

final IntentSender intentSender = pendingIntent.getIntentSender();
act.startIntentSenderForResult(
intentSender, requestCode, new Intent(), 0, 0, 0
);
} else if(listener != null) {
final IabResult result = new NokiaResult(responseCode, "Failed to get buy intent.");
listener.onIabPurchaseFinished(result, null);
}

} catch (RemoteException e) {
if (mService == null) {
if (listener != null) {
logError("Unable to buy item, Error response: service is not connected.");
NokiaResult result = new NokiaResult(RESULT_ERROR, "Unable to buy item");
listener.onIabPurchaseFinished(result, null);
}
} else {
final Bundle buyIntentBundle = mService.getBuyIntent(
3, getPackageName(), sku, IabHelper.ITEM_TYPE_INAPP, extraData
);

logDebug("buyIntentBundle = " + buyIntentBundle);

final int responseCode = buyIntentBundle.getInt("RESPONSE_CODE", 0);
final PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");

if (responseCode == RESULT_OK) {
mRequestCode = requestCode;
mPurchaseListener = listener;

final IntentSender intentSender = pendingIntent.getIntentSender();
act.startIntentSenderForResult(
intentSender, requestCode, new Intent(), 0, 0, 0
);
} else if (listener != null) {
final IabResult result = new NokiaResult(responseCode, "Failed to get buy intent.");
listener.onIabPurchaseFinished(result, null);
}
}
} catch (RemoteException e) {
logError("RemoteException: " + e, e);

final IabResult result = new NokiaResult(IabHelper.IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
Expand Down Expand Up @@ -460,6 +475,11 @@ private void refreshPurchasedItems(final List<String> moreItemSkus, final Invent
storeSkusBundle.putStringArrayList("ITEM_ID_LIST", storeSkus);

try {
if (mService == null) {
logError("Unable to refresh purchased items.");
throw new IabException(RESULT_BAD_RESPONSE, "Error refreshing inventory (querying owned items).");
}

final Bundle purchasedBundle = mService.getPurchases(
3, getPackageName(), OpenIabHelper.ITEM_TYPE_INAPP, storeSkusBundle, null
);
Expand Down Expand Up @@ -535,8 +555,12 @@ private void refreshItemDetails(final List<String> moreItemSkus, final Inventory
storeSkusBundle.putStringArrayList("ITEM_ID_LIST", combinedStoreSkus);

try {
if (mService == null) {
logError("Unable to refresh item details.");
throw new IabException(RESULT_BAD_RESPONSE, "Error refreshing item details.");
}

final Bundle productDetailBundle = mService.getProductDetails(
final Bundle productDetailBundle = mService.getProductDetails(
3, getPackageName(), OpenIabHelper.ITEM_TYPE_INAPP, storeSkusBundle
);

Expand Down