Skip to content

Commit

Permalink
Complete revamp of the library
Browse files Browse the repository at this point in the history
- Amazon in-app purchasing has been added.
- Well written support for subscriptions and in-app purchases.
- Tests have been added.
  • Loading branch information
akshaaatt committed Apr 13, 2021
1 parent 94d7df4 commit cdd8d16
Show file tree
Hide file tree
Showing 21 changed files with 901 additions and 555 deletions.
53 changes: 28 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ allprojects {

```
dependencies {
implementation 'com.github.akshaaatt:Google-IAP:1.0.5'
implementation 'com.github.akshaaatt:Google-IAP:1.1.0'
}
```

Expand All @@ -37,56 +37,59 @@ dependencies {
#### Establishing connection with Play console

```kotlin
iapConnector = IapConnector(this, "...")
.setInAppProductIds(listOf("id1", "id2")) /*pass the list of INAPP IDs*/
.setSubscriptionIds(listOf("id1", "id2")) /*pass the list of SUBS IDs*/
.setConsumableProductIds(listOf("id1", "id2")) /*pass the list of consumable product IDs*/
.autoAcknowledge() /*to enable auto acknowledgement*/
.connect()
val iapConnector = IapConnector(
this,
skuList, // pass the list of in-app products
subsList, // pass the list of subscriptions
"LICENSE KEY", // pass your app's license key
true // to enable/disable logging
)
```

#### Receiving events

```kotlin
iapConnector.setOnInAppEventsListener(object : InAppEventsListener {
iapConnector.addPurchaseListener(object : PurchaseServiceListener {
override fun onPricesUpdated(iapKeyPrices: Map<String, String>) {
// list of available products will be received here, so you can update UI with prices if needed
}

override fun onSubscriptionsFetched(skuDetailsList: List<DataWrappers.SkuInfo>) {
/*provides list of product details of subs type*/
override fun onProductPurchased(sku: String?) {
// will be triggered whenever purchase succeeded
}

override fun onInAppProductsFetched(skuDetailsList: List<DataWrappers.SkuInfo>) {
/*provides list of product details of inapp type*/
override fun onProductRestored(sku: String?) {
// will be triggered fetching owned products using IAPManager.init();
}
})

override fun onPurchaseAcknowledged(purchase: DataWrappers.PurchaseInfo) {
/*callback after purchase being acknowledged*/
iapConnector.addSubscriptionListener(object : SubscriptionServiceListener {
override fun onSubscriptionRestored(sku: String?) {
// will be triggered upon fetching owned subscription upon initialization
}

override fun onProductsPurchased(purchases: List<DataWrappers.PurchaseInfo>) {
/*provides recent purchases*/
override fun onSubscriptionPurchased(sku: String?) {
// will be triggered whenever subscription succeeded
}

override fun onError(inAppConnector: EasyIapConnector, result: DataWrappers.BillingResponse?) {
/*provides error message if anything goes wrong*/
override fun onPricesUpdated(iapKeyPrices: Map<String, String>) {
// list of available products will be received here, so you can update UI with prices if needed
}
})

```

#### Making a purchase

```kotlin
iapConnector.makePurchase(this, "<sku>")
iapConnector.purchase(this, "<sku>")
```

## Sample App

* Replace the key with your App's License Key
* Add your products to the developer console

```kotlin
iapConnector = IapConnector(
this, "key" // License Key
)
```
* Replace the key with your App's License Key

## Contribution

Expand Down
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ plugins {
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.alphelios.superrich"
applicationId "com.alphelios.richierich"
minSdkVersion 21
targetSdkVersion 30
versionCode 6
versionName "1.0.5"
versionCode 7
versionName "1.0.6"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -35,7 +35,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'com.google.android.material:material:1.4.0-alpha01'
implementation 'com.google.android.material:material:1.4.0-alpha02'

implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'com.google.android.gms:play-services-games:21.0.0'
Expand Down
Binary file added app/release/app-release.aab
Binary file not shown.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alphelios.superrich">
package="com.alphelios.richierich">

<application
android:allowBackup="true"
Expand All @@ -10,7 +10,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name="com.alphelios.superrich.MainActivity">
<activity android:name="com.alphelios.richierich.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand Down
102 changes: 102 additions & 0 deletions app/src/main/java/com/alphelios/richierich/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.alphelios.richierich

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.alphelios.iap.IapConnector
import com.alphelios.iap.PurchaseServiceListener
import com.alphelios.iap.SubscriptionServiceListener
import com.alphelios.richierich.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity(R.layout.activity_main) {

private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

binding.bottomnavview.itemIconTintList = null

val skuList = listOf("base", "moderate", "quite", "plenty", "yearly")
val subsList = listOf("subscribe")

val iapConnector = IapConnector(
this,
skuList,
subsList,
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAh09sfdDzMhCh3AG9mq2EsyFUN72FBKabPpMsJyUUwXVsVJRLDWQYKmWnr0bVGsdVHwQtEDi//EY1NubXjCmViAxFnnfbdUrAk9PbRRTaMQ4taifn9fCaQ6XAW70ju3/mXuL+1xX+r8B0O9B373sP0YqiUs0b8HTtTjQoOGtcGb2KlYpQlJjjtISfVpsSk2RdKatkDyeesv+6568O7xgb5zp/KNJk8d1fMqKGWJiveFkZvedDh1ECdi3rSz1aQB+z/aEf6AIiuLzu0V8NNKjvZnxUjVJgL+lcLDrL1YZuKx9h5BX7k8lPZI7fLIVE6b6iNx3msfVdiqPkZ3s49JxA1QIDAQAB",
true
)

iapConnector.addPurchaseListener(object : PurchaseServiceListener {
override fun onPricesUpdated(iapKeyPrices: Map<String, String>) {
// list of available products will be received here, so you can update UI with prices if needed
}

override fun onProductPurchased(sku: String?) {
when (sku) {
"base" -> {

}
"moderate" -> {

}
"quite" -> {

}
"plenty" -> {

}
"subscribe" -> {

}
"yearly" -> {

}
}
}

override fun onProductRestored(sku: String?) {
// will be triggered fetching owned products using IAPManager.init();
}
})

iapConnector.addSubscriptionListener(object : SubscriptionServiceListener {
override fun onSubscriptionRestored(sku: String?) {
// will be triggered upon fetching owned subscription upon initialization
}

override fun onSubscriptionPurchased(sku: String?) {
// will be triggered whenever subscription succeeded
}

override fun onPricesUpdated(iapKeyPrices: Map<String, String>) {
// list of available products will be received here, so you can update UI with prices if needed
}
})

binding.btPurchaseCons.setOnClickListener {
iapConnector.purchase(this, "base")
}
binding.btnMonthly.setOnClickListener {
iapConnector.purchase(this, "subscribe")
}

binding.btnYearly.setOnClickListener {
iapConnector.purchase(this, "yearly")
}
binding.btnQuite.setOnClickListener {
iapConnector.purchase(this, "quite")

}
binding.btnModerate.setOnClickListener {
iapConnector.purchase(this, "moderate")
}

binding.btnUltimate.setOnClickListener {
iapConnector.purchase(this, "plenty")

}
}
}
112 changes: 0 additions & 112 deletions app/src/main/java/com/alphelios/superrich/MainActivity.kt

This file was deleted.

4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.4.31'
ext.kotlin_version = '1.4.32'
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
5 changes: 5 additions & 0 deletions iap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ android {
}

dependencies {
implementation files('libs/in-app-purchasing-2.0.76.jar')
implementation "com.android.billingclient:billing-ktx:3.0.3"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:2.24.0'
}
Binary file added iap/libs/in-app-purchasing-2.0.76.jar
Binary file not shown.
Loading

0 comments on commit cdd8d16

Please sign in to comment.