Skip to content

Commit c5fef1e

Browse files
authored
Release 1.3.0 (#58)
* Add capability to check trial subscription * Increase version to 1.3.0
1 parent 589e5e3 commit c5fef1e

File tree

22 files changed

+450
-9
lines changed

22 files changed

+450
-9
lines changed

app/src/main/java/ir/cafebazaar/poolakeysample/MainActivity.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import ir.cafebazaar.poolakey.config.PaymentConfiguration
1313
import ir.cafebazaar.poolakey.config.SecurityCheck
1414
import ir.cafebazaar.poolakey.exception.DynamicPriceNotSupportedException
1515
import ir.cafebazaar.poolakey.request.PurchaseRequest
16+
import kotlinx.android.synthetic.main.activity_main.checkTrialSubscriptionButton
1617
import kotlinx.android.synthetic.main.activity_main.consumeSwitch
1718
import kotlinx.android.synthetic.main.activity_main.dynamicPriceToken
1819
import kotlinx.android.synthetic.main.activity_main.getSkuDetailInAppButton
@@ -74,6 +75,9 @@ class MainActivity : AppCompatActivity() {
7475
payment.getSubscribedProducts(handlePurchaseQueryCallback())
7576
}
7677
}
78+
checkTrialSubscriptionButton.setOnClickListener {
79+
onCheckTrialSubscriptionClicked()
80+
}
7781
setGetSkuDetailClickListener()
7882
}
7983

@@ -163,6 +167,19 @@ class MainActivity : AppCompatActivity() {
163167
}
164168
}
165169

170+
private fun onCheckTrialSubscriptionClicked() {
171+
if (paymentConnection.getState() == ConnectionState.Connected) {
172+
payment.checkTrialSubscription {
173+
checkTrialSubscriptionSucceed {
174+
toast(it.toString())
175+
}
176+
checkTrialSubscriptionFailed {
177+
it.message?.let { message -> toast(message) }
178+
}
179+
}
180+
}
181+
}
182+
166183
private fun onGetSkuDetailInAppClicked() {
167184
if (paymentConnection.getState() == ConnectionState.Connected) {
168185
payment.getInAppSkuDetails(
@@ -247,8 +264,8 @@ class MainActivity : AppCompatActivity() {
247264
}
248265

249266
companion object {
267+
250268
private const val PURCHASE_REQUEST_CODE = 1000
251269
private const val SUBSCRIBE_REQUEST_CODE = 1001
252270
}
253-
254271
}

app/src/main/res/layout/activity_main.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,11 @@
7777
android:layout_height="wrap_content"
7878
android:text="@string/general_get_sku_detail_sub_text" />
7979

80+
<androidx.appcompat.widget.AppCompatButton
81+
android:id="@+id/checkTrialSubscriptionButton"
82+
android:layout_width="wrap_content"
83+
android:layout_height="wrap_content"
84+
android:text="@string/general_check_trial_subscription_text" />
85+
8086
</LinearLayout>
8187
</ScrollView>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<string name="general_query_subscription_text">Check if user subscribed this item</string>
1515
<string name="general_get_sku_detail_inapp_text">Get Sku detail of in-app item</string>
1616
<string name="general_get_sku_detail_sub_text">Get Sku detail of subscription item</string>
17+
<string name="general_check_trial_subscription_text">Check Trial subscription</string>
1718

1819
<string name="general_purchase_flow_began_message">Purchase flow began</string>
1920
<string name="general_purchase_succeed_message">Purchase succeed</string>
@@ -24,6 +25,7 @@
2425
<string name="general_consume_failed_message">Consume failed</string>
2526
<string name="general_query_purchased_items_failed_message">Query failed</string>
2627
<string name="general_query_get_sku_detail_failed_message">Get sku detail failed</string>
28+
<string name="general_check_trial_subscription_failed_message">Check Trial Subscription failed</string>
2729
<string name="general_user_purchased_item_message">User has bought this item</string>
2830
<string name="general_user_did_not_purchased_item_message">User has not bought this item</string>
2931

detekt.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ complexity:
6363
TooManyFunctions:
6464
active: true
6565
thresholdInFiles: 20
66-
thresholdInClasses: 12
67-
thresholdInInterfaces: 8
66+
thresholdInClasses: 13
67+
thresholdInInterfaces: 9
6868
thresholdInObjects: 11
6969
thresholdInEnums: 11
7070
ignorePrivate: true

poolakey-rx/src/main/java/ir/cafebazaar/poolakey/rx/PaymentRx.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import ir.cafebazaar.poolakey.Connection
1010
import ir.cafebazaar.poolakey.Payment
1111
import ir.cafebazaar.poolakey.entity.PurchaseInfo
1212
import ir.cafebazaar.poolakey.entity.SkuDetails
13+
import ir.cafebazaar.poolakey.entity.TrialSubscriptionInfo
1314
import ir.cafebazaar.poolakey.request.PurchaseRequest
1415
import ir.cafebazaar.poolakey.rxbase.exception.PurchaseCanceledException
1516

@@ -187,6 +188,19 @@ fun Payment.getSubscriptionSkuDetails(
187188
}
188189
}
189190

191+
/**
192+
* You can use this function to check trial subscription,
193+
* @return Single that you can subscribe to it and get the trial subscription info.
194+
*/
195+
fun Payment.checkTrialSubscription(): Single<TrialSubscriptionInfo> {
196+
return Single.create { emitter ->
197+
checkTrialSubscription {
198+
checkTrialSubscriptionSucceed { emitter.onSuccess(it) }
199+
checkTrialSubscriptionFailed { emitter.onError(it) }
200+
}
201+
}
202+
}
203+
190204
/**
191205
* You have to use this function in order to check if user purchased or subscribed the product.
192206
* Note that even if the purchase was successful, it's highly recommended to double check the

poolakey-rx3/src/main/java/ir/cafebazaar/poolakey/rx3/PaymentRx3.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import ir.cafebazaar.poolakey.Connection
1010
import ir.cafebazaar.poolakey.Payment
1111
import ir.cafebazaar.poolakey.entity.PurchaseInfo
1212
import ir.cafebazaar.poolakey.entity.SkuDetails
13+
import ir.cafebazaar.poolakey.entity.TrialSubscriptionInfo
1314
import ir.cafebazaar.poolakey.request.PurchaseRequest
1415
import ir.cafebazaar.poolakey.rxbase.exception.PurchaseCanceledException
1516

@@ -183,6 +184,19 @@ fun Payment.getSubscriptionSkuDetails(skuIds: List<String>): Single<List<SkuDeta
183184
}
184185
}
185186

187+
/**
188+
* You can use this function to check trial subscription,
189+
* @return Single that you can subscribe to it and get the trial subscription info.
190+
*/
191+
fun Payment.checkTrialSubscription(): Single<TrialSubscriptionInfo> {
192+
return Single.create { emitter ->
193+
checkTrialSubscription {
194+
checkTrialSubscriptionSucceed { emitter.onSuccess(it) }
195+
checkTrialSubscriptionFailed { emitter.onError(it) }
196+
}
197+
}
198+
}
199+
186200
/**
187201
* You have to use this function in order to check if user purchased or subscribed the product.
188202
* Note that even if the purchase was successful, it's highly recommended to double check the

poolakey-rxbase/src/main/java/ir/cafebazaar/poolakey/rxbase/exception/PurchaseCanceledException.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import java.lang.Exception
44

55
class PurchaseCanceledException : Exception() {
66

7-
override val message: String?
7+
override val message: String
88
get() = "Purchase canceled by user"
99

1010
}

poolakey/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<action android:name="com.farsitel.bazaar.consume" />
1818
<action android:name="com.farsitel.bazaar.getPurchase" />
1919
<action android:name="com.farsitel.bazaar.skuDetail" />
20+
<action android:name="com.farsitel.bazaar.checkTrialSubscription" />
2021
</intent-filter>
2122
</receiver>
2223
</application>

poolakey/src/main/aidl/com/android/vending/billing/IInAppBillingService.aidl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ interface IInAppBillingService {
4848
String sku,
4949
String developerPayload,
5050
in Bundle extraData);
51+
52+
Bundle checkTrialSubscription(String packageName);
53+
54+
Bundle getFeatureConfig();
5155
}

poolakey/src/main/java/ir/cafebazaar/poolakey/BillingConnection.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ import ir.cafebazaar.poolakey.billing.connection.ServiceBillingConnection
99
import ir.cafebazaar.poolakey.billing.query.QueryFunction
1010
import ir.cafebazaar.poolakey.billing.skudetail.GetSkuDetailFunction
1111
import ir.cafebazaar.poolakey.billing.skudetail.SkuDetailFunctionRequest
12+
import ir.cafebazaar.poolakey.billing.trialsubscription.CheckTrialSubscriptionFunction
13+
import ir.cafebazaar.poolakey.billing.trialsubscription.CheckTrialSubscriptionFunctionRequest
1214
import ir.cafebazaar.poolakey.callback.ConnectionCallback
1315
import ir.cafebazaar.poolakey.callback.ConsumeCallback
1416
import ir.cafebazaar.poolakey.callback.GetSkuDetailsCallback
1517
import ir.cafebazaar.poolakey.callback.PurchaseIntentCallback
1618
import ir.cafebazaar.poolakey.callback.PurchaseQueryCallback
19+
import ir.cafebazaar.poolakey.callback.CheckTrialSubscriptionCallback
1720
import ir.cafebazaar.poolakey.config.PaymentConfiguration
1821
import ir.cafebazaar.poolakey.request.PurchaseRequest
1922
import ir.cafebazaar.poolakey.thread.PoolakeyThread
@@ -24,6 +27,7 @@ internal class BillingConnection(
2427
private val backgroundThread: PoolakeyThread<Runnable>,
2528
private val queryFunction: QueryFunction,
2629
private val skuDetailFunction: GetSkuDetailFunction,
30+
private val checkTrialSubscriptionFunction: CheckTrialSubscriptionFunction,
2731
private val mainThread: PoolakeyThread<() -> Unit>
2832
) {
2933

@@ -41,6 +45,7 @@ internal class BillingConnection(
4145
paymentConfiguration,
4246
queryFunction,
4347
skuDetailFunction,
48+
checkTrialSubscriptionFunction,
4449
::disconnect
4550
)
4651

@@ -133,6 +138,17 @@ internal class BillingConnection(
133138
}
134139
}
135140

141+
fun checkTrialSubscription(
142+
callback: CheckTrialSubscriptionCallback.() -> Unit
143+
) {
144+
runOnCommunicator(TAG_CHECK_TRIAL_SUBSCRIPTION) {
145+
requireNotNull(billingCommunicator).checkTrialSubscription(
146+
CheckTrialSubscriptionFunctionRequest(callback),
147+
callback
148+
)
149+
}
150+
}
151+
136152
private fun stopConnection() {
137153
runOnCommunicator(TAG_STOP_CONNECTION) {
138154
requireNotNull(billingCommunicator).stopConnection()
@@ -165,10 +181,12 @@ internal class BillingConnection(
165181
}
166182

167183
companion object {
184+
168185
private const val TAG_STOP_CONNECTION = "stopConnection"
169186
private const val TAG_QUERY_PURCHASE_PRODUCT = "queryPurchasedProducts"
170187
private const val TAG_CONSUME = "consume"
171188
private const val TAG_PURCHASE = "purchase"
172189
private const val TAG_GET_SKU_DETAIL = "skuDetial"
190+
private const val TAG_CHECK_TRIAL_SUBSCRIPTION = "checkTrialSubscription"
173191
}
174192
}

poolakey/src/main/java/ir/cafebazaar/poolakey/Payment.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import android.content.Intent
66
import androidx.fragment.app.Fragment
77
import ir.cafebazaar.poolakey.billing.query.QueryFunction
88
import ir.cafebazaar.poolakey.billing.skudetail.GetSkuDetailFunction
9+
import ir.cafebazaar.poolakey.billing.trialsubscription.CheckTrialSubscriptionFunction
910
import ir.cafebazaar.poolakey.callback.ConnectionCallback
1011
import ir.cafebazaar.poolakey.callback.ConsumeCallback
1112
import ir.cafebazaar.poolakey.callback.GetSkuDetailsCallback
1213
import ir.cafebazaar.poolakey.callback.PurchaseCallback
1314
import ir.cafebazaar.poolakey.callback.PurchaseIntentCallback
1415
import ir.cafebazaar.poolakey.callback.PurchaseQueryCallback
16+
import ir.cafebazaar.poolakey.callback.CheckTrialSubscriptionCallback
1517
import ir.cafebazaar.poolakey.config.PaymentConfiguration
1618
import ir.cafebazaar.poolakey.mapper.RawDataToPurchaseInfo
1719
import ir.cafebazaar.poolakey.request.PurchaseRequest
@@ -40,12 +42,18 @@ class Payment(context: Context, private val config: PaymentConfiguration) {
4042
mainThread
4143
)
4244

45+
private val checkTrialSubscriptionFunction = CheckTrialSubscriptionFunction(
46+
context,
47+
mainThread
48+
)
49+
4350
private val connection = BillingConnection(
4451
context = context,
4552
paymentConfiguration = config,
4653
queryFunction = queryFunction,
4754
backgroundThread = backgroundThread,
4855
skuDetailFunction = getSkuFunction,
56+
checkTrialSubscriptionFunction = checkTrialSubscriptionFunction,
4957
mainThread = mainThread
5058
)
5159

@@ -213,6 +221,16 @@ class Payment(context: Context, private val config: PaymentConfiguration) {
213221
connection.getSkuDetail(PurchaseType.SUBSCRIPTION, skuIds, callback)
214222
}
215223

224+
/**
225+
* You can use this function to check trial subscription,
226+
* @param callback You have to use callback in order to get notified about check trial subscription result.
227+
*/
228+
fun checkTrialSubscription(
229+
callback: CheckTrialSubscriptionCallback.() -> Unit
230+
) {
231+
connection.checkTrialSubscription(callback)
232+
}
233+
216234
/**
217235
* You have to use this function in order to check if user purchased or subscribed the product.
218236
* Note that even if the purchase was successful, it's highly recommended to double check the
@@ -256,6 +274,7 @@ class Payment(context: Context, private val config: PaymentConfiguration) {
256274
}
257275

258276
companion object {
277+
259278
@Volatile
260279
private var requestCode: Int = -1
261280
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package ir.cafebazaar.poolakey.billing
2+
3+
import android.os.Bundle
4+
5+
internal object FeatureConfig {
6+
7+
internal fun isFeatureAvailable(
8+
featureConfigBundle: Bundle?,
9+
feature: Feature
10+
): Boolean {
11+
return featureConfigBundle?.getBoolean(
12+
feature.key,
13+
false
14+
) ?: false
15+
}
16+
}
17+
18+
internal enum class Feature(val key: String) {
19+
CHECK_TRIAL_SUBSCRIPTION("INTENT_TRIAL_SUBSCRIPTION_SUPPORT")
20+
}

poolakey/src/main/java/ir/cafebazaar/poolakey/billing/connection/BillingConnectionCommunicator.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import android.content.Context
55
import androidx.fragment.app.Fragment
66
import ir.cafebazaar.poolakey.PurchaseType
77
import ir.cafebazaar.poolakey.billing.skudetail.SkuDetailFunctionRequest
8+
import ir.cafebazaar.poolakey.billing.trialsubscription.CheckTrialSubscriptionFunctionRequest
89
import ir.cafebazaar.poolakey.callback.ConnectionCallback
910
import ir.cafebazaar.poolakey.callback.ConsumeCallback
1011
import ir.cafebazaar.poolakey.callback.GetSkuDetailsCallback
1112
import ir.cafebazaar.poolakey.callback.PurchaseIntentCallback
1213
import ir.cafebazaar.poolakey.callback.PurchaseQueryCallback
14+
import ir.cafebazaar.poolakey.callback.CheckTrialSubscriptionCallback
1315
import ir.cafebazaar.poolakey.request.PurchaseRequest
1416

1517
internal interface BillingConnectionCommunicator {
@@ -48,5 +50,10 @@ internal interface BillingConnectionCommunicator {
4850
callback: GetSkuDetailsCallback.() -> Unit,
4951
)
5052

53+
fun checkTrialSubscription(
54+
request: CheckTrialSubscriptionFunctionRequest,
55+
callback: CheckTrialSubscriptionCallback.() -> Unit,
56+
)
57+
5158
fun stopConnection()
5259
}

0 commit comments

Comments
 (0)