Skip to content

Commit

Permalink
Fixes shared secret should be an optional config.
Browse files Browse the repository at this point in the history
  • Loading branch information
linjunpop committed May 27, 2017
1 parent 3ca60d3 commit 72cae3b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/receipt_verifier.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ defmodule ReceiptVerifier do

defp prepare_request_body(receipt) do
%{
"receipt-data" => receipt,
"password" => load_password()
} |> Poison.encode!
"receipt-data" => receipt
}
|> set_password()
|> Poison.encode!
end

defp process_response(%{"status" => 0, "receipt" => receipt, "latest_receipt" => latest_receipt, "latest_receipt_info" => latest_receipt_info}) do
Expand Down Expand Up @@ -130,7 +131,13 @@ defmodule ReceiptVerifier do
{:error, %Error{code: 21_009, message: message}}
end

defp load_password do
Application.get_env(:receipt_verifier, :shared_secret, "")
defp set_password(data) do
case Application.get_env(:receipt_verifier, :shared_secret) do
nil ->
data
shared_secret ->
data
|> Map.put("password", shared_secret)
end
end
end

0 comments on commit 72cae3b

Please sign in to comment.