-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GET transaction info api call (#5)
* Add intial steps for transaction info * Adding some test resources from the python lib Available at: https://github.com/apple/app-store-server-library-python * Add 200 response for get_transacion_info test * Remove support files * Remove decode function. Not within the scope of this PR * Bump minor version to 0.2.0 * Revert to v0.1.0, add details to CHANGELOG * remove empty line
- Loading branch information
1 parent
fea3d2e
commit 933658f
Showing
5 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule AppStore.API.TransactionInfo do | ||
@moduledoc """ | ||
The module for Transaction Info | ||
""" | ||
|
||
alias AppStore.API.{Config, Response, Error, HTTP} | ||
|
||
@type transaction_id :: String.t() | ||
|
||
@path_prefix "/inApps/v1/transactions/" | ||
|
||
@doc """ | ||
Get information about a single transaction for your app. | ||
Official documentation: https://developer.apple.com/documentation/appstoreserverapi/get_transaction_info | ||
""" | ||
@spec get_transaction_info(Config.t(), String.t(), transaction_id) :: | ||
{:error, Error.t()} | {:ok, Response.t()} | ||
def get_transaction_info(%Config{} = api_config, token, transaction_id) do | ||
path = "#{@path_prefix}/#{transaction_id}" | ||
|
||
HTTP.get(api_config, token, path) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
defmodule AppStore.API.TransactionInfoTest do | ||
use AppStore.TestCase, async: false | ||
|
||
alias AppStore.API.TransactionInfo | ||
|
||
describe "get_transaction_info/3" do | ||
test "returns 200 and an expected response body", %{bypass: bypass, app_store: app_store} do | ||
expected_body = %{signedTransactionInfo: "signed_transaction_info_value"} |> Jason.encode!() | ||
|
||
Bypass.expect_once(bypass, "GET", "/inApps/v1/transactions/1234", fn conn -> | ||
conn | ||
|> Plug.Conn.put_resp_header("server", "daiquiri/3.0.0") | ||
|> Plug.Conn.resp(200, expected_body) | ||
end) | ||
|
||
{:ok, %AppStore.API.Response{body: body, status: status}} = | ||
TransactionInfo.get_transaction_info( | ||
app_store.api_config, | ||
"token", | ||
"1234" | ||
) | ||
|
||
assert status === 200 | ||
assert body === expected_body | ||
end | ||
|
||
test "returns 401 for unauthenticated request", %{bypass: bypass, app_store: app_store} do | ||
Bypass.expect_once(bypass, "GET", "/inApps/v1/transactions/transaction-id", fn conn -> | ||
conn | ||
|> Plug.Conn.put_resp_header("server", "daiquiri/3.0.0") | ||
|> Plug.Conn.resp(401, "Unauthenticated\n\nRequest ID: PXYVB35MOBBC5TL6UOXY6DGJGY.0.0\n") | ||
end) | ||
|
||
{:ok, %AppStore.API.Response{body: body, status: status}} = | ||
TransactionInfo.get_transaction_info( | ||
app_store.api_config, | ||
"token", | ||
"transaction-id" | ||
) | ||
|
||
assert status === 401 | ||
assert body === "Unauthenticated\n\nRequest ID: PXYVB35MOBBC5TL6UOXY6DGJGY.0.0\n" | ||
end | ||
end | ||
end |