Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
abbasghasemi committed Dec 20, 2023
1 parent 9040154 commit d1c092a
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 61 deletions.
22 changes: 4 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions billing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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'
}
1 change: 1 addition & 0 deletions billing/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</intent>
</queries>

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application>
<meta-data
android:name="market_id"
Expand Down
41 changes: 22 additions & 19 deletions billing/src/main/java/com/farasource/billing/Payment.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,22 @@ public void setOnPaymentResultListener(OnPaymentResultListener onPaymentResultLi
return;
}
try {
mHelper.startSetup(new PaymentHelper.OnIabSetupFinishedListener() {
@Override
public void onIabSetupFinished(IabResult result) {
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);
}
mHelper.startSetup(result -> {
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) {
Expand All @@ -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);
}
Expand Down
16 changes: 12 additions & 4 deletions billing/src/main/java/com/farasource/billing/PaymentHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}

Expand Down
20 changes: 9 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
android.useAndroidX=true
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding\=UTF-8
6 changes: 3 additions & 3 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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')
}
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down

0 comments on commit d1c092a

Please sign in to comment.