chartmogul-ruby 0.1.4 → 1.0.0
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 +4 -4
- data/.gitignore +1 -0
- data/README.md +11 -6
- data/bin/setup +1 -0
- data/changelog.md +4 -0
- data/fixtures/vcr_cassettes/{ChartMogul_Import_Customer → ChartMogul_Customer}/API_Interactions/correctly_handles_a_422_response.yml +3 -3
- data/fixtures/vcr_cassettes/{ChartMogul_Import_Customer → ChartMogul_Customer}/API_Interactions/correctly_interracts_with_the_API.yml +15 -15
- data/fixtures/vcr_cassettes/{ChartMogul_Import_Customer → ChartMogul_Customer}/_find_by_external_id/when_external_id_is_provided/returns_matching_user_if_exists.yml +2 -2
- data/fixtures/vcr_cassettes/{ChartMogul_Import_Customer → ChartMogul_Customer}/_find_by_external_id/when_external_id_is_provided/returns_nil_if_customer_does_not_exist.yml +2 -2
- data/fixtures/vcr_cassettes/{ChartMogul_Import_CustomerInvoices → ChartMogul_CustomerInvoices}/API_Interactions/correctly_interracts_with_the_API.yml +4 -4
- data/fixtures/vcr_cassettes/ChartMogul_DataSource/API_Interactions/correctly_interracts_with_the_API.yml +12 -12
- data/fixtures/vcr_cassettes/ChartMogul_DataSource/API_Interactions/correctly_raises_errors_on_404.yml +3 -3
- data/fixtures/vcr_cassettes/ChartMogul_DataSource/API_Interactions/correctly_raises_errors_on_422.yml +3 -3
- data/fixtures/vcr_cassettes/ChartMogul_DataSource/API_Interactions/retrieves_existing_data_source_matching_uuid.yml +101 -0
- data/fixtures/vcr_cassettes/ChartMogul_Enrichment_Customer/API_Interactions/raises_401_if_invalid_credentials.yml +38 -0
- data/fixtures/vcr_cassettes/ChartMogul_Ping/pings/and_fails_on_incorrect_credentials.yml +38 -0
- data/fixtures/vcr_cassettes/ChartMogul_Ping/pings/when_credentials_correct.yml +38 -0
- data/fixtures/vcr_cassettes/{ChartMogul_Import_Plan/API_Interractions → ChartMogul_Plan/API_Interactions}/correctly_handles_a_422_error.yml +3 -3
- data/fixtures/vcr_cassettes/{ChartMogul_Import_Plan/API_Interractions/correctly_interracts_with_the_API.yml → ChartMogul_Plan/API_Interactions/correctly_interacts_with_the_API.yml} +9 -9
- data/fixtures/vcr_cassettes/{ChartMogul_Import_DataSource/API_Interactions/correctly_interracts_with_the_API.yml → ChartMogul_Plan/API_Interactions/deletes_existing_plan.yml} +61 -52
- data/fixtures/vcr_cassettes/ChartMogul_Plan/API_Interactions/retrieves_existing_plan_by_uuid.yml +151 -0
- data/fixtures/vcr_cassettes/ChartMogul_Plan/API_Interactions/updates_existing_plan.yml +198 -0
- data/fixtures/vcr_cassettes/{ChartMogul_Import_Subscription → ChartMogul_Subscription}/API_Interactions/correctly_interracts_with_the_API.yml +4 -4
- data/fixtures/vcr_cassettes/{ChartMogul_Import_Transactions_Payment → ChartMogul_Transactions_Payment}/API_Interactions/correctly_interracts_with_the_API.yml +3 -3
- data/lib/chartmogul.rb +12 -11
- data/lib/chartmogul/api_resource.rb +12 -1
- data/lib/chartmogul/customer.rb +41 -0
- data/lib/chartmogul/customer_invoices.rb +42 -0
- data/lib/chartmogul/data_source.rb +22 -0
- data/lib/chartmogul/errors/unauthorized_error.rb +4 -0
- data/lib/chartmogul/invoice.rb +62 -0
- data/lib/chartmogul/line_items/one_time.rb +23 -0
- data/lib/chartmogul/line_items/subscription.rb +29 -0
- data/lib/chartmogul/ping.rb +14 -0
- data/lib/chartmogul/plan.rb +26 -0
- data/lib/chartmogul/subscription.rb +31 -0
- data/lib/chartmogul/transactions/payment.rb +24 -0
- data/lib/chartmogul/transactions/refund.rb +24 -0
- data/lib/chartmogul/version.rb +1 -1
- metadata +30 -24
- data/fixtures/vcr_cassettes/ChartMogul_Import_DataSource/API_Interactions/correctly_raises_errors_on_404.yml +0 -46
- data/fixtures/vcr_cassettes/ChartMogul_Import_DataSource/API_Interactions/correctly_raises_errors_on_422.yml +0 -48
- data/lib/chartmogul/import/customer.rb +0 -43
- data/lib/chartmogul/import/customer_invoices.rb +0 -44
- data/lib/chartmogul/import/data_source.rb +0 -19
- data/lib/chartmogul/import/invoice.rb +0 -64
- data/lib/chartmogul/import/line_items/one_time.rb +0 -25
- data/lib/chartmogul/import/line_items/subscription.rb +0 -31
- data/lib/chartmogul/import/plan.rb +0 -21
- data/lib/chartmogul/import/subscription.rb +0 -33
- data/lib/chartmogul/import/transactions/payment.rb +0 -26
- data/lib/chartmogul/import/transactions/refund.rb +0 -26
@@ -1,43 +0,0 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
module Import
|
3
|
-
class Customer < APIResource
|
4
|
-
set_resource_name 'Customer'
|
5
|
-
set_resource_path '/v1/import/customers'
|
6
|
-
set_resource_root_key :customers
|
7
|
-
|
8
|
-
readonly_attr :uuid
|
9
|
-
|
10
|
-
writeable_attr :external_id
|
11
|
-
writeable_attr :name
|
12
|
-
writeable_attr :email
|
13
|
-
writeable_attr :company
|
14
|
-
writeable_attr :country
|
15
|
-
writeable_attr :state
|
16
|
-
writeable_attr :city
|
17
|
-
writeable_attr :zip
|
18
|
-
writeable_attr :data_source_uuid
|
19
|
-
writeable_attr :lead_created_at, type: :time
|
20
|
-
writeable_attr :free_trial_started_at, type: :time
|
21
|
-
|
22
|
-
include API::Actions::All
|
23
|
-
include API::Actions::Create
|
24
|
-
include API::Actions::Destroy
|
25
|
-
|
26
|
-
def self.find_by_external_id(external_id)
|
27
|
-
all(external_id: external_id).first
|
28
|
-
end
|
29
|
-
|
30
|
-
def subscriptions(options = {})
|
31
|
-
@subscriptions ||= Subscription.all(uuid, options)
|
32
|
-
end
|
33
|
-
|
34
|
-
def invoices(options = {})
|
35
|
-
@invoices ||= CustomerInvoices.all(uuid, options)
|
36
|
-
end
|
37
|
-
|
38
|
-
def invoices=(invoices_array)
|
39
|
-
@invoices = CustomerInvoices.new(customer_uuid: uuid, invoices: invoices_array)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
|
3
|
-
module ChartMogul
|
4
|
-
module Import
|
5
|
-
class CustomerInvoices < APIResource
|
6
|
-
extend Forwardable
|
7
|
-
include Enumerable
|
8
|
-
|
9
|
-
set_resource_name 'Invoices'
|
10
|
-
set_resource_path '/v1/import/customers/:customer_uuid/invoices'
|
11
|
-
|
12
|
-
writeable_attr :invoices, default: []
|
13
|
-
|
14
|
-
writeable_attr :customer_uuid
|
15
|
-
|
16
|
-
include API::Actions::All
|
17
|
-
include API::Actions::Create
|
18
|
-
|
19
|
-
def serialize_invoices
|
20
|
-
map(&:serialize_for_write)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.all(customer_uuid, options = {})
|
24
|
-
super(options.merge(customer_uuid: customer_uuid))
|
25
|
-
end
|
26
|
-
|
27
|
-
def_delegators :invoices, :each, :[], :<<, :size, :length
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def set_invoices(invoices_attributes)
|
32
|
-
@invoices = invoices_attributes.map.with_index do |invoice_attributes, index|
|
33
|
-
existing_invoice = invoices[index]
|
34
|
-
|
35
|
-
if existing_invoice
|
36
|
-
existing_invoice.assign_all_attributes(invoice_attributes)
|
37
|
-
else
|
38
|
-
Invoice.new_from_json(invoice_attributes)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
module Import
|
3
|
-
class DataSource < APIResource
|
4
|
-
set_resource_name 'Data Source'
|
5
|
-
set_resource_path '/v1/import/data_sources'
|
6
|
-
set_resource_root_key :data_sources
|
7
|
-
|
8
|
-
readonly_attr :uuid
|
9
|
-
readonly_attr :status
|
10
|
-
readonly_attr :created_at, type: :time
|
11
|
-
|
12
|
-
writeable_attr :name
|
13
|
-
|
14
|
-
include API::Actions::All
|
15
|
-
include API::Actions::Create
|
16
|
-
include API::Actions::Destroy
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
module Import
|
3
|
-
class Invoice < ChartMogul::Object
|
4
|
-
readonly_attr :uuid
|
5
|
-
|
6
|
-
writeable_attr :date, type: :time
|
7
|
-
writeable_attr :currency
|
8
|
-
writeable_attr :line_items, default: []
|
9
|
-
writeable_attr :transactions, default: []
|
10
|
-
writeable_attr :external_id
|
11
|
-
writeable_attr :due_date, type: :time
|
12
|
-
|
13
|
-
def serialize_line_items
|
14
|
-
line_items.map(&:serialize_for_write)
|
15
|
-
end
|
16
|
-
|
17
|
-
def serialize_transactions
|
18
|
-
transactions.map(&:serialize_for_write)
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def set_line_items(line_items_attributes)
|
24
|
-
@line_items = line_items_attributes.map.with_index do |line_item_attributes, index|
|
25
|
-
existing_line_item = line_items[index]
|
26
|
-
|
27
|
-
if existing_line_item
|
28
|
-
existing_line_item.assign_all_attributes(line_item_attributes)
|
29
|
-
else
|
30
|
-
line_item_class(line_item_attributes[:type])
|
31
|
-
.new_from_json(line_item_attributes.merge(invoice_uuid: uuid))
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def set_transactions(transactions_attributes)
|
37
|
-
@transactions = transactions_attributes.map.with_index do |transaction_attributes, index|
|
38
|
-
existing_transaction = transactions[index]
|
39
|
-
|
40
|
-
if existing_transaction
|
41
|
-
existing_transaction.assign_all_attributes(transaction_attributes)
|
42
|
-
else
|
43
|
-
transaction_class(transaction_attributes[:type])
|
44
|
-
.new_from_json(transaction_attributes.merge(invoice_uuid: uuid))
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def line_item_class(type)
|
50
|
-
case type
|
51
|
-
when 'subscription' then ChartMogul::Import::LineItems::Subscription
|
52
|
-
when 'one_time' then ChartMogul::Import::LineItems::OneTime
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def transaction_class(type)
|
57
|
-
case type
|
58
|
-
when 'payment' then ChartMogul::Import::Transactions::Payment
|
59
|
-
when 'refund' then ChartMogul::Import::Transactions::Refund
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
module Import
|
3
|
-
module LineItems
|
4
|
-
class OneTime < ChartMogul::Object
|
5
|
-
readonly_attr :uuid
|
6
|
-
|
7
|
-
writeable_attr :type, default: 'one_time'
|
8
|
-
writeable_attr :amount_in_cents
|
9
|
-
writeable_attr :description
|
10
|
-
writeable_attr :quantity
|
11
|
-
writeable_attr :discount_amount_in_cents
|
12
|
-
writeable_attr :discount_code
|
13
|
-
writeable_attr :tax_amount_in_cents
|
14
|
-
writeable_attr :external_id
|
15
|
-
|
16
|
-
writeable_attr :invoice_uuid
|
17
|
-
|
18
|
-
def initialize(attributes = {})
|
19
|
-
super(attributes)
|
20
|
-
@type = 'one_time'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
module Import
|
3
|
-
module LineItems
|
4
|
-
class Subscription < ChartMogul::Object
|
5
|
-
readonly_attr :uuid
|
6
|
-
|
7
|
-
writeable_attr :type, default: 'subscription'
|
8
|
-
writeable_attr :subscription_external_id
|
9
|
-
writeable_attr :service_period_start, type: :time
|
10
|
-
writeable_attr :service_period_end, type: :time
|
11
|
-
writeable_attr :amount_in_cents
|
12
|
-
writeable_attr :cancelled_at, type: :time
|
13
|
-
writeable_attr :prorated
|
14
|
-
writeable_attr :quantity
|
15
|
-
writeable_attr :discount_amount_in_cents
|
16
|
-
writeable_attr :discount_code
|
17
|
-
writeable_attr :tax_amount_in_cents
|
18
|
-
writeable_attr :external_id
|
19
|
-
|
20
|
-
readonly_attr :subscription_uuid
|
21
|
-
writeable_attr :invoice_uuid
|
22
|
-
writeable_attr :plan_uuid
|
23
|
-
|
24
|
-
def initialize(attributes = {})
|
25
|
-
super(attributes)
|
26
|
-
@type = 'subscription'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
module Import
|
3
|
-
class Plan < APIResource
|
4
|
-
set_resource_name 'Plan'
|
5
|
-
set_resource_path '/v1/import/plans'
|
6
|
-
set_resource_root_key :plans
|
7
|
-
|
8
|
-
readonly_attr :uuid
|
9
|
-
|
10
|
-
writeable_attr :name
|
11
|
-
writeable_attr :interval_count
|
12
|
-
writeable_attr :interval_unit
|
13
|
-
writeable_attr :external_id
|
14
|
-
|
15
|
-
writeable_attr :data_source_uuid
|
16
|
-
|
17
|
-
include API::Actions::All
|
18
|
-
include API::Actions::Create
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
module Import
|
3
|
-
class Subscription < APIResource
|
4
|
-
set_resource_name 'Subscription'
|
5
|
-
set_resource_path '/v1/import/customers/:customer_uuid/subscriptions'
|
6
|
-
set_resource_root_key :subscriptions
|
7
|
-
|
8
|
-
readonly_attr :uuid
|
9
|
-
readonly_attr :external_id
|
10
|
-
readonly_attr :cancellation_dates, default: []
|
11
|
-
|
12
|
-
readonly_attr :plan_uuid
|
13
|
-
readonly_attr :data_source_uuid
|
14
|
-
|
15
|
-
include API::Actions::All
|
16
|
-
include API::Actions::Custom
|
17
|
-
|
18
|
-
def set_cancellation_dates(cancellation_dates_array)
|
19
|
-
@cancellation_dates = cancellation_dates_array.map do |cancellation_date|
|
20
|
-
Time.parse(cancellation_date)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def cancel(cancelled_at)
|
25
|
-
custom!(:patch, "/v1/import/subscriptions/#{uuid}", cancelled_at: cancelled_at)
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.all(customer_uuid, options = {})
|
29
|
-
super(options.merge(customer_uuid: customer_uuid))
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
module Import
|
3
|
-
module Transactions
|
4
|
-
class Payment < APIResource
|
5
|
-
set_resource_name 'Payment Transaction'
|
6
|
-
set_resource_path '/v1/import/invoices/:invoice_uuid/transactions'
|
7
|
-
|
8
|
-
readonly_attr :uuid
|
9
|
-
|
10
|
-
writeable_attr :type, default: 'payment'
|
11
|
-
writeable_attr :date, type: :time
|
12
|
-
writeable_attr :result
|
13
|
-
writeable_attr :external_id
|
14
|
-
|
15
|
-
writeable_attr :invoice_uuid
|
16
|
-
|
17
|
-
def initialize(attributes = {})
|
18
|
-
super(attributes)
|
19
|
-
@type = 'payment'
|
20
|
-
end
|
21
|
-
|
22
|
-
include API::Actions::Create
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
module Import
|
3
|
-
module Transactions
|
4
|
-
class Refund < APIResource
|
5
|
-
set_resource_name 'Refund Transaction'
|
6
|
-
set_resource_path '/v1/import/invoices/:invoice_uuid/transactions'
|
7
|
-
|
8
|
-
readonly_attr :uuid
|
9
|
-
|
10
|
-
writeable_attr :type, default: 'refund'
|
11
|
-
writeable_attr :date, type: :time
|
12
|
-
writeable_attr :result
|
13
|
-
writeable_attr :external_id
|
14
|
-
|
15
|
-
writeable_attr :invoice_uuid
|
16
|
-
|
17
|
-
def initialize(attributes = {})
|
18
|
-
super(attributes)
|
19
|
-
@type = 'refund'
|
20
|
-
end
|
21
|
-
|
22
|
-
include API::Actions::Create
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|