Comments (8)
@Buratti I love the idea of using property wrappers. And you're in the same vein of how I was thinking of implementing it with a StripeExpandable
protocol etc. We can dive a bit more into it when you get a chance.
from stripe-kit.
@anthonycastelli @ksmandersen thoughts on this approach?
from stripe-kit.
I’m all for it. Right now Stripe and Vapor still aren’t at a full official release so a breaking change isn’t a big deal right now. I like the idea of incorporating property wrappers this way too. My only question is what is the benefit of doing this?
from stripe-kit.
I like this approach.
My main concern with expandable objects is the difference in types. E.g if you don’t expand the latestInvoice
on Subscription
it is String?
if you do expand it becomes a Invoice?
. The key in the json is the same.
from stripe-kit.
@ksmandersen Actually this is a tough one. I'm working on a way to get around this now.
from stripe-kit.
@ksmandersen that's one of the reason beyond property wrappers. If you decide to not expand latestInvoice you are still able to access its id property as a string using the projected value ($latestInvoice.id
).
There might be a smarter solution though. A couple of days ago Andrew and I were discussing on Discord about the "multi type" problem. The default source of a user can be a Card object but it might also be another type of payment method. The current approach would not be able to handle this situation.
A different solution might be to have
@Expandable
var defaultSource: String?
If we always keep String
as the wrapped value we can project some other object. The projected object will be responsible to decode the expanded object as the user request.
For example:
customer.defaultSource // "card_1234" <- not source breaking, the wrapped value will always be the object id or nil if no defaultSource exists.
customer.$defaultSource.decoded(as: StripeCard.self)?.last4 // "4242" if the expanded object was a Card, nil if it was a different form of Payment Method.
This solution is a bit uglier from a syntax point of view but with Swift 5.2 we can improve from
customer.$defaultSource.decoded(as: StripeCard.self)?.last4
to
customer.$defaultSource(as: StripeCard.self)?.last4
which is not so bad.
from stripe-kit.
Regarding the same key problem, you can find a custom implementation of init(from decoder: Decoder) throws
here
If the object is not expanded, the key for latestInvoice
will map to a single value container
which will contain a string. If the object is expanded, the key will map to a keyed container
keyed by StripeCard.CodingKeys.self
.
Therefor, if the object is expanded String.init(from: decoder)
will fail and if the object is not expanded StripeCard.init(from: decoder)
will fail.
from stripe-kit.
This was implemented in #72
from stripe-kit.
Related Issues (20)
- Error decoding response when retrieving a price for a product. HOT 3
- SwiftCrypto Platform Version Issue HOT 3
- customerCreation -> ifRequired throws error in Stripe dashboard HOT 1
- Decoding issue for response of checkout session HOT 1
- US Bank Account Enum for Charges HOT 3
- Ephemeral Keys? HOT 2
- No ID in CustomerRoutes update method
- Incorrect Ephemeral Keys Endpoint HOT 1
- ChargePaymentMethodDetailsType of type link does not exist
- Mistake in the mapping of allowed documents for verificationSessions/Reports
- CustomerSearchResult Data field is incorrect HOT 1
- AddHeaders not available on UsageRecordRoutes
- Incorrect API paths in TerminalReaderRoutes
- Initting objects does not have nil defaults.
- Cannot create a PaymentLink
- Cannot retrieve connected account (using old URL) HOT 3
- Missing enum on PaymentMethodCardNetwork HOT 1
- previousAttributes on Webhook events HOT 14
- EventObject is not actually Encodable
- Failing to decode EventObject of type 'application'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stripe-kit.