sebastien_muh_mobi

getPublisherInfo

Nov 29th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. private fun getPublisherInfo(subscriptionCallback: Callback<Subscription>) {
  2.  
  3. td?.let {
  4. val subscription = subscriptionInstance.subscriptionExpiresOn(it.purchaseInfo.purchaseData.purchaseToken)
  5. subscription.enqueue(subscriptionCallback)
  6. }
  7. }
  8.  
  9. fun updateExpirationDate(){
  10. if (isPremium()) {
  11.  
  12. val saveEndDate = getEndDateSaved()
  13. if ((saveEndDate != null && getRemainingDays() < 0) || saveEndDate == null ) {
  14. //need to get the expire date
  15.  
  16. td?.purchaseInfo?.purchaseData?.purchaseToken?.let { token ->
  17. getPublisherInfo( token, subscriptionCallback )
  18. }
  19.  
  20. getPublisherInfo(object : Callback<Subscription> {
  21. override fun onResponse(call: Call<Subscription>, response: Response<Subscription>) {
  22.  
  23. val b = response.body() ?: return
  24. val expireDate = Date(b.expiryTimeMillis)
  25.  
  26. StorageUtils.writePremiumEndDate(ctx, expireDate)
  27. Log.d(TAG, "Subscription date : " + expireDate)
  28. }
  29.  
  30. override fun onFailure(call: Call<Subscription>, t: Throwable) {
  31. Log.e(TAG, "e : " + t.localizedMessage)
  32. }
  33. })
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment