compile-time safety for api call parameters and types
See original GitHub issueThe current java api provides no compile-time safety for api call parameters. Neither the names of the parameters nor the types being passed as values are checked at compile time. It would be beneficial to users of the API to have a fluent style api for Stripe api calls. For example:
final Refund refund =
stripe.refund()
.create(chargeId)
.reverseTransfer(true)
.metadata("reason", "refund due to cancellation")
.idempotencyKey(stripeRefundNonce)
.get();
This might seem like a lot of work, however the official Stripe API reference is structured so well that such an API can be generated directly from the HTML. In fact, I know it can be done because that’s what I’m doing in my project. A little bit of Javascript, jQuery, and Mustache is all that’s needed to create a fluent style api directly from the official reference documentation. Every time the API changes, the corresponding java code can be regenerated automatically. Additionally, because it comes directly from the documentation, we can also incorporate Javadoc:
/**
* A cursor for use in pagination. <code>ending_before</code> is an
* object ID that defines your place in the list. For instance, if
* you make a list request and receive 100 objects, starting with
* <code>obj_bar</code>, your subsequent call can include
* <code>ending_before=obj_bar</code> in order to fetch the previous
* page of the list.
*/
public final AllMethod endingBefore(final String endingBefore) {
return set("ending_before", endingBefore);
}
If this is something that should be in the official Stripe API then I can create a pull request for it, otherwise I can create a separate project that builds on top of stripe-java.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:6
- Comments:23 (16 by maintainers)
+1 - the current design of this library is horribly non-object-oriented, this type of change would be much appreciated
Hi everyone. I know it’s been a long time since this issue was opened, but I’m happy to report that as of stripe-java v9.0.0, the library finally has support for fully typed request parameters!
You can see an example of the new syntax in our migration guide here. Over the next few weeks, the examples on Stripe’s site will also be updated to use the new syntax.
Thanks a lot for your patience. I’m closing the issue, but please do feel free to share your feedback.