mock_chargebee 0.0.5 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a1dacacdeaba17195a81469b6255b93b42281e4c8bca5007240c5eb2462e230
4
- data.tar.gz: 6647cf5f6df2dcf813f71f9e497b93319d8164019687b1c339fb9997423350e8
3
+ metadata.gz: ba35b1bccf05af34b795bb7e842c2c154b733d10901efee6ad1a62e86c210da1
4
+ data.tar.gz: 7dd874bfdbfac8a865a6bc9d569c84d93845a2585fd08f660e9c30e0bac2b8a9
5
5
  SHA512:
6
- metadata.gz: 559f494502225903758e9048a7f73efd92f6b632c02b15dcd615c28395a3a12c6dc61289323428852136368b7be13944f465b4175a6d4875ea2d408c43bcfb22
7
- data.tar.gz: 8bf154b7ecc6093547226918eb12259674aadca138c7167639983ae22e4d92759be2523d82eaf7988eb3dc1a04a4580dfc91319b7d299c3658997e6c0b1980fd
6
+ metadata.gz: 76bdaec258a452d977527ab7461058cf2b597e8999b9c8a6d2ade838d191d9d368b3d9ad46fac791f61fa8b291b5151d3cd7c1aac017663994fc7be9e3da1c4a
7
+ data.tar.gz: e33f5580422c46b0a8eb2e34a95fdda1071640fef069d68a76852957e78a7418e14a46dfcab64f3d50c5b6582d13a8ea205f756cc7180d4dccad6e7522e8cf34
@@ -0,0 +1,65 @@
1
+ {
2
+ "invoices": [
3
+ {
4
+ "adjustment_credit_notes": [],
5
+ "amount_adjusted": 0,
6
+ "amount_due": 895,
7
+ "amount_paid": 0,
8
+ "amount_to_collect": 895,
9
+ "applied_credits": [],
10
+ "base_currency_code": "USD",
11
+ "credits_applied": 0,
12
+ "currency_code": "USD",
13
+ "customer_id": "__test__KyVnHhSBWSjWC2p",
14
+ "date": 1517501348,
15
+ "deleted": false,
16
+ "due_date": 1517501348,
17
+ "dunning_attempts": [],
18
+ "exchange_rate": 1,
19
+ "first_invoice": true,
20
+ "has_advance_charges": false,
21
+ "id": "__demo_inv__1",
22
+ "is_gifted": false,
23
+ "issued_credit_notes": [],
24
+ "line_items": [
25
+ {
26
+ "amount": 895,
27
+ "customer_id": "__test__KyVnHhSBWSjWC2p",
28
+ "date_from": 1517501348,
29
+ "date_to": 1519920548,
30
+ "description": "No Trial",
31
+ "discount_amount": 0,
32
+ "entity_id": "no_trial",
33
+ "entity_type": "plan",
34
+ "id": "li___test__KyVnHhSBWSjXc2r",
35
+ "is_taxed": false,
36
+ "item_level_discount_amount": 0,
37
+ "object": "line_item",
38
+ "pricing_model": "per_unit",
39
+ "quantity": 1,
40
+ "subscription_id": "__test__KyVnHhSBWSjWC2p",
41
+ "tax_amount": 0,
42
+ "tax_exempt_reason": "tax_not_configured",
43
+ "unit_amount": 895
44
+ }
45
+ ],
46
+ "linked_orders": [],
47
+ "linked_payments": [],
48
+ "net_term_days": 0,
49
+ "new_sales_amount": 895,
50
+ "object": "invoice",
51
+ "price_type": "tax_exclusive",
52
+ "recurring": true,
53
+ "resource_version": 1517501348000,
54
+ "round_off_amount": 0,
55
+ "status": "payment_due",
56
+ "sub_total": 895,
57
+ "subscription_id": "__test__KyVnHhSBWSjWC2p",
58
+ "tax": 0,
59
+ "term_finalized": true,
60
+ "total": 895,
61
+ "updated_at": 1517501348,
62
+ "write_off_amount": 0
63
+ }
64
+ ]
65
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "card": {
3
+ "brand": "visa",
4
+ "expiry_month": 5,
5
+ "expiry_year": 2022,
6
+ "first_name": "MyCard",
7
+ "funding_type": "credit",
8
+ "iin": "******",
9
+ "last4": "4242",
10
+ "last_name": "testing",
11
+ "masked_number": "************4242",
12
+ "object": "card"
13
+ },
14
+ "created_at": 1517501366,
15
+ "customer_id": "__test__KyVnHhSBWSnun3m",
16
+ "deleted": false,
17
+ "gateway": "stripe",
18
+ "gateway_account_id": "gw___test__KyVnGlSBWSlFuCx",
19
+ "id": "pm___test__KyVnHhSBWSoLV3o",
20
+ "issuing_country": "US",
21
+ "object": "payment_source",
22
+ "reference_id": "cus_I57Fg22l3szyZI/card_1HUx0bJv9j0DyntJi5f2GxEj",
23
+ "resource_version": 1517501366000,
24
+ "status": "valid",
25
+ "type": "card",
26
+ "updated_at": 1517501366
27
+ }
@@ -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
+ }
@@ -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,9 +12,11 @@ module MockChargebee
12
12
  end
13
13
 
14
14
  def self.create(params)
15
- params["id"] ||= unique_id
15
+ already_exists!(params['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)
18
20
 
19
21
  customer
20
22
  end
@@ -22,10 +24,23 @@ module MockChargebee
22
24
  def self.update(id, params)
23
25
  customer = find(id)
24
26
  customer.merge!(params)
25
- repositories.customers.store(customer["id"], customer)
27
+ repositories.customers.store(customer['id'], customer)
26
28
 
27
29
  customer
28
30
  end
31
+
32
+ def self.delete(id)
33
+ customer = find(id)
34
+ repositories.customers.delete(id)
35
+
36
+ customer
37
+ end
38
+
39
+ def self.already_exists?(id)
40
+ return false if id.nil?
41
+
42
+ repositories.customers[id].present?
43
+ end
29
44
  end
30
45
  end
31
46
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MockChargebee
4
+ module Models
5
+ class PaymentSource < Base
6
+ RESOURCE_ID_PREFIX = 'payment_source'
7
+
8
+ load_fixtures :payment_source
9
+
10
+ def self.find(id)
11
+ repositories.payment_sources.fetch(id)
12
+ end
13
+
14
+ def self.create(params)
15
+ already_exists!(params['reference_id']) if already_exists?(params['reference_id'])
16
+
17
+ params['id'] = unique_id
18
+ source = payment_source_fixture.merge(params)
19
+ repositories.payment_sources.store(source['id'], source)
20
+
21
+ source
22
+ end
23
+
24
+ def self.already_exists?(ref_id)
25
+ return false if ref_id.nil?
26
+
27
+ repositories.payment_sources.values.include?(ref_id)
28
+ end
29
+ end
30
+ end
31
+ 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
@@ -13,7 +13,9 @@ module MockChargebee
13
13
  add_repositories :customers,
14
14
  :subscriptions,
15
15
  :coupons,
16
- :portal_sessions
16
+ :portal_sessions,
17
+ :plans,
18
+ :payment_sources
17
19
 
18
20
  class RepoHash < Hash
19
21
  def fetch(*)
@@ -15,6 +15,12 @@ module MockChargebee
15
15
  { customer: customer }
16
16
  end
17
17
 
18
+ def post_delete
19
+ customer = Models::Customer.delete(id)
20
+
21
+ { customer: customer }
22
+ end
23
+
18
24
  def post_subscriptions
19
25
  customer = Models::Customer.find(id)
20
26
  subscription = Models::Subscription.create_for_customer(customer, params)
@@ -0,0 +1,14 @@
1
+ module MockChargebee
2
+ module RequestHandlers
3
+ class PaymentSources < Base
4
+ private
5
+
6
+ def post
7
+ customer = Models::Customer.find(params['customer_id'])
8
+ payment_source = Models::PaymentSource.create(params)
9
+
10
+ { customer: customer, payment_source: payment_source }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
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
+
21
+ { plan: plan }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ module MockChargebee
2
+ module RequestHandlers
3
+ class UnbilledCharges < Base
4
+ load_fixtures :invoice_unbilled_charges_response
5
+
6
+ private
7
+
8
+ def post
9
+ Models::Subscription.find(params['subscription_id'])
10
+
11
+ invoice_unbilled_charges_response_fixture
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MockChargebee
4
- VERSION = '0.0.5'
4
+ VERSION = '0.0.10'
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.5
4
+ version: 0.0.10
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-02-04 00:00:00.000000000 Z
11
+ date: 2021-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -110,6 +110,9 @@ 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/invoice_unbilled_charges_response.json
114
+ - lib/mock_chargebee/fixtures/payment_source.json
115
+ - lib/mock_chargebee/fixtures/plan.json
113
116
  - lib/mock_chargebee/fixtures/portal_session.json
114
117
  - lib/mock_chargebee/fixtures/subscription.json
115
118
  - lib/mock_chargebee/fixtures/subscription_cancel_response.json
@@ -209,6 +212,8 @@ files:
209
212
  - lib/mock_chargebee/models/base.rb
210
213
  - lib/mock_chargebee/models/coupon.rb
211
214
  - lib/mock_chargebee/models/customer.rb
215
+ - lib/mock_chargebee/models/payment_source.rb
216
+ - lib/mock_chargebee/models/plan.rb
212
217
  - lib/mock_chargebee/models/portal_session.rb
213
218
  - lib/mock_chargebee/models/subscription.rb
214
219
  - lib/mock_chargebee/repositories.rb
@@ -216,8 +221,11 @@ files:
216
221
  - lib/mock_chargebee/request_handlers/base.rb
217
222
  - lib/mock_chargebee/request_handlers/coupons.rb
218
223
  - lib/mock_chargebee/request_handlers/customers.rb
224
+ - lib/mock_chargebee/request_handlers/payment_sources.rb
225
+ - lib/mock_chargebee/request_handlers/plans.rb
219
226
  - lib/mock_chargebee/request_handlers/portal_sessions.rb
220
227
  - lib/mock_chargebee/request_handlers/subscriptions.rb
228
+ - lib/mock_chargebee/request_handlers/unbilled_charges.rb
221
229
  - lib/mock_chargebee/services/apply_coupons.rb
222
230
  - lib/mock_chargebee/util.rb
223
231
  - lib/mock_chargebee/validations/base.rb