-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
farasource
committed
Sep 22, 2022
0 parents
commit 9f37e37
Showing
73 changed files
with
4,556 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
.idea | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
[![](https://jitpack.io/v/farasource/billing-client.svg)](https://jitpack.io/#farasource/billing-client) | ||
- | ||
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 | ||
```groovy | ||
dependencies { | ||
implementation "com.github.farasource:billing-client:[latest_version]" | ||
} | ||
``` | ||
|
||
Then you need to add jitpack as your maven repository in `build.gradle` file: | ||
|
||
```groovy | ||
repositories { | ||
google() | ||
jcenter() | ||
maven { url 'https://jitpack.io' } | ||
} | ||
``` | ||
|
||
Then you need to add config in `build.gradle` file: | ||
|
||
```GRADLE | ||
android { | ||
defaultConfig { | ||
def marketApplicationId = "com.farsitel.bazaar" // com.android.vending or ir.mservices.market | ||
def marketBindAddress = "ir.cafebazaar.pardakht.InAppBillingService.BIND" // com.android.vending.billing.InAppBillingService.BIND or ir.mservices.market.InAppBillingService.BIND | ||
manifestPlaceholders = [marketApplicationId: "${marketApplicationId}", | ||
marketBindAddress : "${marketBindAddress}", | ||
marketPermission : "${marketApplicationId}.permission.PAY_THROUGH_BAZAAR"] // .BILLING | ||
} | ||
} | ||
``` | ||
## Sample | ||
There is a fully functional sample application that demonstrates the usage of billing-client, all you have to do is cloning the project and running the [sample](https://github.com/farasource/billing-client/tree/master/sample) module. | ||
## How to use | ||
### AppCompatActivity | ||
|
||
* onCreate | ||
```JAVA | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
|
||
payment = new Payment(getActivityResultRegistry(), this, BuildConfig.IAB_PUBLIC_KEY); | ||
payment.setCanAutoConsume(false); | ||
payment.setOnPaymentResultListener(new OnPaymentResultListener() { | ||
@Override | ||
public void onBillingSuccess(Purchase purchase) { | ||
// | ||
} | ||
|
||
@Override | ||
public void onConsumeFinished(Purchase purchase, boolean success) { | ||
// | ||
} | ||
|
||
@Override | ||
public void onBillingStatus(int code) { | ||
if (code != TableCodes.SETUP_SUCCESS) { | ||
// | ||
} | ||
} | ||
|
||
@Override | ||
public void onQueryInventoryFinished(Inventory inventory) { | ||
// | ||
} | ||
}); | ||
} | ||
``` | ||
|
||
* launchPayment | ||
```JAVA | ||
payment.launchPayment(SKU_INFINITE_GAS, IabHelper.ITEM_TYPE_SUBS, payload); | ||
// or | ||
payment.launchPayment(sku, IabHelper.ITEM_TYPE_SUBS, payload, canAutoConsume); | ||
``` | ||
|
||
* consume | ||
```JAVA | ||
consume(purchase); | ||
``` | ||
|
||
* onDestroy | ||
```JAVA | ||
@Override | ||
public void onDestroy() { | ||
super.onDestroy(); | ||
if (payment != null) { | ||
payment.dispose(); | ||
payment = null; | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
plugins { | ||
id 'com.android.library' | ||
} | ||
|
||
android { | ||
compileSdk 31 | ||
|
||
defaultConfig { | ||
minSdk 16 | ||
targetSdk 31 | ||
|
||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles "consumer-rules.pro" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
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' | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
25 changes: 25 additions & 0 deletions
25
billing/src/androidTest/java/com/farasource/billing/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.farasource.billing; | ||
|
||
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.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); | ||
assertEquals("com.farasource.billing.test", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.farasource.billing"> | ||
|
||
<uses-permission android:name="${marketPermission}" /> | ||
|
||
<queries> | ||
<package android:name="${marketApplicationId}" /> | ||
<intent> | ||
<action android:name="${marketBindAddress}" /> | ||
<data android:mimeType="*/*" /> | ||
</intent> | ||
</queries> | ||
|
||
<application> | ||
<meta-data | ||
android:name="market_id" | ||
android:value="${marketApplicationId}" /> | ||
<meta-data | ||
android:name="market_bind_address" | ||
android:value="${marketBindAddress}" /> | ||
|
||
<receiver | ||
android:name=".receiver.PaymentReceiver" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="${marketApplicationId}.ping" /> | ||
<action android:name="${marketApplicationId}.purchase" /> | ||
<action android:name="${marketApplicationId}.getPurchase" /> | ||
<action android:name="${marketApplicationId}.billingSupport" /> | ||
<action android:name="${marketApplicationId}.skuDetail" /> | ||
<action android:name="${marketApplicationId}.consume" /> | ||
</intent-filter> | ||
</receiver> | ||
</application> | ||
|
||
</manifest> |
21 changes: 21 additions & 0 deletions
21
billing/src/main/aidl/com/android/vending/billing/IInAppBillingService.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.android.vending.billing; | ||
|
||
import android.os.Bundle; | ||
|
||
interface IInAppBillingService { | ||
int isBillingSupported(int apiVersion, String packageName, String type); | ||
|
||
Bundle getSkuDetails(int apiVersion, String packageName, String type, in Bundle skusBundle); | ||
|
||
Bundle getBuyIntent(int apiVersion, String packageName, String sku, String type, | ||
String developerPayload); | ||
|
||
Bundle getPurchases(int apiVersion, String packageName, String type, String continuationToken); | ||
|
||
int consumePurchase(int apiVersion, String packageName, String purchaseToken); | ||
|
||
Bundle getBuyIntentV2(int apiVersion, String packageName, String sku, String type, | ||
String developerPayload); | ||
|
||
Bundle getPurchaseConfig(int apiVersion); | ||
} |
42 changes: 42 additions & 0 deletions
42
billing/src/main/java/com/farasource/billing/NetworkCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.farasource.billing; | ||
|
||
import android.content.Context; | ||
import android.net.ConnectivityManager; | ||
import android.net.NetworkInfo; | ||
|
||
class NetworkCheck { | ||
|
||
static boolean isOnline(Context context) { | ||
try { | ||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | ||
|
||
NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); | ||
|
||
NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); | ||
|
||
NetworkInfo mobileNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); | ||
|
||
boolean isWifi = false; | ||
boolean isOtherNetwork = false; | ||
|
||
if (wifiNetwork != null) { | ||
isWifi = wifiNetwork.isConnectedOrConnecting(); | ||
} | ||
|
||
if (mobileNetwork != null) { | ||
isOtherNetwork = mobileNetwork.isConnectedOrConnecting(); | ||
} | ||
|
||
if (activeNetwork != null) { | ||
isOtherNetwork = activeNetwork.isConnectedOrConnecting(); | ||
|
||
} | ||
|
||
return isWifi || isOtherNetwork; | ||
} catch (Exception e) { | ||
// | ||
} | ||
return true; | ||
} | ||
|
||
} |
Oops, something went wrong.