调整三星包支付无法唤起问题(R文件被覆盖)

This commit is contained in:
2024-09-11 15:23:01 +08:00
parent 8e860b80d4
commit ec5f32cf1e
132 changed files with 8 additions and 5472 deletions

View File

@@ -0,0 +1,134 @@
package com.samsung.utils;
import android.content.Context;
import android.util.Log;
import com.google.gson.Gson;
import com.samsung.android.sdk.iap.lib.constants.HelperDefine;
import com.samsung.android.sdk.iap.lib.helper.IapHelper;
import com.samsung.android.sdk.iap.lib.listener.OnConsumePurchasedItemsListener;
import com.samsung.android.sdk.iap.lib.listener.OnGetOwnedListListener;
import com.samsung.android.sdk.iap.lib.vo.ConsumeVo;
import com.samsung.android.sdk.iap.lib.vo.ErrorVo;
import com.samsung.android.sdk.iap.lib.vo.OwnedProductVo;
import com.samsung.iap6helper.R;
import java.util.ArrayList;
public class SamsungUtil {
private Context mContext;
IapHelper iapHelper;
private static SamsungUtil samsungUtil;
public static SamsungUtil newInstance(Context context) {
if (samsungUtil == null) {
samsungUtil = new SamsungUtil(context);
}
return samsungUtil;
}
public SamsungUtil(Context mContext) {
this.mContext = mContext;
}
/**
* 初始化
*/
public void init() {
iapHelper = IapHelper.getInstance(mContext);
//设置支付模式 OPERATION_MODE_PRODUCTION 正式模式 OPERATION_MODE_TEST 测试模式
iapHelper.setOperationMode(HelperDefine.OperationMode.OPERATION_MODE_TEST);
}
public void dispose() {
if (iapHelper != null) {
iapHelper.dispose();
}
}
/**
* 购买
*
* @param skuId
*/
public void buy(String skuId, OnPaymentListener onPaymentListener) {
//购买
iapHelper.startPayment(skuId, "", (errorVo, purchaseVo) -> {
if (purchaseVo != null) {
onPaymentListener.onPaymentSuccess(purchaseVo.getPurchaseId());
} else {
if (errorVo.getErrorCode() == HelperDefine.IAP_PAYMENT_IS_CANCELED) {
onPaymentListener.onPaymentFailed(mContext.getString(R.string.pay_cancel));
} else {
onPaymentListener.onPaymentFailed(errorVo.getErrorString());
}
}
});
}
public interface OnPaymentListener {
void onPaymentSuccess(String purchaseVo);
void onPaymentFailed(String errorVo);
}
/**
* 消耗指定商品
*
* @param skuId
*/
public void consume(String skuId) {
//消耗
iapHelper.consumePurchasedItems(skuId, new OnConsumePurchasedItemsListener() {
@Override
public void onConsumePurchasedItems(ErrorVo _errorVO, ArrayList<ConsumeVo> _consumeList) {
if (_consumeList != null) {
Log.e("samsung","消耗:" + new Gson().toJson(_consumeList));
Log.e("samsung","ErrorVo" + _errorVO.dump());
}
}
});
}
public void consumeAll(ArrayList<OwnedProductVo> _ownedList) {
if (_ownedList.size() > 0) {
iapHelper.consumePurchasedItems(_ownedList.get(0).getPurchaseId(), new OnConsumePurchasedItemsListener() {
@Override
public void onConsumePurchasedItems(ErrorVo _errorVO, ArrayList<ConsumeVo> _consumeList1) {
if (_errorVO.getErrorCode() == IapHelper.IAP_ERROR_NONE) {
Log.e("samsung","消耗:" + new Gson().toJson(_consumeList1));
Log.e("samsung","ErrorVo" + _errorVO.dump());
_ownedList.remove(0);
consumeAll(_ownedList);
}
}
});
}
}
/**
* 消耗所有未消耗的消耗品
*/
public void query() {
//查询商品 PRODUCT_TYPE_ITEM 消耗品&非消耗品
iapHelper.getOwnedList(HelperDefine.PRODUCT_TYPE_ITEM, new OnGetOwnedListListener() {
@Override
public void onGetOwnedProducts(ErrorVo _errorVo, ArrayList<OwnedProductVo> _ownedList) {
if (_errorVo != null) {
if (_errorVo.getErrorCode() == IapHelper.IAP_ERROR_NONE) {
if (_ownedList != null) {
consumeAll(_ownedList);
}
}
}
}
});
}
}