Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a schema to fully specify the configuration options for the JSON files #51

Open
JlUgia opened this issue Jun 4, 2021 · 2 comments

Comments

@JlUgia
Copy link
Member

JlUgia commented Jun 4, 2021

One alternative to configure payment providers for this plugin is to create a configuration file in JSON format, and reference it in the instantiation of the payment client or the widgets directly.

This configuration is not fully specified for all providers.:

Create a fully specified JSON schema for the parameters, types and values allowed for each provider. The current plan is to use JSON Schema, currently published as a draft IETF tool, and open to other suggestions.

@remonh87
Copy link

remonh87 commented Jun 4, 2021

I think this is a very good suggestion to give devs more insights because currently the config parameters are not clear to me for all cases.

However why not directly go for a config object in Dart that helps developers and use build in jsonserialization ? Advantage of this is that we have type safety and analyzer can help us. Also JSON Schema can be very complex to read when you have a lot of parameters .

@vincevargadev
Copy link

vincevargadev commented Jul 1, 2021

At the project I am working on, we currently use our own "pay" plugin (it's a heavily edited fork of the flutter_pay plugin). That plugin has a set of Dart classes that help developers build the correct payloads that are necessary for the pay plugin to work.

We found that building the JSON (Map<String, dynamic>) correctly is quite difficult as the payloads are quite big. Having the more idiomatic Dart classes helps us spot mistakes at "analyze" or compile time as it enables static type checking.

What we can do is take our "well-defined classes" and provide that as an optional additional dependency. It could maybe even be in a separate little package (for example pay_data, or something like that), as for defining the data classes we used freezed+json_serializable, and maybe it would be better to leave those "big" dependencies out of the main pay package.

Integrating it into this plugin will take some time as in our plugin, we tried to match the original data structures very closely. Their format are documented here: Google's Android JSON request objects, JSON response objects, and Apple Pay's PKPaymentRequest, PKPayment.

The simple JSON based resource is great if the backend sets all the payment options, or if a developer likes the "simpler" approach, but the Dart classes really improve the developer experience (better documentation and compile time errors).

What was the thought process that made you land these two dependencies?

json_serializable is a "standard" way of converting from plain-old-Dart-objects to JSON (mainly Map<String, dynamic>) in the Dart eco-system.

We found that freezed is also helpful for its unions and pattern-matching capabilities. This was useful for example in cases where a parameter can be of multiple different types, for example Google Pay's request object's payment method parameter than can be either "card parameter" or "paypal parameter

The whole build process requires a couple of more dependencies: freezed_annotation, freezed, json_annotation, json_serializable, and build_runner, but "conceptually", it can be considered as two dependencies: json_serializable and freezed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants