三星内购调用

This commit is contained in:
hch
2023-12-15 18:29:12 +08:00
parent c723e14182
commit a21352302b
5 changed files with 88 additions and 24 deletions

View File

@@ -402,6 +402,14 @@ public class CommonHttpUtil {
HttpClient.getInstance().get("Charge.Google_sec_pay", "Charge.Google_sec_pay").params("purchaseToken", purchaseToken).params("orderno", orderNo).params("trade_no", tradeNo).params("package_name", "com.pdlive.shayu").execute(callback);
}
public static void notifySamsung(String purchaseId, String selfOrderId,HttpCallback callback) {
HttpClient.getInstance().get("Charge.SamsungNotify", "Charge.SamsungNotify")
.params("purchaseID", purchaseId)
.params("SelfOrderId", selfOrderId)
.params("PackageName", "pd")
.execute(callback);
}
//不做任何操作的HttpCallback
public static final HttpCallback NO_CALLBACK = new HttpCallback() {
@Override

View File

@@ -2,6 +2,7 @@ package com.yunbao.common.pay.samsung;
import android.content.Context;
import com.google.gson.Gson;
import com.samsung.android.sdk.iap.lib.helper.HelperDefine;
import com.samsung.android.sdk.iap.lib.helper.IapHelper;
import com.samsung.android.sdk.iap.lib.listener.OnConsumePurchasedItemsListener;
@@ -48,14 +49,9 @@ public class SamsungUtil {
*
* @param skuId
*/
public void buy(String skuId) {
public void buy(String skuId, OnPaymentListener onPaymentListener) {
//购买
iapHelper.startPayment(skuId, "", new OnPaymentListener() {
@Override
public void onPayment(ErrorVo _errorVO, PurchaseVo _purchaseVO) {
L.e(_errorVO.getErrorString());
}
});
iapHelper.startPayment(skuId, "", onPaymentListener);
}
/**
@@ -68,11 +64,31 @@ public class SamsungUtil {
iapHelper.consumePurchasedItems(skuId, new OnConsumePurchasedItemsListener() {
@Override
public void onConsumePurchasedItems(ErrorVo _errorVO, ArrayList<ConsumeVo> _consumeList) {
if (_consumeList != null) {
L.e("消耗:" + new Gson().toJson(_consumeList));
L.e("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) {
L.e("消耗:" + new Gson().toJson(_consumeList1));
L.e("ErrorVo" + _errorVO.dump());
_ownedList.remove(0);
consumeAll(_ownedList);
}
}
});
}
}
/**
* 消耗所有未消耗的消耗品
*/
@@ -84,15 +100,8 @@ public class SamsungUtil {
if (_errorVo != null) {
if (_errorVo.getErrorCode() == IapHelper.IAP_ERROR_NONE) {
if (_ownedList != null) {
for (OwnedProductVo item : _ownedList) {
if (item.getIsConsumable()) {
// TODO: 消耗尚未消耗的消耗品
consume(item.getPurchaseId());
}
}
consumeAll(_ownedList);
}
} else {
// TODO: Handle the error
}
}
}