recurly 2.4.5 → 2.4.6

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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9129e582c2f343662f42f02a850f10a2c8171aa9
4
- data.tar.gz: a038472ed54dbe931172bbb2a8cc562492e0cf1f
3
+ metadata.gz: 972f95d54db4267cb3a761d4ca74c95e79eb8df3
4
+ data.tar.gz: 61d5fb37a103b1551f19562b1e71600b1ceffa00
5
5
  SHA512:
6
- metadata.gz: 44df4de6338077fcf0e7773fd75d41d927722f46a38415475d47217e2e0be79dfdeb27b67d401a6fb88a3a395861eb5db7d22fc25000004ac589c1352f7f85d4
7
- data.tar.gz: e57590648287086676edf3e884ceeaca561483b65451b3da9eca251d9efddad85c0aae814724abf710ad3b8cf0a84dcad970780f3c626cc54e0589734b7b5d0b
6
+ metadata.gz: 65cf967a326482f1c394289957c670119480797e5864aad3d149c1e2cb305437738dd3f3e3849c61e7d349029dd0bdf9002e2420d6a20646f1d395f4d7c6a098
7
+ data.tar.gz: c94dc16a2010ed26dc803e7bf6f0f7f29c1608f23c0e9f842d192d50a1f1dda3aba44638e347a4dd19ef6a20392b526a2d036cfebd6ce015714c85419f6ac4b9
data/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  <https://github.com/recurly/recurly-client-ruby>
4
4
 
5
- [Recurly](http://recurly.com/)'s Ruby client library is an interface to its
6
- [REST API](http://docs.recurly.com/api/basics).
5
+ [Recurly](https://recurly.com/)'s Ruby client library is an interface to its
6
+ [REST API](https://dev.recurly.com/docs/getting-started).
7
7
 
8
8
 
9
9
  ## Installation
@@ -12,7 +12,7 @@ Recurly is packaged as a Ruby gem. We recommend you install it with
12
12
  [Bundler](http://gembundler.com/) by adding the following line to your Gemfile:
13
13
 
14
14
  ``` ruby
15
- gem 'recurly', '~> 2.4.5'
15
+ gem 'recurly', '~> 2.4.6'
16
16
  ```
17
17
 
18
18
  Recurly will automatically use [Nokogiri](http://nokogiri.org/) (for a nice
@@ -38,7 +38,7 @@ Recurly.api_key = ENV['RECURLY_API_KEY']
38
38
  Configure the client library with
39
39
  [your API credentials](https://app.recurly.com/go/developer/api_access).
40
40
 
41
- * `RECURLY_SUBDOMAIN` should contain subdomain for your recurly account.
41
+ * `RECURLY_SUBDOMAIN` should contain subdomain for your recurly account.
42
42
  * `RECURLY_API_KEY` is your "Private API Key" which can be found under "API Credentials" on the `api_access` admin page.
43
43
 
44
44
  The default currency is USD. To override with a different code:
@@ -47,13 +47,15 @@ The default currency is USD. To override with a different code:
47
47
  Recurly.default_currency = 'EUR' # Assign nil to disable the default entirely.
48
48
  ```
49
49
 
50
- If you are using [Recurly.js](https://js.recurly.com) you can store "Public API Key" (which can be found under "API Credentials" on the `api_access` admin page):
50
+ If you are using [Recurly.js](https://js.recurly.com) you can store "Public API Key" (which can be found
51
+ under "API Credentials" on the `api_access` admin page):
51
52
 
52
53
  ``` ruby
53
54
  Recurly.js.public_key = ENV['RECURLY_PUBLIC_API_KEY']
54
55
  ```
55
56
 
56
- Then, in your Rails project you can create `recurly_service.js.erb` file and [configure](https://docs.recurly.com/js/#configure) recurly.js with public key this way:
57
+ Then, in your Rails project you can create `recurly_service.js.erb` file and
58
+ [configure](https://docs.recurly.com/js/#configure) recurly.js with public key this way:
57
59
 
58
60
  ``` js
59
61
  recurly.configure({ publicKey: '<%= Recurly.js.public_key %>'});
@@ -70,7 +72,8 @@ Recurly::API.net_http = {
70
72
  ```
71
73
 
72
74
  ## Multi-Threaded Configuration
73
- If you are using the client in a multi-threaded environment and require a different configuration per thread you can use the following within the thread's context:
75
+ If you are using the client in a multi-threaded environment and require a different configuration per
76
+ thread you can use the following within the thread's context:
74
77
 
75
78
  ``` ruby
76
79
  Recurly.config({
@@ -81,14 +84,15 @@ Recurly.config({
81
84
  })
82
85
  ```
83
86
 
84
- Any configuration items you do not include in the above config call will be defaulted to the standard configuration items. For example if you do not define default_currency then
85
- Recurly.default_currency will be used.
87
+ Any configuration items you do not include in the above config call will be defaulted to the standard
88
+ configuration items. For example if you do not define default_currency then Recurly.default_currency
89
+ will be used.
86
90
 
87
91
 
88
92
  ## Usage
89
93
 
90
94
  Instructions and examples are available on
91
- [Recurly's documentation site](http://docs.recurly.com/api/basics).
95
+ [Recurly's documentation site](https://dev.recurly.com/docs/getting-started).
92
96
 
93
97
  Recurly's gem API is available
94
98
  [here](http://rubydoc.info/gems/recurly/frames/Recurly).
@@ -107,9 +111,8 @@ Recurly's gem API is available
107
111
 
108
112
  Developing for the Recurly gem is easy with [Bundler](http://gembundler.com/).
109
113
 
110
- Fork and clone the repository, `cd` into the directory, and, with a Ruby of
111
- your choice (1.9.3 or greater), set up your
112
- environment.
114
+ Fork and clone the repository, `cd` into the directory, and, with a Ruby of your choice
115
+ (1.9.3 or greater), set up your environment.
113
116
 
114
117
  If you don't have Bundler installed, install it with the following command:
115
118
 
@@ -138,8 +141,7 @@ $ XML=nokogiri bundle exec rake
138
141
  If you plan on submitting a patch, please write tests for it (we use
139
142
  [MiniTest::Spec](http://bfts.rubyforge.org/minitest/MiniTest/Expectations.html)).
140
143
 
141
- If everything looks good, submit a pull request on GitHub and we'll bring in
142
- your changes.
144
+ If everything looks good, submit a pull request on GitHub and we'll bring in your changes.
143
145
 
144
146
  ## License
145
147
 
@@ -20,8 +20,11 @@ module Recurly
20
20
  # @return [BillingInfo, nil]
21
21
  has_one :billing_info, :readonly => false
22
22
 
23
- # @return [Redemption, nil]
24
- has_one :redemption
23
+ has_many :redemptions
24
+
25
+ def redemption
26
+ redemptions.first
27
+ end
25
28
 
26
29
  define_attribute_methods %w(
27
30
  account_code
@@ -38,6 +41,7 @@ module Recurly
38
41
  tax_exempt
39
42
  entity_use_code
40
43
  created_at
44
+ closed_at
41
45
  vat_location_valid
42
46
  )
43
47
  alias to_param account_code
data/lib/recurly/api.rb CHANGED
@@ -16,6 +16,8 @@ module Recurly
16
16
 
17
17
  @@base_uri = "https://api.recurly.com/v2/"
18
18
 
19
+ RECURLY_API_VERSION = '2.1'
20
+
19
21
  FORMATS = Helper.hash_with_indifferent_read_access(
20
22
  'pdf' => 'application/pdf',
21
23
  'xml' => 'application/xml'
@@ -25,7 +27,7 @@ module Recurly
25
27
  # Additional HTTP headers sent with each API call
26
28
  # @return [Hash{String => String}]
27
29
  def headers
28
- @headers ||= { 'Accept' => accept, 'User-Agent' => user_agent }
30
+ @headers ||= { 'Accept' => accept, 'User-Agent' => user_agent, 'X-Api-Version' => RECURLY_API_VERSION }
29
31
  end
30
32
 
31
33
  # @return [String, nil] Accept-Language header value
@@ -24,11 +24,14 @@ module Recurly
24
24
  temporal_unit
25
25
  temporal_amount
26
26
  max_redemptions
27
+ max_redemptions_per_account
27
28
  applies_to_all_plans
28
29
  created_at
29
30
  plan_codes
30
31
  description
31
32
  invoice_description
33
+ applies_to_non_plan_charges
34
+ redemption_resource
32
35
  )
33
36
  alias to_param coupon_code
34
37
 
@@ -46,14 +49,16 @@ module Recurly
46
49
  #
47
50
  # @return [true]
48
51
  # @param account_or_code [Account, String]
52
+ # @param currency [String]
53
+ # @param opts [Hash]
49
54
  # @example
50
55
  # coupon = Coupon.find coupon_code
51
- # coupon.redeem account_code
56
+ # coupon.redeem account_code, 'USD', subscription_uuid: 'ab3b1dbabc3195'
52
57
  #
53
58
  # coupon = Coupon.find coupon_code
54
59
  # account = Account.find account_code
55
60
  # coupon.redeem account
56
- def redeem account_or_code, currency = nil
61
+ def redeem account_or_code, currency = nil, extra_opts={}
57
62
  return false unless link? :redeem
58
63
 
59
64
  account_code = if account_or_code.is_a? Account
@@ -62,11 +67,15 @@ module Recurly
62
67
  account_or_code
63
68
  end
64
69
 
70
+ redemption_options = {
71
+ :account_code => account_code,
72
+ :currency => currency || Recurly.default_currency
73
+ }.merge(extra_opts)
74
+
75
+ redemption = redemptions.new(redemption_options)
76
+
65
77
  Redemption.from_response follow_link(:redeem,
66
- :body => (redemption = redemptions.new(
67
- :account_code => account_code,
68
- :currency => currency || Recurly.default_currency
69
- )).to_xml
78
+ :body => redemption.to_xml
70
79
  )
71
80
  rescue API::UnprocessableEntity => e
72
81
  redemption.apply_errors e
@@ -78,5 +87,9 @@ module Recurly
78
87
  raise Invalid.new(self) unless redemption.persisted?
79
88
  redemption
80
89
  end
90
+
91
+ def unlimited_redemptions_per_account?
92
+ !max_redemptions_per_account
93
+ end
81
94
  end
82
95
  end
@@ -21,7 +21,11 @@ module Recurly
21
21
  belongs_to :original_invoice, class_name: 'Invoice'
22
22
 
23
23
  # @return [Redemption]
24
- has_one :redemption
24
+ has_many :redemptions
25
+
26
+ def redemption
27
+ redemptions.first
28
+ end
25
29
 
26
30
  def invoice_number_with_prefix
27
31
  "#{invoice_number_prefix}#{invoice_number}"
@@ -78,7 +82,7 @@ module Recurly
78
82
  reload follow_link :mark_failed
79
83
  true
80
84
  end
81
-
85
+
82
86
  def enter_offline_payment(attrs={})
83
87
  Transaction.from_response API.post("#{uri}/transactions", attrs.empty? ? nil : Transaction.to_xml(attrs))
84
88
  rescue Recurly::API::UnprocessableEntity => e
data/lib/recurly/plan.rb CHANGED
@@ -24,6 +24,7 @@ module Recurly
24
24
  trial_interval_unit
25
25
  total_billing_cycles
26
26
  accounting_code
27
+ setup_fee_accounting_code
27
28
  tax_exempt
28
29
  tax_code
29
30
  created_at
@@ -12,14 +12,26 @@ module Recurly
12
12
  # @return [Account]
13
13
  belongs_to :account, :readonly => false
14
14
 
15
+ # @return [Subscription]
16
+ belongs_to :subscription
17
+
18
+ # @return [Invoice]
19
+ belongs_to :invoice
20
+
15
21
  define_attribute_methods %w(
22
+ uuid
16
23
  single_use
17
24
  total_discounted_in_cents
18
25
  currency
19
26
  state
27
+ subscription_uuid
20
28
  created_at
21
29
  )
22
30
 
31
+ def destroy_uri
32
+ uri + "s/#{uuid}"
33
+ end
34
+
23
35
  def save
24
36
  return false if persisted?
25
37
  copy_from coupon.redeem account, currency
@@ -283,8 +283,8 @@ module Recurly
283
283
  # @see Pager#find_each
284
284
  # @example
285
285
  # Recurly::Account.find_each { |a| p a }
286
- def find_each per_page = 50
287
- paginate(:per_page => per_page).find_each(&Proc.new)
286
+ def find_each per_page = 50, &block
287
+ paginate(:per_page => per_page).find_each(&block)
288
288
  end
289
289
 
290
290
  # @return [Integer] The total record count of the resource in question.
@@ -909,12 +909,16 @@ module Recurly
909
909
  # race_condition.destroy # raises Recurly::Resource::NotFound
910
910
  def destroy
911
911
  return false unless persisted?
912
- @response = API.delete uri
912
+ @response = API.delete destroy_uri
913
913
  @destroyed = true
914
914
  rescue API::NotFound => e
915
915
  raise NotFound, e.description
916
916
  end
917
917
 
918
+ def destroy_uri
919
+ uri
920
+ end
921
+
918
922
  def signable_attributes
919
923
  Hash[xml_keys.map { |key| [key, self[key]] }]
920
924
  end
@@ -25,6 +25,9 @@ module Recurly
25
25
  # @return [Invoice]
26
26
  has_one :invoice
27
27
 
28
+ # @return [Redemption]
29
+ has_many :redemptions
30
+
28
31
  define_attribute_methods %w(
29
32
  uuid
30
33
  state
@@ -42,6 +45,7 @@ module Recurly
42
45
  pending_subscription
43
46
  subscription_add_ons
44
47
  coupon_code
48
+ coupon_codes
45
49
  total_billing_cycles
46
50
  remaining_billing_cycles
47
51
  net_terms
@@ -103,6 +107,16 @@ module Recurly
103
107
  attributes[:coupon] = coupon
104
108
  end
105
109
 
110
+ # Assign Coupon resources (rather than coupon codes).
111
+ #
112
+ # @param coupons [[Coupons]]
113
+ def coupons= coupons
114
+ self.coupon_codes = coupons.map do |coupon|
115
+ coupon.coupon_code if coupon.respond_to? :coupon_code
116
+ end.compact
117
+ attributes[:coupons] = coupons
118
+ end
119
+
106
120
  # @return [AddOns]
107
121
  def subscription_add_ons
108
122
  self[:subscription_add_ons] ||= AddOns.new self, super
@@ -44,6 +44,10 @@ module Recurly
44
44
  xml.text '/errors/transaction_error/error_code'
45
45
  end
46
46
 
47
+ def gateway_error_code
48
+ xml.text '/errors/transaction_error/gateway_error_code'
49
+ end
50
+
47
51
  private
48
52
 
49
53
  def update_transaction transaction
@@ -2,7 +2,7 @@ module Recurly
2
2
  module Version
3
3
  MAJOR = 2
4
4
  MINOR = 4
5
- PATCH = 5
5
+ PATCH = 6
6
6
  PRE = nil
7
7
 
8
8
  VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join('.').freeze
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recurly
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.5
4
+ version: 2.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Recurly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-31 00:00:00.000000000 Z
11
+ date: 2015-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake