Class: CreateStripeRemoteRecords

Inherits:
Object
  • Object
show all
Defined in:
app/tasks/create_stripe_remote_records.rb

Class Method Summary collapse

Class Method Details

.runObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/tasks/create_stripe_remote_records.rb', line 2

def self.run
  product = Stripe::Product.create({
                                     name: 'Payroll Automation'
                                   })

  flat_fee = Stripe::Price.create({
                                    product: product.id,
                                    currency: 'cad',
                                    unit_amount: 20_000,
                                    billing_scheme: 'per_unit',
                                    recurring: {
                                      usage_type: 'licensed',
                                      interval: 'month'
                                    }
                                  })

  employees_meter = Stripe::Billing::Meter.create({
                                                    display_name: 'Employees On Payroll',
                                                    event_name: 'employee_on_payroll',
                                                    default_aggregation: { formula: 'sum' },
                                                    value_settings: { event_payload_key: 'employees' },
                                                    customer_mapping: {
                                                      type: 'by_id',
                                                      event_payload_key: 'stripe_customer_id'
                                                    }
                                                  })

  employees_price = Stripe::Price.create({
                                           product: product.id,
                                           currency: 'cad',
                                           billing_scheme: 'tiered',
                                           recurring: {
                                             usage_type: 'metered',
                                             interval: 'month',
                                             meter: employees_meter.id
                                           },
                                           tiers_mode: 'volume',
                                           tiers: [
                                             {
                                               up_to: 5,
                                               unit_amount_decimal: '0'
                                             },
                                             {
                                               up_to: '100',
                                               unit_amount_decimal: '2000'
                                             },
                                             {
                                               up_to: 'inf',
                                               unit_amount_decimal: '1000'
                                             }
                                           ]
                                         })

  companies_meter = Stripe::Billing::Meter.create({
                                                    display_name: 'Managed Companies',
                                                    event_name: 'managed_companies',
                                                    default_aggregation: { formula: 'sum' },
                                                    value_settings: { event_payload_key: 'companies' },
                                                    customer_mapping: {
                                                      type: 'by_id',
                                                      event_payload_key: 'stripe_customer_id'
                                                    }
                                                  })

  companies_price = Stripe::Price.create({
                                           product: product.id,
                                           currency: 'cad',
                                           billing_scheme: 'tiered',
                                           recurring: {
                                             usage_type: 'metered',
                                             interval: 'month',
                                             meter: companies_meter.id
                                           },
                                           tiers_mode: 'volume',
                                           tiers: [
                                             {
                                               up_to: 1,
                                               unit_amount_decimal: '0'
                                             },
                                             {
                                               up_to: '10',
                                               unit_amount_decimal: '5000'
                                             },
                                             {
                                               up_to: 'inf',
                                               unit_amount_decimal: '3000'
                                             }
                                           ]
                                         })

  puts "Product ID: #{product.id}"
  puts "Flat Fee Price ID: #{flat_fee.id}"
  puts "Employees Price ID: #{employees_price.id}"
  puts "Companies Price ID: #{companies_price.id}"
end