Unable to buy item, Error response: 7:Item Already Owned

When i am going for purchasing next time. i am unable to make purchase .
Here are the logs:-

09-28 10:42:36.029: D/IAP(4614): payForProduct invoked com.rgl.rrm.5k_1dol_coins and type: 0
09-28 10:42:36.029: D/IAP(4614): NetWork reachable : true
09-28 10:42:36.039: D/IAP(4614): Starting async operation: launchPurchaseFlow
09-28 10:42:36.039: D/IAP(4614): Constructing buy intent for com.rgl.rrm.5k_1dol_coins, item type: inapp
09-28 10:42:36.049: E/IAP(4614): Unable to buy item, Error response: 7:Item Already Owned
09-28 10:42:36.049: D/IAP(4614): Ending async operation: launchPurchaseFlow
09-28 10:42:36.049: E/IAP(4614): Exception while launching purchase flow for sku com.rgl.rrm.5k_1dol_coins
09-28 10:42:36.049: W/System.err(4614): java.lang.NullPointerException
09-28 10:42:36.049: W/System.err(4614): at com.sdkbox.plugin.SDKBoxIAPGooglePlay$7.onIabPurchaseFinished(SDKBoxIAPGooglePlay.java:502)
09-28 10:42:36.049: W/System.err(4614): at com.sdkbox.plugin.util.iap.IabHelper.launchPurchaseFlow(IabHelper.java:415)
09-28 10:42:36.049: W/System.err(4614): at com.sdkbox.plugin.util.iap.IabHelper.launchPurchaseFlow(IabHelper.java:361)
09-28 10:42:36.049: W/System.err(4614): at com.sdkbox.plugin.util.iap.IabHelper.launchPurchaseFlow(IabHelper.java:356)
09-28 10:42:36.049: W/System.err(4614): at com.sdkbox.plugin.SDKBoxIAPGooglePlay$3.run(SDKBoxIAPGooglePlay.java:230)
09-28 10:42:36.049: W/System.err(4614): at android.os.Handler.handleCallback(Handler.java:615)
09-28 10:42:36.049: W/System.err(4614): at android.os.Handler.dispatchMessage(Handler.java:92)
09-28 10:42:36.049: W/System.err(4614): at android.os.Looper.loop(Looper.java:137)
09-28 10:42:36.049: W/System.err(4614): at android.app.ActivityThread.main(ActivityThread.java:4960)
09-28 10:42:36.049: W/System.err(4614): at java.lang.reflect.Method.invokeNative(Native Method)
09-28 10:42:36.049: W/System.err(4614): at java.lang.reflect.Method.invoke(Method.java:511)
09-28 10:42:36.049: W/System.err(4614): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
09-28 10:42:36.049: W/System.err(4614): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
09-28 10:42:36.049: W/System.err(4614): at dalvik.system.NativeStart.main(Native Method)
09-28 10:42:36.049: D/IAP(4614): Ending async operation:
09-28 10:42:36.049: E/IAP(4614): Error purchasing: IabResult: Exception while starting purchase flow (response: -1008:Unknown error)
09-28 10:42:36.059: D/cocos2d-x debug info(4614): ##Shop Screen Purchase5
09-28 10:42:36.059: D/cocos2d-x debug info(4614): IAP onFailure

My .json file:-
“iap”: {
“items”: {
“remove_ads”: {
“type”: “non_consumable”,
“id”: “com.rgl.rrm.removeads”
},
“coins_20k”: {
“id”: “com.rgl.rrm.20k_3dol_coins”
},
“coins_10k”: {
“id”: “com.rgl.rrm.10k_2dol_coins”
},

            "coins_40k": {
                "id": "com.rgl.rrm.40k_8dol_coins"
            }, 
       
            "coins_30k": {
                "id": "com.rgl.rrm.30k_5dol_coins"
            }, 
            "coins_50k": {
                "id": "com.rgl.rrm.50k_10dol_coins"
            }, 
            "coins_5k": {
                "id": "com.rgl.rrm.5k_1dol_coins"
            },     

Also after first time purchasing successful control is not coming to onSuccess(sdkbox::Product const& p) block

can you double check if your Cocos2dxActivity.java has been modified correctly?
http://docs.sdkbox.com/en/plugins/iap/v3-cpp/#modify-cocos2dxactivityjava

My Cocos2dxActivity.java code:-

package org.cocos2dx.lib;

import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;

import org.cocos2dx.lib.Cocos2dxHelper.Cocos2dxHelperListener;

import android.app.Activity;
import android.content.Context;

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.preference.PreferenceManager.OnActivityResultListener;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import android.content.Intent;
import com.sdkbox.plugin.SDKBox;
import android.opengl.GLSurfaceView;

public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener {
// ===========================================================
// Constants
// ===========================================================

private final static String TAG = Cocos2dxActivity.class.getSimpleName();

// ===========================================================
// Fields
// ===========================================================

private Cocos2dxGLSurfaceView mGLSurfaceView = null;
private int[] mGLContextAttrs = null;
private Cocos2dxHandler mHandler = null;   
private static Cocos2dxActivity sContext = null;
private Cocos2dxVideoHelper mVideoHelper = null;
private Cocos2dxWebViewHelper mWebViewHelper = null;

public static Context getContext() {
    return sContext;
}

public void setKeepScreenOn(boolean value) {
    final boolean newValue = value;
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mGLSurfaceView.setKeepScreenOn(newValue);
        }
    });
}

protected void onLoadNativeLibraries() {
    try {
        ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
        Bundle bundle = ai.metaData;
        String libName = bundle.getString("android.app.lib_name");
        System.loadLibrary(libName);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

// ===========================================================
// Constructors
// ===========================================================

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    onLoadNativeLibraries();
    SDKBox.init(this);

    sContext = this;
    this.mHandler = new Cocos2dxHandler(this);
    
    Cocos2dxHelper.init(this);
    
    this.mGLContextAttrs = getGLContextAttrs();
    this.init();

    if (mVideoHelper == null) {
        mVideoHelper = new Cocos2dxVideoHelper(this, mFrameLayout);
    }
    
    if(mWebViewHelper == null){
        mWebViewHelper = new Cocos2dxWebViewHelper(mFrameLayout);
    }
}

//native method,call GLViewImpl::getGLContextAttrs() to get the OpenGL ES context attributions
private static native int[] getGLContextAttrs();

// ===========================================================
// Getter & Setter
// ===========================================================

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================

@Override
protected void onStart() {
    super.onStart();
    SDKBox.onStart();
}

@Override
protected void onStop() {
    super.onStop();
    SDKBox.onStop();
}

@Override
protected void onResume() {
    super.onResume();
    SDKBox.onResume();

    Cocos2dxHelper.onResume();
    this.mGLSurfaceView.onResume();
}

@Override
protected void onPause() {
    super.onPause();
    SDKBox.onPause();
    Cocos2dxHelper.onPause();
    this.mGLSurfaceView.onPause();
}

@Override
public void onBackPressed() {
    if(!SDKBox.onBackPressed()) {
        super.onBackPressed();
    }
}

@Override
protected void onDestroy() {
    super.onDestroy();
}

@Override
public void showDialog(final String pTitle, final String pMessage) {
    Message msg = new Message();
    msg.what = Cocos2dxHandler.HANDLER_SHOW_DIALOG;
    msg.obj = new Cocos2dxHandler.DialogMessage(pTitle, pMessage);
    this.mHandler.sendMessage(msg);
}

@Override
public void showEditTextDialog(final String pTitle, final String pContent, final int pInputMode, final int pInputFlag, final int pReturnType, final int pMaxLength) { 
    Message msg = new Message();
    msg.what = Cocos2dxHandler.HANDLER_SHOW_EDITBOX_DIALOG;
    msg.obj = new Cocos2dxHandler.EditBoxMessage(pTitle, pContent, pInputMode, pInputFlag, pReturnType, pMaxLength);
    this.mHandler.sendMessage(msg);
}

@Override
public void runOnGLThread(final Runnable pRunnable) {
    this.mGLSurfaceView.queueEvent(pRunnable);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    for (OnActivityResultListener listener : Cocos2dxHelper.getOnActivityResultListeners()) {
        listener.onActivityResult(requestCode, resultCode, data);
    }

    if(!SDKBox.onActivityResult(requestCode, resultCode, data)) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}


protected FrameLayout mFrameLayout = null;
// ===========================================================
// Methods
// ===========================================================
public void init() {
    
    // FrameLayout
    ViewGroup.LayoutParams framelayout_params =
        new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                   ViewGroup.LayoutParams.MATCH_PARENT);
    mFrameLayout = new FrameLayout(this);
    mFrameLayout.setLayoutParams(framelayout_params);

    // Cocos2dxEditText layout
    ViewGroup.LayoutParams edittext_layout_params =
        new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                                   ViewGroup.LayoutParams.WRAP_CONTENT);
    Cocos2dxEditText edittext = new Cocos2dxEditText(this);
    edittext.setLayoutParams(edittext_layout_params);

    // ...add to FrameLayout
    mFrameLayout.addView(edittext);

    // Cocos2dxGLSurfaceView
    this.mGLSurfaceView = this.onCreateView();

    // ...add to FrameLayout
    mFrameLayout.addView(this.mGLSurfaceView);

    // Switch to supported OpenGL (ARGB888) mode on emulator
    if (isAndroidEmulator())
       this.mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);

    this.mGLSurfaceView.setCocos2dxRenderer(new Cocos2dxRenderer());
    this.mGLSurfaceView.setCocos2dxEditText(edittext);

    // Set framelayout as the content view
    setContentView(mFrameLayout);
}

public Cocos2dxGLSurfaceView onCreateView() {
    Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this);
    //this line is need on some device if we specify an alpha bits
    if(this.mGLContextAttrs[3] > 0) glSurfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    
    class cocos2dEGLConfigChooser implements GLSurfaceView.EGLConfigChooser
    {
        protected int[] configAttribs;
        public cocos2dEGLConfigChooser(int redSize, int greenSize, int blueSize, int alphaSize, int depthSize, int stencilSize)
        {
            configAttribs = new int[] {redSize, greenSize, blueSize, alphaSize, depthSize, stencilSize};
        }
        public cocos2dEGLConfigChooser(int[] attribs)
        {
            configAttribs = attribs;
        }
        
        public EGLConfig selectConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs, int[] attribs)
        {
            for (EGLConfig config : configs) {
                int d = findConfigAttrib(egl, display, config,
                        EGL10.EGL_DEPTH_SIZE, 0);
                int s = findConfigAttrib(egl, display, config,
                        EGL10.EGL_STENCIL_SIZE, 0);
                if ((d >= attribs[4]) && (s >= attribs[5])) {
                    int r = findConfigAttrib(egl, display, config,
                            EGL10.EGL_RED_SIZE, 0);
                    int g = findConfigAttrib(egl, display, config,
                             EGL10.EGL_GREEN_SIZE, 0);
                    int b = findConfigAttrib(egl, display, config,
                              EGL10.EGL_BLUE_SIZE, 0);
                    int a = findConfigAttrib(egl, display, config,
                            EGL10.EGL_ALPHA_SIZE, 0);
                    if ((r >= attribs[0]) && (g >= attribs[1])
                            && (b >= attribs[2]) && (a >= attribs[3])) {
                        return config;
                    }
                }
            }
            return null;
        }

        private int findConfigAttrib(EGL10 egl, EGLDisplay display,
                EGLConfig config, int attribute, int defaultValue) {
            int[] value = new int[1];
            if (egl.eglGetConfigAttrib(display, config, attribute, value)) {
                return value[0];
            }
            return defaultValue;
        }
        
        @Override
        public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) 
        {
            int[] numConfigs = new int[1];
            if(egl.eglGetConfigs(display, null, 0, numConfigs))
            {
                EGLConfig[] configs = new EGLConfig[numConfigs[0]];
                int[] EGLattribs = {
                        EGL10.EGL_RED_SIZE, configAttribs[0], 
                        EGL10.EGL_GREEN_SIZE, configAttribs[1],
                        EGL10.EGL_BLUE_SIZE, configAttribs[2],
                        EGL10.EGL_ALPHA_SIZE, configAttribs[3],
                        EGL10.EGL_DEPTH_SIZE, configAttribs[4],
                        EGL10.EGL_STENCIL_SIZE,configAttribs[5],
                        EGL10.EGL_RENDERABLE_TYPE, 4, //EGL_OPENGL_ES2_BIT
                        EGL10.EGL_NONE
                                    };
                int[] choosedConfigNum = new int[1];
                
                egl.eglChooseConfig(display, EGLattribs, configs, numConfigs[0], choosedConfigNum);
                if(choosedConfigNum[0]>0)
                {
                    return selectConfig(egl, display, configs, configAttribs);
                }
                else
                {
                    int[] defaultEGLattribs = {
                            EGL10.EGL_RED_SIZE, 5, 
                            EGL10.EGL_GREEN_SIZE, 6,
                            EGL10.EGL_BLUE_SIZE, 5,
                            EGL10.EGL_ALPHA_SIZE, 0,
                            EGL10.EGL_DEPTH_SIZE, 0,
                            EGL10.EGL_STENCIL_SIZE,0,
                            EGL10.EGL_RENDERABLE_TYPE, 4, //EGL_OPENGL_ES2_BIT
                            EGL10.EGL_NONE
                                        };
                    int[] defaultEGLattribsAlpha = {
                            EGL10.EGL_RED_SIZE, 4, 
                            EGL10.EGL_GREEN_SIZE, 4,
                            EGL10.EGL_BLUE_SIZE, 4,
                            EGL10.EGL_ALPHA_SIZE, 4,
                            EGL10.EGL_DEPTH_SIZE, 0,
                            EGL10.EGL_STENCIL_SIZE,0,
                            EGL10.EGL_RENDERABLE_TYPE, 4, //EGL_OPENGL_ES2_BIT
                            EGL10.EGL_NONE
                                        };
                    int[] attribs = null;
                    //choose one can use
                    if(this.configAttribs[3] == 0)
                    {
                        egl.eglChooseConfig(display, defaultEGLattribs, configs, numConfigs[0], choosedConfigNum);
                        attribs = new int[]{5,6,5,0,0,0};
                    }
                    else
                    {
                        egl.eglChooseConfig(display, defaultEGLattribsAlpha, configs, numConfigs[0], choosedConfigNum);
                        attribs = new int[]{4,4,4,4,0,0};
                    }
                    if(choosedConfigNum[0] > 0)
                    {
                        return selectConfig(egl, display, configs, attribs);
                    }
                    else
                    {
                        Log.e(DEVICE_POLICY_SERVICE, "Can not select an EGLConfig for rendering.");
                        return null;
                    }
                }
            }
            Log.e(DEVICE_POLICY_SERVICE, "Can not select an EGLConfig for rendering.");
            return null;
        }

    }
    cocos2dEGLConfigChooser chooser = new cocos2dEGLConfigChooser(this.mGLContextAttrs);
    glSurfaceView.setEGLConfigChooser(chooser);

    return glSurfaceView;
}

private final static boolean isAndroidEmulator() {
String model = Build.MODEL;
Log.d(TAG, “model=” + model);
String product = Build.PRODUCT;
Log.d(TAG, “product=” + product);
boolean isEmulator = false;
if (product != null) {
isEmulator = product.equals(“sdk”) || product.contains(“sdk") || product.contains("sdk”);
}
Log.d(TAG, “isEmulator=” + isEmulator);
return isEmulator;
}

// ===========================================================
// Inner and Anonymous Classes
// ===========================================================

}

Can you change this to

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if(!SDKBox.onActivityResult(requestCode, resultCode, data)) {
        super.onActivityResult(requestCode, resultCode, data);
    }

    for (OnActivityResultListener listener : Cocos2dxHelper.getOnActivityResultListeners()) {
        listener.onActivityResult(requestCode, resultCode, data);
    }
}

Nothing Happened after doing this change.
this is the log coming when game started.
09-30 10:47:34.074: E/IAP(5017): Failed to query inventory: IabResult: Error response while refreshing inventory. (response: -1008:Unknown error)

I’ve got the same problem.
Purchased consumable item, and now i’m getting “Item Already Owned” error.
I’ve updated sdkbox, verified it’s integration, changed order in onActivityResult method but nothing helped.

Dose this happens 100% of the time? or just sometimes? @sunil9038 @musikov

I can’t reproduce this issue, so it would be great if I can try your builds.

how many times i tried, got this error.

You mean everytime you tried?

yes,you can say that all time.

In my case i didn’t add google play key to config json and that was the problem.
After i add it the problem was solved.
Thanks for your time!

P.S. i didn’t add it because i didn’t want to show anyone my key. My own back-end is responsible for IAP validation and only it knows this key. Is there any way to skip sdkbox validation?

You have to have key in the local config for IAP to work, Currently you can use SDKBOX LiveOps, it will generate encrypted config file from server, we’re still working to improve it.

1 Like

i have dove all the necessary sdkbox_config.json changes.problem is why it is allowing me to do purchase only for first time?

Dose this issue still happening to your game with the 2.3.3 version?