Commit e3d59db6 authored by 王雪伟's avatar 王雪伟

[提交人]:王雪伟

[提交简述] :加入google支付某个环节断开连接重连机制
[实现方案] :
parent c4b96a04
PACKAGE_NAME=com.zhangxin.magicbox PACKAGE_NAME=com.zhangxin.magicbox
VERSION_CODE=12 VERSION_CODE=13
VERSION_NAME=1.0.3.4 VERSION_NAME=1.0.3.5
\ No newline at end of file \ No newline at end of file
...@@ -60,7 +60,18 @@ class GooglePayActivity : BaseActivity() { ...@@ -60,7 +60,18 @@ class GooglePayActivity : BaseActivity() {
} }
// startConnection() // startConnection()
googlePay = GooglePayHelper(this) googlePay = GooglePayHelper(this)
googlePay?.init() googlePay?.init(object :GooglePayCallBack{
override fun onPaySuccess(purchase: GooglePayResult, googleJson: String) {
}
override fun onCancel() {
}
override fun onError(error: String) {
}
})
} }
override fun onDestroy() { override fun onDestroy() {
......
...@@ -12,6 +12,7 @@ import com.zxhl.cms.net.callback.BaseObserver ...@@ -12,6 +12,7 @@ import com.zxhl.cms.net.callback.BaseObserver
import com.zxhl.cms.net.model.other.AnyEntity import com.zxhl.cms.net.model.other.AnyEntity
import com.zxhl.cms.net.model.uc.GooglePayEntity import com.zxhl.cms.net.model.uc.GooglePayEntity
import com.zxhl.cms.utils.EventUtils import com.zxhl.cms.utils.EventUtils
import org.json.JSONObject
/** /**
...@@ -23,7 +24,7 @@ class GooglePayHelper { ...@@ -23,7 +24,7 @@ class GooglePayHelper {
private val TAG = "GooglePayHelper" private val TAG = "GooglePayHelper"
private var mActivity: Activity; private var mActivity: Activity;
private var mPayCallBack: GooglePayCallBack? = null; private var mPayCallBack: GooglePayCallBack? = null;
private var mConsume: String = "2" private var mAutoPayCallBack: GooglePayCallBack? = null;//补单监听
private var productId = "" private var productId = ""
private var obfuscatedAccountid = "" private var obfuscatedAccountid = ""
...@@ -40,18 +41,19 @@ class GooglePayHelper { ...@@ -40,18 +41,19 @@ class GooglePayHelper {
Log.d(TAG, "购买监听 code ${billingResult.responseCode}") Log.d(TAG, "购买监听 code ${billingResult.responseCode}")
Log.d(TAG, "购买监听 size ${purchases?.size}") Log.d(TAG, "购买监听 size ${purchases?.size}")
if (billingResult.responseCode == BillingResponseCode.OK) { if (billingResult.responseCode == BillingResponseCode.OK) {
mConsume = "2"
//支付成功 同步后台 //支付成功 同步后台
if (!purchases.isNullOrEmpty()) { if (!purchases.isNullOrEmpty()) {
for (i in 0 until purchases.size) { for (i in 0 until purchases.size) {
var purchase = purchases[i]; val purchase = purchases[i];
Log.d(TAG, "detail ${purchase.originalJson}") val googleJson = JSONObject(purchase.originalJson)
Log.d(TAG, "obfuscatedAccountid $obfuscatedAccountid") val proId = googleJson.optString("productId") ?: productId
var googlePayResult = GooglePayResult() val accountId =
googleJson.optString("obfuscatedAccountId") ?: obfuscatedAccountid
val googlePayResult = GooglePayResult()
googlePayResult.packageName = purchase.packageName googlePayResult.packageName = purchase.packageName
googlePayResult.orderId = purchase.orderId googlePayResult.orderId = purchase.orderId
googlePayResult.productId = productId googlePayResult.productId = proId
googlePayResult.obfuscatedAccountid = obfuscatedAccountid googlePayResult.obfuscatedAccountid = accountId
googlePayResult.developerPayload = purchase.developerPayload googlePayResult.developerPayload = purchase.developerPayload
googlePayResult.purchaseTime = purchase.purchaseTime.toString() googlePayResult.purchaseTime = purchase.purchaseTime.toString()
googlePayResult.purchaseState = purchase.purchaseState.toString() googlePayResult.purchaseState = purchase.purchaseState.toString()
...@@ -62,9 +64,8 @@ class GooglePayHelper { ...@@ -62,9 +64,8 @@ class GooglePayHelper {
} }
} else if (billingResult.responseCode == BillingResponseCode.ITEM_ALREADY_OWNED) { } else if (billingResult.responseCode == BillingResponseCode.ITEM_ALREADY_OWNED) {
//未消耗掉 //未消耗掉
mConsume = "1" queryPurchases(2)
queryPurchases() // mPayCallBack?.onError("商品未消耗掉 查询补单")
mPayCallBack?.onError("商品未消耗掉 查询补单")
} else if (billingResult.responseCode == BillingResponseCode.USER_CANCELED) { } else if (billingResult.responseCode == BillingResponseCode.USER_CANCELED) {
mPayCallBack?.onCancel() mPayCallBack?.onCancel()
} else { } else {
...@@ -110,11 +111,12 @@ class GooglePayHelper { ...@@ -110,11 +111,12 @@ class GooglePayHelper {
.build() .build()
//检查之前的商品是否被消费 //检查之前的商品是否被消费
fun init() { fun init(autoPayCallBack: GooglePayCallBack) {
mAutoPayCallBack = autoPayCallBack
//已经连接查询订单 //已经连接查询订单
if (billingClient.isReady) { if (billingClient.isReady) {
Log.d(TAG, "init 已连接") Log.d(TAG, "init 已连接")
queryPurchases() queryPurchases(1)
} else { } else {
//开始连接 //开始连接
Log.d(TAG, "init 开始连接") Log.d(TAG, "init 开始连接")
...@@ -123,18 +125,16 @@ class GooglePayHelper { ...@@ -123,18 +125,16 @@ class GooglePayHelper {
if (billingResult.responseCode == BillingResponseCode.OK) { if (billingResult.responseCode == BillingResponseCode.OK) {
//BillingClient准备好了。你可以在这里查询购买情况。 //BillingClient准备好了。你可以在这里查询购买情况。
Log.d(TAG, "init 连接成功") Log.d(TAG, "init 连接成功")
queryPurchases() queryPurchases(1)
} else { } else {
Log.d(TAG, "init 连接失败 code:" + billingResult.responseCode) Log.d(TAG, "init 连接失败 code:" + billingResult.responseCode)
mPayCallBack?.onError("初始化连接失败 code:" + billingResult.responseCode + " msg:" + billingResult.debugMessage) mAutoPayCallBack?.onError("初始化连接失败 code:" + billingResult.responseCode + " msg:" + billingResult.debugMessage)
} }
} }
override fun onBillingServiceDisconnected() { override fun onBillingServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
Log.d(TAG, "init onBillingServiceDisconnected") Log.d(TAG, "init onBillingServiceDisconnected")
mPayCallBack?.onError("初始化连接失败 onBillingServiceDisconnected") mAutoPayCallBack?.onError("初始化连接失败 onBillingServiceDisconnected")
} }
}) })
} }
...@@ -160,7 +160,6 @@ class GooglePayHelper { ...@@ -160,7 +160,6 @@ class GooglePayHelper {
if (!skuDetailsList.isNullOrEmpty()) { if (!skuDetailsList.isNullOrEmpty()) {
for (i in 0 until skuDetailsList.size) { for (i in 0 until skuDetailsList.size) {
val skuDetails = skuDetailsList[i] val skuDetails = skuDetailsList[i]
Log.d(TAG, "purchase skuDetails $skuDetails")
if (mSku == skuDetails.sku) { if (mSku == skuDetails.sku) {
val flowParams = BillingFlowParams.newBuilder() val flowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetails) .setSkuDetails(skuDetails)
...@@ -174,6 +173,11 @@ class GooglePayHelper { ...@@ -174,6 +173,11 @@ class GooglePayHelper {
flowParams flowParams
).responseCode ).responseCode
Log.d(TAG, "purchase 去支付 code $responseCode") Log.d(TAG, "purchase 去支付 code $responseCode")
break
} else {
if (i == skuDetailsList.size - 1) {
mPayCallBack?.onError("GooglePay 未匹配到对应的商品")
}
} }
} }
...@@ -188,7 +192,23 @@ class GooglePayHelper { ...@@ -188,7 +192,23 @@ class GooglePayHelper {
} }
} else { } else {
Log.d(TAG, "purchase 购买 未连接") Log.d(TAG, "purchase 购买 未连接")
mPayCallBack?.onError("GooglePay purchase 购买 未连接") billingClient.startConnection(object : BillingClientStateListener {
override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingResponseCode.OK) {
//BillingClient准备好了。你可以在这里查询购买情况。
purchase(mSku, orderId)
} else {
mPayCallBack?.onError("purchase 购买 连接失败 code:" + billingResult.responseCode + " msg:" + billingResult.debugMessage)
}
}
override fun onBillingServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
mPayCallBack?.onError("purchase 购买连接失败 onBillingServiceDisconnected")
}
})
// mPayCallBack?.onError("GooglePay purchase 购买 未连接")
} }
} }
...@@ -208,7 +228,7 @@ class GooglePayHelper { ...@@ -208,7 +228,7 @@ class GooglePayHelper {
) { billingResult, s -> ) { billingResult, s ->
if (billingResult.responseCode == BillingResponseCode.OK) { if (billingResult.responseCode == BillingResponseCode.OK) {
// Handle the success of the consume operation. // Handle the success of the consume operation.
Log.d(TAG, "consume 消耗成功${googlePayResult.purchaseToken}") // Log.d(TAG, "consume 1消耗成功${googlePayResult.purchaseToken}")
//同步后台 消耗掉 //同步后台 消耗掉
updateToService(googlePayResult, purchase) updateToService(googlePayResult, purchase)
productId = "" productId = ""
...@@ -262,20 +282,22 @@ class GooglePayHelper { ...@@ -262,20 +282,22 @@ class GooglePayHelper {
* *
* @param purchaseToken 商品token * @param purchaseToken 商品token
*/ */
private fun consume2(purchaseToken: String) { private fun consume2(googlePayResult: GooglePayResult, purchase: Purchase) {
if (billingClient.isReady) { if (billingClient.isReady) {
val consumeParams = val consumeParams =
ConsumeParams.newBuilder() ConsumeParams.newBuilder()
.setPurchaseToken(purchaseToken) .setPurchaseToken(purchase.purchaseToken)
.build() .build()
billingClient.consumeAsync( billingClient.consumeAsync(
consumeParams consumeParams
) { billingResult, s -> ) { billingResult, s ->
if (billingResult.responseCode == BillingResponseCode.OK) { if (billingResult.responseCode == BillingResponseCode.OK) {
// Handle the success of the consume operation. // Handle the success of the consume operation.
Log.d(TAG, "consume 消耗成功$purchaseToken") Log.d(TAG, "consume 消耗成功${purchase.purchaseToken}")
//同步后台 消耗掉
updateToService2(googlePayResult, purchase)
} else { } else {
Log.d(TAG, "consume 消耗失败 code:" + billingResult.responseCode) mAutoPayCallBack?.onError("补单消耗失败 code:${billingResult.responseCode} msg:${billingResult.debugMessage}")
} }
} }
} else { } else {
...@@ -285,27 +307,27 @@ class GooglePayHelper { ...@@ -285,27 +307,27 @@ class GooglePayHelper {
//重连后 消耗掉 //重连后 消耗掉
val consumeParams = val consumeParams =
ConsumeParams.newBuilder() ConsumeParams.newBuilder()
.setPurchaseToken(purchaseToken) .setPurchaseToken(purchase.purchaseToken)
.build() .build()
billingClient.consumeAsync( billingClient.consumeAsync(
consumeParams consumeParams
) { billingResult, s -> ) { billingResult, s ->
if (billingResult.responseCode == BillingResponseCode.OK) { if (billingResult.responseCode == BillingResponseCode.OK) {
// Handle the success of the consume operation. // Handle the success of the consume operation.
Log.d(TAG, "consume 消耗成功$purchaseToken") Log.d(TAG, "consume 消耗成功${purchase.purchaseToken}")
//同步后台 消耗掉
updateToService2(googlePayResult, purchase)
} else { } else {
Log.d(TAG, "consume 消耗失败 code:" + billingResult.responseCode) mAutoPayCallBack?.onError("重连 补单消耗失败 code:${billingResult.responseCode} msg:${billingResult.debugMessage}")
} }
} }
} else { } else {
Log.d(TAG, "consume init 连接失败 code:" + billingResult.responseCode) mAutoPayCallBack?.onError("补单 连接失败 Error code:${billingResult.responseCode} msg:${billingResult.debugMessage}")
} }
} }
override fun onBillingServiceDisconnected() { override fun onBillingServiceDisconnected() {
// Try to restart the connection on the next request to mAutoPayCallBack?.onError("补单 连接失败 Error onBillingServiceDisconnected")
// Google Play by calling the startConnection() method.
Log.d(TAG, "consume init onBillingServiceDisconnected")
} }
}) })
} }
...@@ -313,26 +335,59 @@ class GooglePayHelper { ...@@ -313,26 +335,59 @@ class GooglePayHelper {
/** /**
* 补单操作 查询购买交易,以确保所有购买交易都得到成功处理,如购买未发货,或者未消耗 * 补单操作 查询购买交易,以确保所有购买交易都得到成功处理,如购买未发货,或者未消耗
* type 1 初始化查询补单 2 实时支付成功回调补单
*/ */
private fun queryPurchases() { private fun queryPurchases(type: Int) {
if (billingClient.isReady) { if (billingClient.isReady) {
billingClient.queryPurchasesAsync( billingClient.queryPurchasesAsync(
SkuType.INAPP SkuType.INAPP
) { billingResult, mutableList -> ) { billingResult, mutableList ->
if (billingResult.responseCode == BillingResponseCode.OK) { if (billingResult.responseCode == BillingResponseCode.OK) {
if (mutableList.isNullOrEmpty()) { if (mutableList.isNullOrEmpty()) {
Log.d(TAG, "queryPurchases null") if (type == 2) {
mPayCallBack?.onError("GooglePay支付回调补单未查询到需补单的商品")
}
} else { } else {
for (i in 0 until mutableList.size) { for (i in 0 until mutableList.size) {
Log.d(TAG, "queryPurchases init " + mutableList[i].purchaseState)
if (mutableList[i].purchaseState == Purchase.PurchaseState.PURCHASED) { if (mutableList[i].purchaseState == Purchase.PurchaseState.PURCHASED) {
val purchase = mutableList[i];
val googleJson = JSONObject(purchase.originalJson)
val proId = googleJson.optString("productId") ?: ""
val accountId = googleJson.optString("obfuscatedAccountId") ?: ""
var googlePayResult = GooglePayResult()
googlePayResult.packageName = purchase.packageName
googlePayResult.orderId = purchase.orderId
googlePayResult.productId = proId
googlePayResult.obfuscatedAccountid = accountId
googlePayResult.developerPayload = purchase.developerPayload
googlePayResult.purchaseTime = purchase.purchaseTime.toString()
googlePayResult.purchaseState =
purchase.purchaseState.toString()
googlePayResult.purchaseToken = purchase.purchaseToken
if (type == 2) {
//已购买,消耗即可 //已购买,消耗即可
consume2(mutableList[i].purchaseToken) consume(googlePayResult, purchase)
} else if (type == 1) {
//之前已购买,消耗即可
consume2(googlePayResult, purchase)
}
} else {
if (i == mutableList.size - 1) {
if (type == 2) {
mPayCallBack?.onError("GooglePay支付回调补单商品状态异常 status${mutableList[i].purchaseState}")
} else if (type == 1) {
mAutoPayCallBack?.onError("GooglePay初始化查询补单商品状态异常 status${mutableList[i].purchaseState}")
}
}
} }
} }
} }
} else { } else {
Log.d(TAG, "queryPurchases error code" + billingResult.responseCode) if (type == 2) {
mPayCallBack?.onError("GooglePay支付补单查询异常 code${billingResult.responseCode} msg:${billingResult.debugMessage}")
} else if (type == 1) {
mAutoPayCallBack?.onError("GooglePay初始化补单查询异常 code${billingResult.responseCode} msg:${billingResult.debugMessage}")
}
} }
} }
} else { } else {
...@@ -340,26 +395,86 @@ class GooglePayHelper { ...@@ -340,26 +395,86 @@ class GooglePayHelper {
override fun onBillingSetupFinished(billingResult: BillingResult) { override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingResponseCode.OK) { if (billingResult.responseCode == BillingResponseCode.OK) {
//BillingClient准备好了。你可以在这里查询购买情况。 //BillingClient准备好了。你可以在这里查询购买情况。
Log.d(TAG, "queryPurchases init 连接成功") billingClient.queryPurchasesAsync(
SkuType.INAPP
) { billingResult, mutableList ->
if (billingResult.responseCode == BillingResponseCode.OK) {
if (mutableList.isNullOrEmpty()) {
if (type == 2) {
mPayCallBack?.onError("GooglePay支付回调补单未查询到需补单的商品")
}
} else { } else {
Log.d(TAG, "queryPurchases init 连接失败 code:" + billingResult.responseCode) for (i in 0 until mutableList.size) {
if (mutableList[i].purchaseState == Purchase.PurchaseState.PURCHASED) {
val purchase = mutableList[i];
var googlePayResult = GooglePayResult()
val googleJson = JSONObject(purchase.originalJson)
val proId = googleJson.optString("productId") ?: ""
val accountId =
googleJson.optString("obfuscatedAccountId") ?: ""
googlePayResult.packageName = purchase.packageName
googlePayResult.orderId = purchase.orderId
googlePayResult.productId = proId
googlePayResult.obfuscatedAccountid = accountId
googlePayResult.developerPayload =
purchase.developerPayload
googlePayResult.purchaseTime =
purchase.purchaseTime.toString()
googlePayResult.purchaseState =
purchase.purchaseState.toString()
googlePayResult.purchaseToken = purchase.purchaseToken
if (type == 2) {
//已购买,消耗即可
consume(googlePayResult, purchase)
} else if (type == 1) {
//之前已购买,消耗即可
consume2(googlePayResult, purchase)
}
} else {
if (i == mutableList.size - 1) {
if (type == 2) {
mPayCallBack?.onError("GooglePay支付回调补单商品状态异常 status${mutableList[i].purchaseState}")
} else if (type == 1) {
mAutoPayCallBack?.onError("GooglePay初始化查询补单商品状态异常 status${mutableList[i].purchaseState}")
}
}
}
}
}
} else {
if (type == 2) {
mPayCallBack?.onError("GooglePay支付补单查询异常 code${billingResult.responseCode} msg:${billingResult.debugMessage}")
} else if (type == 1) {
mAutoPayCallBack?.onError("GooglePay初始化补单查询异常 code${billingResult.responseCode} msg:${billingResult.debugMessage}")
}
}
}
} else {
if (type == 2) {
mPayCallBack?.onError("GooglePay支付补单查询重连 连接异常 code${billingResult.responseCode} msg:${billingResult.debugMessage}")
} else if (type == 1) {
mAutoPayCallBack?.onError("GooglePay初始化补单查询重连 连接异常 code${billingResult.responseCode} msg:${billingResult.debugMessage}")
}
} }
} }
override fun onBillingServiceDisconnected() { override fun onBillingServiceDisconnected() {
// Try to restart the connection on the next request to // Try to restart the connection on the next request to
// Google Play by calling the startConnection() method. // Google Play by calling the startConnection() method.
Log.d(TAG, "queryPurchases init onBillingServiceDisconnected") if (type == 2) {
mPayCallBack?.onError("GooglePay支付补单查询连接异常 重连失败 onBillingServiceDisconnected")
} else if (type == 1) {
mAutoPayCallBack?.onError("GooglePay初始化补单查询连接异常 重连失败 onBillingServiceDisconnected")
}
} }
}) })
} }
} }
/** /**
* google支付 * google支付
*/ */
fun googlePay(goodsId: String,payMode: String, payCallBack: GooglePayCallBack) { fun googlePay(goodsId: String, payMode: String, payCallBack: GooglePayCallBack) {
mPayCallBack = payCallBack mPayCallBack = payCallBack
//向服务端获取订单ID //向服务端获取订单ID
ApiClient.userInfoAPi.googlePay(goodsId, "4", "", "", payMode) ApiClient.userInfoAPi.googlePay(goodsId, "4", "", "", payMode)
...@@ -368,10 +483,9 @@ class GooglePayHelper { ...@@ -368,10 +483,9 @@ class GooglePayHelper {
override fun onSuccess(result: GooglePayEntity?) { override fun onSuccess(result: GooglePayEntity?) {
if (result != null) { if (result != null) {
var sku = goodsId.replace("-", "_") var sku = goodsId.replace("-", "_")
Log.d(TAG, "请求支付${sku}") // Log.d(TAG, "请求支付${sku}")
purchase("xymh_$sku", result.outTradeNo ?: "") purchase("xymh_$sku", result.outTradeNo ?: "")
} else { } else {
Log.d(TAG, "未获取到订单")
mPayCallBack?.onError("GooglePay 未获取到订单数据") mPayCallBack?.onError("GooglePay 未获取到订单数据")
} }
} }
...@@ -392,25 +506,44 @@ class GooglePayHelper { ...@@ -392,25 +506,44 @@ class GooglePayHelper {
.compose(RxSchedulers.observableIO2Main()) .compose(RxSchedulers.observableIO2Main())
.subscribe(object : BaseObserver<Any>() { .subscribe(object : BaseObserver<Any>() {
override fun onSuccess(result: Any?) { override fun onSuccess(result: Any?) {
EventUtils.onEvent("googlepaysuccess_onsuccess") // EventUtils.onEvent("googlepaysuccess_onsuccess")
mPayCallBack?.onPaySuccess(googlePayResult, purchase.originalJson)//支付成功 mPayCallBack?.onPaySuccess(googlePayResult, purchase.originalJson)//支付成功
if (result != null) {
}
} }
override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) { override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
EventUtils.onEvent("googlepaysuccess_onfailure", "${errorMsg}") // EventUtils.onEvent("googlepaysuccess_onfailure", "${errorMsg}")
mPayCallBack?.onError("服务器同步失败 code:$code msg:$errorMsg") mPayCallBack?.onError("服务器同步失败 code:$code msg:$errorMsg")
} }
}) })
} }
/**
* google支付 成功后 补单消耗 同步给服务器
*/
private fun updateToService2(googlePayResult: GooglePayResult, purchase: Purchase) {
//支付成功 向后端同步 网络问题再次重试
ApiClient.shopApi.googlePaySuccess(googlePayResult)
.compose(RxSchedulers.observableIO2Main())
.subscribe(object : BaseObserver<Any>() {
override fun onSuccess(result: Any?) {
// EventUtils.onEvent("googlepaysuccess_onsuccess")
mAutoPayCallBack?.onPaySuccess(googlePayResult, purchase.originalJson)//补单支付成功
}
override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
// EventUtils.onEvent("googlepaysuccess_onfailure", "${errorMsg}")
mAutoPayCallBack?.onError("补单 服务器同步失败 code:$code msg:$errorMsg")
}
})
}
fun release() { fun release() {
if (billingClient.isReady) { if (billingClient.isReady) {
billingClient.endConnection(); billingClient.endConnection();
} }
mPayCallBack = null mPayCallBack = null
mAutoPayCallBack = null
Log.d(TAG, "billingClient release") Log.d(TAG, "billingClient release")
} }
......
...@@ -35,8 +35,10 @@ import io.reactivex.Observable ...@@ -35,8 +35,10 @@ import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Consumer import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.activity_member.* import kotlinx.android.synthetic.main.activity_member.*
import org.json.JSONObject
import java.util.* import java.util.*
/** /**
* Created by gaoleichao on 2021/8/30 * Created by gaoleichao on 2021/8/30
*/ */
...@@ -83,9 +85,25 @@ class PayActivity : BaseActivity(), PayContract.View, ...@@ -83,9 +85,25 @@ class PayActivity : BaseActivity(), PayContract.View,
false, false,
false false
) )
mPresenter = PayPresenter(this)
googlePay = GooglePayHelper(this) googlePay = GooglePayHelper(this)
googlePay?.init() googlePay?.init(object : GooglePayCallBack {
override fun onPaySuccess(purchase: GooglePayResult, googleJson: String) {
mPresenter?.verifyPay(googleJson, GOOGLE_PAY)
//mLoading?.setResult(true, "Pay for success", 1000)
EventUtils.onEvent("GooglePaySuccess_bd")
}
override fun onCancel() {
EventUtils.onEvent("GooglePayCancel_bd")
}
override fun onError(error: String) {
Log.d("wxw", "补单PayError:$error")
EventUtils.onEvent("GooglePayError_bd", error)
}
})
id_img_back?.setOnClickListener { id_img_back?.setOnClickListener {
finish() finish()
...@@ -139,7 +157,6 @@ class PayActivity : BaseActivity(), PayContract.View, ...@@ -139,7 +157,6 @@ class PayActivity : BaseActivity(), PayContract.View,
// setBootmPrice() // setBootmPrice()
id_tv_my_yu_e?.text = SettingPreference.getUserCoinNum() id_tv_my_yu_e?.text = SettingPreference.getUserCoinNum()
mPresenter = PayPresenter(this)
// mAdapter = PayAdapter(this,itemlayout) // mAdapter = PayAdapter(this,itemlayout)
// val data = VideoEntity() // val data = VideoEntity()
...@@ -156,70 +173,13 @@ class PayActivity : BaseActivity(), PayContract.View, ...@@ -156,70 +173,13 @@ class PayActivity : BaseActivity(), PayContract.View,
} }
mLoading?.setLoading("Loading") mLoading?.setLoading("Loading")
mLoading?.show() mLoading?.show()
EventUtils.onEvent("pay_page_pay_btn", product?.cash + "") onEvent("pay_page_pay_btn", product?.cash + "")
if (ifChooseNeedPrice!!) { if (pay_type == GOOGLE_PAY) {
if (pay_type == 1) {
mPresenter?.requestAliPay(
this,
id_tv_need_price.text.toString(),
pay_type.toString(),
"6"
)
} else {
if (pay_type == 2) {
Log.e("MXL", "微信原生支付")
mPresenter?.requestWechatPayOrder("", pay_type.toString())
} else if (pay_type == 11) {
Log.e("MXL", "微信连连支付")
mPresenter?.requestWechatPayOrder("", pay_type.toString())
} else {
Log.e("MXL", "微信敏支付")
mPresenter?.requestMiniProgrom(
id_tv_need_price.text.toString(),
pay_type.toString(),
"6"
)
}
}
} else {
if (pay_type == ALI_PAY) {
mPresenter?.requestAliPay(
this,
product?.goodsId ?: "",
pay_type.toString(),
"6"
)
} else if (pay_type == GOOGLE_PAY) {
googlePay(product?.goodsId ?: "") googlePay(product?.goodsId ?: "")
} else if (pay_type == PAY_PAL_PAY) { } else if (pay_type == PAY_PAL_PAY) {
onEvent("pay_type_error", "暂不支持paypal")
} else { } else {
if (pay_type == 2) { onEvent("pay_type_error", "pay_type$pay_type")
Log.e("MXL", "2微信原生支付")
mPresenter?.requestWechatPayOrder(
product?.goodsId ?: "",
pay_type.toString()
)
} else if (pay_type == 11) {
Log.e("MXL", "2微信连连支付")
mPresenter?.requestWechatPayOrder(
product?.goodsId ?: "",
pay_type.toString()
)
} else {
Log.e("MXL", "2微信敏支付")
mPresenter?.requestMiniProgrom(
product?.goodsId ?: "",
pay_type.toString(),
"6"
)
}
}
} }
} }
...@@ -560,7 +520,7 @@ class PayActivity : BaseActivity(), PayContract.View, ...@@ -560,7 +520,7 @@ class PayActivity : BaseActivity(), PayContract.View,
} }
mLoading?.setLoading(getString(R.string.wait_ing2)) mLoading?.setLoading(getString(R.string.wait_ing2))
mLoading?.show() mLoading?.show()
googlePay?.googlePay(goodsId,"6", object : GooglePayCallBack { googlePay?.googlePay(goodsId, "6", object : GooglePayCallBack {
override fun onPaySuccess(purchase: GooglePayResult, googleJson: String) { override fun onPaySuccess(purchase: GooglePayResult, googleJson: String) {
mPresenter?.verifyPay(googleJson, GOOGLE_PAY) mPresenter?.verifyPay(googleJson, GOOGLE_PAY)
//mLoading?.setResult(true, "Pay for success", 1000) //mLoading?.setResult(true, "Pay for success", 1000)
...@@ -579,7 +539,7 @@ class PayActivity : BaseActivity(), PayContract.View, ...@@ -579,7 +539,7 @@ class PayActivity : BaseActivity(), PayContract.View,
runOnUiThread { runOnUiThread {
mLoading?.setResult(false, "pay error", 1000) mLoading?.setResult(false, "pay error", 1000)
} }
EventUtils.onEvent("GooglePayError",error) EventUtils.onEvent("GooglePayError", error)
} }
}) })
} }
......
...@@ -269,7 +269,19 @@ class OrderDetailActivity : BaseActivity(), OrderDetailContract.View, PayContrac ...@@ -269,7 +269,19 @@ class OrderDetailActivity : BaseActivity(), OrderDetailContract.View, PayContrac
fun initPayConfig() { fun initPayConfig() {
googlePay = GooglePayHelper(this) googlePay = GooglePayHelper(this)
googlePay?.init() googlePay?.init(object :GooglePayCallBack{
override fun onPaySuccess(purchase: GooglePayResult, googleJson: String) {
}
override fun onCancel() {
}
override fun onError(error: String) {
}
})
mPayresenter = PayPresenter(this) mPayresenter = PayPresenter(this)
mPayresenter?.appInfo() mPayresenter?.appInfo()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment