Skip to content

Commit

Permalink
[in_app_purchase] Add in_app_purchase package (flutter-tizen#562)
Browse files Browse the repository at this point in the history
Co-authored-by: Swift Kim <[email protected]>
  • Loading branch information
hyue7 and swift-kim authored Jul 25, 2023
1 parent 6755f60 commit c23e61c
Show file tree
Hide file tree
Showing 35 changed files with 2,874 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
- packages/google_sign_in/**/*
"p: image_picker":
- packages/image_picker/**/*
"p: in_app_purchase":
- packages/in_app_purchase/**/*
"p: integration_test":
- packages/integration_test/**/*
"p: messageport":
Expand Down
1 change: 1 addition & 0 deletions .github/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ plugins:
camera: []
flutter_webrtc: []
geolocator: []
in_app_purchase: []
network_info_plus: []
video_player_videohole: []

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The _"non-endorsed"_ status means that the plugin is not endorsed by the origina
| [**google_maps_flutter_tizen**](packages/google_maps_flutter) | [google_maps_flutter](https://pub.dev/packages/google_maps_flutter) (1st-party) | [![pub package](https://img.shields.io/pub/v/google_maps_flutter_tizen.svg)](https://pub.dev/packages/google_maps_flutter_tizen) | No |
| [**google_sign_in_tizen**](packages/google_sign_in) | [google_sign_in](https://pub.dev/packages/google_sign_in) (1st-party) | [![pub package](https://img.shields.io/pub/v/google_sign_in_tizen.svg)](https://pub.dev/packages/google_sign_in_tizen) | No |
| [**image_picker_tizen**](packages/image_picker) | [image_picker](https://pub.dev/packages/image_picker) (1st-party) | [![pub package](https://img.shields.io/pub/v/image_picker_tizen.svg)](https://pub.dev/packages/image_picker_tizen) | No |
| [**in_app_purchase_tizen**](packages/in_app_purchase) | [in_app_purchase](https://pub.dev/packages/in_app_purchase) (1st-party) | [![pub package](https://img.shields.io/pub/v/in_app_purchase_tizen.svg)](https://pub.dev/packages/in_app_purchase_tizen) | No |
| [**integration_test_tizen**](packages/integration_test) | [integration_test](https://github.com/flutter/flutter/tree/main/packages/integration_test) (1st-party) | [![pub package](https://img.shields.io/pub/v/integration_test_tizen.svg)](https://pub.dev/packages/integration_test_tizen) | No |
| [**messageport_tizen**](packages/messageport) | (Tizen-only) | [![pub package](https://img.shields.io/pub/v/messageport_tizen.svg)](https://pub.dev/packages/messageport_tizen) | N/A |
| [**network_info_plus_tizen**](packages/network_info_plus) | [network_info_plus](https://pub.dev/packages/network_info_plus) (1st-party) | [![pub package](https://img.shields.io/pub/v/network_info_plus_tizen.svg)](https://pub.dev/packages/network_info_plus_tizen) | No |
Expand Down Expand Up @@ -71,6 +72,7 @@ The _"non-endorsed"_ status means that the plugin is not endorsed by the origina
| [**google_maps_flutter_tizen**](packages/google_maps_flutter) | ✔️ | ✔️ | ✔️ | ✔️ |
| [**google_sign_in_tizen**](packages/google_sign_in) | ✔️ | ✔️ | ✔️ | ✔️ |
| [**image_picker_tizen**](packages/image_picker) | ⚠️ |||| No camera,<br>No file manager app |
| [**in_app_purchase_tizen**](packages/in_app_purchase) ||| ✔️ || Only applicable for TV |
| [**integration_test_tizen**](packages/integration_test) | ✔️ | ✔️ | ✔️ | ✔️ |
| [**messageport_tizen**](packages/messageport) | ✔️ | ✔️ | ✔️ | ✔️ |
| [**network_info_plus_tizen**](packages/network_info_plus) | ✔️ || ✔️ || API not supported on emulator |
Expand Down
7 changes: 7 additions & 0 deletions packages/in_app_purchase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.DS_Store
.dart_tool/

.packages
.pub/

build/
3 changes: 3 additions & 0 deletions packages/in_app_purchase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0

* Initial release.
26 changes: 26 additions & 0 deletions packages/in_app_purchase/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved.
Copyright (c) 2013 The Flutter Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the names of the copyright holders nor the names of the
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
79 changes: 79 additions & 0 deletions packages/in_app_purchase/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# in_app_purchase_tizen

The Tizen implementation of [`in_app_purchase`](https://pub.dev/packages/in_app_purchase) based on the [Samsung Checkout](https://developer.samsung.com/smarttv/develop/guides/samsung-checkout/samsung-checkout.html) API.

## Supported devices

This plugin is only supported on Samsung Smart TVs running Tizen 5.5 and above.

## Required privileges

To use this plugin in a Tizen application, you need to declare the following privileges in your `tizen-manifest.xml` file.

```xml
<privileges>
<privilege>http://developer.samsung.com/privilege/billing</privilege>
<privilege>http://developer.samsung.com/privilege/sso.partner</privilege>
<privilege>http://tizen.org/privilege/appmanager.launch</privilege>
</privileges>
```

The sso.partner privilege is required by the [Sso API](https://developer.samsung.com/smarttv/develop/api-references/samsung-product-api-references/sso-api.html) to internally obtain the user's custom ID (UID). Your app must be signed with a [partner-level certificate](https://docs.tizen.org/application/dotnet/get-started/certificates/creating-certificates) to use this privilege.

## Preparation

Follow these steps before setting up in-app purchases for your application:

1. [Register your application](https://github.com/flutter-tizen/flutter-tizen/blob/master/doc/publish-app.md) at the [Samsung Apps TV Seller Office](https://seller.samsungapps.com/tv) if you haven't registered yet. You do not need to complete the registration process at this point. Go to the **Billing Info** page of the app and set the **Samsung Checkout** checkbox to ON. You can return back to this page and finish the registration process when the final version of your app is ready.

2. Log in to the [Samsung Checkout DPI Portal](https://dpi.samsungcheckout.com) and register your in-app items. You can find your **App ID** and **Security Key** in the [**App Details Setting**](https://dpi.samsungcheckout.com/settings/appdetails) page. These values will be used as request parameters in your app code.

## Usage

This package is not an _endorsed_ implementation of `in_app_purchase`. Therefore, you have to include `in_app_purchase_tizen` alongside `in_app_purchase` as dependencies in your `pubspec.yaml` file.

```yaml
dependencies:
in_app_purchase: ^3.1.4
in_app_purchase_tizen: ^0.1.0
```
Then you can import `in_app_purchase` and `in_app_purchase_tizen` in your Dart code:

```dart
import 'package:in_app_purchase/in_app_purchase.dart';
import 'package:in_app_purchase_tizen/in_app_purchase_tizen.dart';
```

You must call `setRequestParameters` to set required parameters before making any plugin API call.

```dart
final InAppPurchaseTizenPlatformAddition platformAddition = _inAppPurchase
.getPlatformAddition<InAppPurchaseTizenPlatformAddition>();
platformAddition.setRequestParameters(
appId: 'your_dpi_app_id',
pageSize: 20,
pageNum: 1,
securityKey: 'your_security_key',
);
final ProductDetailsResponse response =
await _inAppPurchase.queryProductDetails(<String>{});
```

For detailed usage, see https://pub.dev/packages/in_app_purchase#usage and the [example](example/lib) app.

For more information on the Samsung Checkout API, visit the following pages.

- [Samsung Developers: Implementing the Purchase Process](https://developer.samsung.com/smarttv/develop/guides/samsung-checkout/implementing-the-purchase-process.html)
- [Samsung Developers: Billing API References](https://developer.samsung.com/smarttv/develop/api-references/samsung-product-api-references/billing-api.html)

## Supported APIs

- [x] `InAppPurchase.purchaseStream`
- [x] `InAppPurchase.isAvailable`
- [x] `InAppPurchase.queryProductDetails`
- [x] `InAppPurchase.buyNonConsumable`
- [x] `InAppPurchase.buyConsumable`
- [ ] `InAppPurchase.completePurchase` (Andriod/iOS-only)
- [x] `InAppPurchase.restorePurchases`
41 changes: 41 additions & 0 deletions packages/in_app_purchase/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json
7 changes: 7 additions & 0 deletions packages/in_app_purchase/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# in_app_purchase_tizen_example

Demonstrates how to use the in_app_purchase_tizen plugin.

## Getting Started

To run this app on your Tizen device, use [flutter-tizen](https://github.com/flutter-tizen/flutter-tizen).
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_test/flutter_test.dart';
import 'package:in_app_purchase/in_app_purchase.dart';
import 'package:integration_test/integration_test.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('Can create InAppPurchase instance', (WidgetTester tester) async {
final InAppPurchase iapInstance = InAppPurchase.instance;
expect(iapInstance, isNotNull);
});
}
Loading

0 comments on commit c23e61c

Please sign in to comment.