Skip to content

Commit 2d6aa75

Browse files
Merge pull request #43 from cafebazaar/release-1.1.0-beta01
Add get SKU details capability
2 parents 7305860 + 6562ef8 commit 2d6aa75

19 files changed

Lines changed: 470 additions & 56 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
android:theme="@style/AppTheme"
1212
tools:ignore="GoogleAppIndexingWarning">
1313

14-
<activity android:name="ir.cafebazaar.poolakeysample.MainActivity">
14+
<activity android:name="ir.cafebazaar.poolakeysample.MainActivity"
15+
android:windowSoftInputMode="adjustNothing">
1516
<intent-filter>
1617
<action android:name="android.intent.action.MAIN" />
1718
<category android:name="android.intent.category.LAUNCHER" />

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

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import ir.cafebazaar.poolakey.config.PaymentConfiguration
1313
import ir.cafebazaar.poolakey.config.SecurityCheck
1414
import ir.cafebazaar.poolakey.request.PurchaseRequest
1515
import kotlinx.android.synthetic.main.activity_main.consumeSwitch
16+
import kotlinx.android.synthetic.main.activity_main.getSkuDetailInAppButton
17+
import kotlinx.android.synthetic.main.activity_main.getSkuDetailSubscriptionButton
1618
import kotlinx.android.synthetic.main.activity_main.purchaseButton
1719
import kotlinx.android.synthetic.main.activity_main.queryPurchasedItemsButton
1820
import kotlinx.android.synthetic.main.activity_main.querySubscribedItemsButton
@@ -36,14 +38,18 @@ class MainActivity : AppCompatActivity() {
3638
super.onCreate(savedInstanceState)
3739
setContentView(R.layout.activity_main)
3840
startPaymentConnection()
41+
setViewClickListener()
42+
}
43+
44+
private fun setViewClickListener() {
3945
purchaseButton.setOnClickListener {
4046
if (paymentConnection.getState() == ConnectionState.Connected) {
4147
payment.purchaseProduct(
4248
activity = this,
4349
request = PurchaseRequest(
4450
productId = skuValueInput.text.toString(),
4551
requestCode = PURCHASE_REQUEST_CODE,
46-
payload = ""
52+
payload = "payload"
4753
)
4854
) {
4955
purchaseFlowBegan {
@@ -84,6 +90,48 @@ class MainActivity : AppCompatActivity() {
8490
payment.getSubscribedProducts(handlePurchaseQueryCallback())
8591
}
8692
}
93+
setGetSkuDetailClickListener()
94+
}
95+
96+
private fun setGetSkuDetailClickListener() {
97+
98+
getSkuDetailInAppButton.setOnClickListener {
99+
onGetSkuDetailInAppClicked()
100+
}
101+
102+
getSkuDetailSubscriptionButton.setOnClickListener {
103+
onGetSkuDetailSubscriptionClicked()
104+
}
105+
}
106+
107+
private fun onGetSkuDetailSubscriptionClicked() {
108+
if (paymentConnection.getState() == ConnectionState.Connected) {
109+
payment.getSubscriptionSkuDetails(
110+
skuIds = listOf(skuValueInput.text.toString())
111+
) {
112+
getSkuDetailsSucceed {
113+
toast(it.toString())
114+
}
115+
getSkuDetailsFailed {
116+
toast(R.string.general_query_get_sku_detail_failed_message)
117+
}
118+
}
119+
}
120+
}
121+
122+
private fun onGetSkuDetailInAppClicked() {
123+
if (paymentConnection.getState() == ConnectionState.Connected) {
124+
payment.getInAppSkuDetails(
125+
skuIds = listOf(skuValueInput.text.toString())
126+
) {
127+
getSkuDetailsSucceed {
128+
toast(it.toString())
129+
}
130+
getSkuDetailsFailed {
131+
toast(R.string.general_query_get_sku_detail_failed_message)
132+
}
133+
}
134+
}
87135
}
88136

89137
private fun startPaymentConnection() {
@@ -142,6 +190,10 @@ class MainActivity : AppCompatActivity() {
142190
}
143191

144192
private fun toast(@StringRes message: Int) {
193+
toast(getString(message))
194+
}
195+
196+
private fun toast(message: String) {
145197
Toast.makeText(this@MainActivity, message, Toast.LENGTH_LONG).show()
146198
}
147199

Lines changed: 62 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,74 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RelativeLayout
3-
xmlns:android="http://schemas.android.com/apk/res/android"
4-
android:id="@+id/root"
2+
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
53
android:layout_width="match_parent"
6-
android:layout_height="match_parent">
4+
android:layout_height="match_parent"
5+
android:layout_gravity="center">
76

8-
<androidx.appcompat.widget.AppCompatTextView
9-
android:id="@+id/serviceConnectionStatus"
7+
<LinearLayout
8+
android:id="@+id/root"
109
android:layout_width="match_parent"
1110
android:layout_height="wrap_content"
12-
android:layout_marginTop="16sp"
11+
android:layout_gravity="center"
1312
android:gravity="center"
14-
android:text="@string/general_service_connection_not_connected_text" />
13+
android:orientation="vertical">
1514

16-
<androidx.appcompat.widget.AppCompatEditText
17-
android:id="@+id/skuValueInput"
18-
android:layout_width="match_parent"
19-
android:layout_height="56dp"
20-
android:layout_above="@+id/consumeSwitch"
21-
android:hint="@string/general_product_id_hint"
22-
android:padding="16dp" />
15+
<androidx.appcompat.widget.AppCompatTextView
16+
android:id="@+id/serviceConnectionStatus"
17+
android:layout_width="match_parent"
18+
android:layout_height="wrap_content"
19+
android:layout_marginTop="16sp"
20+
android:gravity="center"
21+
android:text="@string/general_service_connection_not_connected_text" />
2322

24-
<androidx.appcompat.widget.SwitchCompat
25-
android:id="@+id/consumeSwitch"
26-
android:layout_width="match_parent"
27-
android:layout_height="56dp"
28-
android:layout_above="@+id/purchaseButton"
29-
android:padding="16dp"
30-
android:text="@string/general_consume_purchase_text" />
31-
32-
<androidx.appcompat.widget.AppCompatButton
33-
android:id="@+id/purchaseButton"
34-
android:layout_width="wrap_content"
35-
android:layout_height="wrap_content"
36-
android:layout_centerInParent="true"
37-
android:text="@string/general_purchase_text" />
23+
<androidx.appcompat.widget.AppCompatEditText
24+
android:id="@+id/skuValueInput"
25+
android:layout_width="match_parent"
26+
android:layout_height="56dp"
27+
android:hint="@string/general_product_id_hint"
28+
android:padding="16dp" />
3829

39-
<androidx.appcompat.widget.AppCompatButton
40-
android:id="@+id/subscribeButton"
41-
android:layout_width="wrap_content"
42-
android:layout_height="wrap_content"
43-
android:layout_below="@id/purchaseButton"
44-
android:layout_centerHorizontal="true"
45-
android:text="@string/general_subscribe_text" />
30+
<androidx.appcompat.widget.SwitchCompat
31+
android:id="@+id/consumeSwitch"
32+
android:layout_width="match_parent"
33+
android:layout_height="56dp"
34+
android:padding="16dp"
35+
android:text="@string/general_consume_purchase_text" />
4636

47-
<androidx.appcompat.widget.AppCompatButton
48-
android:id="@+id/queryPurchasedItemsButton"
49-
android:layout_width="wrap_content"
50-
android:layout_height="wrap_content"
51-
android:layout_below="@id/subscribeButton"
52-
android:layout_centerHorizontal="true"
53-
android:text="@string/general_query_purchase_text" />
37+
<androidx.appcompat.widget.AppCompatButton
38+
android:id="@+id/purchaseButton"
39+
android:layout_width="wrap_content"
40+
android:layout_height="wrap_content"
41+
android:text="@string/general_purchase_text" />
5442

55-
<androidx.appcompat.widget.AppCompatButton
56-
android:id="@+id/querySubscribedItemsButton"
57-
android:layout_width="wrap_content"
58-
android:layout_height="wrap_content"
59-
android:layout_below="@id/queryPurchasedItemsButton"
60-
android:layout_centerHorizontal="true"
61-
android:text="@string/general_query_subscription_text" />
43+
<androidx.appcompat.widget.AppCompatButton
44+
android:id="@+id/subscribeButton"
45+
android:layout_width="wrap_content"
46+
android:layout_height="wrap_content"
47+
android:text="@string/general_subscribe_text" />
48+
49+
<androidx.appcompat.widget.AppCompatButton
50+
android:id="@+id/queryPurchasedItemsButton"
51+
android:layout_width="wrap_content"
52+
android:layout_height="wrap_content"
53+
android:text="@string/general_query_purchase_text" />
54+
55+
<androidx.appcompat.widget.AppCompatButton
56+
android:id="@+id/querySubscribedItemsButton"
57+
android:layout_width="wrap_content"
58+
android:layout_height="wrap_content"
59+
android:text="@string/general_query_subscription_text" />
60+
61+
<androidx.appcompat.widget.AppCompatButton
62+
android:id="@+id/getSkuDetailInAppButton"
63+
android:layout_width="wrap_content"
64+
android:layout_height="wrap_content"
65+
android:text="@string/general_get_sku_detail_inapp_text" />
66+
67+
<androidx.appcompat.widget.AppCompatButton
68+
android:id="@+id/getSkuDetailSubscriptionButton"
69+
android:layout_width="wrap_content"
70+
android:layout_height="wrap_content"
71+
android:text="@string/general_get_sku_detail_sub_text" />
6272

63-
</RelativeLayout>
73+
</LinearLayout>
74+
</ScrollView>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
<string name="general_service_connection_failed_text">Service: Failed to Connect</string>
1212
<string name="general_query_purchase_text">Check if user purchased this item</string>
1313
<string name="general_query_subscription_text">Check if user subscribed this item</string>
14+
<string name="general_get_sku_detail_inapp_text">Get Sku detail of in-app item</string>
15+
<string name="general_get_sku_detail_sub_text">Get Sku detail of subscription item</string>
1416

1517
<string name="general_purchase_flow_began_message">Purchase flow began</string>
1618
<string name="general_purchase_succeed_message">Purchase succeed</string>
@@ -19,6 +21,7 @@
1921
<string name="general_consume_succeed_message">Consume succeed</string>
2022
<string name="general_consume_failed_message">Consume failed</string>
2123
<string name="general_query_purchased_items_failed_message">Query failed</string>
24+
<string name="general_query_get_sku_detail_failed_message">Get sku detail failed</string>
2225
<string name="general_user_purchased_item_message">User has bought this item</string>
2326
<string name="general_user_did_not_purchased_item_message">User has not bought this item</string>
2427

detekt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ complexity:
6363
TooManyFunctions:
6464
active: true
6565
thresholdInFiles: 20
66-
thresholdInClasses: 11
66+
thresholdInClasses: 12
6767
thresholdInInterfaces: 8
6868
thresholdInObjects: 11
6969
thresholdInEnums: 11

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import io.reactivex.Single
99
import ir.cafebazaar.poolakey.Connection
1010
import ir.cafebazaar.poolakey.Payment
1111
import ir.cafebazaar.poolakey.entity.PurchaseInfo
12+
import ir.cafebazaar.poolakey.entity.SkuDetails
1213
import ir.cafebazaar.poolakey.request.PurchaseRequest
1314
import ir.cafebazaar.poolakey.rxbase.exception.PurchaseCanceledException
1415

@@ -154,6 +155,38 @@ fun Payment.getSubscribedProducts(): Single<List<PurchaseInfo>> {
154155
}
155156
}
156157

158+
/**
159+
* You can use this function to get detail of inApp sku's,
160+
* @param skuIds This contain all sku id's that you want to get info about it.
161+
* @return Single that you can subscribe to it and get the detail of requested sku's.
162+
*/
163+
fun Payment.getInAppSkuDetails(
164+
skuIds: List<String>
165+
): Single<List<SkuDetails>> {
166+
return Single.create { emitter ->
167+
getInAppSkuDetails(skuIds) {
168+
getSkuDetailsSucceed { emitter.onSuccess(it) }
169+
getSkuDetailsFailed { emitter.onError(it) }
170+
}
171+
}
172+
}
173+
174+
/**
175+
* You can use this function to get detail of subscriptions sku's,
176+
* @param skuIds This contain all sku id's that you want to get info about it.
177+
* @return Single that you can subscribe to it and get the detail of requested sku's.
178+
*/
179+
fun Payment.getSubscriptionSkuDetails(
180+
skuIds: List<String>
181+
): Single<List<SkuDetails>> {
182+
return Single.create { emitter ->
183+
getSubscriptionSkuDetails(skuIds) {
184+
getSkuDetailsSucceed { emitter.onSuccess(it) }
185+
getSkuDetailsFailed { emitter.onError(it) }
186+
}
187+
}
188+
}
189+
157190
/**
158191
* You have to use this function in order to check if user purchased or subscribed the product.
159192
* 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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import io.reactivex.rxjava3.core.Single
99
import ir.cafebazaar.poolakey.Connection
1010
import ir.cafebazaar.poolakey.Payment
1111
import ir.cafebazaar.poolakey.entity.PurchaseInfo
12+
import ir.cafebazaar.poolakey.entity.SkuDetails
1213
import ir.cafebazaar.poolakey.request.PurchaseRequest
1314
import ir.cafebazaar.poolakey.rxbase.exception.PurchaseCanceledException
1415

@@ -154,6 +155,34 @@ fun Payment.getSubscribedProducts(): Single<List<PurchaseInfo>> {
154155
}
155156
}
156157

158+
/**
159+
* You can use this function to get detail of inApp sku's,
160+
* @param skuIds This contain all sku id's that you want to get info about it.
161+
* @return Single that you can subscribe to it and get the detail of requested sku's.
162+
*/
163+
fun Payment.getInAppSkuDetails(skuIds: List<String>): Single<List<SkuDetails>> {
164+
return Single.create { emitter ->
165+
getInAppSkuDetails(skuIds) {
166+
getSkuDetailsSucceed { emitter.onSuccess(it) }
167+
getSkuDetailsFailed { emitter.onError(it) }
168+
}
169+
}
170+
}
171+
172+
/**
173+
* You can use this function to get detail of subscription sku's,
174+
* @param skuIds This contain all sku id's that you want to get info about it.
175+
* @return Single that you can subscribe to it and get the detail of requested sku's.
176+
*/
177+
fun Payment.getSubscriptionSkuDetails(skuIds: List<String>): Single<List<SkuDetails>> {
178+
return Single.create { emitter ->
179+
getSubscriptionSkuDetails(skuIds) {
180+
getSkuDetailsSucceed { emitter.onSuccess(it) }
181+
getSkuDetailsFailed { emitter.onError(it) }
182+
}
183+
}
184+
}
185+
157186
/**
158187
* You have to use this function in order to check if user purchased or subscribed the product.
159188
* Note that even if the purchase was successful, it's highly recommended to double check the

poolakey/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<action android:name="com.farsitel.bazaar.billingSupport" />
1515
<action android:name="com.farsitel.bazaar.consume" />
1616
<action android:name="com.farsitel.bazaar.getPurchase" />
17+
<action android:name="com.farsitel.bazaar.skuDetail" />
1718
</intent-filter>
1819
</receiver>
1920
</application>

0 commit comments

Comments
 (0)