Skip to content

Commit 4fb4e42

Browse files
committed
Spec tests and some changes for v2 billing
1 parent 31f33d0 commit 4fb4e42

File tree

21 files changed

+853
-92
lines changed

21 files changed

+853
-92
lines changed

lib/travis/api/v3/billing_client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def v2_plans_for_organization(organization_id)
111111
end
112112

113113
def v2_plans_for_user
114-
connection.get("/v2/plans_for/user").body.map do |plan_data|
114+
connection.get('/v2/plans_for/user').body.map do |plan_data|
115115
Travis::API::V3::Models::V2PlanConfig.new(plan_data)
116116
end
117117
end
@@ -128,7 +128,7 @@ def plans_for_organization(organization_id)
128128
end
129129

130130
def plans_for_user
131-
connection.get("/plans_for/user").body.map do |plan_data|
131+
connection.get('/plans_for/user').body.map do |plan_data|
132132
Travis::API::V3::Models::Plan.new(plan_data)
133133
end
134134
end

lib/travis/api/v3/models/v2_subscription.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ module Travis::API::V3
22
class Models::V2Subscription
33
include Models::Owner
44

5-
attr_reader :id, :plan, :permissions, :status, :source, :billing_info, :credit_card_info, :owner, :payment_intent, :addons, :created_at
5+
attr_reader :id, :plan, :permissions, :source, :billing_info, :credit_card_info, :owner, :client_secret, :payment_intent, :addons, :created_at
66

77
def initialize(attributes = {})
88
@id = attributes.fetch('id')
99
plan_data = attributes.fetch('plan_config')
1010
@plan = plan_data && Models::V2PlanConfig.new(plan_data)
1111
@permissions = Models::BillingPermissions.new(attributes.fetch('permissions'))
12-
@status = 'subscribed'
1312
@source = attributes.fetch('source')
1413
@billing_info = attributes['billing_info'] && Models::V2BillingInfo.new(@id, attributes['billing_info'])
1514
@credit_card_info = attributes['credit_card_info'] && Models::V2CreditCardInfo.new(@id, attributes['credit_card_info'])
1615
@payment_intent = attributes['payment_intent'] && Models::PaymentIntent.new(attributes['payment_intent'])
1716
@owner = fetch_owner(attributes.fetch('owner'))
17+
@client_secret = attributes.fetch('client_secret')
1818
@addons = attributes.fetch('addons')
1919
@created_at = attributes.fetch('created_at')
2020
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Travis::API::V3
2+
class Queries::V2Invoices < Query
3+
def all(user_id)
4+
client = BillingClient.new(user_id)
5+
client.get_invoices_for_v2_subscription(params['subscription.id'])
6+
end
7+
end
8+
end

lib/travis/api/v3/queries/v2_subscription.rb

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ def update_address(user_id)
66
client.update_v2_address(params['subscription.id'], address_data)
77
end
88

9-
def cancel(user_id)
10-
reason_data = params.dup.tap { |h| h.delete('subscription.id') }
11-
client = BillingClient.new(user_id)
12-
client.cancel_subscription(params['subscription.id'], reason_data)
13-
end
14-
159
def update_creditcard(user_id)
1610
client = BillingClient.new(user_id)
1711
client.update_v2_creditcard(params['subscription.id'], params['token'])
@@ -23,24 +17,14 @@ def update_plan(user_id)
2317
client.update_v2_subscription(params['subscription.id'], plan_data)
2418
end
2519

26-
def resubscribe(user_id)
27-
client = BillingClient.new(user_id)
28-
client.resubscribe(params['subscription.id'])
29-
end
30-
3120
def invoices(user_id)
3221
client = BillingClient.new(user_id)
33-
client.get_invoices_for_subscription(params['subscription.id'])
34-
end
35-
36-
def trial(user_id)
37-
client = BillingClient.new(user_id)
38-
client.get_trial_info_for_subscription(params['subscription.id'])
22+
client.get_invoices_for_v2_subscription(params['subscription.id'])
3923
end
4024

4125
def pay(user_id)
4226
client = BillingClient.new(user_id)
43-
client.pay(params['subscription.id'])
27+
client.pay_v2(params['subscription.id'])
4428
end
4529
end
4630
end

lib/travis/api/v3/renderer/v2_subscription.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Travis::API::V3
22
class Renderer::V2Subscription < ModelRenderer
3-
representation(:standard, :id, :plan, :addons, :status, :source, :owner, :billing_info, :credit_card_info, :payment_intent, :created_at)
3+
representation(:standard, :id, :plan, :addons, :source, :owner, :client_secret, :billing_info, :credit_card_info, :payment_intent, :created_at)
44

55
def billing_info
66
Renderer.render_model(model.billing_info, mode: :standard) unless model.billing_info.nil?

lib/travis/api/v3/routes.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,6 @@ module Routes
318318
patch :update_address, '/address'
319319
patch :update_creditcard, '/creditcard'
320320
patch :update_plan, '/plan'
321-
patch :resubscribe, '/resubscribe'
322-
post :cancel, '/cancel'
323321
post :pay, '/pay'
324322
get :invoices, '/invoices'
325323
end

lib/travis/api/v3/services/v2_subscription/cancel.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/travis/api/v3/services/v2_subscription/invoices.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Services::V2Subscription::Invoices < Service
44

55
def run!
66
raise LoginRequired unless access_control.full_access_or_logged_in?
7-
result query(:invoices).all(access_control.user.id)
7+
result query(:v2_invoices).all(access_control.user.id)
88
end
99
end
1010
end

lib/travis/api/v3/services/v2_subscription/pay.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Travis::API::V3
22
class Services::V2Subscription::Pay < Service
3-
result_type :subscription
3+
result_type :v2_subscription
44

55
def run!
66
raise LoginRequired unless access_control.full_access_or_logged_in?

lib/travis/api/v3/services/v2_subscription/resubscribe.rb

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)