From d1c092a8bed9eec9117005f4c79173f724df4482 Mon Sep 17 00:00:00 2001 From: AbbasGhasemi Date: Wed, 20 Dec 2023 20:54:55 +0330 Subject: [PATCH] v1.1.0 --- README.md | 22 ++-------- billing/build.gradle | 6 +-- billing/src/main/AndroidManifest.xml | 1 + .../java/com/farasource/billing/Payment.java | 41 ++++++++++--------- .../com/farasource/billing/PaymentHelper.java | 16 ++++++-- gradle.properties | 20 ++++----- sample/build.gradle | 6 +-- .../sample/ExampleInstrumentedTest.java | 6 +-- 8 files changed, 57 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 1a4110c..227d1ab 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,28 @@ [![](https://jitpack.io/v/farasource/billing-client.svg)](https://jitpack.io/#farasource/billing-client) - -GooglePlay/CafeBazaar/Myket/Other In-app purchase sdk +GooglePlay/CafeBazaar/Myket/Other in-app purchase sdk ## Getting Started -To start working with billing-client, you need to add its dependency into your `build.gradle` file: -### Dependency +**Step 1.** Add the dependency in your root `build.gradle`: ```groovy dependencies { implementation "com.github.farasource:billing-client:[latest_version]" } ``` -Then you need to add jitpack as your maven repository: - -* **New method** add in `settings.gradle` file: +**Step 2.** Add it at the end of repositories: ```groovy dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { - google() mavenCentral() maven { url 'https://jitpack.io' } } } ``` -* **Old method** add in `build.gradle` file: -```groovy -allprojects { - repositories { - maven { url 'https://jitpack.io' } - } -} -``` - -Then you need to add config in `build.gradle` file: - +**Step 3.** Add config: ```GRADLE android { defaultConfig { diff --git a/billing/build.gradle b/billing/build.gradle index a5cb053..8089f47 100644 --- a/billing/build.gradle +++ b/billing/build.gradle @@ -3,11 +3,11 @@ plugins { } android { - compileSdk 31 + compileSdk 32 defaultConfig { minSdk 16 - targetSdk 31 + targetSdk 32 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" @@ -29,5 +29,5 @@ dependencies { testImplementation 'junit:junit:4.13.2' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - implementation 'androidx.appcompat:appcompat:1.4.0' + implementation 'androidx.appcompat:appcompat:1.5.1' } \ No newline at end of file diff --git a/billing/src/main/AndroidManifest.xml b/billing/src/main/AndroidManifest.xml index 5a960d3..9ce87f4 100644 --- a/billing/src/main/AndroidManifest.xml +++ b/billing/src/main/AndroidManifest.xml @@ -12,6 +12,7 @@ + { + if (result.isFailure()) { + logger.logDebug("startSetup failed."); + + onBillingStatus(TableCodes.SETUP_FAILED); + // + dispose(); + } else { + // Have we been disposed of in the meantime? If so, quit. + if (mHelper == null) return; + + // IAB is fully set up. Now, let's get an inventory of stuff we own. + logger.logDebug("Setup successful. Querying inventory."); + startedSetup = true; + onBillingStatus(TableCodes.SETUP_SUCCESS); + mHelper.queryInventoryAsync(mGotInventoryListener); } }); } catch (Exception e) { @@ -144,6 +141,12 @@ public void onIabSetupFinished(IabResult result) { } } + public void rebuildActivityResultRegistry(ActivityResultRegistry registry) { + if (mHelper != null) { + mHelper.buildPaymentLauncher(registry); + } + } + public void launchPayment(String sku) { launchPayment(sku, PaymentHelper.ITEM_TYPE_INAPP, "", false); } diff --git a/billing/src/main/java/com/farasource/billing/PaymentHelper.java b/billing/src/main/java/com/farasource/billing/PaymentHelper.java index 8f13736..90f29b1 100644 --- a/billing/src/main/java/com/farasource/billing/PaymentHelper.java +++ b/billing/src/main/java/com/farasource/billing/PaymentHelper.java @@ -140,15 +140,20 @@ public class PaymentHelper { * is NOT your "developer public key". */ protected PaymentHelper(ActivityResultRegistry registry, Context ctx, String base64PublicKey) { - paymentLauncher = new com.farasource.billing.PaymentLauncher.Builder().build( - registry, - result -> Objects.requireNonNull(iabConnection).getPurchaseResultReceiver().onReceiver(result.getResultCode(), result.getData()) - ); + buildPaymentLauncher(registry); mContext = ctx.getApplicationContext(); mSignatureBase64 = base64PublicKey; logger.logDebug("IAB helper created."); } + public void buildPaymentLauncher(ActivityResultRegistry registry) { + if (registry == null) return; + paymentLauncher = new PaymentLauncher.Builder().build( + registry, + result -> Objects.requireNonNull(iabConnection).getPurchaseResultReceiver().onReceiver(result.getResultCode(), result.getData()) + ); + } + /** * Returns a human-readable description for the given response code. * @@ -387,6 +392,9 @@ public void launchPurchaseFlow(String sku, String itemType, OnIabPurchaseFinishedListener listener, String extraData) { checkNotDisposed(); checkSetupDone("launchPurchaseFlow"); + if (paymentLauncher == null) { + throw new IllegalStateException("paymentLauncher can`t be null."); + } iabConnection.launchPurchaseFlow(mContext, paymentLauncher, sku, itemType, listener, extraData); } diff --git a/gradle.properties b/gradle.properties index 25b8ae4..a185d98 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,19 +1,17 @@ -# Project-wide Gradle settings. -# IDE (e.g. Android Studio) users: -# Gradle settings configured through the IDE *will override* -# any settings specified in this file. -# For more details on how to configure your build environment visit +## For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html +# # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# Default value: -Xmx1024m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +# # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -# Enables namespacing of each library's R class so that its R class includes only the -# resources declared in the library itself and none from the library's dependencies, -# thereby reducing the size of the R class for that library +#Wed Dec 20 20:46:04 GMT+03:30 2023 +android.enableJetifier=true android.nonTransitiveRClass=true - -android.useAndroidX=true \ No newline at end of file +android.useAndroidX=true +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding\=UTF-8 diff --git a/sample/build.gradle b/sample/build.gradle index 806c0f5..926349c 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -3,12 +3,12 @@ plugins { } android { - compileSdk 31 + compileSdk 32 defaultConfig { applicationId "com.example.android.trivialdrivesample" minSdk 16 - targetSdk 31 + targetSdk 32 versionCode 1 versionName "1.0.0" @@ -51,6 +51,6 @@ dependencies { testImplementation 'junit:junit:4.13.2' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - implementation 'androidx.appcompat:appcompat:1.4.0' + implementation 'androidx.appcompat:appcompat:1.5.1' implementation project(':billing') } \ No newline at end of file diff --git a/sample/src/androidTest/java/ir/farasource/inapp/payment/sample/ExampleInstrumentedTest.java b/sample/src/androidTest/java/ir/farasource/inapp/payment/sample/ExampleInstrumentedTest.java index c606d6c..83c8548 100644 --- a/sample/src/androidTest/java/ir/farasource/inapp/payment/sample/ExampleInstrumentedTest.java +++ b/sample/src/androidTest/java/ir/farasource/inapp/payment/sample/ExampleInstrumentedTest.java @@ -1,14 +1,14 @@ package ir.farasource.inapp.payment.sample; import android.content.Context; -import android.support.test.InstrumentationRegistry; -import android.support.test.runner.AndroidJUnit4; - import org.junit.Test; import org.junit.runner.RunWith; import static org.junit.Assert.*; +import androidx.test.InstrumentationRegistry; +import androidx.test.runner.AndroidJUnit4; + /** * Instrumented test, which will execute on an Android device. *