Class: CreateTang

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/generators/templates/create_tang.rb

Instance Method Summary collapse

Instance Method Details

#changeObject



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/generators/templates/create_tang.rb', line 2

def change
  create_stripe_webhooks
  create_plans
  create_coupons
  create_customers
  create_subscriptions
  create_cards
  create_invoices
  create_invoice_items
  create_charges
end

#create_cardsObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/generators/templates/create_tang.rb', line 89

def create_cards
  create_table :tang_cards do |t|
    t.integer :customer_id, index: true

    t.string :stripe_id
    t.string :address_line1
    t.string :address_line1_check
    t.string :address_line2
    t.string :address_city
    t.string :address_country
    t.string :address_state
    t.string :address_zip
    t.string :address_zip_check

    t.string :name
    t.string :brand
    t.string :last4
    t.string :dynamic_last4
    t.integer :exp_month
    t.integer :exp_year
    t.string :cvc_check
    t.string :country
    t.string :tokenization_method
    t.string :funding
    t.string :fingerprint

    t.timestamps null: false
  end
end

#create_chargesObject



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/generators/templates/create_tang.rb', line 158

def create_charges
  create_table :tang_charges do |t|
    t.string :stripe_id
    t.integer :amount
    t.string :currency
    t.string :description
    t.string :receipt_email
    t.string :statement_descriptor
    t.integer :invoice_id, index: true, foreign_key: true

    t.string :card_stripe_id
    t.string :card_address_line1
    t.string :card_address_line1_check
    t.string :card_address_line2
    t.string :card_address_city
    t.string :card_address_country
    t.string :card_address_state
    t.string :card_address_zip
    t.string :card_address_zip_check
    t.string :card_name
    t.string :card_brand
    t.string :card_last4
    t.string :card_dynamic_last4
    t.integer :card_exp_month
    t.integer :card_exp_year
    t.string :card_cvc_check
    t.string :card_country
    t.string :card_tokenization_method
    t.string :card_funding
    t.string :card_fingerprint

    t.string :status
    t.timestamp :created

    t.timestamps null: false
  end
end

#create_couponsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/generators/templates/create_tang.rb', line 40

def create_coupons
  create_table :tang_coupons do |t|
    t.string :stripe_id
    t.string :duration
    t.integer :amount_off
    t.string :currency
    t.integer :duration_in_months
    t.integer :max_redemptions
    t.integer :percent_off
    t.timestamp :redeem_by
    t.integer :redemptions

    t.timestamps null: false
  end
end

#create_customersObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/generators/templates/create_tang.rb', line 56

def create_customers
  add_column Tang.customer_class.to_s.downcase.pluralize, :stripe_id, :string
  add_column Tang.customer_class.to_s.downcase.pluralize, :account_balance, :integer
  add_column Tang.customer_class.to_s.downcase.pluralize, :business_vat_id, :string
  add_column Tang.customer_class.to_s.downcase.pluralize, :currency, :string
  add_column Tang.customer_class.to_s.downcase.pluralize, :delinquent, :boolean, null: false, default: false
  add_column Tang.customer_class.to_s.downcase.pluralize, :description, :string
  add_column Tang.customer_class.to_s.downcase.pluralize, :active_until, :timestamp
  add_column Tang.customer_class.to_s.downcase.pluralize, :coupon_id, :integer, index: true, foreign_key: true
  add_column Tang.customer_class.to_s.downcase.pluralize, :coupon_start, :timestamp
  add_column Tang.customer_class.to_s.downcase.pluralize, :subscription_coupon_id, :integer, index: true, foreign_key: true
end

#create_invoice_itemsObject



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/generators/templates/create_tang.rb', line 140

def create_invoice_items
  create_table :tang_invoice_items do |t|
    t.string :stripe_id
    t.integer :amount
    t.string :currency
    t.integer :invoice_id, index: true, foreign_key: true
    t.timestamp :period_start
    t.timestamp :period_end
    t.integer :plan_id, index: true, foreign_key: true
    t.boolean :proration, null: false, default: false
    t.integer :quantity
    t.integer :subscription_id, index: true, foreign_key: true
    t.string :description

    t.timestamps null: false
  end
end

#create_invoicesObject



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/generators/templates/create_tang.rb', line 119

def create_invoices
  create_table :tang_invoices do |t|
    t.string :stripe_id
    t.integer :subscription_id, index: true, foreign_key: true
    t.timestamp :period_start
    t.timestamp :period_end
    t.integer :customer_id, index: true
    t.timestamp :date
    t.string :currency

    t.integer :subtotal
    t.integer :coupon_id, index: true, foreign_key: true
    t.integer :tax_percent
    t.integer :tax
    t.integer :total
    t.integer :amount_due

    t.timestamps null: false
  end
end

#create_plansObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/generators/templates/create_tang.rb', line 22

def create_plans
  create_table :tang_plans do |t|
    t.string :stripe_id
    t.integer :amount
    t.string :currency
    t.string :interval
    t.integer :interval_count
    t.string :name
    t.string :statement_descriptor
    t.integer :trial_period_days
    t.integer :order
    t.boolean :highlight, null: false, default: false
    t.text :features

    t.timestamps null: false
  end
end

#create_stripe_webhooksObject



14
15
16
17
18
19
20
# File 'lib/generators/templates/create_tang.rb', line 14

def create_stripe_webhooks
  create_table :tang_stripe_webhooks do |t|
    t.string :stripe_id

    t.timestamps null: false
  end
end

#create_subscriptionsObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/generators/templates/create_tang.rb', line 69

def create_subscriptions
  create_table :tang_subscriptions do |t|
    t.string :stripe_id
    t.integer :customer_id, index: true
    t.integer :plan_id, index: true, foreign_key: true

    t.decimal :application_fee_percent
    t.integer :quantity
    t.decimal :tax_percent
    t.timestamp :trial_end

    t.integer :coupon_id, index: true, foreign_key: true
    t.timestamp :coupon_start

    t.string :status
    
    t.timestamps null: false
  end
end