Android one store v21版本储值SDK接入

接下来给大家介绍下one store v21版本的储值SDK接入使用流程!!

one store v21接入文档:v21接入教程

一. 配置

build.gradle(project)


repositories {
    ...
    maven { url 'https://repo.onestore.co.kr/repository/onestore-sdk-public' }
}

build.gradle(app/library)


dependencies {
    implementation "com.onestorecorp.sdk:sdk-iap:21.00.00"
    implementation "com.onestorecorp.sdk:sdk-configuration-kr:1.0.0"
}

AndroidManifest.xml

	//适配target 30 Android11
	<queries>
        <intent>
            <action android:name="com.onestore.ipc.iap.IapService.ACTION" />
        </intent>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:scheme="onestore" />
        </intent>
    </queries>

	//适配 target31 Android12
	//请在四大组件(activity,receiver...)中加入这个属性:android:exported="false",true or false 看工程需求。示例:
	 <activity
            android:name="com.xxx.xxxx.xxxActivity"
            android:exported="false"/>

	//支付界面选项,application下添加
	//full: 全屏(竖屏,固定)
	//popup: 弹窗界面(竖屏&横屏)
	<meta-data
            android:name="iap:view_option"
            android:value="popup" />

如果你需要手动集成,而不是通过maven,那么可以使用fat-aar把库拉取下来,使用教程请查看 fat-aar使用教程

二. 接口调用流程

  1. 初始化
//继承PurchasesUpdatedListener 或者 定义变量
private PurchasesUpdatedListener purchasesUpdatedListener = new PurchasesUpdatedListener {
        @Override
        public void onPurchasesUpdated(IapResult iapResult, List<PurchaseData>) {
                // To be implemented in a later section.
                if (iapResult.isSuccess() && purchaseData != null && purchaseData.size() > 0) {
                	//可在此处处理储值,或回调出去再处理
                	//handlePurchase(purchase);//consumeAsync()
                }

            } else if (iapResult.getResponseCode() == PurchaseClient.ResponseCode.RESULT_NEED_UPDATE) {
                // You need the required version of the ONE store service in the SDK.
                
            } else {
                // Other error codes.
                //"Onestore储值异常"
                
            }
        }
};

private PurchaseClient purchaseClient = PurchaseClient.newBuilder(activity)
        .setListener(purchasesUpdatedListener)
        .setBase64PublicKey(/*your public key*/) // optional
        .build();
  1. 设置one store服务连接
    callback.connected();
    callback.disConnection();
    interface 类请自行设计
	purchaseClient.startConnection(new PurchaseClientStateListener() {
                @Override
                public void onSetupFinished(IapResult iapResult) {
                    LogUtil.d(TAG, "onConnected");

                    if (iapResult.isSuccess()) {
                        // The PurchaseClient is ready. You can query purchases here.
                        
                        callback.connected();

                    } else if (iapResult.getResponseCode() == PurchaseClient.ResponseCode.RESULT_NEED_LOGIN) {
                        // The connection is completed successfully but login is required. You must write your login code here.
                        //此处调用登录
                        
                    } else if (iapResult.getResponseCode() == PurchaseClient.ResponseCode.RESULT_NEED_UPDATE) {
                        LogUtil.d(TAG, "connect onErrorNeedUpdateException");
                        //此处调用应用更新接口
                        

                    } else {
                        // Other error codes.
                        
                    }
                }

                @Override
                public void onServiceDisconnected() {
                    LogUtil.d(TAG, "onDisconnected");
                    callback.disConnection();
                    
                }
            });
  1. 登录 one store
GaaSignInClient.getClient(mActivity).launchSignInFlow(mActivity, new OnAuthListener() {
                @Override
                public void onResponse(SignInResult signInResult) {
                    if (signInResult.isSuccessful()) {
                    	//成功
                        LogUtil.e("测试", "code: " + signInResult.getCode());
                        LogUtil.e("测试", "message: " + signInResult.getMessage());
                        
                    } else {
                    	//失败
                        LogUtil.w(TAG, "launchLoginFlow() got an error response code: " + signInResult.getCode());
                        
                    }
                }
            });
  1. 查询商店详细信息
	connect(new Connection() {
                @Override
                public void connected() {
                    LogUtil.i(TAG, "queryPurchases connected: Called!");

                    ProductDetailsParams productDetailsParams = ProductDetailsParams.newBuilder()
                            .setProductIdList(productIdList)
                            .setProductType(PurchaseClient.ProductType.INAPP)
                            .build();

                    mPurchaseClient.queryProductDetailsAsync(productDetailsParams, new ProductDetailsListener() {
                        @Override
                        public void onProductDetailsResponse(IapResult iapResult, List<ProductDetail> productDetails) {
                            // Process the result.
                            
                            if (iapResult.isSuccess()) {
                                if (productDetails != null) {
                                    for (ProductDetail product : productDetails) {
                                    }
                                }
                                
                            } else {
                                LogUtil.w(TAG, "queryPurchasesAsync() got an error response code: " + iapResult.getResponseCode());
                                
                            }
                        }
                    });
                }

                @Override
                public void disConnection() {
                    LogUtil.i(TAG, "queryPurchases disConnection: Called!");
              
                }
            });
  1. 拉起储值
	connect(new Connection() {
                @Override
                public void connected() {
                    LogUtil.i(TAG, "launchPurchase connected: Called!");

                    // Retrieve a value for "productDetail" by calling queryProductDetailsAsync().
                    PurchaseFlowParams purchaseFlowParams = PurchaseFlowParams.newBuilder()
    						.setProductId(productId)
    						.setProductType(PurchaseClient.ProductType.INAPP)
						    .setDeveloperPayload(devPayload) // optional
						    .setQuantity(1) // optional
						    .setProductName("") // optional
						    .setGameUserId("") // optional
						    .setPromotionApplicable(false) // optional
						    .build();

                    mPurchaseClient.launchPurchaseFlow(mActivity, purchaseFlowParams);
                }

                @Override
                public void disConnection() {
                    LogUtil.i(TAG, "launchPurchase disConnection: Called!");
                }
            });
  1. 购买处理
private void handlePurchase(PurchaseData purchase) {
	connect(new Connection() {
                @Override
                public void connected() {
                    LogUtil.i(TAG, "consume connected: Called!");
               
                    ConsumeParams params = ConsumeParams.newBuilder().setPurchaseData(purchase).build();
                    mPurchaseClient.consumeAsync(params, new ConsumeListener() {
                        @Override
                        public void onConsumeResponse(final IapResult iapResult, final PurchaseData purchaseData) {
                            if (iapResult.isSuccess()) {
                                // Process the result. 储值成功完成
                                
                            } else if (iapResult.getResponseCode() == PurchaseClient.ResponseCode.RESULT_NEED_UPDATE) {
                                // You need the required version of the ONE store service in the SDK.
                                
                            } else {
                                // Other error codes.
                                
                            }
                        }
                    });
                }

                @Override
                public void disConnection() {
                    LogUtil.i(TAG, "consume disConnection: Called!");
                    
                }
            });
        }
  1. 查询购买订单

如果存在掉单的,此处会有数据返回,然后自行处理掉单补单逻辑

	connect(new Connection() {
                @Override
                public void connected() {
                    LogUtil.i(TAG, "queryPurchases connected: Called!");

                    mPurchaseClient.queryPurchasesAsync(PurchaseClient.ProductType.INAPP, new QueryPurchasesListener() {
                        @Override
                        public void onPurchasesResponse(IapResult iapResult, List<PurchaseData> purchaseData) {
                            
                            if (iapResult.isSuccess()) {
                                if (purchaseData != null) {
                                    for (PurchaseData purchase : purchaseData) {
                                    //回调出去,或处理
                                        
                                    }
                                }
                                
                            } else {
                                LogUtil.w(TAG, "queryPurchasesAsync() got an error response code: " + iapResult.getResponseCode());
                                
                            }
                        }
                    });
                }

                @Override
                public void disConnection() {
                    LogUtil.i(TAG, "queryPurchases disConnection: Called!");
                   
                }
            });
  1. 安装One store服务
Activity activity = ...

purchaseClient.launchUpdateOrInstallFlow(activity, new IapResultListener() {
    @Override
    public void onResponse(IapResult iapResult) {
        if (iapResult.isSuccess()) {
            // If the installation is completed successfully,
            // you should try to reconnect with the ONE store service.
            // PurchaseClient by calling the startConnection() method.
        }
    }
});

三. 注意事项

1.v17和v19版本是不兼容的,v17掉的单,在v19是不能自动补发的,需要人为手动补发。
2.从2023年6月开始,所有新创建的应用都必须使用v21的SDK。
3.v21是在v19的基础上升级的,所以和v19兼容,使用v19的sdk版本可以直接升至v21版本。
4.沙盒测试记得把账号在后台加入测试计划。

至此,one store v21版本的储值SDK就接入完成了~~希望对你有帮助!!

  • 12
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
这些文件夹是Android中的资源文件夹,用于存放应用程序所需的各种资源文件,例如图片、布局文件、颜色值、字符串等等。其中,drawable-v21和drawable-v24是用于存放特定版本Android系统所需的图片资源文件,下面是它们的区别: - drawable-v21:这个文件夹是用于存放Android 5.0(API level 21)及以上版本所需的图片资源文件。通常,这些图片资源文件用于支持Material Design风格的UI设计,如矢量图标、状态选择器等。 - drawable-v24:这个文件夹是用于存放Android 7.0(API level 24)及以上版本所需的图片资源文件。它主要用于支持Android Nougat(7.0)引入的多窗口模式,以及支持新的设备像素密度。 如果你的应用程序需要支持不同版本Android系统,那么你可以将特定版本所需的图片资源文件放置在对应的文件夹中,这样系统会根据设备的Android版本来自动加载对应版本的图片资源文件。 举个例子,如果你想在Android 5.0及以上版本中使用Material Design风格的矢量图标,那么你可以将这些图片资源文件放置在drawable-v21文件夹中。而如果你想在Android 7.0及以上版本中支持多窗口模式,那么你可以将相关的图片资源文件放置在drawable-v24文件夹中。 在使用这两个文件夹时,你需要注意以下几点: - 文件夹名称必须按照规定的格式命名,即“drawable-vxx”,其中xx代表Android版本号。 - 如果你在drawable文件夹中也有相同名称的图片资源文件,那么系统会优先加载drawable-vxx文件夹中对应版本的图片资源文件。 - 如果你的应用程序只支持较低版本Android系统,那么你可以将所有图片资源文件都放置在drawable文件夹中,系统会自动加载适合当前设备的版本的图片资源文件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值