tab_key

tab_key

Dynamically setting request headers for stripity_stripe library

I am using stripity_stripe library and want to send some requests to stripe through a proxy server but not the others. So, I am trying to dynamically send hackney options on some requests. I looked into the code and documentation of stripity_stripe library but couldn’t find any example to send the hackney options related to proxy. I figured out to set the proxy related information in the config.ex file and it is working fine, but since it is set in the configuration, it will be applied to all the requests.

config :stripity_stripe,
  api_key: System.get_env("STRIPE_API_KEY"),
  hackney_opts: [
    {:ssl_options, [cacertfile: "CERT.pem"]},
    {:proxy, System.get_env("PROXY_SANDBOX_BASE_URL")},
    {:proxy_auth,
     {System.get_env("PROXY_SANDBOX_USERNAME"), System.get_env("PROXY_SANDBOX_PASSWORD")}}
  ]

I found a function request() in stripity_stripe to dynamically send headers and options but could not succeed to send these options successfully. Here is how I tried it:

Stripe.API.request(params, :post, "tokens", %{},
      hackney_opts: [
        {:ssl_options, [cacertfile: "CERT.pem"]},
        {:proxy, System.get_env("PROXY_SANDBOX_BASE_URL")},
        {:proxy_auth,
         {System.get_env("PROXY_SANDBOX_USERNAME"), System.get_env("PROXY_SANDBOX_PASSWORD")}}
      ]
    )

Any help would be appreciated. Thanks

Marked As Solved

tab_key

tab_key

Well omitting the hackney_options key when calling Stripe.API.request/5, and just putting the list of opts worked, i.e.
Stripe.API.request(params, :post, "tokens", %{}, ssl_options: [cacertfile: "/Users/apple/.ssh/CERT.pem"], proxy: System.get_env("PROXY_SANDBOX_BASE_URL"))

Hope it helps someone else.

Where Next?

Popular in Questions Top

vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement