Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion store/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.6.2'

// Purchases
implementation 'com.android.billingclient:billing:6.1.0'
implementation 'com.android.billingclient:billing:8.0.0'

// Dagger
kapt "com.google.dagger:dagger-compiler:$dagger_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@
*/


import com.android.billingclient.api.ProductDetails;
import net.ivpn.client.billing.BillingManagerWrapper.PurchaseState;
import com.android.billingclient.api.QueryProductDetailsResult;

import java.util.List;
import net.ivpn.client.billing.BillingManagerWrapper.PurchaseState;

public interface BillingListener {

void onInitStateChanged(boolean isInit, int error);

void onPurchaseStateChanged(PurchaseState state);

void onCheckingProductDetailsSuccess(List<ProductDetails> productDetailsList);
void onCheckingProductDetailsSuccess(QueryProductDetailsResult productDetailsList);

void onPurchaseError(int errorStatus, String errorMessage);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
import com.android.billingclient.api.BillingResult;
import com.android.billingclient.api.ConsumeParams;
import com.android.billingclient.api.ConsumeResponseListener;
import com.android.billingclient.api.PendingPurchasesParams;
import com.android.billingclient.api.ProductDetails;
import com.android.billingclient.api.ProductDetailsResponseListener;
import com.android.billingclient.api.Purchase;
import com.android.billingclient.api.PurchasesUpdatedListener;
import com.android.billingclient.api.QueryProductDetailsParams;
import com.android.billingclient.api.QueryPurchasesParams;

import net.ivpn.client.StoreIVPNApplication;
import net.ivpn.client.dagger.BillingScope;
Expand Down Expand Up @@ -69,8 +71,8 @@ public class BillingManager implements PurchasesUpdatedListener {
BillingManager() {
LOGGER.info("Creating Billing client.");
billingClient = BillingClient.newBuilder(StoreIVPNApplication.instance)
.enablePendingPurchases()
.setListener(this)
.enablePendingPurchases(PendingPurchasesParams.newBuilder().enableOneTimeProducts().build())
.build();
}

Expand Down Expand Up @@ -118,7 +120,9 @@ public void onBillingServiceDisconnected() {
private void queryPurchases() {
Runnable queryToExecute = () -> {
long time = System.currentTimeMillis();
billingClient.queryPurchasesAsync(BillingClient.SkuType.INAPP, (billingResult, purchases) -> {
billingClient.queryPurchasesAsync(QueryPurchasesParams.newBuilder()
.setProductType(BillingClient.ProductType.INAPP)
.build(), (billingResult, purchases) -> {
LOGGER.info("Querying products elapsed time: " + (System.currentTimeMillis() - time)
+ "ms");
LOGGER.info("Querying products result code: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@
import androidx.databinding.ObservableBoolean;
import androidx.databinding.ObservableField;

import com.android.billingclient.api.ProductDetails;
import com.android.billingclient.api.QueryProductDetailsResult;

import net.ivpn.client.StoreIVPNApplication;
import net.ivpn.core.R;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

import javax.inject.Inject;

public class BillingViewModel implements BillingListener {
Expand Down Expand Up @@ -113,7 +111,7 @@ public void onPurchaseStateChanged(BillingManagerWrapper.PurchaseState state) {
}

@Override
public void onCheckingProductDetailsSuccess(List<ProductDetails> productDetailsList) {
public void onCheckingProductDetailsSuccess(QueryProductDetailsResult productDetailsList) {
// Nothing to do here
}

Expand Down
90 changes: 52 additions & 38 deletions store/src/main/java/net/ivpn/client/signup/SignUpViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.navigation.NavController
import com.android.billingclient.api.BillingClient
import com.android.billingclient.api.ProductDetails
import com.android.billingclient.api.QueryProductDetailsParams.Product
import com.android.billingclient.api.QueryProductDetailsResult
import net.ivpn.client.R
import net.ivpn.client.billing.BillingListener
import net.ivpn.client.billing.BillingManagerWrapper
Expand Down Expand Up @@ -279,29 +280,35 @@ class SignUpViewModel @Inject constructor(
}
}

override fun onCheckingProductDetailsSuccess(productDetailsList: List<ProductDetails>) {
override fun onCheckingProductDetailsSuccess(productDetails: QueryProductDetailsResult?) {
LOGGER.info("productDetailsList")
dataLoading.set(false)

productDetailsList.let { details ->
productDetails?.productDetailsList.let { details ->
selectedPlan.get()?.let { plan ->
for (productDetails in details) {
LOGGER.info("Check ${productDetails.productId}")
when (productDetails.productId) {
plan.skuPath + Period.ONE_WEEK.skuPath -> {
oneWeek.set(productDetails)
}
plan.skuPath + Period.ONE_MONTH.skuPath -> {
oneMonth.set(productDetails)
}
plan.skuPath + Period.ONE_YEAR.skuPath -> {
oneYear.set(productDetails)
}
plan.skuPath + Period.TWO_YEARS.skuPath -> {
twoYear.set(productDetails)
}
plan.skuPath + Period.THREE_YEARS.skuPath -> {
threeYear.set(productDetails)
if (details != null) {
for (productDetails in details) {
LOGGER.info("Check ${productDetails.productId}")
when (productDetails.productId) {
plan.skuPath + Period.ONE_WEEK.skuPath -> {
oneWeek.set(productDetails)
}

plan.skuPath + Period.ONE_MONTH.skuPath -> {
oneMonth.set(productDetails)
}

plan.skuPath + Period.ONE_YEAR.skuPath -> {
oneYear.set(productDetails)
}

plan.skuPath + Period.TWO_YEARS.skuPath -> {
twoYear.set(productDetails)
}

plan.skuPath + Period.THREE_YEARS.skuPath -> {
threeYear.set(productDetails)
}
}
}
}
Expand All @@ -313,25 +320,32 @@ class SignUpViewModel @Inject constructor(
selectPeriod(Period.ONE_YEAR)
}

for (productDetails in details) {
when (productDetails.productId) {
Plan.STANDARD.skuPath + Period.ONE_WEEK.skuPath -> {
standardWeek.set(getPricePerPeriodString(productDetails, "Week"))
}
Plan.STANDARD.skuPath + Period.ONE_MONTH.skuPath -> {
standardMonth.set(getPricePerPeriodString(productDetails, "Month"))
}
Plan.STANDARD.skuPath + Period.ONE_YEAR.skuPath -> {
standardYear.set(getPricePerPeriodString(productDetails, "Year"))
}
Plan.PRO.skuPath + Period.ONE_WEEK.skuPath -> {
proWeek.set(getPricePerPeriodString(productDetails, "Week"))
}
Plan.PRO.skuPath + Period.ONE_MONTH.skuPath -> {
proMonth.set(getPricePerPeriodString(productDetails, "Month"))
}
Plan.PRO.skuPath + Period.ONE_YEAR.skuPath -> {
proYear.set(getPricePerPeriodString(productDetails, "Year"))
if (details != null) {
for (productDetails in details) {
when (productDetails.productId) {
Plan.STANDARD.skuPath + Period.ONE_WEEK.skuPath -> {
standardWeek.set(getPricePerPeriodString(productDetails, "Week"))
}

Plan.STANDARD.skuPath + Period.ONE_MONTH.skuPath -> {
standardMonth.set(getPricePerPeriodString(productDetails, "Month"))
}

Plan.STANDARD.skuPath + Period.ONE_YEAR.skuPath -> {
standardYear.set(getPricePerPeriodString(productDetails, "Year"))
}

Plan.PRO.skuPath + Period.ONE_WEEK.skuPath -> {
proWeek.set(getPricePerPeriodString(productDetails, "Week"))
}

Plan.PRO.skuPath + Period.ONE_MONTH.skuPath -> {
proMonth.set(getPricePerPeriodString(productDetails, "Month"))
}

Plan.PRO.skuPath + Period.ONE_YEAR.skuPath -> {
proYear.set(getPricePerPeriodString(productDetails, "Year"))
}
}
}
}
Expand Down
Loading