mock_chargebee 0.0.2 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ea9ad089b2df70e2e589e8cf239942cfc95b4658a5bae0b924b2ca0a9d029a9
4
- data.tar.gz: cfabdd90e45cd358e124b05083ad159005a914433e155debf33e9fbc94e93b76
3
+ metadata.gz: f1dbb28d7c0aa183440b5d6ea1e2006192dfb74ce0a61e9e98a7c5b31871e64f
4
+ data.tar.gz: 8556fef396a9aea7a4a4b58c381dc9da62fddf0a238bad174733916a99f7bcc4
5
5
  SHA512:
6
- metadata.gz: 8e91583896f1df4e4e665efdd0bf96291c3d6156586f4dd7db950576b89adfdccc02c334d8680cdca76abbdc153ff57a6a78fc210b56aa089a9b9048ad054393
7
- data.tar.gz: 59e6a9d614a6cdbfc39c407156a934d81929f561d04e99d8d7519822a57ef0f5b838fb9ba1c2ec1f5ee13c631011bd89261c3ae171af8dbd2b139a1f32d0cbd9
6
+ metadata.gz: 0ab1262fdcf73d83647f07958ec03a676a5fc6890ac6e5d401f706a81fd62bc89bc81e67be869afa48ed9e4aa344d6592f018d916421c5694597f3a4e06bc827
7
+ data.tar.gz: 6b33a4a4e38f43cd4b6631073844d971c952dd19d6d0a71f5f3191d9b1d64e498485cc20a23bd308dc6c77e9e6f990f176d48bd9e9c58ff9097c0c13777f8a45
@@ -0,0 +1,24 @@
1
+ {
2
+ "addon_applicability": "all",
3
+ "charge_model": "flat_fee",
4
+ "currency_code": "USD",
5
+ "enabled_in_hosted_pages": true,
6
+ "enabled_in_portal": true,
7
+ "free_quantity": 0,
8
+ "giftable": false,
9
+ "id": "silver",
10
+ "invoice_name": "sample plan",
11
+ "is_shippable": false,
12
+ "name": "Silver",
13
+ "object": "plan",
14
+ "period": 1,
15
+ "period_unit": "month",
16
+ "price": 5000,
17
+ "pricing_model": "flat_fee",
18
+ "resource_version": 1517505797000,
19
+ "show_description_in_invoices": false,
20
+ "show_description_in_quotes": false,
21
+ "status": "active",
22
+ "taxable": true,
23
+ "updated_at": 1517505797
24
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "access_url": "https://yourapp.chargebeeportal.com/portal/access/__test__cdBbQgJg5fPSTw9qBPDIaQiVEEx0Gsrrc",
3
+ "created_at": 1517505973,
4
+ "customer_id": "__test__KyVnHhSBWm8kA2sT",
5
+ "expires_at": 1517509573,
6
+ "id": "portal___test__KyVnHhSBWm8l82sV",
7
+ "linked_customers": [
8
+ {
9
+ "customer_id": "__test__KyVnHhSBWm8kA2sT",
10
+ "has_active_subscription": false,
11
+ "has_billing_address": false,
12
+ "has_payment_method": false,
13
+ "object": "linked_customer"
14
+ }
15
+ ],
16
+ "object": "portal_session",
17
+ "redirect_url": "https://yourdomain.com/users/3490343",
18
+ "status": "created",
19
+ "token": "__test__cdBbQgJg5fPSTw9qBPDIaQiVEEx0Gsrrc"
20
+ }
@@ -11,11 +11,16 @@ module MockChargebee
11
11
  Util.generate_id(self::RESOURCE_ID_PREFIX)
12
12
  end
13
13
 
14
+ def self.already_exists!(id)
15
+ raise ChargeBee::InvalidRequestError.new(400, message: "The value #{id} is already present.")
16
+ end
17
+
14
18
  def self.load_fixtures(*args)
15
19
  args.each do |arg|
16
20
  define_singleton_method("#{arg}_fixture") do
17
21
  instance_variable_get("@#{arg}_fixture") ||
18
- instance_variable_set("@#{arg}_fixture", JSON.parse(File.read("#{File.dirname(__FILE__)}/../fixtures/#{arg}.json")))
22
+ instance_variable_set("@#{arg}_fixture",
23
+ JSON.parse(File.read("#{File.dirname(__FILE__)}/../fixtures/#{arg}.json")))
19
24
  end
20
25
  end
21
26
  end
@@ -3,7 +3,7 @@
3
3
  module MockChargebee
4
4
  module Models
5
5
  class Customer < Base
6
- RESOURCE_ID_PREFIX = "cust"
6
+ RESOURCE_ID_PREFIX = 'cust'
7
7
 
8
8
  load_fixtures :customer
9
9
 
@@ -12,12 +12,28 @@ module MockChargebee
12
12
  end
13
13
 
14
14
  def self.create(params)
15
- params["id"] ||= unique_id
15
+ already_exists!(id) if already_exists?(params['id'])
16
+
17
+ params['id'] ||= unique_id
16
18
  customer = customer_fixture.merge(params)
17
- repositories.customers.store(customer["id"], customer)
19
+ repositories.customers.store(customer['id'], customer)
20
+
21
+ customer
22
+ end
23
+
24
+ def self.update(id, params)
25
+ customer = find(id)
26
+ customer.merge!(params)
27
+ repositories.customers.store(customer['id'], customer)
18
28
 
19
29
  customer
20
30
  end
31
+
32
+ def self.already_exists?(id)
33
+ return false if id.nil?
34
+
35
+ repositories.customers[id].present?
36
+ end
21
37
  end
22
38
  end
23
39
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MockChargebee
4
+ module Models
5
+ class Plan < Base
6
+ RESOURCE_ID_PREFIX = 'plan'
7
+
8
+ load_fixtures :plan
9
+
10
+ def self.find(id)
11
+ repositories.plans.fetch(id)
12
+ end
13
+
14
+ def self.create(params)
15
+ params['id'] ||= unique_id
16
+ plan = plan_fixture.merge(params)
17
+ repositories.plans.store(plan['id'], plan)
18
+
19
+ plan
20
+ end
21
+
22
+ def self.update(id, params)
23
+ plan = find(id)
24
+ plan.merge!(params)
25
+ repositories.plans.store(plan['id'], plan)
26
+
27
+ plan
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MockChargebee
4
+ module Models
5
+ class PortalSession < Base
6
+ RESOURCE_ID_PREFIX = 'portal'
7
+
8
+ load_fixtures :portal_session
9
+
10
+ def self.create(params)
11
+ Validations::PortalSessions::CreateParams.validate_required(params)
12
+
13
+ params['id'] ||= unique_id
14
+ params['customer_id'] = params.dig(:customer, :id)
15
+ portal_session = portal_session_fixture.merge(params)
16
+ repositories.portal_sessions.store(portal_session['id'], portal_session)
17
+
18
+ portal_session
19
+ end
20
+ end
21
+ end
22
+ end
@@ -12,7 +12,9 @@ module MockChargebee
12
12
 
13
13
  add_repositories :customers,
14
14
  :subscriptions,
15
- :coupons
15
+ :coupons,
16
+ :portal_sessions,
17
+ :plans
16
18
 
17
19
  class RepoHash < Hash
18
20
  def fetch(*)
@@ -6,12 +6,13 @@ module MockChargebee
6
6
  parsed_path = Util.parse_path_from_url(url)
7
7
  parsed_params = Util.parse_params(params)
8
8
 
9
- handler = RequestHandlers.const_get(parsed_path.resource.capitalize)
9
+ handler = RequestHandlers.const_get(parsed_path.resource.split('_').map(&:capitalize).join(''))
10
10
  resp = handler.call(method, parsed_path, parsed_params)
11
- resp = ChargeBee::Util.symbolize_keys(resp)
12
- resp
11
+ ChargeBee::Util.symbolize_keys(resp)
13
12
  rescue NameError => e
14
- raise MockChargebee::MissingRequestHandler parsed_path.resource if e.message.match?(/uninitialized constant #{parsed_path.resource.capitalize}/)
13
+ if e.message.match?(/uninitialized constant #{parsed_path.resource.capitalize}/)
14
+ raise MockChargebee::MissingRequestHandler parsed_path.resource
15
+ end
15
16
 
16
17
  raise e
17
18
  end
@@ -21,6 +21,12 @@ module MockChargebee
21
21
 
22
22
  { subscription: subscription, customer: customer }
23
23
  end
24
+
25
+ def post_update_billing_info
26
+ customer = Models::Customer.update(id, params)
27
+
28
+ { customer: customer }
29
+ end
24
30
  end
25
31
  end
26
32
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MockChargebee
4
+ module RequestHandlers
5
+ class Plans < Base
6
+ private
7
+
8
+ def post
9
+ plan = if id.nil?
10
+ Models::Plan.create(params)
11
+ else
12
+ Models::Plan.update(id, params)
13
+ end
14
+
15
+ { plan: plan }
16
+ end
17
+
18
+ def get
19
+ plan = Models::Plan.find(id)
20
+ binding.pry
21
+
22
+ { plan: plan }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MockChargebee
4
+ module RequestHandlers
5
+ class PortalSessions < Base
6
+ private
7
+
8
+ def post
9
+ portal_session = Models::PortalSession.create(params)
10
+ { portal_session: portal_session }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MockChargebee
4
+ module Validations
5
+ module PortalSessions
6
+ class CreateParams < Base
7
+ REQUIRED_KEYS = %w[customer].freeze
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MockChargebee
4
- VERSION = "0.0.2"
4
+ VERSION = '0.0.7'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mock_chargebee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Cass
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-19 00:00:00.000000000 Z
11
+ date: 2021-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -110,6 +110,8 @@ files:
110
110
  - lib/mock_chargebee/errors.rb
111
111
  - lib/mock_chargebee/fixtures/coupon.json
112
112
  - lib/mock_chargebee/fixtures/customer.json
113
+ - lib/mock_chargebee/fixtures/plan.json
114
+ - lib/mock_chargebee/fixtures/portal_session.json
113
115
  - lib/mock_chargebee/fixtures/subscription.json
114
116
  - lib/mock_chargebee/fixtures/subscription_cancel_response.json
115
117
  - lib/mock_chargebee/fixtures/subscription_create_response.json
@@ -208,17 +210,22 @@ files:
208
210
  - lib/mock_chargebee/models/base.rb
209
211
  - lib/mock_chargebee/models/coupon.rb
210
212
  - lib/mock_chargebee/models/customer.rb
213
+ - lib/mock_chargebee/models/plan.rb
214
+ - lib/mock_chargebee/models/portal_session.rb
211
215
  - lib/mock_chargebee/models/subscription.rb
212
216
  - lib/mock_chargebee/repositories.rb
213
217
  - lib/mock_chargebee/request.rb
214
218
  - lib/mock_chargebee/request_handlers/base.rb
215
219
  - lib/mock_chargebee/request_handlers/coupons.rb
216
220
  - lib/mock_chargebee/request_handlers/customers.rb
221
+ - lib/mock_chargebee/request_handlers/plans.rb
222
+ - lib/mock_chargebee/request_handlers/portal_sessions.rb
217
223
  - lib/mock_chargebee/request_handlers/subscriptions.rb
218
224
  - lib/mock_chargebee/services/apply_coupons.rb
219
225
  - lib/mock_chargebee/util.rb
220
226
  - lib/mock_chargebee/validations/base.rb
221
227
  - lib/mock_chargebee/validations/coupons.rb
228
+ - lib/mock_chargebee/validations/portal_sessions.rb
222
229
  - lib/mock_chargebee/validations/subscriptions.rb
223
230
  - lib/mock_chargebee/validations/webhooks.rb
224
231
  - lib/mock_chargebee/version.rb