Skip to content

compile-time safety for api call parameters and types #211

@ghost

Description

The 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions