diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e3db30c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# Changelog + +## 0.3.0-dev + +- change return value of `AlipayKit.V3.verify_response/2` from `{:ok, map()} | {:error, :bad_response | :bad_signature}` to `:ok | {:error, :bad_response | :bad_signature}` diff --git a/lib/alipay_kit/v3.ex b/lib/alipay_kit/v3.ex index d72b120..21d7ee6 100644 --- a/lib/alipay_kit/v3.ex +++ b/lib/alipay_kit/v3.ex @@ -165,7 +165,7 @@ defmodule AlipayKit.V3 do """ @spec verify_response(HTTPSpec.Response.t(), verify_response_opts()) :: - {:ok, map()} | {:error, :bad_response | :bad_signature} + :ok | {:error, :bad_response | :bad_signature} def verify_response(%HTTPSpec.Response{} = response, opts) do opts = NimbleOptions.validate!(opts, @verify_response_opts_definition) alipay_public_key = Keyword.fetch!(opts, :alipay_public_key) @@ -182,7 +182,7 @@ defmodule AlipayKit.V3 do ) if verify?(sign_type, string_to_sign, alipay_public_key, signature), - do: {:ok, json_decode!(response.body)}, + do: :ok, else: {:error, :bad_signature} else _ -> @@ -265,11 +265,6 @@ defmodule AlipayKit.V3 do :crypto.strong_rand_bytes(16) |> Base.encode16(case: :lower) end - defp json_decode!(binary) when is_binary(binary) do - {:ok, term} = JXON.decode(binary) - term - end - defp timestamp do DateTime.utc_now() |> DateTime.to_unix(:millisecond) end diff --git a/mix.exs b/mix.exs index 5c21b3d..b6af0e2 100644 --- a/mix.exs +++ b/mix.exs @@ -4,6 +4,7 @@ defmodule AlipayKit.MixProject do @version "0.2.0" @description "A kit for Alipay." @source_url "https://github.com/cozy-elixir/alipay_kit" + @changelog_url "https://github.com/cozy-elixir/alipay_kit/blob/v#{@version}/CHANGELOG.md" def project do [ @@ -46,7 +47,7 @@ defmodule AlipayKit.MixProject do defp docs do [ - extras: ["README.md"], + extras: ["README.md", "CHANGELOG.md"], source_url: @source_url, source_ref: "v#{@version}" ] @@ -55,7 +56,10 @@ defmodule AlipayKit.MixProject do defp package do [ licenses: ["Apache-2.0"], - links: %{GitHub: @source_url} + links: %{ + GitHub: @source_url, + Changelog: @changelog_url + } ] end diff --git a/test/alipay_kit/v3_test.exs b/test/alipay_kit/v3_test.exs index 10e8b51..5d2cf02 100644 --- a/test/alipay_kit/v3_test.exs +++ b/test/alipay_kit/v3_test.exs @@ -99,6 +99,8 @@ defmodule AlipayKit.V3Test do ] } + assert :ok = V3.verify_response(response, alipay_public_key: alipay_public_key) + assert {:ok, %{ "buyer_pay_amount" => "0.00", @@ -108,8 +110,7 @@ defmodule AlipayKit.V3Test do "out_trade_no" => "70501111111S001111120", "point_amount" => "0.00", "receipt_amount" => "0.00" - }} = - V3.verify_response(response, alipay_public_key: alipay_public_key) + }} = JXON.decode(response.body) end end @@ -155,7 +156,7 @@ defmodule AlipayKit.V3Test do headers: headers ) - assert {:ok, _} = V3.verify_response(response, alipay_public_key: alipay_public_key) + assert :ok = V3.verify_response(response, alipay_public_key: alipay_public_key) end end