<manifest>
<!--
if your binary use ONE store's In-app SDK,
Please make sure to declare the following query on Androidmanifest.xml.
Refer to the notice for more information.
https://dev.onestore.net/devpoc/support/news/noticeView.omp?noticeId=32968
-->
<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>
...
<application>
...
</application>
</manifest>
发行全球store的测试选项设置
此是强制SDK和全球store联动的选项。本功能从SDK v21.01.00版本开始适用。
<manifest>
...
<application>
<activity>
...
</activity>
...
<!-- Options for in-app testing on your global store -->
<meta-data android:name="onestore:dev_option" android:value="global" />
</application>
</manifest>
/**
* Set the log level.<br/>
* {@link Log#VERBOSE}, {@link Log#DEBUG}, {@link Log#INFO},
* {@link Log#WARN}, {@link Log#ERROR}
* @param level int
*/
com.gaa.sdk.base.Logger.setLogLevel(2)
常数
值
VERBOSE
2
DEBUG
3
INFO (default)
4
WARN
5
ERROR
6
发行组建版本网络安全比较弱,本选项需要删除。
错误处理
ONE store 支付程序库以IapResult形式反馈错误。IapResult包含分类App内可能出现的支付相关错误的ResponseCode。例如,如果IapResult收到RESULT_NEED_LOGIN 或 RESULT_NEED_UPDATE等错误代码(code),应用软件需要做出相应的处理。
private val listener = PurchasesUpdatedListener { iapResult, purchases ->
// To be implemented in a later section.
}
private var purchaseClient = PurchaseClient.newBuilder(activity)
.setListener(listener)
.setBase64PublicKey(/*your public key*/) // optional
.build()
private PurchasesUpdatedListener listener = new PurchasesUpdatedListener {
@Override
public void onPurchasesUpdated(IapResult iapResult, List<PurchaseData>) {
// To be implemented in a later section.
}
};
private PurchaseClient purchaseClient = PurchaseClient.newBuilder(activity)
.setListener(listener)
.setBase64PublicKey(/*your public key*/) // optional
.build();
purchaseClient.startConnection(object : PurchaseClientStateListener {
override fun onSetupFinished(iapResult: IapResult) {
if (iapResult.isSuccess) {
// The PurchaseClient is ready. You can query purchases here.
}
}
override fun onServiceDisconnected() {
// Try to restart the connection on the next request to
// PurchaseClient by calling the startConnection() method.
}
})
purchaseClient.startConnection(new PurchaseClientStateListener {
@Override
public void onSetupFinished(IapResult iapResult) {
if (iapResult.isSuccess()) {
// The PurchaseClient is ready. You can query purchases here.
}
}
@Override
public void onServiceDisconnected() {
// Try to restart the connection on the next request to
// PurchaseClient by calling the startConnection() method.
}
});
override fun onPurchasesUpdated(iapResult: IapResult, purchases: List<PurchaseData>?) {
if (iapResult.isSuccess && purchases != null) {
for (purchase in purchases) {
handlePurchase(purchase)
}
} else if (iapResult.responseCode == ResponseCode.NEED_UPDATE) {
// PurchaseClient by calling the launchUpdateOrInstallFlow() method.
} else if (iapResult.responseCode == ResponseCode.NEED_LOGIN) {
// PurchaseClient by calling the launchLoginFlow() method.
} else {
// Handle any other error codes.
}
}
@Override
public void onPurchasesUpdated(IapResult iapResult, List<PurchaseData> purchases) {
if (iapResult.isSuccess() && purchases != null) {
for (purchase in purchases) {
handlePurchase(purchase);
}
} else if (iapResult.getResponseCode() == ResponseCode.NEED_UPDATE) {
// PurchaseClient by calling the launchUpdateOrInstallFlow() method.
} else if (iapResult.getResponseCode() == ResponseCode.NEED_LOGIN) {
// PurchaseClient by calling the launchLoginFlow() method.
} else {
// Handle any other error codes.
}
}
fun handlePurchase(purchase: PurchaseData) {
// Purchase retrieved from PurchaseClient#queryPurchasesAsync
// or your PurchasesUpdatedListener.
val purchase: PurchaseData = ...
// Verify the purchase.
// Ensure entitlement was not already granted for this purchaseToken.
// Grant entitlement to the user.
val consumeParams = ConsumeParams.newBuilder()
.setPurchaseData(purchase)
.build()
purchaseClient.consumeAsync(consumeParams) { iapResult, purchaseData ->
// Process the result.
}
}
private void handlePurchase(PurchaseData purchase) {
// Purchase retrieved from PurchaseClient#queryPurchasesAsync or your PurchasesUpdatedListener.
PurchaseData purchase = ...
// Verify the purchase.
// Ensure entitlement was not already granted for this purchaseToken.
// Grant entitlement to the user.
ConsumeParams consumeParams = ConsumeParams.newBuilder()
.setPurchaseData(purchase)
.build();
purchaseClient.consumeAsync(consumeParams, new ConsumeListener() {
@Override
public void onConsumeResponse(IapResult iapResult, PurchaseData purchaseData) {
// Process the result.
}
});
}
// Purchase retrieved from PurchaseClient#queryPurchasesAsync or your PurchasesUpdatedListener.
fun handlePurchase(PurchaseData purchase) {
if (purchase.purchaseState == PurchaseState.PURCHASED) {
if (!purchase.isAcknowledged) {
val acknowledgeParams = AcknowledgeParams.newBuilder()
.setPurchaseData(purchase)
.build()
purchaseClient.acknowledgeAsync(acknowledgeParams) { iapResult, purchaseData ->
// PurchaseClient by calling the queryPurchasesAsync() method.
}
}
}
}
// Purchase retrieved from PurchaseClient#queryPurchasesAsync or your PurchasesUpdatedListener.
private void handlePurchase(purchase: PurchaseData) {
if (purchase.getPurchaseState() == PurchaseState.PURCHASED) {
if (!purchase.isAcknowledged()) {
AcknowledgeParams acknowledgeParams = AcknowledgeParams.newBuilder()
.setPurchaseData(purchase)
.build();
purchaseClient.acknowledgeAsync(acknowledgeParams, new AcknowledgeListener() {
@Override
public void onAcknowledgeResponse(IapResult iapResult, PurchaseData purchaseData) {
// PurchaseClient by calling the queryPurchasesAsync() method.
}
});
}
}
}
purchaseClient.getStoreInfoAsync { iapResult, storeCode ->
// Save storecode and use it in Server to Server API.
}
purchaseClient.getStoreInfoAsync(new StoreInfoListener() {
@Override
public void onStoreInfoResponse(IapResult iapResult, String storeCode) {
// Save storecode and use it in Server to Server API.
}
});
安装ONE store服务
ONE store服务的版本低或者没有时,无法使用app内支付。 通过PurchaseClient.startConnection()连接时,可以在IapResult.getResponseCode()确认。如果发生RESULT_NEED_UPDATE,需要调用launchUpdateOrInstallFlow()方法。
val activity: Activity = ...
purchaseClient.launchUpdateOrInstallFlow(activity) { 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.
}
}