Skip to content

Commit

Permalink
Merge pull request #67 from cb-amutha/feature/show_manage_susbcription
Browse files Browse the repository at this point in the history
Show manage subscriptions settings
  • Loading branch information
cb-amutha authored Aug 17, 2023
2 parents 70a83be + 99e8cdd commit 586d470
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.1.0
New Feature
* Adds show manage subscriptions settings in app (#67)
## 0.0.14
New Feature
* Adds one time purchase support. (#64)
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ To use Chargebee SDK in your Flutter app, follow these steps:

``` dart
dependencies:
chargebee_flutter: ^0.0.14
chargebee_flutter: ^0.1.0
```

2. Install dependency.
Expand Down Expand Up @@ -109,6 +109,17 @@ try {

The above function will handle the purchase against Apple App Store or Google Play Store and send the in-app purchase receipt for server-side receipt verification to your Chargebee account. Use the Subscription ID returned by the above function to check for Subscription status on Chargebee and confirm the access - granted or denied.

### Invoke Show Manage Subscriptions Settings
#### For Android
The `showManageSubscriptionsSettings()` function is designed to invoke the Manage Subscriptions in your app using Chargebee's Flutter SDKs. `Chargebee.showManageSubscriptionsSettings()`, opens the Play Store App subscriptions settings page.
#### For iOS
The `showManageSubscriptionsSettings()` function is designed to invoke the upgrade/downgrade flow in your app using Chargebee's Flutter SDKs. `Chargebee.shared.showManageSubscriptionsSettings()`, opens the App Store App subscriptions settings page.

**Note:** Upgrades and downgrades are handled through [Apple App Store Server Notifications](https://apidocs.chargebee.com/docs/api/in_app_purchase_events?prod_cat_ver=2#app_store_notifications) in Chargebee.
##### Upgrade or Downgrade Subscription
When a user changes their subscription level from a lower price plan to a higher price plan, it's considered an upgrade. On the other hand, when a user switches from a higher-price plan to a lower-price plan, it's considered a downgrade.
In the case of the Apple App Store, you can arrange the subscriptions using the drag-and-drop option in **Edit Subscription Order** in App Store Connect. [Learn more](https://developer.apple.com/app-store/subscriptions/#ranking).

### One-Time Purchases
The `purchaseNonSubscriptionProduct` function handles the one-time purchase against Apple App Store and Google Play Store and then sends the IAP receipt for server-side receipt verification to your Chargebee account. Post verification a Charge corresponding to this one-time purchase will be created in Chargebee. The Apple App Store supports three types of one-time purchases `consumable`, `non_consumable` and `non_renewing_subscription`. The Google Play Store supports two types of one-time purchases `consumable` and `non_consumable`.

Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.chargebee.flutter.sdk'
version '0.0.14'
version '0.1.0'

buildscript {
ext.kotlin_version = '1.6.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class ChargebeeFlutterSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAwar
purchaseProduct(args, result)
}
}
"showManageSubscriptionsSettings" -> {
showManageSubscriptionsSettings(args)
}
"purchaseNonSubscriptionProduct" -> {
if (args != null) {
purchaseNonSubscriptionProduct(args, result)
Expand Down Expand Up @@ -223,6 +226,12 @@ class ChargebeeFlutterSdkPlugin : FlutterPlugin, MethodCallHandler, ActivityAwar
})
}

private fun showManageSubscriptionsSettings(args: Map<String, Any>?) {
val productId = args?.get("productId") as String
val packageName = args?.get("applicationId") as String
Chargebee.showManageSubscriptionsSettings(context = activity, productId = productId, packageName = packageName)
}

private fun purchaseNonSubscriptionProduct(args: Map<String, Any>, callback: Result) {
val customer = CBCustomer(
args["customerId"] as String,
Expand Down
8 changes: 6 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion flutter.compileSdkVersion
compileSdkVersion 33

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand All @@ -50,7 +50,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.chargebee.example"
minSdkVersion flutterMinSdkVersion
targetSdkVersion flutter.targetSdkVersion
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand All @@ -60,6 +60,10 @@ android {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
// minifyEnabled flag will be used to shrink/optimize unused classes and packages.
// And proGuard files are maintained to avoid obfuscate or shrinking the particular packages/classes during the release build
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions example/android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Add project specific ProGuard rules here.
-keep class com.chargebee.android.** { *;}
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.6.0'
ext.kotlin_version = '1.8.10'
repositories {
google()
mavenCentral()
Expand Down
4 changes: 3 additions & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
org.gradle.jvmargs=-Xmx1536M
org.gradle.jvmargs=-Xmx1536M --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
android.useAndroidX=true
android.enableJetifier=true


2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
4 changes: 3 additions & 1 deletion example/lib/Constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class Constants {
'Get Entitlements',
'Get Plans',
'Get Items',
'Restore Purchase'
'Restore Purchase',
'Show Manage Subscriptions',
];

static const String config = 'Configure';
Expand All @@ -22,4 +23,5 @@ class Constants {
static const String getAllPlans = 'Get Plans';
static const String getAllItems = 'Get Items';
static const String restorePurchase = 'Restore Purchase';
static const String showManageSubscriptions = 'Show Manage Subscriptions';
}
3 changes: 3 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ class _MyHomePageState extends State<MyHomePage> {
mProgressBarUtil.showProgressDialog();
restorePurchases();
break;
case Constants.showManageSubscriptions:
Chargebee.showManageSubscriptionsSettings();
break;
default:
break;
}
Expand Down
3 changes: 3 additions & 0 deletions ios/Classes/SwiftChargebeeFlutterSdkPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public class SwiftChargebeeFlutterSdkPlugin: NSObject, FlutterPlugin {
}
}
})
case "showManageSubscriptionsSettings":
Chargebee.shared.showManageSubscriptionsSettings()

case "purchaseNonSubscriptionProduct":
guard let params = call.arguments as? [String: String] else {
return _result(FlutterError.noArgsError)
Expand Down
4 changes: 2 additions & 2 deletions ios/chargebee_flutter.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = 'chargebee_flutter'
s.version = '0.0.14'
s.version = '0.1.0'
s.summary = 'This is the official Software Development Kit (SDK) for Chargebee Flutter.'
s.description = <<-DESC
A new Flutter plugin.
Expand All @@ -14,7 +14,7 @@ A new Flutter plugin.
s.dependency 'Flutter'
s.platform = :ios, '12.0'

s.dependency 'Chargebee', '1.0.25'
s.dependency 'Chargebee', '1.0.26'

# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
Expand Down
15 changes: 15 additions & 0 deletions lib/src/chargebee.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ class Chargebee {
}
}

/// This method will be used to show Manage Subscriptions Settings in your App,
///
/// [productId] it is optional.
///
/// [applicationId] it is optional. packageName/bundleId of the app
static Future<void> showManageSubscriptionsSettings([
String? productId = '',
String? applicationId = '',
]) async {
await platform.invokeMethod(
Constants.mShowManageSubscriptionsSettings,
{Constants.productId: productId, Constants.applicationId: applicationId},
);
}

/// Buy the non-subscription product with/without customer data.
///
/// [product] product object to be passed.
Expand Down
3 changes: 3 additions & 0 deletions lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Constants {
static const params = 'params';
static const includeInactivePurchases = 'includeInactivePurchases';
static const productType = 'product_type';
static const productId = 'productId';
static const applicationId = 'applicationId';

/// API name for both iOS and Android
static const mAuthentication = 'authentication';
Expand All @@ -28,6 +30,7 @@ class Constants {
'purchaseNonSubscriptionProduct';
static const mValidateReceiptForNonSubscriptions =
'validateReceiptForNonSubscriptions';
static const mShowManageSubscriptionsSettings = 'showManageSubscriptionsSettings';

/// Customer info
static const customerId = 'customerId';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: chargebee_flutter
description: This is the official Software Development Kit (SDK) for Chargebee Flutter.
version: 0.0.14
version: 0.1.0
homepage: 'https://chargebee.com'
repository: 'https://github.com/chargebee/chargebee-flutter'

Expand Down

0 comments on commit 586d470

Please sign in to comment.