Search code examples
androidretrofit2stripe-payments

Retrofit POST Request and FormUrlEncoded with :Id in url


I am trying to integrate stripe API and I ran into the problem while using @POST and @FormUrlEncoding annotation. The stripe has the following Url. https://api.stripe.com/v1/customers/:id/sources The API need FormUrlEncoded and POST request. I have no idea how to pass that id in the URL.

    @POST("https://api.stripe.com/v1/customers/:id/sources")
    @FormUrlEncoded
    Completable createBankAccount(@Field("source") String bankToken);

Solution

  • You should pass id as a path parameter.

    So your endpoint will be as following:

    @POST("https://api.stripe.com/v1/customers/{id}/sources")
    @FormUrlEncoded
    Completable createBankAccount(@Path("id") int id,@Field("source") String bankToken);