取消订阅后...应用程序功能仍处于解锁状态

时间:2020-04-20 13:50:16

标签: android kotlin

我的应用程序是免费的,但在用户免费试用后订阅后提供付费功能 但是一旦取消订阅,他们仍然可以使用该付费功能 我想我做错了...这是我的代码(付款活动)

PaymentActivity.kt

class PaymentActivity : AppCompatActivity() , BillingProcessor.IBillingHandler {


private lateinit var bp : BillingProcessor
private val tag  = "PaymentActivity.kt"

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_payment)
    video_view.setMediaController(null)
    val uriString = "android.resource://" + packageName + "/" + R.raw.fish
    video_view.setVideoURI(Uri.parse(uriString))
    video_view.requestFocus()
    video_view.setOnCompletionListener({
        video_view.start()
    })
    video_view.setOnPreparedListener({
        video_view.start()
    })
    bp = BillingProcessor(this, getString(R.string.google_licence_key), getString(R.string.merchant_id),this)
    bp.initialize()
    bp.getSubscriptionTransactionDetails(getString(R.string.subscription_id))
    img.setOnClickListener{
        bp.subscribe(this, getString(R.string.subscription_id))
    }
}

override fun onBillingInitialized() {
    Log.e(tag,"onBillingInitialized() ->>")
    Log.e(tag," is already subscribe "+bp.isSubscribed(getString(R.string.subscription_id)))
    if (!bp.isSubscribed(getString(R.string.subscription_id))) {
        view.visibility = View.VISIBLE
    } else {
        Log.e(tag,"run main ")
        val intent = Intent(this, MainActivity::class.java)
        startActivity(intent)
        finish()
    }
}

override fun onPurchaseHistoryRestored() {
    Log.e(tag,"onPurchaseRestored() ->>")
}

override fun onProductPurchased(productId: String, details: TransactionDetails?) {
    Log.e(tag,"onProductPurchased() ->>")
    val intent = Intent(this, SplashActivity::class.java)
    startActivity(intent)
    finish()
}

override fun onBillingError(errorCode: Int, error: Throwable?) {
    Log.e(tag,"onBillingError() ->> "+error.toString())
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    if (!bp.handleActivityResult(requestCode, resultCode, data)) {
        super.onActivityResult(requestCode, resultCode, data)
    }
}

public override fun onDestroy() {
    if (bp != null) {
        bp.release()
    }
    super.onDestroy()
}

}`

任何帮助将不胜感激..谢谢

0 个答案:

没有答案