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

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Yang committed Feb 18, 2021
1 parent cfc0d04 commit 3c77357
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ class BillingClient {
_callbacks[_kOnBillingServiceDisconnected] ??= [];
disconnectCallbacks.add(onBillingServiceDisconnected);
return BillingResultWrapper.fromJson((await channel
.invokeMapMethod<String, dynamic>(
"BillingClient#startConnection(BillingClientStateListener)",
<String, dynamic>{
'handle': disconnectCallbacks.length - 1,
'enablePendingPurchases': _enablePendingPurchases
})) ?? <String, dynamic>{});
.invokeMapMethod<String, dynamic>(
"BillingClient#startConnection(BillingClientStateListener)",
<String, dynamic>{
'handle': disconnectCallbacks.length - 1,
'enablePendingPurchases': _enablePendingPurchases
})) ??
<String, dynamic>{});
}

/// Calls
Expand Down Expand Up @@ -143,9 +144,10 @@ class BillingClient {
'skusList': skusList
};
return SkuDetailsResponseWrapper.fromJson((await channel.invokeMapMethod<
String, dynamic>(
'BillingClient#querySkuDetailsAsync(SkuDetailsParams, SkuDetailsResponseListener)',
arguments)) ?? <String, dynamic>{});
String, dynamic>(
'BillingClient#querySkuDetailsAsync(SkuDetailsParams, SkuDetailsResponseListener)',
arguments)) ??
<String, dynamic>{});
}

/// Attempt to launch the Play Billing Flow for a given [skuDetails].
Expand Down Expand Up @@ -180,8 +182,9 @@ class BillingClient {
};
return BillingResultWrapper.fromJson(
(await channel.invokeMapMethod<String, dynamic>(
'BillingClient#launchBillingFlow(Activity, BillingFlowParams)',
arguments)) ?? <String, dynamic>{});
'BillingClient#launchBillingFlow(Activity, BillingFlowParams)',
arguments)) ??
<String, dynamic>{});
}

/// Fetches recent purchases for the given [SkuType].
Expand All @@ -198,10 +201,11 @@ class BillingClient {
Future<PurchasesResultWrapper> queryPurchases(SkuType skuType) async {
assert(skuType != null);
return PurchasesResultWrapper.fromJson((await channel
.invokeMapMethod<String, dynamic>(
'BillingClient#queryPurchases(String)', <String, dynamic>{
'skuType': SkuTypeConverter().toJson(skuType)
})) ?? <String, dynamic>{});
.invokeMapMethod<String, dynamic>(
'BillingClient#queryPurchases(String)', <String, dynamic>{
'skuType': SkuTypeConverter().toJson(skuType)
})) ??
<String, dynamic>{});
}

/// Fetches purchase history for the given [SkuType].
Expand All @@ -220,9 +224,12 @@ class BillingClient {
Future<PurchasesHistoryResult> queryPurchaseHistory(SkuType skuType) async {
assert(skuType != null);
return PurchasesHistoryResult.fromJson((await channel.invokeMapMethod<
String, dynamic>(
'BillingClient#queryPurchaseHistoryAsync(String, PurchaseHistoryResponseListener)',
<String, dynamic>{'skuType': SkuTypeConverter().toJson(skuType)})) ?? <String, dynamic>{});
String, dynamic>(
'BillingClient#queryPurchaseHistoryAsync(String, PurchaseHistoryResponseListener)',
<String, dynamic>{
'skuType': SkuTypeConverter().toJson(skuType)
})) ??
<String, dynamic>{});
}

/// Consumes a given in-app product.
Expand All @@ -237,12 +244,13 @@ class BillingClient {
{String? developerPayload}) async {
assert(purchaseToken != null);
return BillingResultWrapper.fromJson((await channel
.invokeMapMethod<String, dynamic>(
'BillingClient#consumeAsync(String, ConsumeResponseListener)',
<String, dynamic>{
'purchaseToken': purchaseToken,
'developerPayload': developerPayload,
}))??<String, dynamic>{});
.invokeMapMethod<String, dynamic>(
'BillingClient#consumeAsync(String, ConsumeResponseListener)',
<String, dynamic>{
'purchaseToken': purchaseToken,
'developerPayload': developerPayload,
})) ??
<String, dynamic>{});
}

/// Acknowledge an in-app purchase.
Expand All @@ -268,12 +276,13 @@ class BillingClient {
{String? developerPayload}) async {
assert(purchaseToken != null);
return BillingResultWrapper.fromJson((await channel.invokeMapMethod<String,
dynamic>(
'BillingClient#(AcknowledgePurchaseParams params, (AcknowledgePurchaseParams, AcknowledgePurchaseResponseListener)',
<String, dynamic>{
'purchaseToken': purchaseToken,
'developerPayload': developerPayload,
}))??<String, dynamic>{});
dynamic>(
'BillingClient#(AcknowledgePurchaseParams params, (AcknowledgePurchaseParams, AcknowledgePurchaseResponseListener)',
<String, dynamic>{
'purchaseToken': purchaseToken,
'developerPayload': developerPayload,
})) ??
<String, dynamic>{});
}

/// The method call handler for [channel].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ part 'sku_details_wrapper.g.dart';
/// The error message shown when the map represents billing result is invalid from method channel.
///
/// This usually indicates a series underlining code issue in the plugin.
const kInvalidBillingResultErrorMessage = 'Invalid billing result map from method channel.';
const kInvalidBillingResultErrorMessage =
'Invalid billing result map from method channel.';

/// Dart wrapper around [`com.android.billingclient.api.SkuDetails`](https://developer.android.com/reference/com/android/billingclient/api/SkuDetails).
///
Expand Down Expand Up @@ -214,10 +215,12 @@ class BillingResultWrapper {
/// The map needs to have named string keys with values matching the names and
/// types of all of the members on this class.
factory BillingResultWrapper.fromJson(Map<String, dynamic>? map) {
if (map == null || map.isEmpty) {
return BillingResultWrapper(responseCode: BillingResponse.error, debugMessage: kInvalidBillingResultErrorMessage);
}
return _$BillingResultWrapperFromJson(map);
if (map == null || map.isEmpty) {
return BillingResultWrapper(
responseCode: BillingResponse.error,
debugMessage: kInvalidBillingResultErrorMessage);
}
return _$BillingResultWrapperFromJson(map);
}

/// Response code returned in the Play Billing API calls.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class SKSubscriptionPeriodUnitConverter
return SKSubscriptionPeriodUnit.day;
}
return _$enumDecode<SKSubscriptionPeriodUnit, dynamic>(
_$SKSubscriptionPeriodUnitEnumMap.cast<SKSubscriptionPeriodUnit, dynamic>(),
_$SKSubscriptionPeriodUnitEnumMap
.cast<SKSubscriptionPeriodUnit, dynamic>(),
json);
}

Expand All @@ -87,7 +88,8 @@ class SKProductDiscountPaymentModeConverter
return SKProductDiscountPaymentMode.payAsYouGo;
}
return _$enumDecode<SKProductDiscountPaymentMode, dynamic>(
_$SKProductDiscountPaymentModeEnumMap.cast<SKProductDiscountPaymentMode, dynamic>(),
_$SKProductDiscountPaymentModeEnumMap
.cast<SKProductDiscountPaymentMode, dynamic>(),
json);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class SKPaymentQueueWrapper {

/// Calls [`-[SKPaymentQueue canMakePayments:]`](https://developer.apple.com/documentation/storekit/skpaymentqueue/1506139-canmakepayments?language=objc).
static Future<bool> canMakePayments() async =>
(await channel.invokeMethod<bool>('-[SKPaymentQueue canMakePayments:]')) ?? false;
(await channel
.invokeMethod<bool>('-[SKPaymentQueue canMakePayments:]')) ??
false;

/// Sets an observer to listen to all incoming transaction events.
///
Expand Down Expand Up @@ -321,7 +323,7 @@ class SKPaymentWrapper {
///
/// The default is 1. The minimum is 1. The maximum is 10.
///
/// If the object is invalid, the value could be 0.
/// If the object is invalid, the value could be 0.
@JsonKey(defaultValue: 0)
final int quantity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class SKProductSubscriptionPeriodWrapper {
factory SKProductSubscriptionPeriodWrapper.fromJson(
Map<String, dynamic>? map) {
if (map == null) {
return SKProductSubscriptionPeriodWrapper(numberOfUnits: 0, unit: SKSubscriptionPeriodUnit.day);
return SKProductSubscriptionPeriodWrapper(
numberOfUnits: 0, unit: SKSubscriptionPeriodUnit.day);
}
return _$SKProductSubscriptionPeriodWrapperFromJson(map);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ void main() {
await billingClient.startConnection(
onBillingServiceDisconnected: () {}),
equals(BillingResultWrapper(
responseCode: BillingResponse.error, debugMessage: kInvalidBillingResultErrorMessage)));
responseCode: BillingResponse.error,
debugMessage: kInvalidBillingResultErrorMessage)));
});
});

Expand Down Expand Up @@ -173,7 +174,8 @@ void main() {
skuType: SkuType.inapp, skusList: <String>['invalid']);

BillingResultWrapper billingResult = BillingResultWrapper(
responseCode: BillingResponse.error, debugMessage: kInvalidBillingResultErrorMessage);
responseCode: BillingResponse.error,
debugMessage: kInvalidBillingResultErrorMessage);
expect(response.billingResult, equals(billingResult));
expect(response.skuDetailsList, isEmpty);
});
Expand Down Expand Up @@ -233,7 +235,8 @@ void main() {
expect(
await billingClient.launchBillingFlow(sku: skuDetails.sku),
equals(BillingResultWrapper(
responseCode: BillingResponse.error, debugMessage: kInvalidBillingResultErrorMessage)));
responseCode: BillingResponse.error,
debugMessage: kInvalidBillingResultErrorMessage)));
});
});

Expand Down Expand Up @@ -294,7 +297,11 @@ void main() {
final PurchasesResultWrapper response =
await billingClient.queryPurchases(SkuType.inapp);

expect(response.billingResult, equals(BillingResultWrapper(responseCode: BillingResponse.error, debugMessage: kInvalidBillingResultErrorMessage)));
expect(
response.billingResult,
equals(BillingResultWrapper(
responseCode: BillingResponse.error,
debugMessage: kInvalidBillingResultErrorMessage)));
expect(response.responseCode, BillingResponse.error);
expect(response.purchasesList, isEmpty);
});
Expand Down Expand Up @@ -354,7 +361,11 @@ void main() {
final PurchasesHistoryResult response =
await billingClient.queryPurchaseHistory(SkuType.inapp);

expect(response.billingResult, equals(BillingResultWrapper(responseCode: BillingResponse.error, debugMessage: kInvalidBillingResultErrorMessage)));
expect(
response.billingResult,
equals(BillingResultWrapper(
responseCode: BillingResponse.error,
debugMessage: kInvalidBillingResultErrorMessage)));
expect(response.purchaseHistoryRecordList, isEmpty);
});
});
Expand Down Expand Up @@ -385,7 +396,11 @@ void main() {
final BillingResultWrapper billingResult = await billingClient
.consumeAsync('dummy token', developerPayload: 'dummy payload');

expect(billingResult, equals(BillingResultWrapper(responseCode: BillingResponse.error, debugMessage: kInvalidBillingResultErrorMessage)));
expect(
billingResult,
equals(BillingResultWrapper(
responseCode: BillingResponse.error,
debugMessage: kInvalidBillingResultErrorMessage)));
});
});

Expand Down Expand Up @@ -416,7 +431,11 @@ void main() {
await billingClient.acknowledgePurchase('dummy token',
developerPayload: 'dummy payload');

expect(billingResult, equals(BillingResultWrapper(responseCode: BillingResponse.error, debugMessage: kInvalidBillingResultErrorMessage)));
expect(
billingResult,
equals(BillingResultWrapper(
responseCode: BillingResponse.error,
debugMessage: kInvalidBillingResultErrorMessage)));
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ void main() {
test('parsed from empty map', () {
final PurchasesResultWrapper parsed =
PurchasesResultWrapper.fromJson(<String, dynamic>{});
expect(parsed.billingResult, equals(BillingResultWrapper(responseCode: BillingResponse.error, debugMessage: kInvalidBillingResultErrorMessage)));
expect(
parsed.billingResult,
equals(BillingResultWrapper(
responseCode: BillingResponse.error,
debugMessage: kInvalidBillingResultErrorMessage)));
expect(parsed.responseCode, BillingResponse.error);
expect(parsed.purchasesList, isEmpty);
});
Expand Down Expand Up @@ -152,7 +156,11 @@ void main() {
test('parsed from empty map', () {
final PurchasesHistoryResult parsed =
PurchasesHistoryResult.fromJson(<String, dynamic>{});
expect(parsed.billingResult, equals(BillingResultWrapper(responseCode: BillingResponse.error, debugMessage: kInvalidBillingResultErrorMessage)));
expect(
parsed.billingResult,
equals(BillingResultWrapper(
responseCode: BillingResponse.error,
debugMessage: kInvalidBillingResultErrorMessage)));
expect(parsed.purchaseHistoryRecordList, isEmpty);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,29 @@ void main() {
expect(parsed.skuDetailsList, containsAll(expected.skuDetailsList));
});

test('fromJson creates an object with default values', (){
test('fromJson creates an object with default values', () {
final SkuDetailsResponseWrapper skuDetails =
SkuDetailsResponseWrapper.fromJson(<String, dynamic>{});
expect(skuDetails.billingResult, equals(BillingResultWrapper(responseCode: BillingResponse.error, debugMessage: kInvalidBillingResultErrorMessage)));
expect(
skuDetails.billingResult,
equals(BillingResultWrapper(
responseCode: BillingResponse.error,
debugMessage: kInvalidBillingResultErrorMessage)));
expect(skuDetails.skuDetailsList, isEmpty);
});
});

group('BillingResultWrapper', () {
test('fromJson on empty map creates an object with default values', (){
final BillingResultWrapper billingResult = BillingResultWrapper.fromJson(<String, dynamic>{});
test('fromJson on empty map creates an object with default values', () {
final BillingResultWrapper billingResult =
BillingResultWrapper.fromJson(<String, dynamic>{});
expect(billingResult.debugMessage, kInvalidBillingResultErrorMessage);
expect(billingResult.responseCode, BillingResponse.error);
});

test('fromJson on null creates an object with default values', (){
final BillingResultWrapper billingResult = BillingResultWrapper.fromJson(null);
test('fromJson on null creates an object with default values', () {
final BillingResultWrapper billingResult =
BillingResultWrapper.fromJson(null);
expect(billingResult.debugMessage, kInvalidBillingResultErrorMessage);
expect(billingResult.responseCode, BillingResponse.error);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ void main() {
expect(await SKPaymentQueueWrapper.canMakePayments(), true);
});

test('canMakePayment returns false if method channel returns null', () async {
test('canMakePayment returns false if method channel returns null',
() async {
fakeIOSPlatform.testReturnNull = true;
expect(await SKPaymentQueueWrapper.canMakePayments(), false);
});
Expand Down
Loading

0 comments on commit 3c77357

Please sign in to comment.