use of com.huawei.hms.iap.entity.PurchaseIntentResult in project Osmand by osmandapp.
the class InAppPurchaseHelperImpl method getPurchaseSubscriptionCommand.
@Override
protected InAppCommand getPurchaseSubscriptionCommand(final WeakReference<Activity> activity, String sku, String userInfo) throws UnsupportedOperationException {
return new InAppCommand() {
@Override
public void run(InAppPurchaseHelper helper) {
try {
Activity a = activity.get();
ProductInfo productInfo = getProductInfo(sku);
if (AndroidUtils.isActivityNotDestroyed(a) && productInfo != null) {
IapRequestHelper.createPurchaseIntent(getIapClient(), sku, IapClient.PriceType.IN_APP_SUBSCRIPTION, userInfo, new IapApiCallback<PurchaseIntentResult>() {
@Override
public void onSuccess(PurchaseIntentResult result) {
if (result == null) {
logError("GetBuyIntentResult is null");
} else {
Activity a = activity.get();
if (AndroidUtils.isActivityNotDestroyed(a)) {
IapRequestHelper.startResolutionForResult(a, result.getStatus(), Constants.REQ_CODE_BUY_SUB);
} else {
logError("startResolutionForResult on destroyed activity");
}
}
commandDone();
}
@Override
public void onFail(Exception e) {
int errorCode = ExceptionHandle.handle(activity.get(), e);
if (ExceptionHandle.SOLVED != errorCode) {
logError("createPurchaseIntent, returnCode: " + errorCode);
if (OrderStatusCode.ORDER_PRODUCT_OWNED == errorCode) {
logError("already own this product");
} else {
logError("unknown error");
}
}
commandDone();
}
});
} else {
stop(true);
}
} catch (Exception e) {
logError("launchPurchaseFlow Error", e);
stop(true);
}
}
};
}
use of com.huawei.hms.iap.entity.PurchaseIntentResult in project Osmand by osmandapp.
the class IapRequestHelper method createPurchaseIntent.
public static void createPurchaseIntent(final IapClient iapClient, String productId, int type, String payload, final IapApiCallback callback) {
Log.i(TAG, "call createPurchaseIntent");
PurchaseIntentReq req = createPurchaseIntentReq(type, productId);
req.setDeveloperPayload(payload);
Task<PurchaseIntentResult> task = iapClient.createPurchaseIntent(req);
task.addOnSuccessListener(new OnSuccessListener<PurchaseIntentResult>() {
@Override
public void onSuccess(PurchaseIntentResult result) {
Log.i(TAG, "createPurchaseIntent, success");
callback.onSuccess(result);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Log.e(TAG, "createPurchaseIntent, fail");
callback.onFail(e);
}
});
}
Aggregations