Skip to content

Commit

Permalink
Merge pull request nsweeting#88 from larskluge/master
Browse files Browse the repository at this point in the history
Shopify Payments: Payouts
  • Loading branch information
nsweeting authored Nov 25, 2019
2 parents 271f1f8 + 7748666 commit 8040e54
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lib/shopify/resources/shopify_payments/payout.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
defmodule Shopify.ShopifyPayments.Payout do
@derive [Poison.Encoder]
@singular "payout"
@plural "payouts"

use Shopify.Resource,
import: [
:find,
:all
]

alias Shopify.ShopifyPayments.PayoutSummary

defstruct [
:amount,
:currency,
:date,
:id,
:status,
:summary
]

@doc false
def empty_resource do
%__MODULE__{
summary: %PayoutSummary{}
}
end

@doc false
def find_url(id), do: "shopify_payments/#{@plural}/#{id}.json"

@doc false
def all_url, do: "shopify_payments/#{@plural}.json"
end
18 changes: 18 additions & 0 deletions lib/shopify/resources/shopify_payments/payout_summary.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule Shopify.ShopifyPayments.PayoutSummary do
@moduledoc false

@derive [Poison.Encoder]

defstruct [
:adjustments_fee_amount,
:adjustments_gross_amount,
:charges_fee_amount,
:charges_gross_amount,
:refunds_fee_amount,
:refunds_gross_amount,
:reserved_funds_fee_amount,
:reserved_funds_gross_amount,
:retried_payouts_fee_amount,
:retried_payouts_gross_amount
]
end
42 changes: 42 additions & 0 deletions test/fixtures/shopify_payments/payouts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"payouts": [
{
"id": 2,
"status": "in_transit",
"date": "2019-11-08",
"currency": "USD",
"amount": "722.79",
"summary": {
"adjustments_fee_amount": "0.00",
"adjustments_gross_amount": "0.68",
"charges_fee_amount": "22.30",
"charges_gross_amount": "771.40",
"refunds_fee_amount": "0.00",
"refunds_gross_amount": "-26.99",
"reserved_funds_fee_amount": "0.00",
"reserved_funds_gross_amount": "0.00",
"retried_payouts_fee_amount": "0.00",
"retried_payouts_gross_amount": "0.00"
}
},
{
"id": 1,
"status": "paid",
"date": "2019-11-07",
"currency": "USD",
"amount": "1175.07",
"summary": {
"adjustments_fee_amount": "-30.00",
"adjustments_gross_amount": "63.22",
"charges_fee_amount": "32.69",
"charges_gross_amount": "1114.54",
"refunds_fee_amount": "0.00",
"refunds_gross_amount": "0.00",
"reserved_funds_fee_amount": "0.00",
"reserved_funds_gross_amount": "0.00",
"retried_payouts_fee_amount": "0.00",
"retried_payouts_gross_amount": "0.00"
}
}
]
}
21 changes: 21 additions & 0 deletions test/fixtures/shopify_payments/payouts/1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"payout": {
"id": 1,
"status": "paid",
"date": "2019-11-07",
"currency": "USD",
"amount": "1175.07",
"summary": {
"adjustments_fee_amount": "-30.00",
"adjustments_gross_amount": "63.22",
"charges_fee_amount": "32.69",
"charges_gross_amount": "1114.54",
"refunds_fee_amount": "0.00",
"refunds_gross_amount": "0.00",
"reserved_funds_fee_amount": "0.00",
"reserved_funds_gross_amount": "0.00",
"retried_payouts_fee_amount": "0.00",
"retried_payouts_gross_amount": "0.00"
}
}
}
21 changes: 21 additions & 0 deletions test/shopify_payments/payout_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule Shopify.ShopifyPayments.PayoutTest do
use ExUnit.Case, async: true

alias Shopify.ShopifyPayments.Payout

test "client can request a single payout" do
assert {:ok, response} = Shopify.session() |> Payout.find(1)
assert %Shopify.Response{} = response
assert 200 == response.code
fixture = Fixture.load("../test/fixtures/shopify_payments/payouts/1.json", "payout", Payout.empty_resource())
assert fixture == response.data
end

test "client can request all payouts" do
assert {:ok, response} = Shopify.session() |> Payout.all()
assert %Shopify.Response{} = response
assert 200 == response.code
fixture = Fixture.load("../test/fixtures/shopify_payments/payouts.json", "payouts", [Payout.empty_resource()])
assert fixture == response.data
end
end

0 comments on commit 8040e54

Please sign in to comment.