Skip to content

Commit d055431

Browse files
in_app_purchases codelab update (#2295)
This PR is for a matching docs update. There are only minor changes in the code: 1. `googlePlayProjectName` -> `googleCloudProjectId` const rename to make it more appropriate. It is used for Pub/Sub to which Google Play publishes purchase-related events but it's on Google Cloud so we need the ID of the GCP project. 2. Steps `09` and `10` were misaligned relative to the instructions and should be steps `10` and `11` instead. 3. Minor update to backend readme. The `constants.dart` already exists, there was a typo in one of the placeholder values, and `constants.dart` uses single quotes. ## Pre-launch Checklist - [x] I read the [Effective Dart: Style] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-devrel channel on [Discord]. <!-- Links --> [Effective Dart: Style]: https://dart.dev/guides/language/effective-dart/style [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
1 parent ced32b4 commit d055431

File tree

128 files changed

+399
-399
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+399
-399
lines changed

in_app_purchases/codelab_rebuild.yaml

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16723,16 +16723,16 @@ steps:
1672316723
replace-contents: |
1672416724
### Configuration Files
1672516725

16726-
Create `lib/constants.dart` with:
16726+
Configure the required IDs and keys in `lib/constants.dart`:
1672716727

1672816728
```
16729-
const androidPackageId = "your Android package ID";
16729+
const androidPackageId = 'your Android package ID';
1673016730
const appStoreIssuerId = 'App Store Key issuer ID';
16731-
const appStoreKeyId = 'App Store Keu ID';
16732-
const appStoreSharedSecret = "App Store shared secret";
16731+
const appStoreKeyId = 'App Store Key ID';
16732+
const appStoreSharedSecret = 'App Store shared secret';
1673316733
const bundleId = 'your iOS bundle ID';
16734-
const googlePlayProjectName = "Google Cloud project name";
16735-
const googlePlayPubsubBillingTopic = "play_billing"; // change if necessary
16734+
const googleCloudProjectId = 'Google Cloud project ID';
16735+
const googlePlayPubsubBillingTopic = 'play_billing'; // change if necessary
1673616736
```
1673716737

1673816738
- Add `assets/service-account-firebase.json` with the server key for the Firebase Firestore project.
@@ -16788,7 +16788,7 @@ steps:
1678816788
const appStoreKeyId = 'App Store Key ID';
1678916789
const appStoreSharedSecret = 'App Store shared secret';
1679016790
const bundleId = 'your iOS bundle ID';
16791-
const googlePlayProjectName = 'Google Cloud project name';
16791+
const googleCloudProjectId = 'Google Cloud project ID';
1679216792
const googlePlayPubsubBillingTopic = 'play_billing';
1679316793
- name: Add dart-backend/lib/helpers.dart
1679416794
path: steps/dart-backend/lib/helpers.dart
@@ -17486,15 +17486,15 @@ steps:
1748617486
from: steps
1748717487
to: step_08
1748817488

17489-
- name: step_09
17489+
- name: step_10
1749017490
steps:
17491-
- name: Remove step_09
17492-
rmdir: step_09
17491+
- name: Remove step_10
17492+
rmdir: step_10
1749317493
- name: Patch app/lib/main.dart
1749417494
path: steps/app/lib/main.dart
1749517495
patch-u: |
17496-
--- b/in_app_purchases/step_09/app/lib/main.dart
17497-
+++ a/in_app_purchases/step_09/app/lib/main.dart
17496+
--- b/in_app_purchases/step_10/app/lib/main.dart
17497+
+++ a/in_app_purchases/step_10/app/lib/main.dart
1749817498
@@ -79,7 +79,11 @@ class _MyHomePageState extends State<MyHomePage> {
1749917499
create: (context) => IAPRepo(context.read<FirebaseNotifier>()),
1750017500
),
@@ -17511,8 +17511,8 @@ steps:
1751117511
- name: Patch app/lib/logic/dash_purchases.dart
1751217512
path: steps/app/lib/logic/dash_purchases.dart
1751317513
patch-u: |
17514-
--- b/in_app_purchases/step_09/app/lib/logic/dash_purchases.dart
17515-
+++ a/in_app_purchases/step_09/app/lib/logic/dash_purchases.dart
17514+
--- b/in_app_purchases/step_10/app/lib/logic/dash_purchases.dart
17515+
+++ a/in_app_purchases/step_10/app/lib/logic/dash_purchases.dart
1751617516
@@ -1,7 +1,9 @@
1751717517
import 'dart:async';
1751817518
+import 'dart:convert';
@@ -17605,8 +17605,8 @@ steps:
1760517605
- name: Patch app/lib/logic/firebase_notifier.dart
1760617606
path: steps/app/lib/logic/firebase_notifier.dart
1760717607
patch-u: |
17608-
--- b/in_app_purchases/step_09/app/lib/logic/firebase_notifier.dart
17609-
+++ a/in_app_purchases/step_09/app/lib/logic/firebase_notifier.dart
17608+
--- b/in_app_purchases/step_10/app/lib/logic/firebase_notifier.dart
17609+
+++ a/in_app_purchases/step_10/app/lib/logic/firebase_notifier.dart
1761017610
@@ -29,6 +29,8 @@ class FirebaseNotifier extends ChangeNotifier {
1761117611
return FirebaseFirestore.instance;
1761217612
}
@@ -17619,8 +17619,8 @@ steps:
1761917619
- name: Patch app/lib/pages/purchase_page.dart
1762017620
path: steps/app/lib/pages/purchase_page.dart
1762117621
patch-u: |
17622-
--- b/in_app_purchases/step_09/app/lib/pages/purchase_page.dart
17623-
+++ a/in_app_purchases/step_09/app/lib/pages/purchase_page.dart
17622+
--- b/in_app_purchases/step_10/app/lib/pages/purchase_page.dart
17623+
+++ a/in_app_purchases/step_10/app/lib/pages/purchase_page.dart
1762417624
@@ -2,15 +2,29 @@ import 'package:flutter/material.dart';
1762517625
import 'package:provider/provider.dart';
1762617626

@@ -17654,8 +17654,8 @@ steps:
1765417654
- name: Patch dart-backend/bin/server.dart
1765517655
path: steps/dart-backend/bin/server.dart
1765617656
patch-u: |
17657-
--- b/in_app_purchases/step_09/dart-backend/bin/server.dart
17658-
+++ a/in_app_purchases/step_09/dart-backend/bin/server.dart
17657+
--- b/in_app_purchases/step_10/dart-backend/bin/server.dart
17658+
+++ a/in_app_purchases/step_10/dart-backend/bin/server.dart
1765917659
@@ -2,12 +2,111 @@
1766017660
// for details. All rights reserved. Use of this source code is governed by a
1766117661
// BSD-style license that can be found in the LICENSE file.
@@ -18099,20 +18099,20 @@ steps:
1809918099
required String token,
1810018100
});
1810118101
}
18102-
- name: Copy to step_09
18102+
- name: Copy to step_10
1810318103
copydir:
1810418104
from: steps
18105-
to: step_09
18105+
to: step_10
1810618106

18107-
- name: step_10
18107+
- name: step_11
1810818108
steps:
18109-
- name: Remove step_10
18110-
rmdir: step_10
18109+
- name: Remove step_11
18110+
rmdir: step_11
1811118111
- name: Patch app/lib/main.dart
1811218112
path: steps/app/lib/main.dart
1811318113
patch-u: |
18114-
--- b/in_app_purchases/step_10/app/lib/main.dart
18115-
+++ a/in_app_purchases/step_10/app/lib/main.dart
18114+
--- b/in_app_purchases/step_11/app/lib/main.dart
18115+
+++ a/in_app_purchases/step_11/app/lib/main.dart
1811618116
@@ -83,6 +83,7 @@ class _MyHomePageState extends State<MyHomePage> {
1811718117
(context) => DashPurchases(
1811818118
context.read<DashCounter>(),
@@ -18124,8 +18124,8 @@ steps:
1812418124
- name: Patch app/lib/logic/dash_purchases.dart
1812518125
path: steps/app/lib/logic/dash_purchases.dart
1812618126
patch-u: |
18127-
--- b/in_app_purchases/step_10/app/lib/logic/dash_purchases.dart
18128-
+++ a/in_app_purchases/step_10/app/lib/logic/dash_purchases.dart
18127+
--- b/in_app_purchases/step_11/app/lib/logic/dash_purchases.dart
18128+
+++ a/in_app_purchases/step_11/app/lib/logic/dash_purchases.dart
1812918129
@@ -10,6 +10,7 @@ import '../constants.dart';
1813018130
import '../main.dart';
1813118131
import '../model/purchasable_product.dart';
@@ -18228,8 +18228,8 @@ steps:
1822818228
- name: Patch dart-backend/bin/server.dart
1822918229
path: steps/dart-backend/bin/server.dart
1823018230
patch-u: |
18231-
--- b/in_app_purchases/step_10/dart-backend/bin/server.dart
18232-
+++ a/in_app_purchases/step_10/dart-backend/bin/server.dart
18231+
--- b/in_app_purchases/step_11/dart-backend/bin/server.dart
18232+
+++ a/in_app_purchases/step_11/dart-backend/bin/server.dart
1823318233
@@ -5,7 +5,9 @@
1823418234
import 'dart:convert';
1823518235
import 'dart:io';
@@ -18315,8 +18315,8 @@ steps:
1831518315
- name: Patch dart-backend/lib/app_store_purchase_handler.dart
1831618316
path: steps/dart-backend/lib/app_store_purchase_handler.dart
1831718317
patch-u: |
18318-
--- b/in_app_purchases/step_10/dart-backend/lib/app_store_purchase_handler.dart
18319-
+++ a/in_app_purchases/step_10/dart-backend/lib/app_store_purchase_handler.dart
18318+
--- b/in_app_purchases/step_11/dart-backend/lib/app_store_purchase_handler.dart
18319+
+++ a/in_app_purchases/step_11/dart-backend/lib/app_store_purchase_handler.dart
1832018320
@@ -7,10 +7,19 @@ import 'iap_repository.dart';
1832118321
import 'products.dart';
1832218322
import 'purchase_handler.dart';
@@ -18395,8 +18395,8 @@ steps:
1839518395
- name: Patch dart-backend/lib/google_play_purchase_handler.dart
1839618396
path: steps/dart-backend/lib/google_play_purchase_handler.dart
1839718397
patch-u: |
18398-
--- b/in_app_purchases/step_10/dart-backend/lib/google_play_purchase_handler.dart
18399-
+++ a/in_app_purchases/step_10/dart-backend/lib/google_play_purchase_handler.dart
18398+
--- b/in_app_purchases/step_11/dart-backend/lib/google_play_purchase_handler.dart
18399+
+++ a/in_app_purchases/step_11/dart-backend/lib/google_play_purchase_handler.dart
1840018400
@@ -1,6 +1,8 @@
1840118401
import 'dart:async';
1840218402
+import 'dart:convert';
@@ -18437,7 +18437,7 @@ steps:
1843718437
+ print('Polling Google Play messages');
1843818438
+ final request = pubsub.PullRequest(maxMessages: 1000);
1843918439
+ final topicName =
18440-
+ 'projects/$googlePlayProjectName/subscriptions/$googlePlayPubsubBillingTopic-sub';
18440+
+ 'projects/$googleCloudProjectId/subscriptions/$googlePlayPubsubBillingTopic-sub';
1844118441
+ final pullResponse = await pubsubApi.projects.subscriptions.pull(
1844218442
+ request,
1844318443
+ topicName,
@@ -18503,7 +18503,7 @@ steps:
1850318503
+ print('ACK Message');
1850418504
+ final request = pubsub.AcknowledgeRequest(ackIds: [id]);
1850518505
+ final subscriptionName =
18506-
+ 'projects/$googlePlayProjectName/subscriptions/$googlePlayPubsubBillingTopic-sub';
18506+
+ 'projects/$googleCloudProjectId/subscriptions/$googlePlayPubsubBillingTopic-sub';
1850718507
+ await pubsubApi.projects.subscriptions.acknowledge(
1850818508
+ request,
1850918509
+ subscriptionName,
@@ -18512,10 +18512,10 @@ steps:
1851218512
}
1851318513

1851418514
NonSubscriptionStatus _nonSubscriptionStatusFrom(int? state) {
18515-
- name: Copy to step_10
18515+
- name: Copy to step_11
1851618516
copydir:
1851718517
from: steps
18518-
to: step_10
18518+
to: step_11
1851918519

1852018520
- name: complete
1852118521
steps:

in_app_purchases/complete/app/pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ publish_to: 'none'
44
version: 0.1.0
55

66
environment:
7-
sdk: ^3.7.0-0
7+
sdk: ^3.7.0
88

99
dependencies:
1010
flutter:
1111
sdk: flutter
12-
cloud_firestore: ^5.6.3
12+
cloud_firestore: ^5.6.5
1313
cupertino_icons: ^1.0.8
14-
firebase_auth: ^5.4.2
15-
firebase_core: ^3.11.0
14+
firebase_auth: ^5.5.1
15+
firebase_core: ^3.12.1
1616
google_sign_in: ^6.2.2
1717
http: ^1.3.0
1818
intl: ^0.20.2

in_app_purchases/complete/dart-backend/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
### Configuration Files
22

3-
Create `lib/constants.dart` with:
3+
Configure the required IDs and keys in `lib/constants.dart`:
44

55
```
6-
const androidPackageId = "your Android package ID";
6+
const androidPackageId = 'your Android package ID';
77
const appStoreIssuerId = 'App Store Key issuer ID';
8-
const appStoreKeyId = 'App Store Keu ID';
9-
const appStoreSharedSecret = "App Store shared secret";
8+
const appStoreKeyId = 'App Store Key ID';
9+
const appStoreSharedSecret = 'App Store shared secret';
1010
const bundleId = 'your iOS bundle ID';
11-
const googlePlayProjectName = "Google Cloud project name";
12-
const googlePlayPubsubBillingTopic = "play_billing"; // change if necessary
11+
const googleCloudProjectId = 'Google Cloud project ID';
12+
const googlePlayPubsubBillingTopic = 'play_billing'; // change if necessary
1313
```
1414

1515
- Add `assets/service-account-firebase.json` with the server key for the Firebase Firestore project.

in_app_purchases/complete/dart-backend/lib/constants.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ const appStoreIssuerId = 'App Store Key issuer ID';
33
const appStoreKeyId = 'App Store Key ID';
44
const appStoreSharedSecret = 'App Store shared secret';
55
const bundleId = 'your iOS bundle ID';
6-
const googlePlayProjectName = 'Google Cloud project name';
6+
const googleCloudProjectId = 'Google Cloud project ID';
77
const googlePlayPubsubBillingTopic = 'play_billing';

in_app_purchases/complete/dart-backend/lib/google_play_purchase_handler.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class GooglePlayPurchaseHandler extends PurchaseHandler {
164164
print('Polling Google Play messages');
165165
final request = pubsub.PullRequest(maxMessages: 1000);
166166
final topicName =
167-
'projects/$googlePlayProjectName/subscriptions/$googlePlayPubsubBillingTopic-sub';
167+
'projects/$googleCloudProjectId/subscriptions/$googlePlayPubsubBillingTopic-sub';
168168
final pullResponse = await pubsubApi.projects.subscriptions.pull(
169169
request,
170170
topicName,
@@ -230,7 +230,7 @@ class GooglePlayPurchaseHandler extends PurchaseHandler {
230230
print('ACK Message');
231231
final request = pubsub.AcknowledgeRequest(ackIds: [id]);
232232
final subscriptionName =
233-
'projects/$googlePlayProjectName/subscriptions/$googlePlayPubsubBillingTopic-sub';
233+
'projects/$googleCloudProjectId/subscriptions/$googlePlayPubsubBillingTopic-sub';
234234
await pubsubApi.projects.subscriptions.acknowledge(
235235
request,
236236
subscriptionName,

in_app_purchases/complete/dart-backend/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ version: 1.0.0
44
# repository: https://github.com/my_org/my_repo
55

66
environment:
7-
sdk: ^3.7.0-0
7+
sdk: ^3.7.0
88

99
dependencies:
10-
app_store_server_sdk: ^1.2.9
10+
app_store_server_sdk: ^1.2.10
1111
googleapis: ^13.2.0
1212
googleapis_auth: ^1.6.0
1313
http: ^1.3.0

in_app_purchases/step_00/app/pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ publish_to: 'none'
44
version: 0.1.0
55

66
environment:
7-
sdk: ^3.7.0-0
7+
sdk: ^3.7.0
88

99
dependencies:
1010
flutter:
1111
sdk: flutter
12-
cloud_firestore: ^5.6.3
12+
cloud_firestore: ^5.6.5
1313
cupertino_icons: ^1.0.8
14-
firebase_auth: ^5.4.2
15-
firebase_core: ^3.11.0
14+
firebase_auth: ^5.5.1
15+
firebase_core: ^3.12.1
1616
google_sign_in: ^6.2.2
1717
http: ^1.3.0
1818
intl: ^0.20.2

in_app_purchases/step_00/dart-backend/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
### Configuration Files
22

3-
Create `lib/constants.dart` with:
3+
Configure the required IDs and keys in `lib/constants.dart`:
44

55
```
6-
const androidPackageId = "your Android package ID";
6+
const androidPackageId = 'your Android package ID';
77
const appStoreIssuerId = 'App Store Key issuer ID';
8-
const appStoreKeyId = 'App Store Keu ID';
9-
const appStoreSharedSecret = "App Store shared secret";
8+
const appStoreKeyId = 'App Store Key ID';
9+
const appStoreSharedSecret = 'App Store shared secret';
1010
const bundleId = 'your iOS bundle ID';
11-
const googlePlayProjectName = "Google Cloud project name";
12-
const googlePlayPubsubBillingTopic = "play_billing"; // change if necessary
11+
const googleCloudProjectId = 'Google Cloud project ID';
12+
const googlePlayPubsubBillingTopic = 'play_billing'; // change if necessary
1313
```
1414

1515
- Add `assets/service-account-firebase.json` with the server key for the Firebase Firestore project.

in_app_purchases/step_00/dart-backend/lib/constants.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ const appStoreIssuerId = 'App Store Key issuer ID';
33
const appStoreKeyId = 'App Store Key ID';
44
const appStoreSharedSecret = 'App Store shared secret';
55
const bundleId = 'your iOS bundle ID';
6-
const googlePlayProjectName = 'Google Cloud project name';
6+
const googleCloudProjectId = 'Google Cloud project ID';
77
const googlePlayPubsubBillingTopic = 'play_billing';

in_app_purchases/step_00/dart-backend/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ version: 1.0.0
44
# repository: https://github.com/my_org/my_repo
55

66
environment:
7-
sdk: ^3.7.0-0
7+
sdk: ^3.7.0
88

99
dependencies:
10-
app_store_server_sdk: ^1.2.9
10+
app_store_server_sdk: ^1.2.10
1111
googleapis: ^13.2.0
1212
googleapis_auth: ^1.6.0
1313
http: ^1.3.0

0 commit comments

Comments
 (0)