Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pay_platform_interface/lib/core/payment_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PaymentConfiguration {
final PayProvider provider;

/// The configuration parameters for a given payment provider.
final Future<Map<String, dynamic>> _parameters;
final Map<String, dynamic> _parameters;

/// The raw configuration provided
final String _rawConfigurationData;
Expand Down Expand Up @@ -105,7 +105,7 @@ class PaymentConfiguration {
(s) async => jsonDecode(s) as Map<String, dynamic>);

/// Returns the core configuration map in this object.
Future<Map<String, dynamic>> parameterMap() async {
Map<String, dynamic> parameterMap() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this be a breaking change?

return _parameters;
}

Expand Down
6 changes: 6 additions & 0 deletions pay_platform_interface/lib/generated/package_info.dart

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

5 changes: 2 additions & 3 deletions pay_platform_interface/lib/pay_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class PayMethodChannel extends PayPlatform {
@override
Future<bool> userCanPay(PaymentConfiguration paymentConfiguration) async {
return await _channel.invokeMethod(
'userCanPay', jsonEncode(await paymentConfiguration.parameterMap()))
as bool;
'userCanPay', jsonEncode(paymentConfiguration.parameterMap())) as bool;
}

/// Shows the payment selector to complete the payment operation.
Expand All @@ -59,7 +58,7 @@ class PayMethodChannel extends PayPlatform {
List<PaymentItem> paymentItems,
) async {
final paymentResult = await _channel.invokeMethod('showPaymentSelector', {
'payment_profile': jsonEncode(await paymentConfiguration.parameterMap()),
'payment_profile': jsonEncode(paymentConfiguration.parameterMap()),
'payment_items': paymentItems.map((item) => item.toMap()).toList(),
}) as String;

Expand Down
21 changes: 6 additions & 15 deletions pay_platform_interface/lib/util/configurations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import 'package:flutter/services.dart';

import 'package:yaml/yaml.dart';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I guess we can also remove the dependency from pubspec.yaml?

import 'package:pay_platform_interface/core/payment_configuration.dart';
import 'package:pay_platform_interface/generated/package_info.dart';

/// A utility class to handle configuration objects and metadata associated
/// with this plugin.
class Configurations {
/// Complements the payment configuration object with metadata about the
/// package.
///
/// Takes the configuration included in [config] and returns and updated
/// version of the object wrapped in a [Future] with additional metadata.
static Future<Map<String, dynamic>> extractParameters(
Map<String, dynamic> configuration) async {
/// Takes the configuration included in [configuration] and returns an updated
/// version of the object with additional metadata.
static Map<String, dynamic> extractParameters(
Map<String, dynamic> configuration) {
PayProvider provider =
PayProviders.fromString(configuration['provider'] as String)!;
Map<String, dynamic> configurationParams =
Expand All @@ -43,7 +41,7 @@ class Configurations {
...(configurationParams['merchantInfo'] ?? {}) as Map,
'softwareInfo': {
'id': 'flutter/pay-plugin',
'version': (await _getPackageConfiguration())['version']
'version': PackageInfo.version
}
};

Expand All @@ -53,11 +51,4 @@ class Configurations {
return updatedPaymentConfiguration;
}
}

/// Retrieves package information from the `pubspec.yaml` file as a [Map].
static Future<Map<dynamic, dynamic>> _getPackageConfiguration() async {
final configurationFile = await rootBundle
.loadString('packages/pay_platform_interface/pubspec.yaml');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: same here. pubspec.yaml can be removed from the assets entry in pubspec.yaml?

return loadYaml(configurationFile) as Map<dynamic, dynamic>;
}
}
6 changes: 3 additions & 3 deletions pay_platform_interface/test/payment_configuration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void main() {
test('Load payment configuration from a string', () async {
final configuration = PaymentConfiguration.fromJsonString(_payConfigString);
expect(configuration.provider, _providerGooglePay);
expect(await configuration.parameterMap(), isNotEmpty);
expect(configuration.parameterMap(), isNotEmpty);
});

test('Load payment configuration from an asset', () async {
Expand All @@ -56,15 +56,15 @@ void main() {
profileLoader: _testProfileLoader);

expect(configuration.provider, _providerGooglePay);
expect(await configuration.parameterMap(), isNotEmpty);
expect(configuration.parameterMap(), isNotEmpty);
});

test('Check that software info is included in Google Pay requests', () async {
final config = await PaymentConfiguration.fromAsset(
'google_pay_prod_payment_profile.json',
profileLoader: _testProfileLoader);

final configParams = await config.parameterMap();
final configParams = config.parameterMap();
expect(configParams.containsKey('merchantInfo'), isTrue);
expect(configParams['merchantInfo'].containsKey('softwareInfo'), isTrue);

Expand Down