ezet / stripe-sdk

A simple and flexible Stripe library for Flutter with complete support for SCA and PSD2.
https://pub.dev/packages/stripe_sdk
Other
137 stars 137 forks source link

Confusing APIs #74

Closed ollyde closed 4 years ago

ollyde commented 4 years ago

There's lots of unknowns and very confusing implementations of the API.

For example, what is this strange way to get the customer API version:

CustomerSession.init((apiVersion) => server.getEphemeralKeyFromServer(apiVersion));
// or, to manage your own instances
final session = CustomerSession((apiVersion) => server.getEphemeralKeyFromServer(apiVersion))

It's not clear what sort of json the server is suppose to return or what these functions are suppose to do.

Why can't it be CustomerSession.init('some string') much easier to understand and implement.

Keep it simple.

eyoeldefare commented 4 years ago

There's lots of unknowns and very confusing implementations of the API.

For example, what is this strange way to get the customer API version:

CustomerSession.init((apiVersion) => server.getEphemeralKeyFromServer(apiVersion));
// or, to manage your own instances
final session = CustomerSession((apiVersion) => server.getEphemeralKeyFromServer(apiVersion))

It's not clear what sort of json the server is suppose to return or what these functions are suppose to do.

Why can't it be CustomerSession.init('some string') much easier to understand and implement.

Keep it simple.

Hey, we meet again on the other side of Github, haha. Anyways, this is a singleton way of initializing the CustomerSession instance with the api version which is by default 2020-08-27. You're basically grabbing the ephemeral key from your server and initializing the session to create a checkout payment. The reason it is not CustomerSession.init('some string') is because CustomerSession returns a Future EphemeralKeyProvider(String apiVersion) function when initializing the CustomerSession, while doing CustomerSession.init('some string') like you have suggested would have only set the instance of CustomerSession internally without returning any session which wouldn't have allowed you to manage it yourself. But now you can return the instance with final session = CustomerSession.instance and work.

I will try to pull a request for this later and will try to show an example on how to work with this SDK using a simple Node.js server as many people seem to be confused by some aspect of its implementation.

ollyde commented 4 years ago

@eyoeldefare haha yah I should delete this :-D