|
@@ -100,41 +100,29 @@ object PayManager {
|
|
dataNet.forEach {
|
|
dataNet.forEach {
|
|
list.add(it.google_product_id)
|
|
list.add(it.google_product_id)
|
|
}
|
|
}
|
|
- val listData = ArrayList<QueryProductDetailsParams.Product>()
|
|
|
|
- list.forEach {
|
|
|
|
- val product = QueryProductDetailsParams.Product.newBuilder()
|
|
|
|
- .setProductId(it)
|
|
|
|
- .setProductType(BillingClient.ProductType.INAPP)
|
|
|
|
- .build()
|
|
|
|
- listData.add(product)
|
|
|
|
- }
|
|
|
|
- val queryProductDetailsParams =
|
|
|
|
- QueryProductDetailsParams.newBuilder().setProductList(listData).build()
|
|
|
|
- billingClient?.queryProductDetailsAsync(queryProductDetailsParams) { billingResult, data ->
|
|
|
|
|
|
+ val skuDetailParams = SkuDetailsParams.newBuilder()
|
|
|
|
+ .setType(BillingClient.SkuType.INAPP)
|
|
|
|
+ .setSkusList(list)
|
|
|
|
+ .build()
|
|
|
|
+ billingClient?.querySkuDetailsAsync(skuDetailParams) { billingResult, data ->
|
|
when (billingResult.responseCode) {
|
|
when (billingResult.responseCode) {
|
|
BillingClient.BillingResponseCode.OK -> {
|
|
BillingClient.BillingResponseCode.OK -> {
|
|
- data.let {
|
|
|
|
|
|
+ data?.let {
|
|
if (it.isNotEmpty()) {
|
|
if (it.isNotEmpty()) {
|
|
- it.forEach { productDetails ->
|
|
|
|
- dataNet.forEach { dataSkuDetails ->
|
|
|
|
- if (productDetails.productId == dataSkuDetails.google_product_id) {
|
|
|
|
- dataSkuDetails.product_price =
|
|
|
|
- productDetails.oneTimePurchaseOfferDetails?.formattedPrice
|
|
|
|
- ?: "0"
|
|
|
|
|
|
+ it.forEach { skuDetails ->
|
|
|
|
+ dataNet.forEach { dataSkuDetails ->
|
|
|
|
+ if(skuDetails.sku == dataSkuDetails.google_product_id){
|
|
|
|
+ dataSkuDetails.product_price = skuDetails.price
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- GlobalScope.launch(Dispatchers.Main) {
|
|
|
|
- listener.forEach {
|
|
|
|
- it.onQueryProductPrice(dataNet)
|
|
|
|
- }
|
|
|
|
|
|
+ listener.forEach {
|
|
|
|
+ it.onQueryProductPrice(dataNet)
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- GlobalScope.launch(Dispatchers.Main) {
|
|
|
|
- listener.forEach {
|
|
|
|
- //未查询到商品
|
|
|
|
- it.onPayError(-5)
|
|
|
|
- }
|
|
|
|
|
|
+ }else{
|
|
|
|
+ listener.forEach {
|
|
|
|
+ //未查询到商品
|
|
|
|
+ it.onPayError(-5)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -182,9 +170,7 @@ object PayManager {
|
|
*/
|
|
*/
|
|
fun queryUnConsumeOrder(productId: String) {
|
|
fun queryUnConsumeOrder(productId: String) {
|
|
billingClient?.let {
|
|
billingClient?.let {
|
|
- val params = QueryPurchasesParams.newBuilder()
|
|
|
|
- .setProductType(BillingClient.ProductType.INAPP)
|
|
|
|
- it.queryPurchasesAsync(params.build()) { billingResult, list ->
|
|
|
|
|
|
+ it.queryPurchasesAsync(BillingClient.SkuType.INAPP) { billingResult, list ->
|
|
when (billingResult.responseCode) {
|
|
when (billingResult.responseCode) {
|
|
BillingClient.BillingResponseCode.OK -> {
|
|
BillingClient.BillingResponseCode.OK -> {
|
|
if (list.size != 0) {
|
|
if (list.size != 0) {
|
|
@@ -238,21 +224,13 @@ object PayManager {
|
|
}
|
|
}
|
|
|
|
|
|
private fun queryProductIsExit(data: ArrayList<String>, userId: String, orderId: String) {
|
|
private fun queryProductIsExit(data: ArrayList<String>, userId: String, orderId: String) {
|
|
- val listData = ArrayList<QueryProductDetailsParams.Product>()
|
|
|
|
- data.forEach {
|
|
|
|
- val product = QueryProductDetailsParams.Product.newBuilder()
|
|
|
|
- .setProductId(it)
|
|
|
|
- .setProductType(BillingClient.ProductType.INAPP)
|
|
|
|
- .build()
|
|
|
|
- listData.add(product)
|
|
|
|
- }
|
|
|
|
- val queryProductDetailsParams =
|
|
|
|
- QueryProductDetailsParams.newBuilder().setProductList(listData).build()
|
|
|
|
- billingClient?.queryProductDetailsAsync(queryProductDetailsParams) { billingResult, dataX ->
|
|
|
|
|
|
+ val params = SkuDetailsParams.newBuilder()
|
|
|
|
+ params.setSkusList(data).setType(BillingClient.SkuType.INAPP)
|
|
|
|
+ billingClient?.querySkuDetailsAsync(params.build()) { billingResult, dataX ->
|
|
when (billingResult.responseCode) {
|
|
when (billingResult.responseCode) {
|
|
BillingClient.BillingResponseCode.OK -> {
|
|
BillingClient.BillingResponseCode.OK -> {
|
|
//查询到商品然后支付
|
|
//查询到商品然后支付
|
|
- dataX.onEach { productDetails ->
|
|
|
|
|
|
+ dataX?.onEach { productDetails ->
|
|
startPay(productDetails, userId, orderId)
|
|
startPay(productDetails, userId, orderId)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -269,20 +247,13 @@ object PayManager {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- private fun startPay(productDetails: ProductDetails, userId: String, orderId: String) {
|
|
|
|
|
|
+ private fun startPay(productDetails: SkuDetails, userId: String, orderId: String) {
|
|
try {
|
|
try {
|
|
- val productDetailsParamsList = listOf(
|
|
|
|
- BillingFlowParams.ProductDetailsParams.newBuilder()
|
|
|
|
- .setProductDetails(productDetails)
|
|
|
|
- .setOfferToken(
|
|
|
|
- productDetails.subscriptionOfferDetails?.get(0)?.offerToken ?: ""
|
|
|
|
- ).build()
|
|
|
|
- )
|
|
|
|
// Retrieve a value for "skuDetails" by calling querySkuDetailsAsync().
|
|
// Retrieve a value for "skuDetails" by calling querySkuDetailsAsync().
|
|
val flowParams = BillingFlowParams.newBuilder()
|
|
val flowParams = BillingFlowParams.newBuilder()
|
|
.setObfuscatedAccountId(userId)
|
|
.setObfuscatedAccountId(userId)
|
|
.setObfuscatedProfileId(orderId)
|
|
.setObfuscatedProfileId(orderId)
|
|
- .setProductDetailsParamsList(productDetailsParamsList)
|
|
|
|
|
|
+ .setSkuDetails(productDetails)
|
|
.build()
|
|
.build()
|
|
billingClient?.launchBillingFlow(
|
|
billingClient?.launchBillingFlow(
|
|
ActivityManagerUtil.get().currentActivity(),
|
|
ActivityManagerUtil.get().currentActivity(),
|