recurly 2.18.24 → 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/client/operations.rb +935 -0
- data/lib/recurly/client.rb +198 -0
- data/lib/recurly/errors/api_errors.rb +35 -0
- data/lib/recurly/errors/network_errors.rb +8 -0
- data/lib/recurly/errors.rb +34 -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 -1112
- 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/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/schema.rb +114 -0
- data/lib/recurly/version.rb +1 -10
- data/lib/recurly.rb +14 -151
- data/recurly.gemspec +32 -0
- data/scripts/build +4 -0
- data/scripts/clean +6 -0
- data/scripts/test +3 -0
- metadata +129 -179
- data/lib/recurly/account.rb +0 -214
- data/lib/recurly/account_acquisition.rb +0 -27
- data/lib/recurly/account_balance.rb +0 -22
- data/lib/recurly/add_on.rb +0 -51
- data/lib/recurly/address.rb +0 -25
- data/lib/recurly/adjustment.rb +0 -84
- data/lib/recurly/api/errors.rb +0 -208
- data/lib/recurly/api/net_http_adapter.rb +0 -111
- data/lib/recurly/api.rb +0 -110
- data/lib/recurly/billing_info.rb +0 -114
- data/lib/recurly/coupon.rb +0 -136
- data/lib/recurly/credit_payment.rb +0 -32
- data/lib/recurly/currency_percentage_tier.rb +0 -17
- data/lib/recurly/custom_field.rb +0 -15
- data/lib/recurly/delivery.rb +0 -19
- data/lib/recurly/dunning_campaign.rb +0 -30
- data/lib/recurly/dunning_cycle.rb +0 -18
- 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 -305
- data/lib/recurly/invoice_collection.rb +0 -14
- data/lib/recurly/invoice_template.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/percentage_tier.rb +0 -17
- data/lib/recurly/plan.rb +0 -44
- data/lib/recurly/purchase.rb +0 -238
- 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/sub_add_on_percentage_tier.rb +0 -17
- data/lib/recurly/subscription/add_ons.rb +0 -82
- data/lib/recurly/subscription.rb +0 -367
- data/lib/recurly/subscription_add_on.rb +0 -63
- data/lib/recurly/tax_detail.rb +0 -18
- data/lib/recurly/tax_type.rb +0 -13
- data/lib/recurly/tier.rb +0 -18
- data/lib/recurly/transaction/errors.rb +0 -115
- data/lib/recurly/transaction.rb +0 -131
- data/lib/recurly/usage.rb +0 -28
- data/lib/recurly/verify.rb +0 -12
- 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/prerenewal_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/scheduled_subscription_update_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/webhook.rb +0 -113
- data/lib/recurly/xml/nokogiri.rb +0 -60
- data/lib/recurly/xml/rexml.rb +0 -52
- data/lib/recurly/xml.rb +0 -122
@@ -1,17 +0,0 @@
|
|
1
|
-
module Recurly
|
2
|
-
class SubAddOnPercentageTier < Resource
|
3
|
-
|
4
|
-
belongs_to :subscription_add_on
|
5
|
-
|
6
|
-
define_attribute_methods %w(
|
7
|
-
ending_amount_in_cents
|
8
|
-
usage_percentage
|
9
|
-
)
|
10
|
-
|
11
|
-
def xml_keys
|
12
|
-
attributes.keys
|
13
|
-
end
|
14
|
-
|
15
|
-
embedded! true
|
16
|
-
end
|
17
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
module Recurly
|
2
|
-
class Subscription < Resource
|
3
|
-
class AddOns
|
4
|
-
instance_methods.each do |method|
|
5
|
-
undef_method method if method !~ /^__|^(object_id|respond_to\?|send)$/
|
6
|
-
end
|
7
|
-
|
8
|
-
# @param subscription [Subscription]
|
9
|
-
# @param add_ons [Array, nil]
|
10
|
-
def initialize subscription, add_ons = []
|
11
|
-
@subscription, @add_ons = subscription, []
|
12
|
-
add_ons and add_ons.each { |a| self << a }
|
13
|
-
end
|
14
|
-
|
15
|
-
# @return [self]
|
16
|
-
# @param add_on [AddOn, String, Symbol, Hash] A {Plan} add-on,
|
17
|
-
# +add_on_code+, or hash with optional <tt>:quantity</tt> and
|
18
|
-
# <tt>:unit_amount_in_cents</tt> keys.
|
19
|
-
# @example
|
20
|
-
# pp subscription.add_ons << '1YEARWAR' << '1YEARWAR' << :BONUS
|
21
|
-
# [
|
22
|
-
# {:add_on_code => "1YEARWAR", :quantity => 2},
|
23
|
-
# {:add_on_code => "BONUS"}
|
24
|
-
# ]
|
25
|
-
def << add_on
|
26
|
-
add_on = SubscriptionAddOn.new(add_on, @subscription)
|
27
|
-
|
28
|
-
exist = @add_ons.find do |a|
|
29
|
-
source1 = a.add_on_source || "plan_add_on"
|
30
|
-
source2 = add_on.add_on_source || "plan_add_on"
|
31
|
-
a.add_on_code == add_on.add_on_code && source1 == source2
|
32
|
-
end
|
33
|
-
|
34
|
-
if exist
|
35
|
-
exist.quantity ||= 1
|
36
|
-
exist.quantity += add_on.quantity || 1
|
37
|
-
|
38
|
-
if add_on.unit_amount_in_cents
|
39
|
-
exist.unit_amount_in_cents = add_on.unit_amount_in_cents
|
40
|
-
end
|
41
|
-
else
|
42
|
-
@add_ons << add_on
|
43
|
-
end
|
44
|
-
|
45
|
-
self
|
46
|
-
end
|
47
|
-
|
48
|
-
def to_a
|
49
|
-
@add_ons.dup
|
50
|
-
end
|
51
|
-
|
52
|
-
def errors
|
53
|
-
@add_ons.map { |add_on| add_on.errors }
|
54
|
-
end
|
55
|
-
|
56
|
-
def to_xml options = {}
|
57
|
-
builder = options[:builder] || XML.new('<subscription_add_ons/>')
|
58
|
-
@add_ons.each do |add_on|
|
59
|
-
node = builder.add_element 'subscription_add_on'
|
60
|
-
add_on.attributes.each_pair do |k, v|
|
61
|
-
node.add_element k.to_s, v if v
|
62
|
-
end
|
63
|
-
end
|
64
|
-
builder.to_s
|
65
|
-
end
|
66
|
-
|
67
|
-
def respond_to? method_name, include_private = false
|
68
|
-
super || @add_ons.respond_to?(method_name, include_private)
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
def method_missing name, *args, &block
|
74
|
-
if @add_ons.respond_to? name
|
75
|
-
return @add_ons.send name, *args, &block
|
76
|
-
end
|
77
|
-
|
78
|
-
super
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
data/lib/recurly/subscription.rb
DELETED
@@ -1,367 +0,0 @@
|
|
1
|
-
module Recurly
|
2
|
-
class Subscription < Resource
|
3
|
-
require 'recurly/subscription/add_ons'
|
4
|
-
|
5
|
-
# @macro [attach] scope
|
6
|
-
# @scope class
|
7
|
-
# @return [Pager<Subscription>] A pager that yields +$1+ subscriptions.
|
8
|
-
scope :active, state: :active
|
9
|
-
scope :canceled, state: :canceled
|
10
|
-
scope :expired, state: :expired
|
11
|
-
scope :future, state: :future
|
12
|
-
# @return [Pager<Subscription>] A pager that yields subscriptions in
|
13
|
-
# trials.
|
14
|
-
scope :in_trial, state: :in_trial
|
15
|
-
# @return [Pager<Subscription>] A pager that yields active, canceled, and
|
16
|
-
# future subscriptions.
|
17
|
-
scope :live, state: :live
|
18
|
-
scope :past_due, state: :past_due
|
19
|
-
|
20
|
-
# @return [Pager<Redemption>, []]
|
21
|
-
has_many :redemptions
|
22
|
-
|
23
|
-
# @return [[CustomField], []]
|
24
|
-
has_many :custom_fields, class_name: :CustomField, readonly: false
|
25
|
-
|
26
|
-
# @return [Account]
|
27
|
-
belongs_to :account
|
28
|
-
|
29
|
-
# @return [Plan]
|
30
|
-
belongs_to :plan
|
31
|
-
|
32
|
-
# @return [Invoice, nil]
|
33
|
-
has_one :invoice
|
34
|
-
|
35
|
-
# @return [GiftCard, nil]
|
36
|
-
has_one :gift_card
|
37
|
-
|
38
|
-
# @return [ShippingAddress, nil]
|
39
|
-
has_one :shipping_address, class_name: :ShippingAddress, readonly: false
|
40
|
-
|
41
|
-
# @return [InvoiceCollection, nil]
|
42
|
-
has_one :invoice_collection, class_name: :InvoiceCollection, readonly: true
|
43
|
-
|
44
|
-
# @return [BillingInfo, nil]
|
45
|
-
has_one :billing_info, class_name: :BillingInfo, readonly: false
|
46
|
-
|
47
|
-
define_attribute_methods %w(
|
48
|
-
uuid
|
49
|
-
state
|
50
|
-
unit_amount_in_cents
|
51
|
-
cost_in_cents
|
52
|
-
currency
|
53
|
-
quantity
|
54
|
-
updated_at
|
55
|
-
activated_at
|
56
|
-
canceled_at
|
57
|
-
expires_at
|
58
|
-
current_period_started_at
|
59
|
-
current_period_ends_at
|
60
|
-
trial_started_at
|
61
|
-
trial_ends_at
|
62
|
-
pending_subscription
|
63
|
-
subscription_add_ons
|
64
|
-
coupon_code
|
65
|
-
coupon_codes
|
66
|
-
total_billing_cycles
|
67
|
-
remaining_billing_cycles
|
68
|
-
net_terms
|
69
|
-
collection_method
|
70
|
-
po_number
|
71
|
-
tax_in_cents
|
72
|
-
tax_type
|
73
|
-
tax_region
|
74
|
-
tax_rate
|
75
|
-
tax_inclusive
|
76
|
-
bulk
|
77
|
-
bank_account_authorized_at
|
78
|
-
terms_and_conditions
|
79
|
-
customer_notes
|
80
|
-
vat_reverse_charge_notes
|
81
|
-
address
|
82
|
-
revenue_schedule_type
|
83
|
-
shipping_address_id
|
84
|
-
shipping_method_code
|
85
|
-
shipping_amount_in_cents
|
86
|
-
timeframe
|
87
|
-
started_with_gift
|
88
|
-
converted_at
|
89
|
-
billing_info_uuid
|
90
|
-
no_billing_info_reason
|
91
|
-
imported_trial
|
92
|
-
credit_customer_notes
|
93
|
-
remaining_pause_cycles
|
94
|
-
paused_at
|
95
|
-
auto_renew
|
96
|
-
renewal_billing_cycles
|
97
|
-
first_billing_date
|
98
|
-
first_bill_date
|
99
|
-
next_bill_date
|
100
|
-
current_term_started_at
|
101
|
-
current_term_ends_at
|
102
|
-
total_amount_in_cents
|
103
|
-
resume_at
|
104
|
-
gateway_code
|
105
|
-
transaction_type
|
106
|
-
)
|
107
|
-
alias to_param uuid
|
108
|
-
|
109
|
-
def self.preview(attributes = {})
|
110
|
-
new(attributes) { |record| record.preview }
|
111
|
-
end
|
112
|
-
|
113
|
-
def preview
|
114
|
-
clear_errors
|
115
|
-
@response = API.send(:post, "#{path}/preview", to_xml)
|
116
|
-
reload response
|
117
|
-
rescue API::UnprocessableEntity => e
|
118
|
-
apply_errors e
|
119
|
-
end
|
120
|
-
|
121
|
-
# @return [Subscription] A new subscription.
|
122
|
-
def initialize(attributes = {})
|
123
|
-
super({ :currency => Recurly.default_currency }.merge attributes)
|
124
|
-
end
|
125
|
-
|
126
|
-
# Assign a Plan resource (rather than a plan code).
|
127
|
-
#
|
128
|
-
# @param plan [Plan]
|
129
|
-
def plan= plan
|
130
|
-
self.plan_code = (plan.plan_code if plan.respond_to? :plan_code)
|
131
|
-
attributes[:plan] = plan
|
132
|
-
end
|
133
|
-
|
134
|
-
def plan_code
|
135
|
-
self[:plan_code] ||= (plan.plan_code if plan.respond_to? :plan_code)
|
136
|
-
end
|
137
|
-
|
138
|
-
def plan_code= plan_code
|
139
|
-
self[:plan_code] = plan_code
|
140
|
-
end
|
141
|
-
|
142
|
-
# Assign a Coupon resource (rather than a coupon code).
|
143
|
-
#
|
144
|
-
# @param coupon [Coupon]
|
145
|
-
def coupon= coupon
|
146
|
-
self.coupon_code = (
|
147
|
-
coupon.coupon_code if coupon.respond_to? :coupon_code
|
148
|
-
)
|
149
|
-
attributes[:coupon] = coupon
|
150
|
-
end
|
151
|
-
|
152
|
-
# Assign Coupon resources (rather than coupon codes).
|
153
|
-
#
|
154
|
-
# @param coupons [[Coupons]]
|
155
|
-
def coupons= coupons
|
156
|
-
self.coupon_codes = coupons.map do |coupon|
|
157
|
-
coupon.coupon_code if coupon.respond_to? :coupon_code
|
158
|
-
end.compact
|
159
|
-
attributes[:coupons] = coupons
|
160
|
-
end
|
161
|
-
|
162
|
-
# @return [AddOns]
|
163
|
-
def subscription_add_ons
|
164
|
-
self[:subscription_add_ons] ||= AddOns.new self, super
|
165
|
-
end
|
166
|
-
alias add_ons subscription_add_ons
|
167
|
-
|
168
|
-
# Assign an array of subscription add-ons.
|
169
|
-
def subscription_add_ons= subscription_add_ons
|
170
|
-
super AddOns.new self, subscription_add_ons
|
171
|
-
end
|
172
|
-
alias add_ons= subscription_add_ons=
|
173
|
-
|
174
|
-
def pending_subscription
|
175
|
-
sub = self[:pending_subscription]
|
176
|
-
sub.tap {|e| e.currency = currency} if sub.is_a? Subscription
|
177
|
-
end
|
178
|
-
|
179
|
-
# Convert free trial to paid subscription when transaction_type is "moto"
|
180
|
-
# which stands for "Mail Order Telephone Order".
|
181
|
-
#
|
182
|
-
# @return true
|
183
|
-
def convert_trial_moto()
|
184
|
-
builder = XML.new("<subscription/>")
|
185
|
-
builder.add_element('transaction_type', "moto")
|
186
|
-
reload API.put("#{uri}/convert_trial", builder.to_s)
|
187
|
-
true
|
188
|
-
end
|
189
|
-
|
190
|
-
# Convert free trial to paid subscription. Optionally uses a 3ds token.
|
191
|
-
#
|
192
|
-
# @param three_d_secure_action_result_token_id [String] three_d_secure_action_result_token_id
|
193
|
-
# returned by Recurly.js referencing the result of the 3DS authentication for PSD2
|
194
|
-
# @return true when payment is accepted
|
195
|
-
def convert_trial(three_d_secure_action_result_token_id = nil)
|
196
|
-
body = if three_d_secure_action_result_token_id != nil
|
197
|
-
builder = Recurly::XML.new("<subscription/>")
|
198
|
-
account = builder.add_element('account')
|
199
|
-
billing_info = account.add_element('billing_info')
|
200
|
-
billing_info.add_element('three_d_secure_action_result_token_id', three_d_secure_action_result_token_id)
|
201
|
-
builder.to_s
|
202
|
-
end
|
203
|
-
|
204
|
-
reload API.put("#{uri}/convert_trial", body)
|
205
|
-
true
|
206
|
-
end
|
207
|
-
|
208
|
-
# Cancel a subscription so that it will not renew.
|
209
|
-
#
|
210
|
-
# @param [String] optional timeframe. Choose one of "bill_date" or "term_end"
|
211
|
-
# @return [true, false] +true+ when successful, +false+ when unable to
|
212
|
-
# (e.g., the subscription is not active).
|
213
|
-
# @example
|
214
|
-
# account = Account.find account_code
|
215
|
-
# subscription = account.subscriptions.first
|
216
|
-
# subscription.cancel # => true
|
217
|
-
def cancel(timeframe = nil)
|
218
|
-
return false unless link? :cancel
|
219
|
-
params = timeframe.nil? ? {} : { 'timeframe': timeframe }
|
220
|
-
reload follow_link :cancel, params: params
|
221
|
-
true
|
222
|
-
end
|
223
|
-
|
224
|
-
# An array of acceptable refund types.
|
225
|
-
REFUND_TYPES = ['none', 'full', 'partial'].freeze
|
226
|
-
|
227
|
-
# Immediately terminate a subscription (with optional refund).
|
228
|
-
#
|
229
|
-
# @return [true, false] +true+ when successful, +false+ when unable to
|
230
|
-
# (e.g., the subscription is not active).
|
231
|
-
# @param refund_type [:none, :full, :partial] <tt>:none</tt> terminates the
|
232
|
-
# subscription with no refund (the default), <tt>:full</tt> refunds the
|
233
|
-
# subscription in full, and <tt>:partial</tt> refunds the subscription in
|
234
|
-
# part.
|
235
|
-
# @raise [ArgumentError] Invalid +refund_type+.
|
236
|
-
# @example
|
237
|
-
# account = Account.find account_code
|
238
|
-
# subscription = account.subscriptions.first
|
239
|
-
# subscription.terminate(:partial) # => true
|
240
|
-
def terminate refund_type = :none
|
241
|
-
return false unless link? :terminate
|
242
|
-
unless REFUND_TYPES.include? refund_type.to_s
|
243
|
-
raise ArgumentError, "refund must be one of: #{REFUND_TYPES.join ', '}"
|
244
|
-
end
|
245
|
-
reload follow_link(:terminate, :params => { :refund => refund_type })
|
246
|
-
true
|
247
|
-
end
|
248
|
-
alias destroy terminate
|
249
|
-
|
250
|
-
# Reactivate a subscription.
|
251
|
-
#
|
252
|
-
# @return [true, false] +true+ when successful, +false+ when unable to
|
253
|
-
# (e.g., the subscription is already active), and may raise an exception
|
254
|
-
# if the reactivation fails.
|
255
|
-
def reactivate
|
256
|
-
return false unless link? :reactivate
|
257
|
-
reload follow_link :reactivate
|
258
|
-
true
|
259
|
-
end
|
260
|
-
|
261
|
-
# Postpone a subscription's renewal date.
|
262
|
-
#
|
263
|
-
# @return [true, false] +true+ when successful, +false+ when unable to
|
264
|
-
# (e.g., the subscription is not active).
|
265
|
-
# @param next_bill_date [Time] when the subscription should renew.
|
266
|
-
# @param bulk [boolean] set to true for bulk updates (bypassing 60 second wait).
|
267
|
-
def postpone next_bill_date, bulk=false
|
268
|
-
return false unless link? :postpone
|
269
|
-
reload follow_link(:postpone,
|
270
|
-
:params => { :next_bill_date => next_bill_date, :bulk => bulk }
|
271
|
-
)
|
272
|
-
true
|
273
|
-
end
|
274
|
-
|
275
|
-
# Update the notes sections of the subscription. This endpoint also allows you to
|
276
|
-
# update the custom fields.
|
277
|
-
#
|
278
|
-
# @example
|
279
|
-
# subscription.custom_fields.first.value = nil
|
280
|
-
# subscription.update_notes(terms_and_conditions: 'New T&C')
|
281
|
-
# #=>
|
282
|
-
# # <subscription>
|
283
|
-
# # <custom_fields><custom_field><name>food</name><value nil="nil"/><custom_field></custom_fields>
|
284
|
-
# # <terms_and_conditions>New T&C</terms_and_conditions>
|
285
|
-
# # </subscription>
|
286
|
-
# # it's also okay to call without notes
|
287
|
-
# subscription.update_notes({})
|
288
|
-
#
|
289
|
-
# @param notes [Hash] should be the notes parameters you wish to update
|
290
|
-
# @return [true, false] +true+ when successful, +false+ when unable to
|
291
|
-
def update_notes(notes)
|
292
|
-
return false unless link? :notes
|
293
|
-
self.attributes = notes
|
294
|
-
reload follow_link(:notes, body: to_xml)
|
295
|
-
true
|
296
|
-
end
|
297
|
-
|
298
|
-
# Pauses a subscription or cancels a scheduled pause.
|
299
|
-
#
|
300
|
-
# * For an active subscription without a pause scheduled already,
|
301
|
-
# this will schedule a pause period to begin at the next renewal
|
302
|
-
# date for the specified number of billing cycles (remaining_pause_cycles).
|
303
|
-
# * When a scheduled pause already exists, this will update the remaining
|
304
|
-
# pause cycles with the new value sent. When zero (0) remaining_pause_cycles
|
305
|
-
# is sent for a subscription with a scheduled pause, the pause will be canceled.
|
306
|
-
# * For a paused subscription, the remaining_pause_cycles will adjust the
|
307
|
-
# length of the current pause period. Sending zero (0) in the remaining_pause_cycles
|
308
|
-
# field will cause the subscription to be resumed at the next renewal date.
|
309
|
-
#
|
310
|
-
# @param remaining_pause_cycles [Integer] The number of billing cycles that the subscription will be paused.
|
311
|
-
# @return true
|
312
|
-
def pause(remaining_pause_cycles)
|
313
|
-
builder = XML.new("<subscription/>")
|
314
|
-
builder.add_element('remaining_pause_cycles', remaining_pause_cycles)
|
315
|
-
reload API.put("#{uri}/pause", builder.to_s)
|
316
|
-
true
|
317
|
-
end
|
318
|
-
|
319
|
-
# Resumes a paused subscription.
|
320
|
-
#
|
321
|
-
# For a paused subscription, this will immediately resume the subscription
|
322
|
-
# from the pause, produce an invoice, and return the newly resumed subscription.
|
323
|
-
# Any at-renewal subscription changes will be immediately applied
|
324
|
-
# when the subscription resumes.
|
325
|
-
#
|
326
|
-
# @return true
|
327
|
-
def resume
|
328
|
-
reload API.put("#{uri}/resume")
|
329
|
-
true
|
330
|
-
end
|
331
|
-
|
332
|
-
# Overrides the behavior of `update_attributes` in Resource class so ensure
|
333
|
-
# all attributes are marked as dirty if the plan code changes
|
334
|
-
def update_attributes attributes = {}
|
335
|
-
clear_attributes_if_plan_code_changed attributes
|
336
|
-
super
|
337
|
-
end
|
338
|
-
|
339
|
-
def update_attributes! attributes = {}
|
340
|
-
clear_attributes_if_plan_code_changed attributes
|
341
|
-
super
|
342
|
-
end
|
343
|
-
|
344
|
-
def signable_attributes
|
345
|
-
super.merge :plan_code => plan_code
|
346
|
-
end
|
347
|
-
|
348
|
-
def changed_attributes
|
349
|
-
attrs = super
|
350
|
-
if custom_fields.any?(&:changed?)
|
351
|
-
attrs['custom_fields'] = custom_fields.select(&:changed?)
|
352
|
-
end
|
353
|
-
attrs
|
354
|
-
end
|
355
|
-
|
356
|
-
|
357
|
-
private
|
358
|
-
|
359
|
-
def clear_attributes_if_plan_code_changed attributes
|
360
|
-
if attributes[:plan_code] != plan_code
|
361
|
-
attributes.each do |key, value|
|
362
|
-
self.attributes[key.to_s] = nil
|
363
|
-
end
|
364
|
-
end
|
365
|
-
end
|
366
|
-
end
|
367
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
module Recurly
|
2
|
-
class SubscriptionAddOn < Resource
|
3
|
-
# @return [MeasuredUnit]
|
4
|
-
has_one :measured_unit
|
5
|
-
|
6
|
-
# @return [Pager<Usage>, []]
|
7
|
-
has_many :usage
|
8
|
-
|
9
|
-
# @return [[Tier], []]
|
10
|
-
has_many :tiers, class_name: :Tier, readonly: false
|
11
|
-
|
12
|
-
# @return [[PercentageTier], []]
|
13
|
-
has_many :percentage_tiers, class_name: :SubAddOnPercentageTier, readonly: false
|
14
|
-
|
15
|
-
define_attribute_methods %w(
|
16
|
-
add_on_code
|
17
|
-
quantity
|
18
|
-
unit_amount_in_cents
|
19
|
-
add_on_type
|
20
|
-
usage_type
|
21
|
-
usage_percentage
|
22
|
-
usage_timeframe
|
23
|
-
add_on_source
|
24
|
-
)
|
25
|
-
|
26
|
-
attr_reader :subscription
|
27
|
-
|
28
|
-
def initialize add_on = nil, subscription = nil
|
29
|
-
super()
|
30
|
-
|
31
|
-
case add_on
|
32
|
-
when AddOn, SubscriptionAddOn
|
33
|
-
@add_on = add_on if add_on.is_a? AddOn
|
34
|
-
self.add_on_code = add_on.add_on_code
|
35
|
-
self.quantity = add_on.quantity
|
36
|
-
if add_on.unit_amount_in_cents
|
37
|
-
self.unit_amount_in_cents = add_on.unit_amount_in_cents.to_i
|
38
|
-
end
|
39
|
-
if add_on.respond_to? :add_on_source
|
40
|
-
self.add_on_source = add_on.add_on_source
|
41
|
-
end
|
42
|
-
self.tiers = add_on.tiers if add_on.tiers.any?
|
43
|
-
self.percentage_tiers = add_on.percentage_tiers if add_on.percentage_tiers.any?
|
44
|
-
when Hash
|
45
|
-
self.attributes = add_on
|
46
|
-
when String, Symbol
|
47
|
-
self.add_on_code = add_on
|
48
|
-
end
|
49
|
-
|
50
|
-
self.add_on_code = add_on_code.to_s
|
51
|
-
|
52
|
-
@subscription = subscription
|
53
|
-
end
|
54
|
-
|
55
|
-
def add_on
|
56
|
-
@add_on ||= subscription.plan.add_ons.find add_on_code
|
57
|
-
end
|
58
|
-
|
59
|
-
def currency
|
60
|
-
subscription.currency if subscription
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
data/lib/recurly/tax_detail.rb
DELETED
data/lib/recurly/tax_type.rb
DELETED
data/lib/recurly/tier.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Recurly
|
2
|
-
class Tier < Resource
|
3
|
-
|
4
|
-
belongs_to :add_on
|
5
|
-
belongs_to :subscription_add_on
|
6
|
-
|
7
|
-
define_attribute_methods %w(
|
8
|
-
ending_quantity
|
9
|
-
unit_amount_in_cents
|
10
|
-
)
|
11
|
-
|
12
|
-
def xml_keys
|
13
|
-
attributes.keys
|
14
|
-
end
|
15
|
-
|
16
|
-
embedded! true
|
17
|
-
end
|
18
|
-
end
|
@@ -1,115 +0,0 @@
|
|
1
|
-
module Recurly
|
2
|
-
class Transaction < Resource
|
3
|
-
# The base error class for transaction errors, raised when a transaction
|
4
|
-
# fails.
|
5
|
-
#
|
6
|
-
# Error messages are customer-friendly, though only {DeclinedError}
|
7
|
-
# messages should be a part of the normal API flow (a {ConfigurationError},
|
8
|
-
# for example, is a problem that a customer cannot solve and requires your
|
9
|
-
# attention).
|
10
|
-
#
|
11
|
-
# If a record of the transaction was stored in Recurly, it will be
|
12
|
-
# accessible via {Error#transaction}.
|
13
|
-
#
|
14
|
-
# @example
|
15
|
-
# begin
|
16
|
-
# subscription.save!
|
17
|
-
# rescue Recurly::Resource::Invalid => e
|
18
|
-
# # Display e.record.errors...
|
19
|
-
# rescue Recurly::Transaction::DeclinedError => e
|
20
|
-
# # Display e.message and/or subscription (and associated) errors...
|
21
|
-
# rescue Recurly::Transaction::RetryableError => e
|
22
|
-
# # You should be able to attempt to save this again later.
|
23
|
-
# rescue Recurly::Transaction::Error => e
|
24
|
-
# # Alert yourself of the issue (i.e., log e.transaction).
|
25
|
-
# # Display a generic error message.
|
26
|
-
# end
|
27
|
-
class Error < API::UnprocessableEntity
|
28
|
-
# @return [Transaction] The transaction as returned (or updated) by
|
29
|
-
# Recurly.
|
30
|
-
attr_reader :transaction
|
31
|
-
|
32
|
-
def initialize request, response, transaction
|
33
|
-
super request, response
|
34
|
-
update_transaction transaction
|
35
|
-
end
|
36
|
-
|
37
|
-
# @return [String] A customer-friendly error message.
|
38
|
-
def to_s
|
39
|
-
xml.text '/errors/transaction_error/customer_message'
|
40
|
-
end
|
41
|
-
|
42
|
-
# @return [String] The transaction error code.
|
43
|
-
def transaction_error_code
|
44
|
-
xml.text '/errors/transaction_error/error_code'
|
45
|
-
end
|
46
|
-
|
47
|
-
def gateway_error_code
|
48
|
-
xml.text '/errors/transaction_error/gateway_error_code'
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def update_transaction transaction
|
54
|
-
return unless transaction_xml = xml['/errors/transaction']
|
55
|
-
|
56
|
-
@transaction = transaction
|
57
|
-
transaction = Transaction.from_xml transaction_xml
|
58
|
-
if @transaction.nil?
|
59
|
-
@transaction = transaction
|
60
|
-
else
|
61
|
-
@transaction.instance_variable_get(:@attributes).update(
|
62
|
-
transaction.attributes
|
63
|
-
)
|
64
|
-
end
|
65
|
-
@transaction.persist!
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# Raised when a transaction fails for a temporary reason. The transaction
|
70
|
-
# should be retried later.
|
71
|
-
class RetryableError < Error
|
72
|
-
end
|
73
|
-
|
74
|
-
# Raised when a transaction fails due to a misconfiguration, e.g. if the
|
75
|
-
# gateway hasn't been configured.
|
76
|
-
class ConfigurationError < Error
|
77
|
-
end
|
78
|
-
|
79
|
-
# Raised when a transaction fails because the billing information was
|
80
|
-
# invalid.
|
81
|
-
class DeclinedError < Error
|
82
|
-
end
|
83
|
-
|
84
|
-
# Raised when the gateway believes this transaction to be a duplicate.
|
85
|
-
class DuplicateError < DeclinedError
|
86
|
-
end
|
87
|
-
|
88
|
-
# Raised when a 3DS result token is needed to complete a transaction
|
89
|
-
class ThreeDSecureError < DeclinedError
|
90
|
-
def three_d_secure_action_token_id
|
91
|
-
xml.text '/errors/transaction_error/three_d_secure_action_token_id'
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
class << Error
|
96
|
-
CATEGORY_MAP = Hash.new DeclinedError
|
97
|
-
CATEGORY_MAP.update(
|
98
|
-
'communication' => RetryableError,
|
99
|
-
'configuration' => ConfigurationError,
|
100
|
-
'duplicate' => DuplicateError,
|
101
|
-
'3d_secure_action_required' => ThreeDSecureError
|
102
|
-
)
|
103
|
-
|
104
|
-
def validate! exception, transaction
|
105
|
-
return unless exception.is_a? API::UnprocessableEntity
|
106
|
-
|
107
|
-
category = exception.send(:xml).text(
|
108
|
-
'/errors/transaction_error/error_category'
|
109
|
-
) and raise CATEGORY_MAP[category].new(
|
110
|
-
exception.request, exception.response, transaction
|
111
|
-
)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|