recurly 0.4.16 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of recurly might be problematic. Click here for more details.
- data/README.markdown +118 -0
- data/bin/recurly +78 -0
- data/lib/rails/generators/recurly/config_generator.rb +16 -0
- data/lib/rails/recurly.rb +13 -0
- data/lib/recurly.rb +64 -139
- data/lib/recurly/account.rb +52 -111
- data/lib/recurly/add_on.rb +20 -0
- data/lib/recurly/adjustment.rb +51 -0
- data/lib/recurly/api.rb +73 -0
- data/lib/recurly/api/errors.rb +205 -0
- data/lib/recurly/api/net_http.rb +77 -0
- data/lib/recurly/billing_info.rb +45 -42
- data/lib/recurly/coupon.rb +63 -8
- data/lib/recurly/helper.rb +39 -0
- data/lib/recurly/invoice.rb +38 -16
- data/lib/recurly/js.rb +113 -0
- data/lib/recurly/money.rb +105 -0
- data/lib/recurly/plan.rb +26 -15
- data/lib/recurly/redemption.rb +34 -0
- data/lib/recurly/resource.rb +925 -0
- data/lib/recurly/resource/pager.rb +210 -0
- data/lib/recurly/subscription.rb +90 -67
- data/lib/recurly/subscription/add_ons.rb +73 -0
- data/lib/recurly/transaction.rb +65 -53
- data/lib/recurly/transaction/errors.rb +98 -0
- data/lib/recurly/version.rb +16 -2
- data/lib/recurly/xml.rb +85 -0
- data/lib/recurly/xml/nokogiri.rb +49 -0
- data/lib/recurly/xml/rexml.rb +50 -0
- metadata +76 -165
- data/LICENSE +0 -21
- data/README.md +0 -104
- data/init.rb +0 -1
- data/lib/patches/rails2/active_resource/base.rb +0 -35
- data/lib/patches/rails2/active_resource/connection.rb +0 -10
- data/lib/patches/rails3/active_model/serializers/xml.rb +0 -28
- data/lib/patches/rails3/active_resource/connection.rb +0 -10
- data/lib/recurly/account_base.rb +0 -35
- data/lib/recurly/base.rb +0 -195
- data/lib/recurly/charge.rb +0 -39
- data/lib/recurly/config_parser.rb +0 -31
- data/lib/recurly/credit.rb +0 -28
- data/lib/recurly/exceptions.rb +0 -32
- data/lib/recurly/formats/xml_with_errors.rb +0 -132
- data/lib/recurly/formats/xml_with_pagination.rb +0 -47
- data/lib/recurly/rails2/compatibility.rb +0 -8
- data/lib/recurly/rails3/railtie.rb +0 -21
- data/lib/recurly/rails3/recurly.rake +0 -28
- data/lib/recurly/transparent.rb +0 -148
- data/lib/recurly/verification.rb +0 -83
- data/spec/config/recurly.yml +0 -6
- data/spec/config/test1.yml +0 -4
- data/spec/config/test2.yml +0 -7
- data/spec/integration/account_spec.rb +0 -286
- data/spec/integration/add_on_spec.rb +0 -84
- data/spec/integration/billing_info_spec.rb +0 -148
- data/spec/integration/charge_spec.rb +0 -176
- data/spec/integration/coupon_spec.rb +0 -49
- data/spec/integration/credit_spec.rb +0 -106
- data/spec/integration/invoice_spec.rb +0 -86
- data/spec/integration/plan_spec.rb +0 -87
- data/spec/integration/subscription_spec.rb +0 -221
- data/spec/integration/transaction_spec.rb +0 -154
- data/spec/integration/transparent_spec.rb +0 -99
- data/spec/spec_helper.rb +0 -34
- data/spec/support/factory.rb +0 -211
- data/spec/support/vcr.rb +0 -11
- data/spec/unit/account_spec.rb +0 -19
- data/spec/unit/billing_info_spec.rb +0 -39
- data/spec/unit/charge_spec.rb +0 -20
- data/spec/unit/config_spec.rb +0 -42
- data/spec/unit/coupon_spec.rb +0 -13
- data/spec/unit/credit_spec.rb +0 -20
- data/spec/unit/plan_spec.rb +0 -18
- data/spec/unit/subscription_spec.rb +0 -25
- data/spec/unit/transaction_spec.rb +0 -32
- data/spec/unit/transparent_spec.rb +0 -152
- data/spec/unit/verification_spec.rb +0 -82
data/README.markdown
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# Recurly
|
2
|
+
|
3
|
+
<http://github.com/recurly/recurly-ruby-client>
|
4
|
+
|
5
|
+
[Recurly](http://recurly.com/)'s Ruby client library is an interface to its
|
6
|
+
[REST API](http://docs.recurly.com/api/basics).
|
7
|
+
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Recurly is packaged as a Ruby gem. We recommend you install it with
|
12
|
+
[Bundler](http://gembundler.com/) by adding the following line to your Gemfile:
|
13
|
+
|
14
|
+
``` ruby
|
15
|
+
gem 'recurly', '~> 2.0.0'
|
16
|
+
```
|
17
|
+
|
18
|
+
Recurly will automatically use [Nokogiri](http://nokogiri.org/) (for a nice
|
19
|
+
speed boost) if it's available and loaded in your app's environment.
|
20
|
+
|
21
|
+
|
22
|
+
## Configuration
|
23
|
+
|
24
|
+
If you're using Rails, you can generate an initializer with the following
|
25
|
+
command:
|
26
|
+
|
27
|
+
``` bash
|
28
|
+
$ rails g recurly:config
|
29
|
+
```
|
30
|
+
|
31
|
+
If you're not using Rails, use the following template:
|
32
|
+
|
33
|
+
``` ruby
|
34
|
+
Recurly.api_key = ENV['RECURLY_API_KEY']
|
35
|
+
Recurly.js.private_key = ENV['RECURLY_JS_PRIVATE_KEY']
|
36
|
+
```
|
37
|
+
|
38
|
+
Configure the client library with the credentials you find at
|
39
|
+
`https://{subdomain}.recurly.com/developer/api_access` (replace `{subdomain}`
|
40
|
+
with your Recurly subdomain).
|
41
|
+
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
Instructions and examples are available on
|
46
|
+
[Recurly's documentation site](http://docs.recurly.com/api/basics).
|
47
|
+
|
48
|
+
Recurly's gem API is available [here](http://rdoc.info/gems/recurly).
|
49
|
+
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Developing for the Recurly gem is easy with [Bundler](http://gembundler.com/).
|
54
|
+
|
55
|
+
Fork and clone the repository, `cd` into the directory, and, with a Ruby of
|
56
|
+
your choice (1.8.7 is supported, but we suggest 1.9.2 or greater), set up your
|
57
|
+
environment.
|
58
|
+
|
59
|
+
If you don't have Bundler installed, install it with the following command:
|
60
|
+
|
61
|
+
``` bash
|
62
|
+
$ [sudo] gem install bundler
|
63
|
+
```
|
64
|
+
|
65
|
+
And bundle:
|
66
|
+
|
67
|
+
``` bash
|
68
|
+
$ bundle --path=vendor/bundle
|
69
|
+
```
|
70
|
+
|
71
|
+
You should now be able to run the test suite with Rake:
|
72
|
+
|
73
|
+
``` bash
|
74
|
+
$ bundle exec rake
|
75
|
+
```
|
76
|
+
|
77
|
+
To run the suite using Nokogiri:
|
78
|
+
|
79
|
+
``` bash
|
80
|
+
$ XML=nokogiri bundle exec rake
|
81
|
+
```
|
82
|
+
|
83
|
+
Or, if [Guard](https://github.com/guard/guard) is more your speed:
|
84
|
+
|
85
|
+
``` bash
|
86
|
+
$ bundle exec guard
|
87
|
+
```
|
88
|
+
|
89
|
+
If you plan on submitting a patch, please write tests for it (we use
|
90
|
+
[MiniTest::Spec](http://bfts.rubyforge.org/minitest/MiniTest/Expectations.html)).
|
91
|
+
|
92
|
+
If everything looks good, submit a pull request on GitHub and we'll bring in
|
93
|
+
your changes.
|
94
|
+
|
95
|
+
|
96
|
+
## License
|
97
|
+
|
98
|
+
(The MIT License.)
|
99
|
+
|
100
|
+
© 2011 Recurly Inc.
|
101
|
+
|
102
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
103
|
+
of this software and associated documentation files (the "Software"), to deal
|
104
|
+
in the Software without restriction, including without limitation the rights
|
105
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
106
|
+
copies of the Software, and to permit persons to whom the Software is
|
107
|
+
furnished to do so, subject to the following conditions:
|
108
|
+
|
109
|
+
The above copyright notice and this permission notice shall be included in all
|
110
|
+
copies or substantial portions of the Software.
|
111
|
+
|
112
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
113
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
114
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
115
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
116
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
117
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
118
|
+
SOFTWARE.
|
data/bin/recurly
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
|
4
|
+
module CLI
|
5
|
+
def version
|
6
|
+
require 'recurly/version'
|
7
|
+
"Recurly v#{Recurly::Version::VERSION}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def clear
|
11
|
+
print `clear`
|
12
|
+
end
|
13
|
+
end
|
14
|
+
include CLI
|
15
|
+
|
16
|
+
require 'optparse'
|
17
|
+
options = {}
|
18
|
+
OptionParser.new do |opts|
|
19
|
+
opts.banner = 'Usage: recurly [options] -- [irb options]'
|
20
|
+
|
21
|
+
opts.on '-k', '--api-key [api key]', 'Your API key' do |api_key|
|
22
|
+
options[:api_key] = api_key
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on '-v', '--verbose', 'Show full request/response log' do |verbose|
|
26
|
+
options[:verbose] = verbose
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on(
|
30
|
+
'-e', '--exec [code]', 'Execute a line of code before the session'
|
31
|
+
) do |line|
|
32
|
+
options[:exec] = line
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.separator nil
|
36
|
+
|
37
|
+
opts.on '-h', '--help', 'Display this screen' do
|
38
|
+
puts opts
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
|
42
|
+
opts.on '--version', 'The current version' do
|
43
|
+
puts version
|
44
|
+
exit
|
45
|
+
end
|
46
|
+
end.parse!
|
47
|
+
|
48
|
+
require 'recurly'
|
49
|
+
Recurly.api_key = options[:api_key] || ENV['RECURLY_API_KEY']
|
50
|
+
include Recurly
|
51
|
+
|
52
|
+
require 'logger'
|
53
|
+
Recurly.logger = Logger.new(
|
54
|
+
STDOUT, options[:verbose] ? Logger::DEBUG : Logger::INFO
|
55
|
+
)
|
56
|
+
|
57
|
+
require 'irb'
|
58
|
+
require 'irb/completion'
|
59
|
+
|
60
|
+
class << IRB
|
61
|
+
alias old_setup setup
|
62
|
+
def setup ap_path
|
63
|
+
old_setup ap_path
|
64
|
+
conf[:PROMPT][:RECURLY] = {
|
65
|
+
:PROMPT_N => 'recurly> ',
|
66
|
+
:PROMPT_I => 'recurly> ',
|
67
|
+
:PROMPT_S => nil,
|
68
|
+
:PROMPT_C => ' ?> ',
|
69
|
+
:RETURN => " => %s\n"
|
70
|
+
}
|
71
|
+
conf[:PROMPT_MODE] = :RECURLY
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
puts version
|
76
|
+
eval options[:exec] if options[:exec]
|
77
|
+
IRB.start $0
|
78
|
+
exit!
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Recurly
|
2
|
+
class ConfigGenerator < Rails::Generators::Base
|
3
|
+
desc "Creates a configuration file at config/initializers/recurly.rb"
|
4
|
+
|
5
|
+
# Creates a configuration file at <tt>config/initializers/recurly.rb</tt>
|
6
|
+
# when running <tt>rails g recurly:config</tt>.
|
7
|
+
def create_recurly_file
|
8
|
+
create_file 'config/initializers/recurly.rb', <<EOF
|
9
|
+
Recurly.api_key = ENV['RECURLY_API_KEY']
|
10
|
+
Recurly.js.private_key = ENV['RECURLY_JS_PRIVATE_KEY']
|
11
|
+
|
12
|
+
# Recurly.default_currency = 'USD'
|
13
|
+
EOF
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Recurly
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer :recurly_set_logger do
|
4
|
+
Recurly.logger = Rails.logger
|
5
|
+
end
|
6
|
+
|
7
|
+
initializer :recurly_set_accept_language do
|
8
|
+
ActionController::Base.prepend_before_filter do
|
9
|
+
Recurly::API.accept_language = request.env['HTTP_ACCEPT_LANGUAGE']
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/recurly.rb
CHANGED
@@ -1,154 +1,79 @@
|
|
1
|
-
|
2
|
-
require 'active_support/deprecation'
|
3
|
-
require 'cgi'
|
4
|
-
require 'openssl'
|
5
|
-
require 'addressable/uri'
|
6
|
-
|
7
|
-
# load ActiveResource patches
|
8
|
-
if ::ActiveResource::VERSION::MAJOR == 3
|
9
|
-
if ::ActiveResource::VERSION::MINOR == 0 &&
|
10
|
-
::ActiveResource::VERSION::TINY < 20
|
11
|
-
require 'patches/rails3/active_model/serializers/xml'
|
12
|
-
end
|
13
|
-
require 'patches/rails3/active_resource/connection'
|
14
|
-
elsif ::ActiveResource::VERSION::MAJOR == 2
|
15
|
-
require 'patches/rails2/active_resource/connection'
|
16
|
-
end
|
17
|
-
|
18
|
-
if ::ActiveResource::VERSION::MAJOR == 2 ||
|
19
|
-
(::ActiveResource::VERSION::MAJOR == 3 &&
|
20
|
-
::ActiveResource::VERSION::MINOR == 0)
|
21
|
-
require 'patches/rails2/active_resource/base'
|
22
|
-
end
|
23
|
-
|
24
|
-
require 'recurly/version'
|
25
|
-
require 'recurly/exceptions'
|
26
|
-
require 'recurly/formats/xml_with_pagination'
|
27
|
-
require 'recurly/formats/xml_with_errors'
|
28
|
-
require 'recurly/config_parser'
|
29
|
-
require 'recurly/rails3/railtie' if defined?(::Rails::Railtie)
|
30
|
-
require 'recurly/base'
|
31
|
-
|
32
|
-
# load rails2 fixes
|
33
|
-
if ::ActiveResource::VERSION::MAJOR == 2
|
34
|
-
require 'recurly/rails2/compatibility'
|
35
|
-
end
|
36
|
-
|
37
|
-
# configuration
|
1
|
+
# Recurly is a Ruby client for Recurly's REST API.
|
38
2
|
module Recurly
|
39
|
-
|
40
|
-
autoload :
|
41
|
-
autoload :
|
42
|
-
autoload :
|
43
|
-
autoload :
|
44
|
-
autoload :Coupon,
|
45
|
-
autoload :
|
46
|
-
autoload :Invoice,
|
47
|
-
autoload :
|
48
|
-
autoload :
|
49
|
-
autoload :
|
50
|
-
autoload :
|
51
|
-
autoload :
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
def settings_path=(new_settings_path)
|
63
|
-
@settings_path = new_settings_path
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def configured?
|
68
|
-
Base.user && Base.site
|
3
|
+
autoload :Account, 'recurly/account'
|
4
|
+
autoload :AddOn, 'recurly/add_on'
|
5
|
+
autoload :Adjustment, 'recurly/adjustment'
|
6
|
+
autoload :API, 'recurly/api'
|
7
|
+
autoload :BillingInfo, 'recurly/billing_info'
|
8
|
+
autoload :Coupon, 'recurly/coupon'
|
9
|
+
autoload :Helper, 'recurly/helper'
|
10
|
+
autoload :Invoice, 'recurly/invoice'
|
11
|
+
autoload :JS, 'recurly/js'
|
12
|
+
autoload :Money, 'recurly/money'
|
13
|
+
autoload :Plan, 'recurly/plan'
|
14
|
+
autoload :Redemption, 'recurly/redemption'
|
15
|
+
autoload :Resource, 'recurly/resource'
|
16
|
+
autoload :Subscription, 'recurly/subscription'
|
17
|
+
autoload :Transaction, 'recurly/transaction'
|
18
|
+
autoload :Version, 'recurly/version'
|
19
|
+
autoload :XML, 'recurly/xml'
|
20
|
+
|
21
|
+
# The exception class from which all Recurly exceptions inherit.
|
22
|
+
class Error < StandardError
|
23
|
+
def set_message message
|
24
|
+
@message = message
|
69
25
|
end
|
70
26
|
|
71
|
-
#
|
72
|
-
def
|
73
|
-
|
74
|
-
end
|
75
|
-
def password=(password)
|
76
|
-
self.api_key = password
|
27
|
+
# @return [String]
|
28
|
+
def to_s
|
29
|
+
defined? @message and @message or super
|
77
30
|
end
|
31
|
+
end
|
78
32
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
83
|
-
def username=(_)
|
84
|
-
end
|
85
|
-
|
86
|
-
def configure
|
87
|
-
if block_given?
|
88
|
-
yield self
|
89
|
-
|
90
|
-
Base.user = api_key
|
91
|
-
Base.site = site_for_environment(environment)
|
92
|
-
|
93
|
-
return true
|
94
|
-
else
|
95
|
-
if ENV["RECURLY_CONFIG"]
|
96
|
-
Recurly.configure_from_json(ENV["RECURLY_CONFIG"])
|
97
|
-
else
|
98
|
-
Recurly.configure_from_yaml
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def site_for_environment(environment)
|
104
|
-
if environment == :development
|
105
|
-
"http://api.lvh.me:3000"
|
106
|
-
else
|
107
|
-
"https://api.recurly.com"
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
|
112
|
-
# allows configuration from a yml file that contains the fields:
|
113
|
-
# api_key,site,private_key
|
114
|
-
def configure_from_yaml(path = nil)
|
115
|
-
configure do |c|
|
116
|
-
# parse configuration from yml
|
117
|
-
recurly_config = ConfigParser.parse(path)
|
118
|
-
|
119
|
-
if recurly_config.present?
|
120
|
-
|
121
|
-
# check for environment specific config
|
122
|
-
recurly_env = Rails.env if defined?(Rails) and Rails.respond_to?(:env)
|
123
|
-
recurly_env ||= ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
|
124
|
-
recurly_config = recurly_config[recurly_env] if recurly_config.has_key?(recurly_env)
|
33
|
+
# This exception is raised if Recurly has not been configured.
|
34
|
+
class ConfigurationError < Error
|
35
|
+
end
|
125
36
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
37
|
+
class << self
|
38
|
+
# @return [String] An API key.
|
39
|
+
# @raise [ConfigurationError] If not configured.
|
40
|
+
def api_key
|
41
|
+
defined? @api_key and @api_key or raise(
|
42
|
+
ConfigurationError, "Recurly.api_key not configured"
|
43
|
+
)
|
132
44
|
end
|
45
|
+
attr_writer :api_key
|
133
46
|
|
134
|
-
#
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
configure do |c|
|
139
|
-
c.api_key = config_data['api_key'] || config_data['password']
|
140
|
-
c.subdomain = config_data['subdomain']
|
141
|
-
c.private_key = config_data['private_key']
|
142
|
-
c.environment = config_data['environment']
|
143
|
-
end
|
47
|
+
# @return [String, nil] A default currency.
|
48
|
+
def default_currency
|
49
|
+
return @default_currency if defined? @default_currency
|
50
|
+
@default_currency = 'USD'
|
144
51
|
end
|
52
|
+
attr_writer :default_currency
|
145
53
|
|
146
|
-
|
147
|
-
|
54
|
+
# @return [JS] The Recurly.js module.
|
55
|
+
def js
|
56
|
+
JS
|
148
57
|
end
|
149
58
|
|
150
|
-
|
151
|
-
|
59
|
+
# Assigns a logger to log requests/responses and more.
|
60
|
+
#
|
61
|
+
# @return [Logger, nil]
|
62
|
+
# @example
|
63
|
+
# require 'logger'
|
64
|
+
# Recurly.logger = Logger.new STDOUT
|
65
|
+
# @example Rails applications automatically log to the Rails log:
|
66
|
+
# Recurly.logger = Rails.logger
|
67
|
+
# @example Turn off logging entirely:
|
68
|
+
# Recurly.logger = nil # Or Recurly.logger = Logger.new nil
|
69
|
+
attr_accessor :logger
|
70
|
+
|
71
|
+
# Convenience logging method includes a Logger#progname dynamically.
|
72
|
+
# @return [true, nil]
|
73
|
+
def log level, message
|
74
|
+
logger and logger.send(level, name) { message }
|
152
75
|
end
|
153
76
|
end
|
154
77
|
end
|
78
|
+
|
79
|
+
require 'rails/recurly' if defined? Rails::Railtie
|
data/lib/recurly/account.rb
CHANGED
@@ -1,114 +1,55 @@
|
|
1
1
|
module Recurly
|
2
|
-
class Account <
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
# Account.list(:all) #=> returns all accounts
|
54
|
-
# Account.list(:active) #=> returns active accounts
|
55
|
-
# Account.list(:pastdue) #=> returns pastdue accounts
|
56
|
-
# Account.list(:free) #=> returns the free accounts
|
57
|
-
# Account.list(:active, {:page => 3}) #=> returns the 3rd page of active accounts
|
58
|
-
#
|
59
|
-
def self.list(status = :all, params = {})
|
60
|
-
opts = {:params => params}
|
61
|
-
|
62
|
-
if status && status != :all
|
63
|
-
params[:show] = SHOW_PARAMS[status] || status
|
64
|
-
end
|
65
|
-
find(:all, opts)
|
66
|
-
end
|
67
|
-
|
68
|
-
def close_account
|
69
|
-
destroy
|
70
|
-
end
|
71
|
-
|
72
|
-
def charges(status = :all)
|
73
|
-
Charge.list(account_code, status)
|
2
|
+
class Account < Resource
|
3
|
+
# @macro [attach] scope
|
4
|
+
# @scope class
|
5
|
+
# @return [Pager<Account>] A pager that yields +$1+ accounts.
|
6
|
+
scope :active, :state => :active
|
7
|
+
scope :closed, :state => :closed
|
8
|
+
scope :subscriber, :state => :subscriber
|
9
|
+
scope :non_subscriber, :state => :non_subscriber
|
10
|
+
scope :past_due, :state => :past_due
|
11
|
+
|
12
|
+
# @macro [attach] has_many
|
13
|
+
# @return [Pager<Resource>, Array] A pager that yields $1 for persisted
|
14
|
+
# accounts; an empty array otherwise.
|
15
|
+
has_many :adjustments
|
16
|
+
has_many :invoices
|
17
|
+
has_many :subscriptions
|
18
|
+
has_many :transactions
|
19
|
+
|
20
|
+
# @return [BillingInfo, nil]
|
21
|
+
has_one :billing_info, :readonly => false
|
22
|
+
|
23
|
+
# @return [Redemption, nil]
|
24
|
+
has_one :redemption
|
25
|
+
|
26
|
+
define_attribute_methods %w(
|
27
|
+
account_code
|
28
|
+
state
|
29
|
+
username
|
30
|
+
email
|
31
|
+
first_name
|
32
|
+
last_name
|
33
|
+
company_name
|
34
|
+
accept_language
|
35
|
+
created_at
|
36
|
+
)
|
37
|
+
alias to_param account_code
|
38
|
+
|
39
|
+
# @return [Invoice] A newly-created invoice.
|
40
|
+
# @raise [Invalid] Raised if the account cannot be invoiced.
|
41
|
+
def invoice!
|
42
|
+
Invoice.from_response API.post(invoices.uri)
|
43
|
+
rescue Recurly::API::UnprocessableEntity => e
|
44
|
+
raise Invalid, e.message
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def xml_keys
|
50
|
+
keys = super
|
51
|
+
keys << 'account_code' if account_code? && !account_code_changed?
|
52
|
+
keys.sort
|
74
53
|
end
|
75
|
-
memoize :charges
|
76
|
-
|
77
|
-
def lookup_charge(id)
|
78
|
-
Charge.lookup(account_code, id)
|
79
|
-
end
|
80
|
-
|
81
|
-
def credits
|
82
|
-
Credit.list(account_code)
|
83
|
-
end
|
84
|
-
memoize :credits
|
85
|
-
|
86
|
-
def lookup_credit(id)
|
87
|
-
Credit.lookup(account_code, id)
|
88
|
-
end
|
89
|
-
|
90
|
-
def transactions(status)
|
91
|
-
Transaction.list_for_account(account_code, status)
|
92
|
-
end
|
93
|
-
memoize :transactions
|
94
|
-
|
95
|
-
def lookup_transaction(id)
|
96
|
-
Transaction.lookup(account_code, id)
|
97
|
-
end
|
98
|
-
|
99
|
-
def invoices
|
100
|
-
Invoice.list(account_code)
|
101
|
-
end
|
102
|
-
memoize :invoices
|
103
|
-
|
104
|
-
def lookup_invoice(id)
|
105
|
-
Invoice.lookup(account_code, id)
|
106
|
-
end
|
107
|
-
|
108
|
-
def coupon
|
109
|
-
Coupon.find(account_code)
|
110
|
-
end
|
111
|
-
memoize :coupon
|
112
|
-
|
113
54
|
end
|
114
|
-
end
|
55
|
+
end
|