Commit 460cdf3b authored by 王雪伟's avatar 王雪伟

[提交人]:王雪伟

[提交简述] :修改充值弹窗
[实现方案] :
parent 5729eae5
......@@ -13,6 +13,12 @@ import androidx.multidex.MultiDex
import com.heytap.msp.push.HeytapPushManager
import com.huawei.hms.push.HmsMessaging
import com.meizu.cloud.pushsdk.PushManager
import com.paypal.checkout.PayPalCheckout
import com.paypal.checkout.config.CheckoutConfig
import com.paypal.checkout.config.Environment
import com.paypal.checkout.config.SettingsConfig
import com.paypal.checkout.createorder.CurrencyCode
import com.paypal.checkout.createorder.UserAction
import com.tencent.android.tpush.XGPushConfig
import com.tencent.bugly.crashreport.CrashReport
import com.tencent.imsdk.v2.V2TIMCallback
......@@ -105,8 +111,26 @@ class Appli : Application() {
// }
// })
registerActivityLifecycleCallbacks(StatisticActivityLifecycleCallback())
}
initPayPal()
}
private fun initPayPal() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val config = CheckoutConfig(
application = this,
clientId = Constant.PAY_PAL_CLIENT_ID,
environment = Environment.SANDBOX,//正式上线后,改为Environment.LIVE
returnUrl = "com.zhangxin.starlight://paypalpay",//创建应用时填的RETURN_URL
currencyCode = CurrencyCode.USD,//货币种类:CNY-人民币;HKD-港币;TWD-新台币;USD-美元...
userAction = UserAction.PAY_NOW,
settingsConfig = SettingsConfig(
loggingEnabled = false,
shouldFailEligibility = false
)
)
PayPalCheckout.setConfig(config)
}
}
private fun getOaid() {
MiitHelper(appIdsUpdater).getDeviceIds(AppContext.mAppContext)
}
......
......@@ -8,6 +8,8 @@ import android.Manifest;
public class Constant {
public static String PAY_PAL_CLIENT_ID ="AeCOQewq8tWcuy7V2YsL3S3IRMDZk6zSTtHP76x-yiHIgYN7PZ1xT4Iyzv-2zJm15OqR5sWjc6__9xhE";
//公共参数
String UMENG_APPKEY = "597dbf2abbea835685001b27";
......
......@@ -30,6 +30,7 @@ public class NetConfig {
public static String BASE_FEED_URL = "";
public static final String URL_REPORT_BASE = "http://report.zhangxinhulian.com/";
public static final String HOME_BANNER_BASE_URL = "https://bs.zhangxinhulian.com/";
public static final String URL_PAY_BASE = "http://paytest.zhangxinhulian.com/";
public static void setBase_Url(Environment s) {
sEnvironment = s;
......@@ -155,6 +156,9 @@ public class NetConfig {
public static final String URL_AUTH_GOOGLE_LOGIN = "app/v1/auth/googleLogin";//绑定谷歌登录
public static final String URL_AUTH_FACEBOOK_LOGIN = "app/v1/auth/facebookLogin";//绑定FaceBook登录
///unifiedpay/gateway/google/替换包名/notify/order
public static final String URL_GOOGLE_NOTIFY = URL_PAY_BASE + "unifiedpay/gateway/google/com.zhangxin.magicbox/notify/order";
}
public static class Task {
......
......@@ -8,6 +8,7 @@ import com.zxhl.cms.net.model.other.IsWeChatLoginEntity
import com.zxhl.cms.net.model.other.WxBindEntity
import com.zxhl.cms.net.model.uc.UserInfo
import com.zxhl.cms.net.model.uc.VersionEntity
import com.zxhl.cms.pay.googlepay.GooglePayResult
import io.reactivex.Observable
import okhttp3.MultipartBody
import retrofit2.http.*
......@@ -305,4 +306,12 @@ interface IHomeApi {
@POST(NetConfig.StarLight.HOME_STAR_CONSTELLATION_RESLUT)
fun getStarMachReslut(): Observable<Response<StarMachEntity>>
/**
* google支付成功后 通知后台
*/
@POST(NetConfig.User.URL_GOOGLE_NOTIFY)
fun googlePaySuccess(
@Body entity: GooglePayResult?
): Observable<Response<Any>>
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.zxhl.cms.net.api;
import com.zxhl.cms.ad.upload.model.Response;
import com.zxhl.cms.common.NetConfig;
import com.zxhl.cms.net.model.pay.GooglePayEntity;
import com.zxhl.cms.net.model.uc.AliPayEntity;
import com.zxhl.cms.net.model.uc.PayVerifyEntity;
import com.zxhl.cms.net.model.uc.UserInfo;
......@@ -64,6 +65,13 @@ public interface IUserInfoApi {
@POST(NetConfig.User.URL_PAY_ORDER)
Observable<Response<AliPayEntity>> aliPay(@Query("goodsId") String goodsId, @Query("payType") String payType, @Query("voucherId") String voucherId, @Query("appId") String appId);
/**
* Google支付
*
* @return
*/
@POST(NetConfig.User.URL_PAY_ORDER)
Observable<Response<GooglePayEntity>> googlePay(@Query("goodsId") String goodsId, @Query("payType") String payType, @Query("voucherId") String voucherId, @Query("appId") String appId, @Query("payMode") String payMode);
/**
* 获取用户资料
......
package com.zxhl.cms.net.model.pay;
/**
* @author (wangXuewei)
* @detail :
*/
public class GooglePayEntity {
/**
* payType : 4
* wakeup : {"orderNo":1503315110133714944}
* payPlatform : null
* outTradeNo : 1503315110133714944
*/
private int payType;
private WakeupBean wakeup;
private String outTradeNo;
public int getPayType() {
return payType;
}
public void setPayType(int payType) {
this.payType = payType;
}
public WakeupBean getWakeup() {
return wakeup;
}
public void setWakeup(WakeupBean wakeup) {
this.wakeup = wakeup;
}
public String getOutTradeNo() {
return outTradeNo;
}
public void setOutTradeNo(String outTradeNo) {
this.outTradeNo = outTradeNo;
}
public static class WakeupBean {
/**
* orderNo : 1503315110133714944
*/
private long orderNo;
public long getOrderNo() {
return orderNo;
}
public void setOrderNo(long orderNo) {
this.orderNo = orderNo;
}
}
}
package com.zxhl.cms.pay.adapter
import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.zxhl.cms.R
import com.zxhl.cms.common.base.BaseRecyclerAdapter
import com.zxhl.cms.net.model.pay.VipPayEntity
import com.zxhl.cms.utils.OnRecycleItemClickListener
/**
* @author (wangXuewei)
* @datetime 2022-04-12 19:04 GMT+8
* @detail :
*/
class BecomeVipDialogPriceAdapter : BaseRecyclerAdapter<VipPayEntity, BecomeVipDialogPriceAdapter.ViewHolder> {
private var mContext: Context? = null
private var mPosition = 0
private val listener: OnRecycleItemClickListener<VipPayEntity>
constructor(
content: Context?,
listener: OnRecycleItemClickListener<VipPayEntity>
) : super() {
this.listener = listener
mContext = content
}
fun setSelectView(position: Int) {
mPosition = position;
notifyDataSetChanged()
}
override fun onCreateViewHolder(holder: ViewGroup, p1: Int): BecomeVipDialogPriceAdapter.ViewHolder {
return ViewHolder(
LayoutInflater.from(holder.context)
.inflate(R.layout.item_layout_become_dialog_vip_price_view, holder, false)
)
}
override fun onBindViewHolder(holder: BecomeVipDialogPriceAdapter.ViewHolder, position: Int) {
// val data = mList[position]
holder.id_vip_time.text = "1 Week +"
holder.id_coin_num.text = "780"
holder.id_money.text = "$${2.99}"
if (mPosition==position){
holder.id_item_view.background = mContext?.getDrawable(R.drawable.shape_8857ff_bd8aff_bg_r10)
holder.id_vip_time.setTextColor(Color.parseColor("#FFFFFF"))
holder.id_coin_num.setTextColor(Color.parseColor("#FFFFFF"))
holder.id_money.setTextColor(Color.parseColor("#FFFFFF"))
}else{
holder.id_item_view.background = mContext?.getDrawable(R.drawable.shape_f4edff_r10_bg)
holder.id_vip_time.setTextColor(Color.parseColor("#333333"))
holder.id_coin_num.setTextColor(Color.parseColor("#333333"))
holder.id_money.setTextColor(Color.parseColor("#333333"))
}
holder.id_item_view?.setOnClickListener {
listener.onItemClick(it,position,null)
}
}
override fun getItemCount(): Int {
return 3
}
inner class ViewHolder : RecyclerView.ViewHolder {
var id_vip_time: TextView
var id_money: TextView
var id_coin_num: TextView
var id_item_view: LinearLayout
constructor(itemView: View) : super(itemView) {
id_item_view = itemView.findViewById(R.id.id_ll_dialog_item_become_vip_view)
id_vip_time = itemView.findViewById(R.id.id_tv_dialog_item_vip_time)
id_coin_num = itemView.findViewById(R.id.id_tv_dialog_coin_num)
id_money = itemView.findViewById(R.id.id_tv_dialog_item_price)
}
}
}
\ No newline at end of file
package com.zxhl.cms.pay.googlepay
/**
* @author (wangXuewei)
* @datetime 2022-03-14 16:49 GMT+8
* @detail :
*/
interface GooglePayCallBack {
fun onPaySuccess(purchase: GooglePayResult, googleJson:String)
fun onCancel()
fun onError(error: String)
}
\ No newline at end of file
package com.zxhl.cms.pay.googlepay
import android.app.Activity
import android.util.Log
import com.android.billingclient.api.*
import com.android.billingclient.api.BillingClient.BillingResponseCode
import com.android.billingclient.api.BillingClient.SkuType
import com.zxhl.cms.AppContext
import com.zxhl.cms.net.ApiClient
import com.zxhl.cms.net.RxSchedulers
import com.zxhl.cms.net.callback.BaseObserver
import com.zxhl.cms.net.model.pay.GooglePayEntity
import com.zxhl.cms.utils.EventUtils
import org.json.JSONObject
/**
* @author (wangXuewei)
* @datetime 2022-03-09 15:12 GMT+8
* @detail :
*/
class GooglePayHelper {
private val TAG = "GooglePayHelper"
private var mActivity: Activity;
private var mPayCallBack: GooglePayCallBack? = null;
private var mAutoPayCallBack: GooglePayCallBack? = null;//补单监听
private var productId = ""
private var obfuscatedAccountid = ""
constructor(mActivity: Activity) {
this.mActivity = mActivity
}
/**
* 购买监听
*/
private val purchasesUpdatedListener =
PurchasesUpdatedListener { billingResult, purchases ->
// To be implemented in a later section.
Log.d(TAG, "购买监听 code ${billingResult.responseCode}")
Log.d(TAG, "购买监听 size ${purchases?.size}")
EventUtils.onEvent(
"GooglePayGotoPayE",
"Google支付结束回调结果 code${billingResult.responseCode}"
)
if (billingResult.responseCode == BillingResponseCode.OK) {
//支付成功 同步后台
if (!purchases.isNullOrEmpty()) {
for (i in 0 until purchases.size) {
val purchase = purchases[i];
val googleJson = JSONObject(purchase.originalJson)
val proId = googleJson.optString("productId") ?: productId
val accountId =
googleJson.optString("obfuscatedAccountId") ?: obfuscatedAccountid
val 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
//购买成功 消耗掉
consume(googlePayResult, purchase)
}
}else{
mPayCallBack?.onError("支付异常: google支付成功,未获取到商品结果信息")
}
} else if (billingResult.responseCode == BillingResponseCode.ITEM_ALREADY_OWNED) {
//未消耗掉
queryPurchases(2)
// mPayCallBack?.onError("商品未消耗掉 查询补单")
} else if (billingResult.responseCode == BillingResponseCode.USER_CANCELED) {
mPayCallBack?.onCancel()
} else {
mPayCallBack?.onError("支付异常: code:" + billingResult.responseCode + " msg:" + billingResult.debugMessage)
// when (billingResult.responseCode) {
// BillingResponseCode.SERVICE_TIMEOUT -> {
// //服务连接超时
// }
// BillingResponseCode.FEATURE_NOT_SUPPORTED -> {
// }
// BillingResponseCode.SERVICE_DISCONNECTED -> {
// //服务未连接
// }
// BillingResponseCode.USER_CANCELED -> {
// //取消
// }
// BillingResponseCode.SERVICE_UNAVAILABLE -> {
// //服务不可用
// }
// BillingResponseCode.BILLING_UNAVAILABLE -> {
// //购买不可用
// }
// BillingResponseCode.ITEM_UNAVAILABLE -> {
// //商品不存在
//
// }
// BillingResponseCode.DEVELOPER_ERROR -> {
// //提供给 API 的无效参数
// }
// BillingResponseCode.ERROR -> {
// //错误
// }
// BillingResponseCode.ITEM_NOT_OWNED -> {
// //不可购买
// }
// }
}
}
private var billingClient = BillingClient.newBuilder(AppContext.get())
.setListener(purchasesUpdatedListener)
.enablePendingPurchases()
.build()
//检查之前的商品是否被消费
fun init(autoPayCallBack: GooglePayCallBack) {
mAutoPayCallBack = autoPayCallBack
//已经连接查询订单
if (billingClient.isReady) {
Log.d(TAG, "init 已连接")
queryPurchases(1)
} else {
//开始连接
Log.d(TAG, "init 开始连接")
billingClient.startConnection(object : BillingClientStateListener {
override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingResponseCode.OK) {
//BillingClient准备好了。你可以在这里查询购买情况。
Log.d(TAG, "init 连接成功")
queryPurchases(1)
} else {
Log.d(TAG, "init 连接失败 code:" + billingResult.responseCode)
mAutoPayCallBack?.onError("初始化连接失败 code:" + billingResult.responseCode + " msg:" + billingResult.debugMessage)
}
}
override fun onBillingServiceDisconnected() {
Log.d(TAG, "init onBillingServiceDisconnected")
mAutoPayCallBack?.onError("初始化连接失败 onBillingServiceDisconnected")
}
})
}
}
/**
* 购买商品
*/
private fun purchase(mSku: String, orderId: String) {
EventUtils.onEvent("GooglePayPurchaseS", "预备购买Google商品")
productId = mSku
obfuscatedAccountid = orderId
if (billingClient.isReady) {
val skuList: MutableList<String> = ArrayList()
skuList.add(mSku)
val params = SkuDetailsParams.newBuilder()
params.setSkusList(skuList).setType(SkuType.INAPP)
EventUtils.onEvent("GooglePayQuerySkuS", "开始查询Google商品")
billingClient.querySkuDetailsAsync(
params.build()
) { billingResult, skuDetailsList ->
// Process the result.
if (billingResult.responseCode == BillingResponseCode.OK) {
if (!skuDetailsList.isNullOrEmpty()) {
for (i in 0 until skuDetailsList.size) {
val skuDetails = skuDetailsList[i]
if (mSku == skuDetails.sku) {
val flowParams = BillingFlowParams.newBuilder()
.setSkuDetails(skuDetails)
// .setObfuscatedProfileId()
.setObfuscatedAccountId(orderId)
.build()
EventUtils.onEvent(
"GooglePayGotoPayS",
"查询成功,开始吊起Google支付"
)
//吊起支付
val responseCode =
billingClient.launchBillingFlow(
mActivity,
flowParams
).responseCode
Log.d(TAG, "purchase 去支付 code $responseCode")
EventUtils.onEvent(
"GooglePayQuerySkuE",
"查询商品结束 吊起支付Code:${responseCode}"
)
EventUtils.onEvent(
"GooglePayPurchaseE",
"预备购买结束"
)
break
} else {
if (i == skuDetailsList.size - 1) {
EventUtils.onEvent(
"GooglePayQuerySkuE",
"查询商品结束 未匹配到对应的商品:${mSku}"
)
mPayCallBack?.onError("GooglePay 未匹配到对应的商品${mSku}")
}
}
}
} else {
Log.d(TAG, "purchase 未查询到商品")
EventUtils.onEvent(
"GooglePayQuerySkuE",
"未查询到Google商品列表"
)
mPayCallBack?.onError("GooglePay 未查询到Google商品列表")
}
} else {
Log.d(TAG, "purchase 查询连接失败 cede" + billingResult.responseCode)
EventUtils.onEvent(
"GooglePayQuerySkuE",
"商品查询连接失败 cede${billingResult.responseCode}"
)
mPayCallBack?.onError("GooglePay error code:" + billingResult.responseCode + " msg:" + billingResult.debugMessage)
}
}
} else {
EventUtils.onEvent(
"GooglePayPurchaseE",
"预备购买未连接到Google"
)
billingClient.startConnection(object : BillingClientStateListener {
override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingResponseCode.OK) {
//BillingClient准备好了。你可以在这里查询购买情况。
purchase(mSku, orderId)
} else {
EventUtils.onEvent(
"GooglePayPurchaseE",
"预备购买重连失败 code:${billingResult.responseCode}"
)
mPayCallBack?.onError("purchase 购买 连接失败 code:" + billingResult.responseCode + " msg:" + billingResult.debugMessage)
}
}
override fun onBillingServiceDisconnected() {
EventUtils.onEvent(
"GooglePayPurchaseE",
"预备购买重连失败 Disconnected"
)
mPayCallBack?.onError("purchase 购买连接失败 onBillingServiceDisconnected")
}
})
}
}
/**
* 消耗商品
*
* @param purchaseToken 商品token
*/
private fun consume(googlePayResult: GooglePayResult, purchase: Purchase) {
EventUtils.onEvent(
"GooglePayConsumeS",
"支付成功,开始消耗商品"
)
if (billingClient.isReady) {
val consumeParams =
ConsumeParams.newBuilder()
.setPurchaseToken(googlePayResult.purchaseToken)
.build()
billingClient.consumeAsync(
consumeParams
) { billingResult, s ->
if (billingResult.responseCode == BillingResponseCode.OK) {
// Handle the success of the consume operation.
// Log.d(TAG, "consume 1消耗成功${googlePayResult.purchaseToken}")
EventUtils.onEvent(
"GooglePayConsumeE",
"消耗商品成功"
)
//同步后台 消耗掉
updateToService(googlePayResult, purchase)
productId = ""
obfuscatedAccountid = ""
} else {
EventUtils.onEvent(
"GooglePayConsumeE",
"商品消耗失败 code${billingResult.responseCode}}"
)
Log.d(TAG, "consume 消耗失败 code:" + billingResult.responseCode)
mPayCallBack?.onError("consume 消耗失败 code:" + billingResult.responseCode + " msg:" + billingResult.debugMessage)//支付成功
}
}
} else {
EventUtils.onEvent(
"GooglePayConsumeE",
"消耗商品 未连接Google"
)
EventUtils.onEvent(
"GooglePayConsumeS",
"支付成功,开始重连消耗商品"
)
billingClient.startConnection(object : BillingClientStateListener {
override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingResponseCode.OK) {
//重连后 消耗掉
val consumeParams =
ConsumeParams.newBuilder()
.setPurchaseToken(googlePayResult.purchaseToken)
.build()
billingClient.consumeAsync(
consumeParams
) { billingResult, s ->
if (billingResult.responseCode == BillingResponseCode.OK) {
// Handle the success of the consume operation.
Log.d(TAG, "consume 消耗成功${googlePayResult.purchaseToken}")
EventUtils.onEvent(
"GooglePayConsumeE",
"重连成功 消耗商品成功"
)
//同步后台 消耗掉
updateToService(googlePayResult, purchase)
productId = ""
obfuscatedAccountid = ""
} else {
Log.d(TAG, "consume 消耗失败 code:" + billingResult.responseCode)
EventUtils.onEvent(
"GooglePayConsumeE",
"重连成功 消耗商品失败code:${billingResult.responseCode}}"
)
mPayCallBack?.onError("重连成功 消耗商品失败code:${billingResult.responseCode}")
}
}
} else {
// Log.d(TAG, "consume init 连接失败 code:" + billingResult.responseCode)
EventUtils.onEvent(
"GooglePayConsumeE",
"消耗商品 重连失败code:${billingResult.responseCode}"
)
mPayCallBack?.onError("consume 消耗连接失败 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.
EventUtils.onEvent(
"GooglePayConsumeE",
"消耗商品重连失败 Disconnected"
)
mPayCallBack?.onError("consume onBillingServiceDisconnected")
}
})
}
}
/**
* 补单消耗商品
*
* @param purchaseToken 商品token
*/
private fun consume2(googlePayResult: GooglePayResult, purchase: Purchase) {
if (billingClient.isReady) {
val consumeParams =
ConsumeParams.newBuilder()
.setPurchaseToken(purchase.purchaseToken)
.build()
billingClient.consumeAsync(
consumeParams
) { billingResult, s ->
if (billingResult.responseCode == BillingResponseCode.OK) {
// Handle the success of the consume operation.
Log.d(TAG, "consume 消耗成功${purchase.purchaseToken}")
//同步后台 消耗掉
updateToService2(googlePayResult, purchase)
} else {
mAutoPayCallBack?.onError("补单消耗失败 code:${billingResult.responseCode} msg:${billingResult.debugMessage}")
}
}
} else {
billingClient.startConnection(object : BillingClientStateListener {
override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingResponseCode.OK) {
//重连后 消耗掉
val consumeParams =
ConsumeParams.newBuilder()
.setPurchaseToken(purchase.purchaseToken)
.build()
billingClient.consumeAsync(
consumeParams
) { billingResult, s ->
if (billingResult.responseCode == BillingResponseCode.OK) {
// Handle the success of the consume operation.
Log.d(TAG, "consume 消耗成功${purchase.purchaseToken}")
//同步后台 消耗掉
updateToService2(googlePayResult, purchase)
} else {
mAutoPayCallBack?.onError("重连 补单消耗失败 code:${billingResult.responseCode} msg:${billingResult.debugMessage}")
}
}
} else {
mAutoPayCallBack?.onError("补单 连接失败 Error code:${billingResult.responseCode} msg:${billingResult.debugMessage}")
}
}
override fun onBillingServiceDisconnected() {
mAutoPayCallBack?.onError("补单 连接失败 Error onBillingServiceDisconnected")
}
})
}
}
/**
* 补单操作 查询购买交易,以确保所有购买交易都得到成功处理,如购买未发货,或者未消耗
* type 1 初始化查询补单 2 实时支付成功回调补单
*/
private fun queryPurchases(type: Int) {
if (billingClient.isReady) {
billingClient.queryPurchasesAsync(
SkuType.INAPP
) { billingResult, mutableList ->
if (billingResult.responseCode == BillingResponseCode.OK) {
if (mutableList.isNullOrEmpty()) {
if (type == 2) {
mPayCallBack?.onError("GooglePay支付回调补单未查询到需补单的商品")
}
} else {
for (i in 0 until mutableList.size) {
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) {
//已购买,消耗即可
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 {
billingClient.startConnection(object : BillingClientStateListener {
override fun onBillingSetupFinished(billingResult: BillingResult) {
if (billingResult.responseCode == BillingResponseCode.OK) {
//BillingClient准备好了。你可以在这里查询购买情况。
billingClient.queryPurchasesAsync(
SkuType.INAPP
) { billingResult, mutableList ->
if (billingResult.responseCode == BillingResponseCode.OK) {
if (mutableList.isNullOrEmpty()) {
if (type == 2) {
mPayCallBack?.onError("GooglePay支付回调补单未查询到需补单的商品")
}
} else {
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() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
if (type == 2) {
mPayCallBack?.onError("GooglePay支付补单查询连接异常 重连失败 onBillingServiceDisconnected")
} else if (type == 1) {
mAutoPayCallBack?.onError("GooglePay初始化补单查询连接异常 重连失败 onBillingServiceDisconnected")
}
}
})
}
}
/**
* google支付
*/
fun googlePay(goodsId: String, payMode: String, payCallBack: GooglePayCallBack) {
EventUtils.onEvent("GooglePayGetOrderIdS", "获取订单号")
mPayCallBack = payCallBack
//向服务端获取订单ID
ApiClient.userInfoAPi.googlePay(goodsId, "4", "", "", payMode)
.compose(RxSchedulers.observableIO2Main())
.subscribe(object : BaseObserver<GooglePayEntity>() {
override fun onSuccess(result: GooglePayEntity?) {
if (result != null) {
EventUtils.onEvent("GooglePayGetOrderIdE", "获取订单号_成功")
var sku = goodsId.replace("-", "_")
Log.e(TAG,"SKU${sku}")
purchase("xymh_$sku", result.outTradeNo ?: "")
} else {
EventUtils.onEvent(
"GooglePayGetOrderIdE",
"未获取到订单数据"
)
mPayCallBack?.onError("GooglePay 未获取到订单数据")
}
}
override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
EventUtils.onEvent(
"GooglePayGetOrderIdE",
"获取订单号接口异常:$errorMsg"
)
mPayCallBack?.onError("订单接口 Error:$errorMsg")
}
})
}
/**
* google支付 成功后 同步给服务器
*/
private fun updateToService(googlePayResult: GooglePayResult, purchase: Purchase) {
EventUtils.onEvent(
"GooglePayToServiceS",
"google支付成功,开始同步后端校验"
)
//支付成功 向后端同步 网络问题再次重试
ApiClient.homeApi.googlePaySuccess(googlePayResult)
.compose(RxSchedulers.observableIO2Main())
.subscribe(object : BaseObserver<Any>() {
override fun onSuccess(result: Any?) {
// EventUtils.onEvent("googlepaysuccess_onsuccess")
EventUtils.onEvent(
"GooglePayToServiceE",
"google支付成功,后端校验成功"
)
mPayCallBack?.onPaySuccess(googlePayResult, purchase.originalJson)//支付成功
}
override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
// EventUtils.onEvent("googlepaysuccess_onfailure", "${errorMsg}")
EventUtils.onEvent(
"GooglePayToServiceE",
"google支付成功,后端校验失败 code:$code msg:$errorMsg"
)
mPayCallBack?.onError("服务器同步失败 code:$code msg:$errorMsg")
}
})
}
/**
* google支付 成功后 补单消耗 同步给服务器
*/
private fun updateToService2(googlePayResult: GooglePayResult, purchase: Purchase) {
//支付成功 向后端同步 网络问题再次重试
ApiClient.homeApi.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() {
if (billingClient.isReady) {
billingClient.endConnection();
}
mPayCallBack = null
mAutoPayCallBack = null
Log.d(TAG, "billingClient release")
}
}
\ No newline at end of file
package com.zxhl.cms.pay.googlepay
class GooglePayResult {
var packageName: String = ""
var orderId: String = ""
var productId: String = ""
var developerPayload: String = ""
var obfuscatedAccountid: String = ""
var purchaseTime: String = ""
var purchaseState: String = ""
var purchaseToken: String = ""
}
\ No newline at end of file
package com.zxhl.cms.pay.paypal
import android.app.Activity
import android.util.Log
import com.paypal.checkout.approve.OnApprove
import com.paypal.checkout.cancel.OnCancel
import com.paypal.checkout.createorder.*
import com.paypal.checkout.error.OnError
import com.paypal.checkout.order.*
import com.paypal.checkout.paymentbutton.PayPalButton
import com.zxhl.cms.net.ApiClient
import com.zxhl.cms.net.RxSchedulers
import com.zxhl.cms.net.callback.BaseObserver
import com.zxhl.cms.net.model.pay.GooglePayEntity
import com.zxhl.cms.paypal.PayPalPayCallBack
import kotlinx.android.synthetic.main.activity_member.*
import java.util.*
/**
* @author (wangXuewei)
* @datetime 2022-03-10 16:06 GMT+8
* @detail :
*/
class PayPalHelper {
private val TAG = "PayPalHelper"
private var mActivity: Activity;
private var mPayCallBack: PayPalPayCallBack? = null;
private var mPayButton: PayPalButton? = null;//payPal按钮
constructor(mActivity: Activity) {
this.mActivity = mActivity
}
/**
* payPal支付
*/
fun payPalPay(
goodsId: String,
goodsPrice: String,
payMode: String,
payCallBack: PayPalPayCallBack,
payView: PayPalButton
) {
mPayButton = payView;
mPayCallBack = payCallBack
startPay("2222", goodsPrice)
//向服务端获取订单ID
// ApiClient.userInfoAPi.googlePay(goodsId, "5", "", "", payMode)
// .compose(RxSchedulers.observableIO2Main())
// .subscribe(object : BaseObserver<GooglePayEntity>() {
// override fun onSuccess(result: GooglePayEntity?) {
// if (result != null) {
// startPay(result.outTradeNo, goodsPrice)
// } else {
// mPayCallBack?.onError("payPalPay 未获取到订单数据")
// }
// }
//
// override fun onFailure(e: Throwable?, code: String?, errorMsg: String?) {
// mPayCallBack?.onError("payPalPay 获取订单号接口异常 Error:$errorMsg")
// }
// })
}
private fun startPay(orderId: String, price: String) {
mPayButton?.setup(
createOrder = CreateOrder { createOrderActions ->
val order =
Order(
intent = OrderIntent.CAPTURE,
appContext = AppContext(userAction = UserAction.PAY_NOW),
purchaseUnitList =
listOf(
PurchaseUnit(
//金额相关
amount = Amount(currencyCode = CurrencyCode.USD, value = price),
//发票编号
invoiceId = orderId,
//引用ID
// referenceId = "" + System.currentTimeMillis(),
// customId = orderId,
// description = "这是一笔订单描述",
//收款人(商户的电子邮件地址,商家加密的PayPal账号ID)
// payee = Payee("",""),
// items = listOf(
// Items
// .Builder()
// .name("测试订单")
// .category(category = ItemCategory.DIGITAL_GOODS)
// .quantity("1")
// .build()
// ),
// payments = Payments(),
// shipping = Shipping(),
// softDescriptor = "简单说明"
)
)/*,
ProcessingInstruction.ORDER_COMPLETE_ON_PAYMENT_APPROVAL*/
)
// createOrderActions.set(orderId)
createOrderActions.create(order)
// Log.i("id_PayPal_btn", "createOrderActions order: ${order.purchaseUnitList.size}")
},
onApprove = OnApprove { approval ->
approval.orderActions.capture { captureOrderResult ->
// Log.e(TAG, "CaptureOrder CaptureOrderResult: $captureOrderResult")
// Log.e(TAG, "CaptureOrder approval.data.orderId: ${approval.data.payerId}")
// Log.e(TAG, "CaptureOrder approval.data.orderId: ${approval.data.paymentId}")
// Log.e(TAG, "CaptureOrder approval.data.orderId: ${approval.data.cart}")
// Log.e(TAG, "CaptureOrder approval.data.orderId: ${approval.data.payer}")
if (captureOrderResult is CaptureOrderResult.Success) {
var result = if (!captureOrderResult.orderResponse?.purchaseUnits?.get(0)?.payments?.captures?.get(0)?.id.isNullOrEmpty()) {
"{\"orderId\":\"${orderId}\",\"payPalId\":\"${captureOrderResult.orderResponse?.purchaseUnits?.get(0)?.payments?.captures?.get(0)?.id}\"}"
} else {
"{\"orderId\":\"${orderId}\",\"payPalId\":\"\"}"
}
mPayCallBack?.onPaySuccess(result)
} else if (captureOrderResult is CaptureOrderResult.Error) {
mPayCallBack?.onError("PayPal 获取订单失败 msg: ${captureOrderResult.message} reason:${captureOrderResult.reason}")
}
}
},
onError = OnError { errorInfo ->
Log.e(TAG, "Wid_PayPal_btn OnError Error: $errorInfo")
mPayCallBack?.onError("payPalError:$errorInfo")
},
onCancel = OnCancel {
Log.e(TAG, " OnCancel Buyer canceled the PayPal experience.")
mPayCallBack?.onCancel()
}
)
mPayButton?.callOnClick()
}
// private val TAG = "PayPaylHelper"
// private var checkOrderMax: Int = 300//循环检测的最大次数
// private var checkOrderCount: Int = -1//循环检测的初始次数
// private var isCheckOrderFlag: Boolean = false//是否检测订单状态中
// @RequiresApi(Build.VERSION_CODES.M)
// private fun startPayPal(context: Activity, paypalOrderId: String) {
// PayPalCheckout.start(CreateOrder { createOrderActions ->
// createOrderActions.set(
// paypalOrderId
// )
// }, null, null,
// OnCancel {//实测取消订单后没走这个方法,走到了报错,报的returnUrl是空,但我们再paypal后台和sdk初始化均设置了的,而且在手机浏览器登录paypal买家账号后也是可以拉回我们app的,但是它还是会报这个错,无语子,估计还是paypal得bug
// resetCheckPaypalOrder()
// System.out.println("用户取消Paypal支付")
// },
// OnError { errorInfo ->
// resetCheckPaypalOrder()
// System.out.println("==========paypal onError=======ErrorInfo=======>: $errorInfo")
// System.out.println(
// if (errorInfo?.reason.isNullOrBlank()) (if (errorInfo?.error?.message.isNullOrBlank())
// "Paypal支付未知错误" else errorInfo.error.message) else errorInfo!!.reason
// )
// })
// checkOrderCount = 0
// isCheckOrderFlag = true
// startCheckPaypalOrder(context, paypalOrderId)
// }
//
// private fun startCheckPaypalOrder(context: Activity, paypalOrderId: String) {
// System.out.println("======Stephen=======checkPaypalOrder====>Count:$checkOrderCount")
// if (!isCheckOrderFlag) return
// if (checkOrderCount >= checkOrderMax) {
// resetCheckPaypalOrder()
// System.out.println("Paypal订单支付等待超时")
// return
// }//end of if
// ApiRequestMethod.checkPaypalOrder(paypalOrderId, object : RequestAllCallback<String> {
// //这个是我们接口调用封装方法,换成你们自己的哈(REST v2订单详情接口:https://developer.paypal.com/api/orders/v2/#orders_get)
// override fun onSuccess(data: String?) {//接口返回正确json形如:{"paypal_status":"CREATED"}
// var isContinueLoop = true
// val jsonObject = ToolUtils.instance.fromJsonToObj(data)
// if (null != jsonObject && jsonObject.has("paypal_status")) {
// when (jsonObject.getString("paypal_status")) {
// "APPROVED" -> {//这个状态表示用户已经支付完成,后台开始捕获订单并开始执行确认了,实测这个状态有时差不多得持续1分多钟,快的话也是耗费20多秒,因此添加一个loading逻辑如下,此具体loading显示逻辑更换成你自己实际的loading框,注意loading框得依附在你自己App的当前支付界面上,因为你看到paypal的支付框实质是一个activity,依附在paypal上面会被误关闭
// if (!ToolUtils.instance.isLoadingShow()) ToolUtils.instance.showLoading(
// "确认支付结果中...",
// appendActivity = context
// )
// }
// "COMPLETED" -> {//这个状态表示后台捕获确认订单完成,也就是这笔订单真正的完成了
// isContinueLoop = false
// resetCheckPaypalOrder()
// System.out.println("Paypal订单支付成功")
// }
// }
// }//end of if
// if (isContinueLoop) {
//// ToolUtils.instance.delayExecute(1000L){//这个是我们延时调用封装方法,换成你们自己的哈
//// checkOrderCount++
//// startCheckPaypalOrder(context, paypalOrderId)
//// }
// }//end of if
// }
//
// override fun onFailure(aliErrorResponse: AliErrorResponse, httpCode: Int): Boolean {
// ToolUtils.instance.delayExecute(1000L) {
// checkOrderCount++
// startCheckPaypalOrder(context, paypalOrderId)
// }
// return false
// }
// })
// }
//
// private fun resetCheckPaypalOrder() {
// checkOrderCount = 0
// isCheckOrderFlag = false
//
//// ToolUtils.instance.closeLoading()//关闭loading框
// }
}
\ No newline at end of file
package com.zxhl.cms.paypal
/**
* @author (wangXuewei)
* @datetime 2022-03-14 16:49 GMT+8
* @detail :
*/
interface PayPalPayCallBack {
fun onPaySuccess(result:String)
fun onCancel()
fun onError(error: String)
}
\ No newline at end of file
......@@ -17,7 +17,7 @@ class PaymentPagePresenter:PaymentPageContract.Presenter {
}
override fun verifyThePayment(result: String?, payType: Int) {
mView.orderVerificationSuccessful("")
}
override fun appInfo() {
......
......@@ -58,6 +58,6 @@ class CoinStoreActivity : BaseActivity(), CoinStoreContract.View,
}
override fun onItemClick(view: View?, position: Int, data: RecordEntity?) {
JumpUtils.paymentPageJump(Constant.Key.PAY_TYPE_COIN,"1","name","0.0")
JumpUtils.paymentPageJump(Constant.Key.PAY_TYPE_COIN,"1","name","0.1")
}
}
\ No newline at end of file
package com.zxhl.cms.pay.view
import android.content.Intent
import android.os.Build
import android.util.Log
import android.view.View
import com.paypal.checkout.PayPalCheckout
import com.zxhl.cms.R
import com.zxhl.cms.common.base.BaseActivity
import com.zxhl.cms.net.model.box.AppInEntity
import com.zxhl.cms.pay.PayContract
import com.zxhl.cms.pay.contract.PaymentPageContract
import com.zxhl.cms.pay.googlepay.GooglePayCallBack
import com.zxhl.cms.pay.googlepay.GooglePayHelper
import com.zxhl.cms.pay.googlepay.GooglePayResult
import com.zxhl.cms.pay.paypal.PayPalHelper
import com.zxhl.cms.pay.presenter.PaymentPagePresenter
import com.zxhl.cms.paypal.PayPalPayCallBack
import com.zxhl.cms.utils.EventUtils
import com.zxhl.cms.utils.Utils
import com.zxhl.cms.widget.CenterDialog
import com.zxhl.cms.widget.LoadingDialog
import kotlinx.android.synthetic.main.activity_layout_payment_page.*
import kotlinx.android.synthetic.main.activity_layout_payment_page.id_img_back
import kotlinx.android.synthetic.main.activity_member.*
......@@ -30,11 +43,21 @@ class PaymentPageActivity : BaseActivity(), PaymentPageContract.View {
private var payType: Int? = GOOGLE_PAY
private var googlePay: GooglePayHelper? = null
private var payPalPay: PayPalHelper? = null
private var mLoading: LoadingDialog? = null
private var mPresenter: PaymentPageContract.Presenter? = null
private var goodsType: String = "";
private var goodsId: String = "";
private var goodsName: String = "";
private var goodsPrice: String = "";
override fun init() {
val goodsType = intent?.data?.getQueryParameter("pay_goods_type") ?: ""
val goodsId = intent?.data?.getQueryParameter("pay_goods_id") ?: ""
val goodsName = intent?.data?.getQueryParameter("pay_goods_name") ?: ""
val goodsPrice = intent?.data?.getQueryParameter("pay_goods_price") ?: ""
goodsType = intent?.data?.getQueryParameter("pay_goods_type") ?: ""
goodsId = intent?.data?.getQueryParameter("pay_goods_id") ?: ""
goodsName = intent?.data?.getQueryParameter("pay_goods_name") ?: ""
goodsPrice = intent?.data?.getQueryParameter("pay_goods_price") ?: ""
id_tv_goods_name.text = goodsName
id_tv_goods_price.text = "Price:$${goodsPrice}"
......@@ -44,6 +67,35 @@ class PaymentPageActivity : BaseActivity(), PaymentPageContract.View {
id_img_google_btn.setOnClickListener(this)
id_rl_paypal_pay.setOnClickListener(this)
id_tv_pay_btn.setOnClickListener(this)
mLoading = LoadingDialog.getLoadingDialog(
this,
getString(com.zxhl.cms.R.string.wait_ing),
false,
false
)
mPresenter = PaymentPagePresenter(this)
googlePay = GooglePayHelper(this)
googlePay?.init(object : GooglePayCallBack {
override fun onPaySuccess(purchase: GooglePayResult, googleJson: String) {
mPresenter?.verifyThePayment(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)
}
})
payPalPay = PayPalHelper(this)
}
override fun onClick(v: View?) {
......@@ -58,7 +110,20 @@ class PaymentPageActivity : BaseActivity(), PaymentPageContract.View {
selectPayType(PAY_PAL_PAY)
}
id_tv_pay_btn -> {
CenterDialog.showPaySuccessDialog(this)
//CenterDialog.showPaySuccessDialog(this)
if (payType == 0) {
Utils.showToast(this, "Please select payment type")
return
}
EventUtils.onEvent("pay_page_pay_btn", goodsPrice)
Log.d("wxw","Payment${goodsId}${goodsPrice}")
if (payType == GOOGLE_PAY) {
googlePay(goodsId)
} else if (payType == PAY_PAL_PAY) {
payPalPay(goodsId, goodsPrice)
} else {
EventUtils.onEvent("pay_type_error", "pay_type$payType")
}
}
}
}
......@@ -82,15 +147,94 @@ class PaymentPageActivity : BaseActivity(), PaymentPageContract.View {
}
override fun orderVerificationSuccessful(status: String) {
EventUtils.onEvent("pay_suc")
mLoading?.setResult(true, "Pay for success", 1000)
}
override fun orderVerificationFailed(errorMsg: String) {
EventUtils.onEvent("pay_fail")
mLoading?.setResult(false, "Pay for failure", 1000)
}
override fun setAppInfo(result: AppInEntity?) {
}
private fun googlePay(goodsId: String) {
if (goodsId == "") {
EventUtils.onEvent("GooglePayGoodsIdNull")
return
}
mLoading?.setLoading(getString(R.string.wait_ing))
mLoading?.show()
EventUtils.onEvent("GooglePayStart", "开始支付")
googlePay?.googlePay(goodsId, "6", object : GooglePayCallBack {
override fun onPaySuccess(purchase: GooglePayResult, googleJson: String) {
mPresenter?.verifyThePayment(googleJson, GOOGLE_PAY)
EventUtils.onEvent("GooglePaySuccess")
EventUtils.onEvent("GooglePayEnd", "支付结束_成功")
}
override fun onCancel() {
runOnUiThread {
mLoading?.setResult(false, "pay cancel", 1000)
}
EventUtils.onEvent("GooglePayCancel")
EventUtils.onEvent("GooglePayEnd", "支付结束_取消")
}
override fun onError(error: String) {
Log.d("wxw", "PayError:$error")
runOnUiThread {
mLoading?.setResult(false, "pay error", 1000)
}
EventUtils.onEvent("GooglePayError", error)
EventUtils.onEvent("GooglePayEnd", "支付结束_异常 msg:${error}")
}
})
}
private fun payPalPay(goodsId: String, goodsPrice: String) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
showToast("Sorry your device does not currently support this payment method")
return
}
if (goodsId == "" || goodsPrice == "") {
EventUtils.onEvent("PayPalPayGoodsIdNull")
return
}
mLoading?.setLoading(getString(R.string.wait_ing))
mLoading?.show()
payPalPay?.payPalPay(goodsId, goodsPrice, "6", object : PayPalPayCallBack {
override fun onPaySuccess(result: String) {
EventUtils.onEvent("PayPalPaySuccess")
mPresenter?.verifyThePayment(result, PAY_PAL_PAY)
// runOnUiThread {
// mLoading?.setResult(false, "pay success", 1000)
// }
}
override fun onCancel() {
EventUtils.onEvent("PayPalPayCancel")
runOnUiThread {
mLoading?.setResult(false, "pay cancel", 1000)
}
}
override fun onError(error: String) {
Log.d("wxw", "PayError:$error")
EventUtils.onEvent("PayPalPayError", error)
runOnUiThread {
mLoading?.setResult(false, "pay error", 1000)
}
}
}, id_PayPal_btn)
}
}
\ No newline at end of file
......@@ -11,6 +11,8 @@ import androidx.recyclerview.widget.RecyclerView
import com.zxhl.cms.R
import com.zxhl.cms.pay.adapter.BecomeVipBannerAdapter
import com.zxhl.cms.pay.adapter.BecomeVipDialogBannerAdapter
import com.zxhl.cms.pay.adapter.BecomeVipDialogPriceAdapter
import com.zxhl.cms.utils.OnRecycleItemClickListener
import com.zxhl.cms.widget.CenterDialog
import com.zxhl.cms.widget.RecyclerViewPageChangeListenerHelper
import com.zxhl.cms.widget.UIndicator
......@@ -25,6 +27,7 @@ import org.greenrobot.eventbus.EventBus
object VipPayDialog {
private var mActivity: Activity? = null;
private var mBannerAdapter: BecomeVipDialogBannerAdapter? = null
private var mPriceAdapter: BecomeVipDialogPriceAdapter? = null
private var mCallBack: VipPayCallBack? = null
fun setDialogDismissCallback(callback: VipPayCallBack?) {
this.mCallBack = callback
......@@ -60,9 +63,9 @@ object VipPayDialog {
val pay_banner = mDialogView.findViewById<RecyclerView>(R.id.id_rcl_pay_banner)
val banner_indic = mDialogView.findViewById<UIndicator>(R.id.id_banner_indicator)
val btn_continue = mDialogView.findViewById<TextView>(R.id.id_tv_vip_dialog_pay_btn)
val price_list = mDialogView.findViewById<RecyclerView>(R.id.id_rcl_pay_price_list)
//banner
banner_indic.setIndicatorCount(5)
mBannerAdapter = BecomeVipDialogBannerAdapter(act)
pay_banner?.layoutManager = LinearLayoutManager(
act, LinearLayoutManager.HORIZONTAL,
......@@ -87,7 +90,13 @@ object VipPayDialog {
}
})
)
//price
mPriceAdapter =
BecomeVipDialogPriceAdapter(act) { view, position, data ->
mPriceAdapter?.setSelectView(position)
}
price_list?.layoutManager = LinearLayoutManager(act)
price_list?.adapter = mPriceAdapter
btn_continue.setOnClickListener {
mDialog?.dismiss()
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#F4EDFF" />
<corners android:radius="10dp" />
</shape>
\ No newline at end of file
......@@ -165,4 +165,11 @@
android:textSize="18sp"
android:textStyle="bold" />
<com.paypal.checkout.paymentbutton.PayPalButton
android:id="@+id/id_PayPal_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="-100dp"
android:visibility="gone" />
</RelativeLayout>
\ No newline at end of file
......@@ -33,9 +33,10 @@
android:id="@+id/id_rcl_pay_price_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/id_rcl_pay_banner"
android:layout_below="@id/id_banner_indicator"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginTop="30dp"
android:layout_above="@id/id_tv_vip_dialog_pay_btn"
android:layout_marginRight="10dp" />
<TextView
......@@ -44,7 +45,10 @@
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_margin="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:layout_marginTop="5dp"
android:background="@drawable/shape_8857ff_bd8aff_bg_r25"
android:gravity="center"
android:text="Continue"
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/id_ll_dialog_item_become_vip_view"
android:layout_width="match_parent"
android:layout_height="50dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:background="@drawable/shape_8857ff_bd8aff_bg_r10"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/id_tv_dialog_item_vip_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1 Month +"
android:textColor="@color/white"
android:textSize="18sp"
android:textStyle="bold" />
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginLeft="10dp"
android:layout_marginEnd="5dp"
android:src="@drawable/icon_xingbi_da_wode" />
<TextView
android:id="@+id/id_tv_dialog_coin_num"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="780"
android:textColor="@color/white"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/id_tv_dialog_item_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$2.99"
android:textColor="@color/white"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
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