@@ -152,10 +152,10 @@ defmodule Gringotts.Gateways.Mercadopago do
152
152
# For consistency with other gateway implementations, make your (final)
153
153
# network request in here, and parse it using another private method called
154
154
# `respond`.
155
- # @spec commit(_, _, _, _ ) :: {:ok | :error, Response}
156
- defp commit ( method , path , body , opts ) do
155
+ @ spec commit ( atom , String . t ( ) , String . t ( ) , keyword , keyword ) :: { :ok | :error , Response . t ( ) }
156
+ defp commit ( method , path , body , opts , url_params ) do
157
157
headers = [ { "content-type" , "application/json" } , { "accept" , "application/json" } ]
158
- HTTPoison . request ( method , path , body , headers , [ ] ) |> respond ( opts )
158
+ HTTPoison . request ( method , " #{ @ base_url } #{ path } " , body , headers , url_params ) |> respond ( opts )
159
159
end
160
160
161
161
# Parses mercadopago's response and returns a `Gringotts.Response` struct
@@ -174,15 +174,16 @@ defmodule Gringotts.Gateways.Mercadopago do
174
174
defp auth ( amount , % CreditCard { } = card , opts , token_id , capture ) do
175
175
{ _ , value , _ , _ } = Money . to_integer_exp ( amount )
176
176
opts = opts ++ [ token_id: token_id ]
177
- url = " #{ @ base_url } /v1/payments? access_token= #{ opts [ :config ] [ :access_token ] } "
177
+ url_params = [ access_token: opts [ :config ] [ :access_token ] ]
178
178
body = authorize_params ( value , card , opts , opts [ :token_id ] , opts [ :customer_id ] , capture ) |> Poison . encode!
179
- commit ( :post , url , body , opts )
179
+ commit ( :post , "/v1/payments" , body , opts , params: url_params )
180
180
end
181
181
182
182
defp create_customer ( opts ) do
183
- url = " #{ @ base_url } /v1/customers? access_token= #{ opts [ :config ] [ :access_token ] } "
183
+ url_params = [ access_token: opts [ :config ] [ :access_token ] ]
184
184
body = % { "email": opts [ :email ] } |> Poison . encode!
185
- { state , res } = commit ( :post , url , body , opts )
185
+
186
+ { state , res } = commit ( :post , "/v1/customers" , body , opts , params: url_params )
186
187
if state == :error do
187
188
{ state , res }
188
189
else
@@ -201,9 +202,9 @@ defmodule Gringotts.Gateways.Mercadopago do
201
202
end
202
203
203
204
defp create_token ( % CreditCard { } = card , opts ) do
204
- url = " #{ @ base_url } /v1/card_tokens/ #{ opts [ :customer_id ] } ? public_key= #{ opts [ :config ] [ :public_key ] } "
205
+ url_params = [ public_key: opts [ :config ] [ :public_key ] ]
205
206
body = token_params ( card ) |> Poison . encode!
206
- { state , res } = commit ( :post , url , body , opts )
207
+ { state , res } = commit ( :post , "/v1/card_tokens/ #{ opts [ :customer_id ] } " , body , opts , params: url_params )
207
208
case state do
208
209
:error -> { state , res }
209
210
_ -> { state , res . id }
@@ -257,7 +258,7 @@ defmodule Gringotts.Gateways.Mercadopago do
257
258
end
258
259
end
259
260
260
- defp respond ( { :error , % HTTPoison.Error { } = error } , opts ) do
261
+ defp respond ( { :error , % HTTPoison.Error { } = error } , _ ) do
261
262
{
262
263
:error ,
263
264
Response . error (
0 commit comments