Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 9772843

Browse files
author
Chris Yang
committed
add types
1 parent 446e783 commit 9772843

20 files changed

+237
-196
lines changed

packages/in_app_purchase/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 0.4.0-nullsafety.0
22

33
* Migrate to nullsafety.
4+
* Deprecate `sandboxTesting`, introduce `simulatesAskToBuyInSandbox`.
45
* **Breaking Change:**
56
* Removed `callbackChannel` in `channels.dart`, see https://github.com/flutter/flutter/issues/69225.
67

packages/in_app_purchase/example/lib/main.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,7 @@ class _MyAppState extends State<_MyApp> {
255255
onPressed: () {
256256
PurchaseParam purchaseParam = PurchaseParam(
257257
productDetails: productDetails,
258-
applicationUserName: null,
259-
sandboxTesting: true);
258+
applicationUserName: null);
260259
if (productDetails.id == _kConsumableId) {
261260
_connection.buyConsumable(
262261
purchaseParam: purchaseParam,

packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ - (void)refreshReceipt:(FlutterMethodCall *)call result:(FlutterResult)result {
290290
}];
291291
}
292292

293-
#pragma mark - delegates
293+
#pragma mark - delegatestransactionIdentifier:
294294

295295
- (void)handleTransactionsUpdated:(NSArray<SKPaymentTransaction *> *)transactions {
296296
NSMutableArray *maps = [NSMutableArray new];

packages/in_app_purchase/lib/src/billing_client_wrappers/enum_converters.dart

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ part 'enum_converters.g.dart';
1212
///
1313
/// Use these in `@JsonSerializable()` classes by annotating them with
1414
/// `@BillingResponseConverter()`.
15-
class BillingResponseConverter implements JsonConverter<BillingResponse, int> {
15+
class BillingResponseConverter implements JsonConverter<BillingResponse, int?> {
1616
/// Default const constructor.
1717
const BillingResponseConverter();
1818

1919
@override
20-
BillingResponse fromJson(int json) => _$enumDecode<BillingResponse, dynamic>(
20+
BillingResponse fromJson(int? json) {
21+
if (json == null) {
22+
return BillingResponse.error;
23+
}
24+
return _$enumDecode<BillingResponse, dynamic>(
2125
_$BillingResponseEnumMap.cast<BillingResponse, dynamic>(), json);
26+
}
2227

2328
@override
2429
int toJson(BillingResponse object) => _$BillingResponseEnumMap[object]!;
@@ -28,13 +33,18 @@ class BillingResponseConverter implements JsonConverter<BillingResponse, int> {
2833
///
2934
/// Use these in `@JsonSerializable()` classes by annotating them with
3035
/// `@SkuTypeConverter()`.
31-
class SkuTypeConverter implements JsonConverter<SkuType, String> {
36+
class SkuTypeConverter implements JsonConverter<SkuType, String?> {
3237
/// Default const constructor.
3338
const SkuTypeConverter();
3439

3540
@override
36-
SkuType fromJson(String json) => _$enumDecode<SkuType, dynamic>(
41+
SkuType fromJson(String? json) {
42+
if (json == null) {
43+
return SkuType.inapp;
44+
}
45+
return _$enumDecode<SkuType, dynamic>(
3746
_$SkuTypeEnumMap.cast<SkuType, dynamic>(), json);
47+
}
3848

3949
@override
4050
String toJson(SkuType object) => _$SkuTypeEnumMap[object]!;
@@ -53,15 +63,19 @@ class _SerializedEnums {
5363
/// Use these in `@JsonSerializable()` classes by annotating them with
5464
/// `@PurchaseStateConverter()`.
5565
class PurchaseStateConverter
56-
implements JsonConverter<PurchaseStateWrapper, int> {
66+
implements JsonConverter<PurchaseStateWrapper, int?> {
5767
/// Default const constructor.
5868
const PurchaseStateConverter();
5969

6070
@override
61-
PurchaseStateWrapper fromJson(int json) =>
62-
_$enumDecode<PurchaseStateWrapper, dynamic>(
71+
PurchaseStateWrapper fromJson(int? json) {
72+
if (json == null) {
73+
return PurchaseStateWrapper.unspecified_state;
74+
}
75+
return _$enumDecode<PurchaseStateWrapper, dynamic>(
6376
_$PurchaseStateWrapperEnumMap.cast<PurchaseStateWrapper, dynamic>(),
6477
json);
78+
}
6579

6680
@override
6781
int toJson(PurchaseStateWrapper object) =>

packages/in_app_purchase/lib/src/billing_client_wrappers/purchase_wrapper.dart

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class PurchaseWrapper {
4040
required this.purchaseState});
4141

4242
/// Factory for creating a [PurchaseWrapper] from a [Map] with the purchase details.
43-
factory PurchaseWrapper.fromJson(Map map) => _$PurchaseWrapperFromJson(map);
43+
factory PurchaseWrapper.fromJson(Map<String, dynamic> map) => _$PurchaseWrapperFromJson(map);
4444

4545
@override
4646
bool operator ==(Object other) {
@@ -74,22 +74,28 @@ class PurchaseWrapper {
7474

7575
/// The unique ID for this purchase. Corresponds to the Google Payments order
7676
/// ID.
77+
@JsonKey(defaultValue: '')
7778
final String orderId;
7879

7980
/// The package name the purchase was made from.
81+
@JsonKey(defaultValue: '')
8082
final String packageName;
8183

8284
/// When the purchase was made, as an epoch timestamp.
85+
@JsonKey(defaultValue: 0)
8386
final int purchaseTime;
8487

8588
/// A unique ID for a given [SkuDetailsWrapper], user, and purchase.
89+
@JsonKey(defaultValue: '')
8690
final String purchaseToken;
8791

8892
/// Signature of purchase data, signed with the developer's private key. Uses
8993
/// RSASSA-PKCS1-v1_5.
94+
@JsonKey(defaultValue: '')
9095
final String signature;
9196

9297
/// The product ID of this purchase.
98+
@JsonKey(defaultValue: '')
9399
final String sku;
94100

95101
/// True for subscriptions that renew automatically. Does not apply to
@@ -105,15 +111,18 @@ class PurchaseWrapper {
105111
/// device"](https://developer.android.com/google/play/billing/billing_library_overview#Verify-purchase-device).
106112
/// Note though that verifying a purchase locally is inherently insecure (see
107113
/// the article for more details).
114+
@JsonKey(defaultValue: '')
108115
final String originalJson;
109116

110117
/// The payload specified by the developer when the purchase was acknowledged or consumed.
118+
@JsonKey(defaultValue: '')
111119
final String developerPayload;
112120

113121
/// Whether the purchase has been acknowledged.
114122
///
115123
/// A successful purchase has to be acknowledged within 3 days after the purchase via [BillingClient.acknowledgePurchase].
116124
/// * See also [BillingClient.acknowledgePurchase] for more details on acknowledging purchases.
125+
@JsonKey(defaultValue: false)
117126
final bool isAcknowledged;
118127

119128
/// Determines the current state of the purchase.
@@ -146,20 +155,24 @@ class PurchaseHistoryRecordWrapper {
146155
});
147156

148157
/// Factory for creating a [PurchaseHistoryRecordWrapper] from a [Map] with the record details.
149-
factory PurchaseHistoryRecordWrapper.fromJson(Map map) =>
158+
factory PurchaseHistoryRecordWrapper.fromJson(Map<String, dynamic> map) =>
150159
_$PurchaseHistoryRecordWrapperFromJson(map);
151160

152161
/// When the purchase was made, as an epoch timestamp.
162+
@JsonKey(defaultValue: 0)
153163
final int purchaseTime;
154164

155165
/// A unique ID for a given [SkuDetailsWrapper], user, and purchase.
166+
@JsonKey(defaultValue: '')
156167
final String purchaseToken;
157168

158169
/// Signature of purchase data, signed with the developer's private key. Uses
159170
/// RSASSA-PKCS1-v1_5.
171+
@JsonKey(defaultValue: '')
160172
final String signature;
161173

162174
/// The product ID of this purchase.
175+
@JsonKey(defaultValue: '')
163176
final String sku;
164177

165178
/// Details about this purchase, in JSON.
@@ -168,9 +181,11 @@ class PurchaseHistoryRecordWrapper {
168181
/// device"](https://developer.android.com/google/play/billing/billing_library_overview#Verify-purchase-device).
169182
/// Note though that verifying a purchase locally is inherently insecure (see
170183
/// the article for more details).
184+
@JsonKey(defaultValue: '')
171185
final String originalJson;
172186

173187
/// The payload specified by the developer when the purchase was acknowledged or consumed.
188+
@JsonKey(defaultValue: '')
174189
final String developerPayload;
175190

176191
@override
@@ -232,11 +247,13 @@ class PurchasesResultWrapper {
232247
///
233248
/// This can represent either the status of the "query purchase history" half
234249
/// of the operation and the "user made purchases" transaction itself.
250+
@JsonKey(defaultValue: BillingResponse.error)
235251
final BillingResponse responseCode;
236252

237253
/// The list of successful purchases made in this transaction.
238254
///
239255
/// May be empty, especially if [responseCode] is not [BillingResponse.ok].
256+
@JsonKey(defaultValue: <PurchaseWrapper>[])
240257
final List<PurchaseWrapper> purchasesList;
241258
}
242259

@@ -273,6 +290,7 @@ class PurchasesHistoryResult {
273290
/// The list of queried purchase history records.
274291
///
275292
/// May be empty, especially if [billingResult.responseCode] is not [BillingResponse.ok].
293+
@JsonKey(defaultValue: <PurchaseHistoryRecordWrapper>[])
276294
final List<PurchaseHistoryRecordWrapper> purchaseHistoryRecordList;
277295
}
278296

packages/in_app_purchase/lib/src/billing_client_wrappers/purchase_wrapper.g.dart

Lines changed: 43 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)