recurly 2.18.15 → 3.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +158 -110
- data/Rakefile +6 -0
- data/bin/bundle +105 -0
- data/bin/coderay +29 -0
- data/bin/console +14 -0
- data/bin/htmldiff +29 -0
- data/bin/ldiff +29 -0
- data/bin/pry +29 -0
- data/bin/rake +29 -0
- data/bin/rspec +29 -0
- data/bin/setup +8 -0
- data/bin/yard +29 -0
- data/bin/yardoc +29 -0
- data/bin/yri +29 -0
- data/lib/data/ca-certificates.crt +31 -0
- data/lib/recurly.rb +14 -145
- data/lib/recurly/client.rb +198 -0
- data/lib/recurly/client/operations.rb +935 -0
- data/lib/recurly/errors.rb +34 -0
- data/lib/recurly/errors/api_errors.rb +35 -0
- data/lib/recurly/errors/network_errors.rb +8 -0
- data/lib/recurly/pager.rb +119 -0
- data/lib/recurly/request.rb +30 -0
- data/lib/recurly/requests/account_acquisition_updatable.rb +22 -0
- data/lib/recurly/requests/account_create_only.rb +18 -0
- data/lib/recurly/requests/account_updatable.rb +50 -0
- data/lib/recurly/requests/add_on_create.rb +38 -0
- data/lib/recurly/requests/add_on_update.rb +38 -0
- data/lib/recurly/requests/address.rb +42 -0
- data/lib/recurly/requests/billing_info_create.rb +58 -0
- data/lib/recurly/requests/coupon_create_only.rb +66 -0
- data/lib/recurly/requests/coupon_updatable.rb +30 -0
- data/lib/recurly/requests/create_account.rb +62 -0
- data/lib/recurly/requests/create_coupon.rb +90 -0
- data/lib/recurly/requests/invoice_create.rb +42 -0
- data/lib/recurly/requests/invoice_refund.rb +30 -0
- data/lib/recurly/requests/line_item_create.rb +46 -0
- data/lib/recurly/requests/plan_create.rb +66 -0
- data/lib/recurly/requests/plan_update.rb +70 -0
- data/lib/recurly/requests/shipping_address_create.rb +58 -0
- data/lib/recurly/requests/shipping_address_update.rb +62 -0
- data/lib/recurly/requests/subscription_add_on_create.rb +22 -0
- data/lib/recurly/requests/subscription_change_create.rb +42 -0
- data/lib/recurly/requests/subscription_create.rb +86 -0
- data/lib/recurly/requests/subscription_update.rb +42 -0
- data/lib/recurly/requests/update_coupon.rb +30 -0
- data/lib/recurly/resource.rb +16 -1103
- data/lib/recurly/resources/account.rb +86 -0
- data/lib/recurly/resources/account_acquisition.rb +42 -0
- data/lib/recurly/resources/account_balance.rb +22 -0
- data/lib/recurly/resources/account_note.rb +30 -0
- data/lib/recurly/resources/add_on.rb +62 -0
- data/lib/recurly/resources/address.rb +42 -0
- data/lib/recurly/resources/billing_info.rb +62 -0
- data/lib/recurly/resources/coupon.rb +110 -0
- data/lib/recurly/resources/coupon_discount.rb +22 -0
- data/lib/recurly/resources/coupon_redemption.rb +46 -0
- data/lib/recurly/resources/credit_payment.rb +62 -0
- data/lib/recurly/resources/error.rb +18 -0
- data/lib/recurly/resources/error_may_have_transaction.rb +22 -0
- data/lib/recurly/resources/invoice.rb +138 -0
- data/lib/recurly/resources/invoice_collection.rb +18 -0
- data/lib/recurly/resources/line_item.rb +166 -0
- data/lib/recurly/resources/plan.rb +86 -0
- data/lib/recurly/resources/settings.rb +18 -0
- data/lib/recurly/resources/shipping_address.rb +74 -0
- data/lib/recurly/resources/site.rb +46 -0
- data/lib/recurly/resources/subscription.rb +134 -0
- data/lib/recurly/resources/subscription_add_on.rb +42 -0
- data/lib/recurly/resources/subscription_change.rb +54 -0
- data/lib/recurly/resources/tax_info.rb +18 -0
- data/lib/recurly/resources/transaction.rb +146 -0
- data/lib/recurly/resources/unique_coupon_code.rb +38 -0
- data/lib/recurly/resources/user.rb +38 -0
- data/lib/recurly/schema.rb +114 -0
- data/lib/recurly/schema/json_deserializer.rb +53 -0
- data/lib/recurly/schema/json_parser.rb +71 -0
- data/lib/recurly/schema/request_caster.rb +66 -0
- data/lib/recurly/schema/schema_factory.rb +50 -0
- data/lib/recurly/schema/schema_validator.rb +125 -0
- data/lib/recurly/version.rb +1 -10
- data/recurly.gemspec +32 -0
- data/scripts/build +4 -0
- data/scripts/clean +6 -0
- data/scripts/test +3 -0
- metadata +121 -245
- data/lib/recurly/account.rb +0 -190
- data/lib/recurly/account_acquisition.rb +0 -27
- data/lib/recurly/account_balance.rb +0 -21
- data/lib/recurly/add_on.rb +0 -44
- data/lib/recurly/address.rb +0 -25
- data/lib/recurly/adjustment.rb +0 -81
- data/lib/recurly/api.rb +0 -110
- data/lib/recurly/api/errors.rb +0 -208
- data/lib/recurly/api/net_http_adapter.rb +0 -111
- data/lib/recurly/billing_info.rb +0 -109
- data/lib/recurly/coupon.rb +0 -134
- data/lib/recurly/credit_payment.rb +0 -32
- data/lib/recurly/custom_field.rb +0 -15
- data/lib/recurly/delivery.rb +0 -19
- data/lib/recurly/error.rb +0 -13
- data/lib/recurly/gift_card.rb +0 -85
- data/lib/recurly/helper.rb +0 -51
- data/lib/recurly/invoice.rb +0 -297
- data/lib/recurly/invoice_collection.rb +0 -14
- data/lib/recurly/item.rb +0 -36
- data/lib/recurly/js.rb +0 -14
- data/lib/recurly/juris_detail.rb +0 -15
- data/lib/recurly/measured_unit.rb +0 -16
- data/lib/recurly/money.rb +0 -120
- data/lib/recurly/note.rb +0 -14
- data/lib/recurly/plan.rb +0 -43
- data/lib/recurly/purchase.rb +0 -234
- data/lib/recurly/redemption.rb +0 -46
- data/lib/recurly/resource/association.rb +0 -16
- data/lib/recurly/resource/errors.rb +0 -20
- data/lib/recurly/resource/pager.rb +0 -313
- data/lib/recurly/shipping_address.rb +0 -26
- data/lib/recurly/shipping_fee.rb +0 -17
- data/lib/recurly/shipping_method.rb +0 -13
- data/lib/recurly/subscription.rb +0 -365
- data/lib/recurly/subscription/add_ons.rb +0 -82
- data/lib/recurly/subscription_add_on.rb +0 -58
- data/lib/recurly/tax_detail.rb +0 -16
- data/lib/recurly/tax_type.rb +0 -13
- data/lib/recurly/tier.rb +0 -18
- data/lib/recurly/transaction.rb +0 -131
- data/lib/recurly/transaction/errors.rb +0 -115
- data/lib/recurly/usage.rb +0 -28
- data/lib/recurly/verify.rb +0 -12
- data/lib/recurly/webhook.rb +0 -111
- data/lib/recurly/webhook/account_notification.rb +0 -13
- data/lib/recurly/webhook/billing_info_update_failed_notification.rb +0 -6
- data/lib/recurly/webhook/billing_info_updated_notification.rb +0 -6
- data/lib/recurly/webhook/canceled_account_notification.rb +0 -6
- data/lib/recurly/webhook/canceled_gift_card_notification.rb +0 -6
- data/lib/recurly/webhook/canceled_subscription_notification.rb +0 -6
- data/lib/recurly/webhook/closed_credit_invoice_notification.rb +0 -6
- data/lib/recurly/webhook/closed_invoice_notification.rb +0 -6
- data/lib/recurly/webhook/credit_payment_notification.rb +0 -12
- data/lib/recurly/webhook/deactivated_item_notification.rb +0 -6
- data/lib/recurly/webhook/deleted_shipping_address_notification.rb +0 -6
- data/lib/recurly/webhook/dunning_notification.rb +0 -14
- data/lib/recurly/webhook/expired_subscription_notification.rb +0 -6
- data/lib/recurly/webhook/failed_charge_invoice_notification.rb +0 -6
- data/lib/recurly/webhook/failed_payment_notification.rb +0 -6
- data/lib/recurly/webhook/fraud_info_updated_notification.rb +0 -6
- data/lib/recurly/webhook/gift_card_notification.rb +0 -8
- data/lib/recurly/webhook/invoice_notification.rb +0 -12
- data/lib/recurly/webhook/item_notification.rb +0 -7
- data/lib/recurly/webhook/low_balance_gift_card_notification.rb +0 -6
- data/lib/recurly/webhook/new_account_notification.rb +0 -6
- data/lib/recurly/webhook/new_charge_invoice_notification.rb +0 -6
- data/lib/recurly/webhook/new_credit_invoice_notification.rb +0 -6
- data/lib/recurly/webhook/new_credit_payment_notification.rb +0 -6
- data/lib/recurly/webhook/new_dunning_event_notification.rb +0 -6
- data/lib/recurly/webhook/new_invoice_notification.rb +0 -6
- data/lib/recurly/webhook/new_item_notification.rb +0 -6
- data/lib/recurly/webhook/new_shipping_address_notification.rb +0 -6
- data/lib/recurly/webhook/new_subscription_notification.rb +0 -6
- data/lib/recurly/webhook/new_usage_notification.rb +0 -8
- data/lib/recurly/webhook/notification.rb +0 -18
- data/lib/recurly/webhook/paid_charge_invoice_notification.rb +0 -6
- data/lib/recurly/webhook/past_due_charge_invoice_notification.rb +0 -6
- data/lib/recurly/webhook/past_due_invoice_notification.rb +0 -6
- data/lib/recurly/webhook/paused_subscription_renewal_notification.rb +0 -6
- data/lib/recurly/webhook/processing_charge_invoice_notification.rb +0 -6
- data/lib/recurly/webhook/processing_credit_invoice_notification.rb +0 -6
- data/lib/recurly/webhook/processing_invoice_notification.rb +0 -6
- data/lib/recurly/webhook/processing_payment_notification.rb +0 -6
- data/lib/recurly/webhook/purchased_gift_card_notification.rb +0 -7
- data/lib/recurly/webhook/reactivated_account_notification.rb +0 -6
- data/lib/recurly/webhook/reactivated_item_notification.rb +0 -6
- data/lib/recurly/webhook/redeemed_gift_card_notification.rb +0 -7
- data/lib/recurly/webhook/regenerated_gift_card_notification.rb +0 -6
- data/lib/recurly/webhook/renewed_subscription_notification.rb +0 -6
- data/lib/recurly/webhook/reopened_charge_invoice_notification.rb +0 -6
- data/lib/recurly/webhook/reopened_credit_invoice_notification.rb +0 -6
- data/lib/recurly/webhook/scheduled_payment_notification.rb +0 -6
- data/lib/recurly/webhook/scheduled_subscription_pause_notification.rb +0 -6
- data/lib/recurly/webhook/subscription_notification.rb +0 -12
- data/lib/recurly/webhook/subscription_pause_canceled_notification.rb +0 -6
- data/lib/recurly/webhook/subscription_pause_modified_notification.rb +0 -6
- data/lib/recurly/webhook/subscription_paused_notification.rb +0 -6
- data/lib/recurly/webhook/subscription_resumed_notification.rb +0 -6
- data/lib/recurly/webhook/successful_payment_notification.rb +0 -6
- data/lib/recurly/webhook/successful_refund_notification.rb +0 -6
- data/lib/recurly/webhook/transaction_authorized_notification.rb +0 -6
- data/lib/recurly/webhook/transaction_notification.rb +0 -12
- data/lib/recurly/webhook/transaction_status_updated_notification.rb +0 -6
- data/lib/recurly/webhook/updated_account_notification.rb +0 -6
- data/lib/recurly/webhook/updated_balance_gift_card_notification.rb +0 -7
- data/lib/recurly/webhook/updated_gift_card_notification.rb +0 -6
- data/lib/recurly/webhook/updated_invoice_notification.rb +0 -6
- data/lib/recurly/webhook/updated_item_notification.rb +0 -6
- data/lib/recurly/webhook/updated_shipping_address_notification.rb +0 -6
- data/lib/recurly/webhook/updated_subscription_notification.rb +0 -6
- data/lib/recurly/webhook/void_payment_notification.rb +0 -6
- data/lib/recurly/webhook/voided_credit_invoice_notification.rb +0 -6
- data/lib/recurly/webhook/voided_credit_payment_notification.rb +0 -6
- data/lib/recurly/xml.rb +0 -122
- data/lib/recurly/xml/nokogiri.rb +0 -60
- data/lib/recurly/xml/rexml.rb +0 -52
data/lib/recurly/account.rb
DELETED
@@ -1,190 +0,0 @@
|
|
1
|
-
module Recurly
|
2
|
-
# Accounts are core to managing your customers inside of Recurly.
|
3
|
-
# The account object stores the entire Recurly history of your customer and acts as the entry point
|
4
|
-
# for working with a customer's billing information, subscription data, transactions, invoices and more.
|
5
|
-
#
|
6
|
-
# Recurly Documentation: https://dev.recurly.com/docs/account-object
|
7
|
-
class Account < Resource
|
8
|
-
# @macro [attach] scope
|
9
|
-
# @scope class
|
10
|
-
# @return [Pager<Account>] A pager that yields +$1+ accounts.
|
11
|
-
scope :active, state: :active
|
12
|
-
scope :closed, state: :closed
|
13
|
-
scope :subscriber, state: :subscriber
|
14
|
-
scope :non_subscriber, state: :non_subscriber
|
15
|
-
scope :past_due, state: :past_due
|
16
|
-
|
17
|
-
# @return [Pager<Adjustment>, []] A pager that yields Adjustments for persisted
|
18
|
-
has_many :adjustments
|
19
|
-
|
20
|
-
# @return [Pager<Invoice>, []] A pager that yields Invoices for persisted
|
21
|
-
has_many :invoices
|
22
|
-
|
23
|
-
# @return [Pager<Subscription>, []] A pager that yields Subscriptions for persisted
|
24
|
-
has_many :subscriptions
|
25
|
-
|
26
|
-
# @return [Pager<Transaction>, []] A pager that yields Transaction for persisted
|
27
|
-
has_many :transactions
|
28
|
-
|
29
|
-
# @return [Pager<Note>, []] A pager that yields Note for persisted
|
30
|
-
has_many :notes
|
31
|
-
|
32
|
-
# @return [Pager<Redemption>, []] A pager that yields Redemptions for persisted
|
33
|
-
has_many :redemptions
|
34
|
-
|
35
|
-
# @return [Pager<ShippingAddress>, [ShippingAddress], []] A pager that yields ShippingAddresses;
|
36
|
-
# or a list of ShippingAddresses if set by the programmer
|
37
|
-
has_many :shipping_addresses, readonly: false
|
38
|
-
|
39
|
-
# @return [BillingInfo, nil]
|
40
|
-
has_one :billing_info, readonly: false
|
41
|
-
|
42
|
-
# @return [AccountBalance, nil]
|
43
|
-
has_one :account_balance, readonly: true
|
44
|
-
|
45
|
-
# @return [Account, nil]
|
46
|
-
belongs_to :parent_account, class_name: :Account
|
47
|
-
|
48
|
-
# @return [Pager<Account>, []] A pager that yields Account for persisted
|
49
|
-
has_many :child_accounts, class_name: :Account
|
50
|
-
|
51
|
-
# @return [Pager<CreditPayment>, []]
|
52
|
-
has_many :credit_payments, class_name: :CreditPayment, readonly: true
|
53
|
-
|
54
|
-
# @return [[CustomField], []]
|
55
|
-
has_many :custom_fields, class_name: :CustomField, readonly: false
|
56
|
-
|
57
|
-
# @return [AccountAcquisition, nil]
|
58
|
-
has_one :account_acquisition, class_name: :AccountAcquisition, readonly: false
|
59
|
-
|
60
|
-
# Get's the first redemption given a coupon code
|
61
|
-
# @deprecated Use #{redemptions} instead
|
62
|
-
# @param coupon_code [String] The coupon code for the redemption
|
63
|
-
def redemption(coupon_code)
|
64
|
-
redemptions.detect { |r| r.coupon_code == coupon_code }
|
65
|
-
end
|
66
|
-
|
67
|
-
define_attribute_methods %w(
|
68
|
-
account_code
|
69
|
-
parent_account_code
|
70
|
-
state
|
71
|
-
username
|
72
|
-
email
|
73
|
-
cc_emails
|
74
|
-
first_name
|
75
|
-
last_name
|
76
|
-
company_name
|
77
|
-
company
|
78
|
-
phone
|
79
|
-
accept_language
|
80
|
-
hosted_login_token
|
81
|
-
vat_number
|
82
|
-
address
|
83
|
-
tax_exempt
|
84
|
-
exemption_certificate
|
85
|
-
entity_use_code
|
86
|
-
created_at
|
87
|
-
updated_at
|
88
|
-
closed_at
|
89
|
-
vat_location_valid
|
90
|
-
has_live_subscription
|
91
|
-
has_active_subscription
|
92
|
-
has_future_subscription
|
93
|
-
has_canceled_subscription
|
94
|
-
has_past_due_invoice
|
95
|
-
has_paused_subscription
|
96
|
-
preferred_locale
|
97
|
-
transaction_type
|
98
|
-
)
|
99
|
-
alias to_param account_code
|
100
|
-
|
101
|
-
def company_name
|
102
|
-
super || company
|
103
|
-
end
|
104
|
-
|
105
|
-
# Creates an invoice from the pending charges on the account.
|
106
|
-
# Raises an error if it fails.
|
107
|
-
#
|
108
|
-
# @return [InvoiceCollection] A newly-created invoice.
|
109
|
-
# @raise [Invalid] Raised if the account cannot be invoiced.
|
110
|
-
def invoice!(attrs={})
|
111
|
-
InvoiceCollection.from_response API.post(invoices.uri, attrs.empty? ? nil : Invoice.to_xml(attrs))
|
112
|
-
rescue Recurly::API::UnprocessableEntity => e
|
113
|
-
raise Invalid, e.message
|
114
|
-
end
|
115
|
-
|
116
|
-
# Builds an invoice from the pending charges on the account but does not persist the invoice.
|
117
|
-
# Raises an error if it fails.
|
118
|
-
#
|
119
|
-
# @return [InvoiceCollection] The newly-built invoice that has not been persisted.
|
120
|
-
# @raise [Invalid] Raised if the account cannot be invoiced.
|
121
|
-
def build_invoice
|
122
|
-
InvoiceCollection.from_response API.post("#{invoices.uri}/preview")
|
123
|
-
rescue Recurly::API::UnprocessableEntity => e
|
124
|
-
raise Invalid, e.message
|
125
|
-
end
|
126
|
-
|
127
|
-
# Reopen an account.
|
128
|
-
#
|
129
|
-
# @return [true, false] +true+ when successful, +false+ when unable to
|
130
|
-
# (e.g., the account is already open), and may raise an exception if the
|
131
|
-
# attempt fails.
|
132
|
-
def reopen
|
133
|
-
return false unless link? :reopen
|
134
|
-
reload follow_link :reopen
|
135
|
-
true
|
136
|
-
end
|
137
|
-
|
138
|
-
# Verify a cvv code for the account's billing info.
|
139
|
-
#
|
140
|
-
# @example
|
141
|
-
# acct = Recurly::Account.find('benjamin-du-monde')
|
142
|
-
# begin
|
143
|
-
# # If successful, returned billing_info will contain
|
144
|
-
# # updated billing info details.
|
145
|
-
# billing_info = acct.verify_cvv!("504")
|
146
|
-
# rescue Recurly::API::BadRequest => e
|
147
|
-
# e.message # => "This credit card has too many cvv check attempts."
|
148
|
-
# rescue Recurly::Transaction::Error => e
|
149
|
-
# # this will be the errors coming back from gateway
|
150
|
-
# e.transaction_error_code # => "fraud_security_code"
|
151
|
-
# e.gateway_error_code # => "fraud"
|
152
|
-
# rescue Recurly::Resource::Invalid => e
|
153
|
-
# e.message # => "verification_value must be three digits"
|
154
|
-
# end
|
155
|
-
#
|
156
|
-
# @param [String] verification_value The CVV code to check
|
157
|
-
# @return [BillingInfo] The updated billing info
|
158
|
-
# @raise [Recurly::Transaction::Error] A Transaction Error will be raised if the gateway declines
|
159
|
-
# the cvv code.
|
160
|
-
# @raise [API::BadRequest] A BadRequest error will be raised if you attempt to check too many times
|
161
|
-
# and are locked out.
|
162
|
-
# @raise [Resource::Invalid] An Invalid Error will be raised if you send an invalid request (such as
|
163
|
-
# a value that is not a propert verification number).
|
164
|
-
def verify_cvv!(verification_value)
|
165
|
-
bi = BillingInfo.new(verification_value: verification_value)
|
166
|
-
bi.uri = "#{path}/billing_info/verify_cvv"
|
167
|
-
bi.save!
|
168
|
-
bi
|
169
|
-
end
|
170
|
-
|
171
|
-
def changed_attributes
|
172
|
-
attrs = super
|
173
|
-
if address.respond_to?(:changed?) && address.changed?
|
174
|
-
attrs['address'] = address
|
175
|
-
end
|
176
|
-
if custom_fields.any?(&:changed?)
|
177
|
-
attrs['custom_fields'] = custom_fields.select(&:changed?)
|
178
|
-
end
|
179
|
-
attrs
|
180
|
-
end
|
181
|
-
|
182
|
-
private
|
183
|
-
|
184
|
-
def xml_keys
|
185
|
-
keys = super
|
186
|
-
keys << 'account_code' if account_code? && !account_code_changed?
|
187
|
-
keys.sort
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Recurly
|
2
|
-
# Recurly Documentation: https://dev.recurly.com/docs/create-account-acquisition
|
3
|
-
class AccountAcquisition < Resource
|
4
|
-
# @return [Account]
|
5
|
-
belongs_to :account
|
6
|
-
|
7
|
-
define_attribute_methods %w(
|
8
|
-
cost_in_cents
|
9
|
-
currency
|
10
|
-
channel
|
11
|
-
subchannel
|
12
|
-
campaign
|
13
|
-
)
|
14
|
-
|
15
|
-
def self.member_name
|
16
|
-
"acquisition"
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.xml_root_key
|
20
|
-
"account_acquisition"
|
21
|
-
end
|
22
|
-
|
23
|
-
# Acquisitions are only writeable and readable through {Account} instances.
|
24
|
-
embedded!
|
25
|
-
private_class_method :find
|
26
|
-
end
|
27
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Recurly
|
2
|
-
# The AccountBalance object contains some information about the account's balance.
|
3
|
-
# It exists to give us parity with the v1 API which used to include this information with
|
4
|
-
# the {Account}. You can get an account's balance by calling {Account#account_balance} on an account instance.
|
5
|
-
#
|
6
|
-
# Recurly Documentation: https://dev.recurly.com/docs/lookup-account-balance
|
7
|
-
class AccountBalance < Resource
|
8
|
-
# @return [Account, nil]
|
9
|
-
has_one :account, readonly: true
|
10
|
-
|
11
|
-
define_attribute_methods %w(
|
12
|
-
past_due
|
13
|
-
balance_in_cents
|
14
|
-
)
|
15
|
-
|
16
|
-
# This object does not represent a model on the server side
|
17
|
-
# so we do not need to expose these methods.
|
18
|
-
protected(*%w(save save!))
|
19
|
-
private_class_method(*%w(all find_each first paginate scoped where create! create))
|
20
|
-
end
|
21
|
-
end
|
data/lib/recurly/add_on.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
module Recurly
|
2
|
-
class AddOn < Resource
|
3
|
-
# @return [Plan]
|
4
|
-
belongs_to :plan
|
5
|
-
# @return [[Tier], []]
|
6
|
-
has_many :tiers, class_name: :Tier, readonly: false
|
7
|
-
|
8
|
-
define_attribute_methods %w(
|
9
|
-
add_on_code
|
10
|
-
item_code
|
11
|
-
name
|
12
|
-
accounting_code
|
13
|
-
default_quantity
|
14
|
-
unit_amount_in_cents
|
15
|
-
display_quantity_on_hosted_page
|
16
|
-
tax_code
|
17
|
-
add_on_type
|
18
|
-
measured_unit_id
|
19
|
-
optional
|
20
|
-
usage_type
|
21
|
-
usage_percentage
|
22
|
-
revenue_schedule_type
|
23
|
-
created_at
|
24
|
-
updated_at
|
25
|
-
tier_type
|
26
|
-
avalara_service_type
|
27
|
-
avalara_transaction_type
|
28
|
-
)
|
29
|
-
alias to_param add_on_code
|
30
|
-
alias quantity default_quantity
|
31
|
-
|
32
|
-
def changed_attributes
|
33
|
-
attrs = super
|
34
|
-
if tiers.any?(&:changed?)
|
35
|
-
attrs['tiers'] = tiers.select(&:changed?)
|
36
|
-
end
|
37
|
-
attrs
|
38
|
-
end
|
39
|
-
|
40
|
-
# Add-ons are only writeable and readable through {Plan} instances.
|
41
|
-
embedded!
|
42
|
-
private_class_method :find
|
43
|
-
end
|
44
|
-
end
|
data/lib/recurly/address.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
module Recurly
|
2
|
-
class Address < Resource
|
3
|
-
define_attribute_methods %w(
|
4
|
-
first_name
|
5
|
-
last_name
|
6
|
-
name_on_account
|
7
|
-
company
|
8
|
-
address1
|
9
|
-
address2
|
10
|
-
city
|
11
|
-
state
|
12
|
-
zip
|
13
|
-
country
|
14
|
-
phone
|
15
|
-
geo_code
|
16
|
-
)
|
17
|
-
|
18
|
-
# This ensures every attribute is rendered
|
19
|
-
# when updating. The Address object does not
|
20
|
-
# accept partial updates on the server
|
21
|
-
def xml_keys
|
22
|
-
attributes.keys
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/lib/recurly/adjustment.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
module Recurly
|
2
|
-
# The history of your customer's Recurly account can be tracked through adjustments, made up of credits and charges.
|
3
|
-
#
|
4
|
-
# Recurly Documentation: https://dev.recurly.com/docs/adjustment-object
|
5
|
-
class Adjustment < Resource
|
6
|
-
# @macro [attach] scope
|
7
|
-
# @scope class
|
8
|
-
# @return [Pager<Adjustment>] a pager that yields +$1+.
|
9
|
-
scope :charges, type: 'charge'
|
10
|
-
scope :credits, type: 'credit'
|
11
|
-
scope :pending, state: 'pending'
|
12
|
-
scope :invoiced, state: 'invoiced'
|
13
|
-
|
14
|
-
# @return [Account, nil]
|
15
|
-
belongs_to :account
|
16
|
-
# @return [Invoice, nil]
|
17
|
-
belongs_to :invoice
|
18
|
-
# @return [Subscription, nil]
|
19
|
-
belongs_to :subscription
|
20
|
-
|
21
|
-
# @return [Pager<Adjustment>, []]
|
22
|
-
has_many :credit_adjustments, class_name: :Adjustment, readonly: true
|
23
|
-
|
24
|
-
# @return [ShippingAddress, nil]
|
25
|
-
has_one :shipping_address, class_name: :ShippingAddress, readonly: false
|
26
|
-
|
27
|
-
define_attribute_methods %w(
|
28
|
-
uuid
|
29
|
-
state
|
30
|
-
description
|
31
|
-
accounting_code
|
32
|
-
origin
|
33
|
-
unit_amount_in_cents
|
34
|
-
quantity
|
35
|
-
discount_in_cents
|
36
|
-
total_in_cents
|
37
|
-
currency
|
38
|
-
product_code
|
39
|
-
item_code
|
40
|
-
external_sku
|
41
|
-
start_date
|
42
|
-
end_date
|
43
|
-
created_at
|
44
|
-
updated_at
|
45
|
-
quantity_remaining
|
46
|
-
revenue_schedule_type
|
47
|
-
tax_in_cents
|
48
|
-
tax_type
|
49
|
-
tax_region
|
50
|
-
tax_rate
|
51
|
-
tax_exempt
|
52
|
-
tax_code
|
53
|
-
tax_details
|
54
|
-
tax_types
|
55
|
-
proration_rate
|
56
|
-
credit_reason_code
|
57
|
-
original_adjustment_uuid
|
58
|
-
shipping_address_id
|
59
|
-
surcharge_in_cents
|
60
|
-
avalara_transaction_type
|
61
|
-
avalara_service_type
|
62
|
-
)
|
63
|
-
alias to_param uuid
|
64
|
-
|
65
|
-
# @return ["charge", "credit", nil] The type of adjustment.
|
66
|
-
attr_reader :type
|
67
|
-
|
68
|
-
# Adjustments should be built through {Account} instances.
|
69
|
-
#
|
70
|
-
# @return [Adjustment] A new adjustment.
|
71
|
-
# @example
|
72
|
-
# account.adjustments.new attributes
|
73
|
-
# @see Resource#initialize
|
74
|
-
def initialize(attributes = {})
|
75
|
-
super({ :currency => Recurly.default_currency }.merge attributes)
|
76
|
-
end
|
77
|
-
|
78
|
-
# Adjustments are only writeable through an {Account} instance.
|
79
|
-
embedded! true
|
80
|
-
end
|
81
|
-
end
|
data/lib/recurly/api.rb
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
module Recurly
|
2
|
-
# The API class handles all requests to the Recurly API. While most of its
|
3
|
-
# functionality is leveraged by the Resource class, it can be used directly,
|
4
|
-
# as well.
|
5
|
-
#
|
6
|
-
# Requests are made with methods named after the four main HTTP verbs
|
7
|
-
# recognized by the Recurly API.
|
8
|
-
#
|
9
|
-
# @example
|
10
|
-
# Recurly::API.get 'accounts' # => #<Net::HTTPOK ...>
|
11
|
-
# Recurly::API.post 'accounts', xml_body # => #<Net::HTTPCreated ...>
|
12
|
-
# Recurly::API.put 'accounts/1', xml_body # => #<Net::HTTPOK ...>
|
13
|
-
# Recurly::API.delete 'accounts/1' # => #<Net::HTTPNoContent ...>
|
14
|
-
class API
|
15
|
-
require 'recurly/api/errors'
|
16
|
-
require 'openssl'
|
17
|
-
|
18
|
-
@@base_uri = "https://api.recurly.com/v2/"
|
19
|
-
@@valid_domains = [".recurly.com"]
|
20
|
-
|
21
|
-
RECURLY_API_VERSION = '2.29'
|
22
|
-
|
23
|
-
FORMATS = Helper.hash_with_indifferent_read_access(
|
24
|
-
'pdf' => 'application/pdf',
|
25
|
-
'xml' => 'application/xml'
|
26
|
-
)
|
27
|
-
|
28
|
-
class << self
|
29
|
-
# Additional HTTP headers sent with each API call
|
30
|
-
# @return [Hash{String => String}]
|
31
|
-
def headers
|
32
|
-
@headers ||= { 'Accept' => accept, 'User-Agent' => user_agent, 'X-Api-Version' => RECURLY_API_VERSION }
|
33
|
-
end
|
34
|
-
|
35
|
-
# @return [String, nil] Accept-Language header value
|
36
|
-
def accept_language
|
37
|
-
headers['Accept-Language']
|
38
|
-
end
|
39
|
-
|
40
|
-
# @param [String] language Accept-Language header value
|
41
|
-
def accept_language=(language)
|
42
|
-
headers['Accept-Language'] = language
|
43
|
-
end
|
44
|
-
|
45
|
-
# @return [Net::HTTPOK, Net::HTTPResponse]
|
46
|
-
# @raise [ResponseError] With a non-2xx status code.
|
47
|
-
def head uri, params = {}, options = {}
|
48
|
-
request :head, uri, { :params => params || {} }.merge(options)
|
49
|
-
end
|
50
|
-
|
51
|
-
# @return [Net::HTTPOK, Net::HTTPResponse]
|
52
|
-
# @raise [ResponseError] With a non-2xx status code.
|
53
|
-
def get uri, params = {}, options = {}
|
54
|
-
request :get, uri, { :params => params || {} }.merge(options)
|
55
|
-
end
|
56
|
-
|
57
|
-
# @return [Net::HTTPCreated, Net::HTTPResponse]
|
58
|
-
# @raise [ResponseError] With a non-2xx status code.
|
59
|
-
def post uri, body = nil, options = {}
|
60
|
-
request :post, uri, { :body => body.to_s }.merge(options)
|
61
|
-
end
|
62
|
-
|
63
|
-
# @return [Net::HTTPOK, Net::HTTPResponse]
|
64
|
-
# @raise [ResponseError] With a non-2xx status code.
|
65
|
-
def put uri, body = nil, options = {}
|
66
|
-
request :put, uri, { :body => body.to_s }.merge(options)
|
67
|
-
end
|
68
|
-
|
69
|
-
# @return [Net::HTTPNoContent, Net::HTTPResponse]
|
70
|
-
# @raise [ResponseError] With a non-2xx status code.
|
71
|
-
def delete uri, body = nil, options = {}
|
72
|
-
request :delete, uri, options
|
73
|
-
end
|
74
|
-
|
75
|
-
# @return [URI::Generic]
|
76
|
-
def base_uri
|
77
|
-
URI.parse @@base_uri.sub('api', Recurly.subdomain)
|
78
|
-
end
|
79
|
-
|
80
|
-
def validate_uri!(uri)
|
81
|
-
domain = @@valid_domains.detect { |d| uri.host.end_with?(d) }
|
82
|
-
unless domain
|
83
|
-
raise ArgumentError, "URI #{uri} is invalid. You may only make requests to a Recurly domain."
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# @return [String]
|
88
|
-
def user_agent
|
89
|
-
agent_string = "Recurly/#{Version}; #{RUBY_DESCRIPTION};"
|
90
|
-
|
91
|
-
if OpenSSL.const_defined?(:OPENSSL_VERSION)
|
92
|
-
"#{agent_string} #{OpenSSL::OPENSSL_VERSION}"
|
93
|
-
elsif OpenSSL.const_defined?(:OPENSSL_LIBRARY_VERSION)
|
94
|
-
"#{agent_string} #{OpenSSL::OPENSSL_LIBRARY_VERSION}"
|
95
|
-
else
|
96
|
-
agent_string
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
private
|
101
|
-
|
102
|
-
def accept
|
103
|
-
FORMATS['xml']
|
104
|
-
end
|
105
|
-
alias content_type accept
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
require 'recurly/api/net_http_adapter'
|