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

Commit

Permalink
add types
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Yang committed Feb 17, 2021
1 parent 446e783 commit 9772843
Show file tree
Hide file tree
Showing 20 changed files with 237 additions and 196 deletions.
1 change: 1 addition & 0 deletions packages/in_app_purchase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.4.0-nullsafety.0

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

Expand Down
3 changes: 1 addition & 2 deletions packages/in_app_purchase/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,7 @@ class _MyAppState extends State<_MyApp> {
onPressed: () {
PurchaseParam purchaseParam = PurchaseParam(
productDetails: productDetails,
applicationUserName: null,
sandboxTesting: true);
applicationUserName: null);
if (productDetails.id == _kConsumableId) {
_connection.buyConsumable(
purchaseParam: purchaseParam,
Expand Down
2 changes: 1 addition & 1 deletion packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ - (void)refreshReceipt:(FlutterMethodCall *)call result:(FlutterResult)result {
}];
}

#pragma mark - delegates
#pragma mark - delegatestransactionIdentifier:

- (void)handleTransactionsUpdated:(NSArray<SKPaymentTransaction *> *)transactions {
NSMutableArray *maps = [NSMutableArray new];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ part 'enum_converters.g.dart';
///
/// Use these in `@JsonSerializable()` classes by annotating them with
/// `@BillingResponseConverter()`.
class BillingResponseConverter implements JsonConverter<BillingResponse, int> {
class BillingResponseConverter implements JsonConverter<BillingResponse, int?> {
/// Default const constructor.
const BillingResponseConverter();

@override
BillingResponse fromJson(int json) => _$enumDecode<BillingResponse, dynamic>(
BillingResponse fromJson(int? json) {
if (json == null) {
return BillingResponse.error;
}
return _$enumDecode<BillingResponse, dynamic>(
_$BillingResponseEnumMap.cast<BillingResponse, dynamic>(), json);
}

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

@override
SkuType fromJson(String json) => _$enumDecode<SkuType, dynamic>(
SkuType fromJson(String? json) {
if (json == null) {
return SkuType.inapp;
}
return _$enumDecode<SkuType, dynamic>(
_$SkuTypeEnumMap.cast<SkuType, dynamic>(), json);
}

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

@override
PurchaseStateWrapper fromJson(int json) =>
_$enumDecode<PurchaseStateWrapper, dynamic>(
PurchaseStateWrapper fromJson(int? json) {
if (json == null) {
return PurchaseStateWrapper.unspecified_state;
}
return _$enumDecode<PurchaseStateWrapper, dynamic>(
_$PurchaseStateWrapperEnumMap.cast<PurchaseStateWrapper, dynamic>(),
json);
}

@override
int toJson(PurchaseStateWrapper object) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class PurchaseWrapper {
required this.purchaseState});

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

@override
bool operator ==(Object other) {
Expand Down Expand Up @@ -74,22 +74,28 @@ class PurchaseWrapper {

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

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

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

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

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

/// The product ID of this purchase.
@JsonKey(defaultValue: '')
final String sku;

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

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

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

/// Determines the current state of the purchase.
Expand Down Expand Up @@ -146,20 +155,24 @@ class PurchaseHistoryRecordWrapper {
});

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

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

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

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

/// The product ID of this purchase.
@JsonKey(defaultValue: '')
final String sku;

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

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

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

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

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

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9772843

Please sign in to comment.