2017-01-21 2 views
1

내 앱에 가입 제품을 설정했으며 구매에 적합합니다. Google 개발자 콘솔에서 구매 한 것을 볼 수 있습니다. 로그 아웃하고 앱에 다시 들어가면 구독 페이지로 다시 이동합니다. 앱에서 구독을 구매했음을 인식하지 못하고 사용자 액세스가 허용되어야합니다. 구독 버튼을 다시 클릭하면 "이미 가입했습니다 ... 구독 관리"라고 표시됩니다. 구독을 확인한 후 구독 정보에 사용자를 보내거나 구독을 찾을 수 없으면 구독을 거부하고 구독 페이지로 사용자를 보내려면 무엇을해야하는지 잘 모르겠습니다. 나는 그것을 구축하는 법을 아직 알지 못한다고 생각합니다. 여기 내가 가진 코드가있다. 내가 처리 할 코드 덩어리가 빠졌습니까?Google InAppBilling 앱 로그인시 구독 확인

등록/로그인을위한 백엔드로 firebase를 사용하고 있습니다. 토큰 등을 지키기 위해 파이어베이스를 사용해야 할 지 모르겠다. 어떤 도움이라도 인정 될 것이다. 나는 초심자이고 배우는 것을 알고있다. 그러나 나의 프로젝트는 98 % 완전하다. 그리고 이것은 나를 뒤로 붙들고있다.

import android.content.Intent; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.util.Log; 
import android.view.View; 
import android.widget.Button; 

import com.iliprivateequity.btfxforexalerts.Util.IabHelper; 
import com.iliprivateequity.btfxforexalerts.Util.IabResult; 
import com.iliprivateequity.btfxforexalerts.Util.Inventory; 
import com.iliprivateequity.btfxforexalerts.Util.Purchase; 

public class GoogleInAppBilling extends AppCompatActivity implements View.OnClickListener { 

    private String base64EncodedPublicKey = "*****"; 

    public Button buttonSubscribe; 
    public Button buttonSubscribed; 
    IabHelper mHelper; 
    static final String SKU_SUBSCRIBE_BTFX = "btfx_alerts_service_50"; 
    static final String TAG = "BTFX_Alerts"; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_google_in_app_billing); 

     loadInAppPurchase(); 

     buttonSubscribe = (Button) findViewById(R.id.buttonsubscribe); 
     buttonSubscribed = (Button) findViewById(R.id.button_subscribed); 
     buttonSubscribed.setEnabled(false); //todo remember to set back to false. its true just for testing the build 

     buttonSubscribe.setOnClickListener(this); 
     buttonSubscribed.setOnClickListener(this); 

    } 

    private void loadInAppPurchase() { 
     mHelper = new IabHelper(this, base64EncodedPublicKey); 
     mHelper.enableDebugLogging(true); 

     mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { 

      @Override 
      public void onIabSetupFinished(IabResult result) { 
       if (!result.isSuccess()) { 
        Log.d(TAG, "Problem setting up in-app billing: " + result); 
       } else { 
        Log.d(TAG, "Setup successful. Querying inventory."); 
       } 
       mHelper.queryInventoryAsync(mGotInventoryListener); 
      } 


     }); 
    } 

    IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() { 

     @Override 
     public void onQueryInventoryFinished(IabResult result, Inventory inventory) { 
      Log.d(TAG, "Query inventory finished."); 
      if (result.isFailure()) { 
       Log.d(TAG, "Failed to query inventory: " + result); 
       return; 

      } 
      Log.d(TAG, "Query inventory was successful."); 

      Purchase sku_purchase = inventory.getPurchase(SKU_SUBSCRIBE_BTFX); 
      if (sku_purchase != null) { 
       mHelper.consumeAsync(inventory.getPurchase(SKU_SUBSCRIBE_BTFX), 
         mConsumeFinishedListener); 
       return; 

      } 
     } 
    }; 

    IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener(){ 
     public void onConsumeFinished(Purchase purchase, IabResult result) { 
      Log.d("Tag", "Consumption finished. Purchase: " + purchase + ", result: " + result); 

      if (mHelper == null) 
       return; 

      if (result.isSuccess()) { 
       Log.d("TAG", "Consumption successful. Provisioning."); 
      } else { 
       Log.d("TAG", "Error while consuming: " + result); 
      } 
      Log.d("Tag", "End consumption flow."); 
     } 
    }; 

    @Override 
    public void onClick(View v) { 
     if (v == buttonSubscribe) { 
      mHelper.launchPurchaseFlow(GoogleInAppBilling.this, SKU_SUBSCRIBE_BTFX, IabHelper.ITEM_TYPE_SUBS 
        , 10001, mPurchaseFinishedListener, "alertservicepurchased"); 
     } 
     if (v == buttonSubscribed){ 
      startActivity(new Intent(this, ProfileActivity.class)); 
     } 

    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    { 
     if (!mHelper.handleActivityResult(requestCode, resultCode, data)){ 
      super.onActivityResult(requestCode,resultCode,data); 
     }else{ 
      Log.d("TAG", "onActivityResult handled by IABUtil."); 
     } 
    } 

    // Callback for when a purchase is finished 
    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener 
      = new IabHelper.OnIabPurchaseFinishedListener() { 
     public void onIabPurchaseFinished(IabResult result, Purchase purchase) { 
      Log.d(TAG, "Purchase finished: " + result + ", purchase: " + purchase); 

      if (mHelper == null) return; 

      if (result.isFailure()) { 
       Log.d(TAG, "Error purchasing: " + result); 
       return; 

      } 
      Log.d(TAG, "BTFX Alerts subscription purchased."); 
      if (purchase.getSku().equals(SKU_SUBSCRIBE_BTFX)) { 
       Log.d("TAG", "Thank you for subscribing!"); 
       mHelper.consumeAsync(purchase, mConsumeFinishedListener); 
       // bought the btfx alerts subscription 

       buttonSubscribe.setEnabled(false); 
       buttonSubscribed.setEnabled(true); 

      } 

     } 
    }; 
}; 

답변

1

사용자가 이미 가입되어 있는지 확인하고 유료 콘텐츠 표시/숨기기에 따라 달라집니다.

There is 예제 방법. 또한 library을 사용하면 안드로이드에서 IAP 작업을 단순화 할 수 있습니다.