Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/recurly.ex
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ defmodule Recurly do
"""

@doc false
def api_version, do: "2.4"
def api_version, do: "2.5"

@doc false
def client_version do
Expand Down
7 changes: 6 additions & 1 deletion lib/recurly/account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Recurly.Account do
for more details
"""
use Recurly.Resource
alias Recurly.{Resource,Account,BillingInfo,Address,Transaction,Adjustment,Invoice,Subscription}
alias Recurly.{Resource, Account, BillingInfo, Address, Transaction, Adjustment, Invoice, Subscription}

@endpoint "/accounts"

Expand All @@ -22,6 +22,11 @@ defmodule Recurly.Account do
field :email, :string
field :entity_use_code, :string
field :first_name, :string
field :has_active_subscription, :boolean
field :has_canceled_subscription, :boolean
field :has_future_subscription, :boolean
field :has_live_subscription, :boolean
field :has_past_due_invoice, :boolean
field :hosted_login_token, :string, read_only: true
field :invoices, Invoice, list: true, read_only: true
field :last_name, :string
Expand Down
11 changes: 10 additions & 1 deletion lib/recurly/adjustment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ defmodule Recurly.Adjustment do
for more details
"""
use Recurly.Resource
alias Recurly.{Resource,Adjustment,Account,Invoice,Subscription}
alias Recurly.{Resource, Adjustment, Account, Invoice, Subscription}

@account_endpoint "/accounts/<%= account_code %>/adjustments"
@invoice_endpoint "/invoices/<%= invoice_number %>/adjustments"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be two streamable endpoints now. How should that be handled?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is probably a much cleaner way to implement, but this is how I'd imagine the interface to work:

def stream(options) do
  keys = Keyword.keys(options)
  cond do
    :account_code in keys ->
      {account_code, options} = Keyword.pop_first(options, :account_code)
      Resource.stream(Adjustment, account_path(account_code), options)
    :invoice_number in keys ->
      {invoice_number, options} = Keyword.pop_first(options, :invoice_number)
      Resource.stream(Adjustment, invoice_path(invoice_number), options)
  end
end

# examples:
stream(account_code: "myaccount", order: :desc)
stream(invoice_number: "1001", order: :asc)

@find_endpoint "/adjustments/<%= uuid %>"

schema :adjustment do
Expand Down Expand Up @@ -86,6 +87,10 @@ defmodule Recurly.Adjustment do
def stream(account_code, options \\ []) do
Resource.stream(Adjustment, account_path(account_code), options)
end
# FIXME: How should this be handled?
# def stream(invoice_number, options \\ []) do
# Resource.stream(Adjustment, invoice_path(invoice_number), options)
# end

@doc """
Creates an adjustment from a changeset.
Expand Down Expand Up @@ -124,6 +129,10 @@ defmodule Recurly.Adjustment do
EEx.eval_string(@account_endpoint, account_code: account_code)
end

def invoice_path(invoice_number) do
EEx.eval_string(@account_endpoint, invoice_number: invoice_number)
end

@doc """
Generates the path to find an adjustment given the uuid.

Expand Down
1 change: 1 addition & 0 deletions lib/recurly/billing_info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ defmodule Recurly.BillingInfo do
field :routing_number, :string
field :state, :string
field :token_id, :string
field :updated_at, :date_time, read_only: true
field :vat_number, :string
field :verification_value, :string
field :year, :integer
Expand Down
3 changes: 2 additions & 1 deletion lib/recurly/coupon.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Recurly.Coupon do
for more details
"""
use Recurly.Resource
alias Recurly.{Resource,Coupon,Money}
alias Recurly.{Resource, Coupon, Money}

@endpoint "/coupons"

Expand All @@ -21,6 +21,7 @@ defmodule Recurly.Coupon do
field :discount_in_cents, Money
field :discount_percent, :integer
field :duration, :string
field :id, :integer
field :invoice_description, :string
field :max_redemptions, :integer
field :max_redemptions_per_account, :integer
Expand Down
5 changes: 4 additions & 1 deletion lib/recurly/invoice.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ defmodule Recurly.Invoice do
for more details
"""
use Recurly.Resource
alias Recurly.{Resource,Invoice,Account,Address,Adjustment,Transaction}
alias Recurly.{Resource, Invoice, Account, Address, Adjustment, Transaction}

@endpoint "/invoices"

schema :invoice do
field :account, Account
field :address, Address
field :attempt_next_collection_at, :date_time, read_only: true
field :closed_at, :date_time, read_only: true
field :collection_method, :string
field :created_at, :date_time, read_only: true
Expand All @@ -22,7 +23,9 @@ defmodule Recurly.Invoice do
field :line_items, Adjustment, list: true
field :net_terms, :integer
field :po_number, :string
field :recovery_reason, :string
field :state, :string
field :subtotal_after_discount_in_cents, :integer
field :subtotal_in_cents, :integer
field :tax_in_cents, :integer
field :tax_rate, :float
Expand Down
4 changes: 3 additions & 1 deletion lib/recurly/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Recurly.Subscription do
TODO implement postpone and reactivate
"""
use Recurly.Resource
alias Recurly.{Resource,Subscription,Account,SubscriptionAddOn,Plan,Invoice}
alias Recurly.{Resource, Subscription, Account, SubscriptionAddOn, Plan, Invoice}

@endpoint "/subscriptions"

Expand All @@ -18,6 +18,7 @@ defmodule Recurly.Subscription do
field :bulk, :boolean
field :canceled_at, :date_time, read_only: true
field :collection_method, :string
field :converted_at, :date_time, read_only: true
field :coupon_code, :string
field :customer_notes, :string
field :currency, :string
Expand All @@ -30,6 +31,7 @@ defmodule Recurly.Subscription do
field :plan_code, :string
field :po_number, :string
field :quantity, :integer
field :started_with_gift, :boolean
field :state, :string, read_only: true
field :subscription_add_ons, SubscriptionAddOn, list: true
field :starts_at, :date_time
Expand Down
8 changes: 7 additions & 1 deletion lib/recurly/transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ defmodule Recurly.Transaction do
for more details
"""
use Recurly.Resource
alias Recurly.{Resource,Transaction,TransactionDetails,Account,Invoice,Subscription}
alias Recurly.{Resource, Transaction, TransactionDetails, Account, Invoice, Subscription}

@endpoint "/transactions"

schema :transaction do
field :account, Account, read_only: true
field :action, :string
field :amount_in_cents, :integer
field :approval_code, :string
field :currency, :string
field :collected_at, :date_time, read_only: true
field :description, :string
field :details, TransactionDetails, read_only: true
field :gateway_type, :string
field :invoice, Invoice, read_only: true
field :ip_address, :string
field :message, :string
field :origin, :string
field :original_transaction, Transaction, read_only: true
field :payment_method, :string
field :recurring_type, :boolean
Expand Down
10 changes: 10 additions & 0 deletions test/recurly/account_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ defmodule Recurly.AccountTest do
email
entity_use_code
first_name
has_active_subscription
has_canceled_subscription
has_future_subscription
has_live_subscription
has_past_due_invoice
hosted_login_token
invoices
last_name
Expand All @@ -38,6 +43,11 @@ defmodule Recurly.AccountTest do
email
entity_use_code
first_name
has_active_subscription
has_canceled_subscription
has_future_subscription
has_live_subscription
has_past_due_invoice
last_name
tax_exempt
username
Expand Down
1 change: 1 addition & 0 deletions test/recurly/billing_info_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ defmodule Recurly.BillingInfoTest do
routing_number
state
token_id
updated_at
vat_number
verification_value
year
Expand Down
4 changes: 3 additions & 1 deletion test/recurly/coupon_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule Recurly.CouponTest do
discount_in_cents
discount_percent
duration
id
invoice_description
max_redemptions
max_redemptions_per_account
Expand All @@ -35,10 +36,11 @@ defmodule Recurly.CouponTest do
coupon_code
coupon_type
description
discount_type
discount_in_cents
discount_percent
discount_type
duration
id
invoice_description
max_redemptions
max_redemptions_per_account
Expand Down
5 changes: 5 additions & 0 deletions test/recurly/invoice_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Recurly.InvoiceTest do
@readable_fields ~w(
account
address
attempt_next_collection_at
closed_at
collection_method
created_at
Expand All @@ -16,7 +17,9 @@ defmodule Recurly.InvoiceTest do
line_items
net_terms
po_number
recovery_reason
state
subtotal_after_discount_in_cents
subtotal_in_cents
tax_in_cents
tax_rate
Expand All @@ -41,7 +44,9 @@ defmodule Recurly.InvoiceTest do
line_items
net_terms
po_number
recovery_reason
state
subtotal_after_discount_in_cents
subtotal_in_cents
tax_in_cents
tax_rate
Expand Down
27 changes: 15 additions & 12 deletions test/recurly/subscription_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,28 @@ defmodule Recurly.SubscriptionTest do
@readable_fields ~w(
account
activated_at
canceled_at
currency
current_period_started_at
expires_at
bank_account_authorized_at
bulk
coupon_code
canceled_at
collection_method
converted_at
coupon_code
currency
current_period_started_at
customer_notes
expires_at
first_renewal_date
invoice
net_terms
plan
plan_code
po_number
quantity
revenue_schedule_type
started_with_gift
starts_at
state
subscription_add_ons
starts_at
tax_in_cents
tax_rate
tax_region
Expand All @@ -36,26 +39,27 @@ defmodule Recurly.SubscriptionTest do
updated_at
uuid
vat_reverse_charge_notes
revenue_schedule_type
)a

@writeable_fields ~w(
account
currency
current_period_started_at
bank_account_authorized_at
bulk
coupon_code
collection_method
coupon_code
currency
current_period_started_at
customer_notes
first_renewal_date
net_terms
plan
plan_code
po_number
quantity
subscription_add_ons
revenue_schedule_type
started_with_gift
starts_at
subscription_add_ons
tax_in_cents
tax_rate
tax_region
Expand All @@ -66,7 +70,6 @@ defmodule Recurly.SubscriptionTest do
unit_amount_in_cents
uuid
vat_reverse_charge_notes
revenue_schedule_type
)a

test "should maintain the list of writeable fields" do
Expand Down
11 changes: 11 additions & 0 deletions test/recurly/transaction_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ defmodule Recurly.TransactionTest do
account
action
amount_in_cents
approval_code
collected_at
currency
description
details
gateway_type
invoice
ip_address
message
origin
original_transaction
payment_method
recurring_type
Expand All @@ -28,8 +34,13 @@ defmodule Recurly.TransactionTest do
@writeable_fields ~w(
action
amount_in_cents
approval_code
currency
description
gateway_type
ip_address
message
origin
payment_method
recurring_type
reference
Expand Down