paid_up 0.8.1 → 0.9.0

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
  SHA1:
3
- metadata.gz: 7bcbfa8b886ace05a249ff1dda01562116d7eb5c
4
- data.tar.gz: 9a3e88ec68321ae0e03bfd6512ebabbbdff00772
3
+ metadata.gz: 7db38d9e4239f5e00398569781f9815754cb17d4
4
+ data.tar.gz: 1fca9230db0e9c5566cba8b45788a5ba62605a9a
5
5
  SHA512:
6
- metadata.gz: 2510e57c6c5805f76283610c48cd22ec1d09691c0c199d74177cbdc00b8357d9eb8c591d628f8b9ed4716bb84cdf748074381a5dea5a8644cd32785cb973305b
7
- data.tar.gz: 82ab394b686c6ae14194f01ee8a89fe9b5a80af9d71e408d12180ca7b78200e06f8b94a29687fbd60507e69bb269d3683cbb3dbf6d83398c6919befc34574a65
6
+ metadata.gz: 7c231aa9bc9fe587e2a4fc3319df4475babdd602165975fa4f404065f253a6cf520934d0865c497a4790d43ebf9dcedcc704f7e5c1d2cecfd754f38972469b69
7
+ data.tar.gz: f875a8cd9d45dffeb709a3293a34e81880567799d2958ee3086f102b8fe262c1b917a2ff7bfe3a789778459f117aac63a52e8e66f871fe9bbc51ed3dcb9f479e
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Build Status](https://travis-ci.org/gemvein/paid_up.svg)](https://travis-ci.org/gemvein/paid_up)
5
5
  [![Coverage Status](https://coveralls.io/repos/gemvein/paid_up/badge.png)](https://coveralls.io/r/gemvein/paid_up)
6
6
 
7
- Paid Up is a start-to-finish Stripe subscription engine. You set up the plans you want on Stripe, and the gem gives you a way to tie those plans to authenticated users, granting them abilities based on the features outlined for their plan.
7
+ Paid Up is a start-to-finish Stripe subscription engine. You set up the plans and coupons you want on Stripe, and the gem gives you a way to tie those plans and coupons to authenticated users, granting them abilities based on the features outlined for their plan.
8
8
 
9
9
  * Ruby 2, Rails 4
10
10
  * Authentication by Devise
@@ -37,7 +37,11 @@ Set your environment variables with your STRIPE_PUBLISHABLE_KEY and your STRIPE_
37
37
 
38
38
  ## Stripe Setup
39
39
 
40
- Using your own code or Stripe's convenient web interface, add the plans you intend to offer. Each will also need a record in your own database, so for each `Stripe::Plan` you create, note the `id` and use it as the `stripe_id` in the corresponding `PaidUp::Plan`. At a minimum, you will need an anonymous plan, a free plan, both with a cost amount of `0`; and also at least one paid plan.
40
+ Using your own code or Stripe's convenient web interface, add the plans and coupons you intend to offer.
41
+
42
+ Each plan will also need a record in your own database, so for each `Stripe::Plan` you create, note the `id` and use it as the `stripe_id` in the corresponding `PaidUp::Plan`. At a minimum, you will need an anonymous plan, a free plan, both with a cost amount of `0`; and also at least one paid plan.
43
+
44
+ Coupons do not need any further configuration, other than adding them to your Stripe Account.
41
45
 
42
46
  Next, add a `Stripe::Customer` to serve as the Anonymous User, and subscribe that customer to the anonymous plan. Note the customer's `id` and copy that into your stripe configuration file.
43
47
 
@@ -97,7 +101,15 @@ The resources referred to in your config will need to call `paid_for`, like this
97
101
 
98
102
  ### Upgrading
99
103
 
100
- Version 0.8.0 introduced database changes to the foreign key columns to work with Rails 4.2.5. Let me know if you need help migrating your app to the newly named foreign keys.
104
+ #### Version 0.9.0
105
+
106
+ Version 0.9.0 enabled coupon codes, which are saved on the user's record. Be sure to run `rake paid_up:install:migrations` and migrate your database after upgrading.
107
+
108
+ #### Version 0.8.0
109
+
110
+ Version 0.8.0 introduced database changes to the foreign key columns to work with namespacing in Rails 4.2.5:
111
+
112
+ `paid_up_plan_feature_settings`.`plan_id` must be changed to `paid_up_plan_feature_settings`.`paid_up_plan_id`.
101
113
 
102
114
  ## Contributing to Paid Up
103
115
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.1
1
+ 0.9.0
@@ -16,6 +16,7 @@ module PaidUp
16
16
 
17
17
  def create
18
18
  # @plan set by #set_plan
19
+ current_user.update_attribute(:coupon_code, params[:coupon_code])
19
20
  if current_user.subscribe_to_plan(@plan, params[:stripeToken])
20
21
  redirect_to subscriptions_path, flash: { notice: :you_are_now_subscribed_to_the_plan.l(plan_name: current_user.plan.title) }
21
22
  else
@@ -2,8 +2,24 @@ module PaidUp
2
2
  module PlansHelper
3
3
  include ::ActionView::Helpers::NumberHelper
4
4
 
5
- def plan_charge_human(plan)
6
- plan.money.format + '/' + plan_period_phrase(plan)
5
+ def plan_charge_human(plan, discount)
6
+ if !discount.nil? and !discount.coupon.nil?
7
+ orig_amount = plan.amount
8
+ amount = orig_amount
9
+ amount -= (discount.coupon.percent_off || 0) * 0.01 * amount
10
+ amount -= (discount.coupon.amount_off || 0)
11
+ amount = amount > 0 ? amount : 0
12
+
13
+ orig_money = Money.new(orig_amount, plan.currency)
14
+ money = Money.new(amount, plan.currency)
15
+
16
+ html = content_tag :s, (orig_money.format + '/' + plan_period_phrase(plan))
17
+ html << ' '
18
+ html << content_tag(:span, (money.format + '/' + plan_period_phrase(plan)), class: 'text-danger')
19
+ else
20
+ html = plan.money.format + '/' + plan_period_phrase(plan)
21
+ end
22
+ html
7
23
  end
8
24
 
9
25
  def plan_period_phrase(plan)
@@ -9,7 +9,7 @@
9
9
  - for plan in plans
10
10
  %tr{ class: highlight_plan == plan ? 'info' : ''}
11
11
  %td= plan.title
12
- %td= plan_charge_human plan
12
+ %td= plan_charge_human plan, user_signed_in? ? current_user.stripe_data.discount : nil
13
13
  - for feature in features
14
14
  %td= feature_display feature, plan
15
15
  - if should_add_buttons
@@ -6,7 +6,7 @@
6
6
  .well
7
7
  %h2
8
8
  = plan.title
9
- .small= plan_charge_human plan
9
+ .small= plan_charge_human plan, user_signed_in? ? current_user.stripe_data.discount : nil
10
10
  %p= plan.description.html_safe
11
11
  %div{class:plan.title.gsub(' ',"_").downcase+'_subscribe_button'}
12
12
  = plan_button plan
@@ -2,7 +2,7 @@
2
2
 
3
3
  %h2
4
4
  = current_user.plan.title
5
- .small= plan_charge_human current_user.plan
5
+ .small= plan_charge_human current_user.plan, current_user.stripe_data.discount
6
6
 
7
7
  = subscription_dl current_user.subscription
8
8
 
@@ -4,7 +4,7 @@
4
4
  = features_table only: @plan, should_add_buttons: false
5
5
 
6
6
  %h2= :select_payment_info.l
7
- %p= :you_will_be_charged.l charge_amount: plan_charge_human(@plan)
7
+ %p= :you_will_be_charged.l charge_amount: plan_charge_human(@plan, current_user.stripe_data.discount)
8
8
  .row
9
9
  .col-md-6
10
10
  = form_tag paid_up.plan_subscriptions_path(@plan), class: 'form-horizontal', id: 'payment-form' do
@@ -49,6 +49,11 @@
49
49
  .col-xs-2
50
50
  /
51
51
  %input.form-control#exp-year.col-xs-1{ size: '4', data: { stripe: 'exp-year' } }
52
+ .form-group
53
+ %label.control-label.col-xs-2{for: 'coupon_code'}
54
+ = :coupon_code.l
55
+ .col-md-10
56
+ %input.form-control#coupon_code{ size: '16', name: 'coupon_code', value: current_user.coupon_code }
52
57
  .form-group
53
58
  .col-xs-10.col-xs-offset-2
54
59
  %button#submit-button.form-control.btn.btn-info
@@ -35,6 +35,7 @@ en:
35
35
  could_not_create_subscription: 'Could not create subscription'
36
36
  could_not_subscribe_to_plan: "Could not subscribe to %{plan}"
37
37
  could_not_update_subscription: 'Could not update subscription'
38
+ coupon_code: 'Coupon Code'
38
39
  currently_awaiting_confirmation_for_resource: "Currently awaiting confirmation for %{resource}"
39
40
  cvc: 'CVC'
40
41
  default_currency: 'usd'
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "result": {
3
- "covered_percent": 95.52
3
+ "covered_percent": 95.74
4
4
  }
5
5
  }
@@ -140,7 +140,7 @@
140
140
  null,
141
141
  null,
142
142
  1,
143
- 79,
143
+ 97,
144
144
  null,
145
145
  null,
146
146
  1,
@@ -166,7 +166,7 @@
166
166
  null,
167
167
  null,
168
168
  1,
169
- 1356,
169
+ 1374,
170
170
  null,
171
171
  null,
172
172
  null,
@@ -182,7 +182,7 @@
182
182
  1,
183
183
  null,
184
184
  1,
185
- 1356,
185
+ 1374,
186
186
  null,
187
187
  null,
188
188
  1,
@@ -202,7 +202,7 @@
202
202
  null,
203
203
  null,
204
204
  1,
205
- 1275,
205
+ 1293,
206
206
  null,
207
207
  null,
208
208
  1,
@@ -232,12 +232,12 @@
232
232
  null,
233
233
  1,
234
234
  null,
235
- 1,
235
+ 3,
236
236
  0,
237
- 1,
237
+ 3,
238
238
  1,
239
239
  null,
240
- 0,
240
+ 2,
241
241
  null,
242
242
  null,
243
243
  null,
@@ -297,8 +297,8 @@
297
297
  1,
298
298
  null,
299
299
  1,
300
- 486,
301
- 486,
300
+ 498,
301
+ 498,
302
302
  null,
303
303
  1,
304
304
  null,
@@ -359,13 +359,13 @@
359
359
  1,
360
360
  null,
361
361
  1,
362
- 50,
363
- 50,
364
- 50,
362
+ 65,
363
+ 65,
364
+ 65,
365
365
  null,
366
366
  1,
367
- 1638,
368
- 1638,
367
+ 1842,
368
+ 1842,
369
369
  null,
370
370
  null,
371
371
  1,
@@ -376,31 +376,39 @@
376
376
  null,
377
377
  null,
378
378
  1,
379
- 44,
380
- 37,
381
- 6,
379
+ 56,
380
+ 49,
381
+ 9,
382
+ 9,
383
+ 9,
384
+ null,
385
+ 49,
382
386
  6,
383
387
  6,
384
388
  null,
385
- 37,
386
- 37,
389
+ 49,
390
+ 49,
387
391
  null,
388
392
  7,
389
393
  null,
390
394
  null,
391
395
  null,
396
+ null,
397
+ 7,
392
398
  0,
393
399
  null,
394
400
  7,
401
+ null,
402
+ 7,
395
403
  7,
396
404
  null,
397
405
  0,
398
406
  null,
399
407
  null,
400
- 44,
401
- 44,
402
- 44,
403
- 44,
408
+ 56,
409
+ 56,
410
+ 56,
411
+ 56,
404
412
  null,
405
413
  0,
406
414
  null,
@@ -409,7 +417,7 @@
409
417
  2,
410
418
  null,
411
419
  1,
412
- 656,
420
+ 662,
413
421
  null,
414
422
  1,
415
423
  21,
@@ -443,10 +451,10 @@
443
451
  2,
444
452
  null,
445
453
  1,
446
- 793,
454
+ 841,
447
455
  0,
448
456
  null,
449
- 793,
457
+ 841,
450
458
  null,
451
459
  1,
452
460
  201,
@@ -461,32 +469,32 @@
461
469
  2,
462
470
  null,
463
471
  1,
464
- 273,
472
+ 300,
465
473
  30,
466
474
  null,
467
475
  null,
468
476
  1,
469
477
  1,
470
- 323,
478
+ 365,
471
479
  30,
472
480
  null,
473
- 293,
481
+ 335,
474
482
  0,
475
483
  null,
476
- 293,
484
+ 335,
477
485
  null,
478
486
  null,
479
- 323,
480
- 44,
487
+ 365,
488
+ 56,
481
489
  null,
482
490
  null,
483
- 323,
491
+ 365,
484
492
  0,
485
493
  null,
486
494
  null,
487
495
  1,
488
496
  1,
489
- 14,
497
+ 32,
490
498
  7,
491
499
  null,
492
500
  null,
@@ -1084,6 +1092,7 @@
1084
1092
  1,
1085
1093
  null,
1086
1094
  null,
1095
+ null,
1087
1096
  1,
1088
1097
  1,
1089
1098
  null,
@@ -1138,9 +1147,9 @@
1138
1147
  ],
1139
1148
  "/Users/karen/Gems/paid_up/spec/support/features.rb": [
1140
1149
  1,
1141
- 210,
1142
- 210,
1143
- 210,
1150
+ 216,
1151
+ 216,
1152
+ 216,
1144
1153
  null
1145
1154
  ],
1146
1155
  "/Users/karen/Gems/paid_up/spec/support/groups.rb": [
@@ -1162,11 +1171,11 @@
1162
1171
  ],
1163
1172
  "/Users/karen/Gems/paid_up/spec/support/plans.rb": [
1164
1173
  1,
1165
- 210,
1166
- 210,
1167
- 210,
1168
- 210,
1169
- 210,
1174
+ 216,
1175
+ 216,
1176
+ 216,
1177
+ 216,
1178
+ 216,
1170
1179
  null
1171
1180
  ],
1172
1181
  "/Users/karen/Gems/paid_up/spec/support/stripe.rb": [
@@ -1177,11 +1186,11 @@
1177
1186
  null,
1178
1187
  null,
1179
1188
  null,
1180
- 6,
1189
+ 9,
1181
1190
  null,
1182
1191
  null,
1183
1192
  1,
1184
- 6,
1193
+ 9,
1185
1194
  0,
1186
1195
  null,
1187
1196
  null,
@@ -1191,13 +1200,13 @@
1191
1200
  null,
1192
1201
  null,
1193
1202
  null,
1194
- 6,
1203
+ 9,
1195
1204
  null
1196
1205
  ],
1197
1206
  "/Users/karen/Gems/paid_up/spec/support/users.rb": [
1198
1207
  1,
1199
- 41,
1200
- 37,
1208
+ 44,
1209
+ 40,
1201
1210
  29,
1202
1211
  59,
1203
1212
  16,
@@ -1222,7 +1231,7 @@
1222
1231
  null,
1223
1232
  1,
1224
1233
  1,
1225
- 30,
1234
+ 36,
1226
1235
  null,
1227
1236
  null,
1228
1237
  null
@@ -1322,6 +1331,22 @@
1322
1331
  null,
1323
1332
  1,
1324
1333
  176,
1334
+ 12,
1335
+ 12,
1336
+ 12,
1337
+ 12,
1338
+ 12,
1339
+ null,
1340
+ 12,
1341
+ 12,
1342
+ null,
1343
+ 12,
1344
+ 12,
1345
+ 12,
1346
+ null,
1347
+ 164,
1348
+ null,
1349
+ 176,
1325
1350
  null,
1326
1351
  null,
1327
1352
  1,
@@ -1399,7 +1424,7 @@
1399
1424
  null,
1400
1425
  1,
1401
1426
  1,
1402
- 26,
1427
+ 32,
1403
1428
  null,
1404
1429
  1,
1405
1430
  1,
@@ -1521,6 +1546,7 @@
1521
1546
  1,
1522
1547
  1,
1523
1548
  1,
1549
+ 1,
1524
1550
  3,
1525
1551
  3,
1526
1552
  3,
@@ -1538,6 +1564,45 @@
1538
1564
  2,
1539
1565
  null,
1540
1566
  null,
1567
+ 1,
1568
+ 1,
1569
+ 3,
1570
+ 3,
1571
+ 3,
1572
+ null,
1573
+ 1,
1574
+ 3,
1575
+ null,
1576
+ 1,
1577
+ 3,
1578
+ 2,
1579
+ 2,
1580
+ null,
1581
+ 1,
1582
+ 2,
1583
+ 2,
1584
+ null,
1585
+ null,
1586
+ null,
1587
+ null,
1588
+ 1,
1589
+ 1,
1590
+ 1,
1591
+ 3,
1592
+ 3,
1593
+ null,
1594
+ 1,
1595
+ 3,
1596
+ null,
1597
+ 1,
1598
+ 3,
1599
+ 2,
1600
+ 2,
1601
+ null,
1602
+ 1,
1603
+ 2,
1604
+ 2,
1605
+ null,
1541
1606
  null,
1542
1607
  1,
1543
1608
  1,
@@ -1559,6 +1624,7 @@
1559
1624
  null,
1560
1625
  null,
1561
1626
  null,
1627
+ null,
1562
1628
  null
1563
1629
  ],
1564
1630
  "/Users/karen/Gems/paid_up/app/controllers/paid_up/subscriptions_controller.rb": [
@@ -1580,8 +1646,9 @@
1580
1646
  null,
1581
1647
  1,
1582
1648
  null,
1583
- 12,
1584
- 12,
1649
+ 18,
1650
+ 18,
1651
+ 18,
1585
1652
  null,
1586
1653
  0,
1587
1654
  null,
@@ -1595,7 +1662,7 @@
1595
1662
  null,
1596
1663
  1,
1597
1664
  1,
1598
- 16,
1665
+ 22,
1599
1666
  null,
1600
1667
  null,
1601
1668
  null
@@ -1877,7 +1944,7 @@
1877
1944
  1,
1878
1945
  1,
1879
1946
  null,
1880
- 1736,
1947
+ 1778,
1881
1948
  54,
1882
1949
  4,
1883
1950
  null,
@@ -1937,7 +2004,7 @@
1937
2004
  null,
1938
2005
  null,
1939
2006
  1,
1940
- 180,
2007
+ 168,
1941
2008
  null,
1942
2009
  null,
1943
2010
  1,
@@ -1945,8 +2012,8 @@
1945
2012
  null,
1946
2013
  null,
1947
2014
  1,
1948
- 182,
1949
- 182,
2015
+ 194,
2016
+ 194,
1950
2017
  null,
1951
2018
  0,
1952
2019
  null,
@@ -1955,8 +2022,8 @@
1955
2022
  1,
1956
2023
  null,
1957
2024
  1,
1958
- 1856,
1959
- 1851,
2025
+ 1898,
2026
+ 1893,
1960
2027
  5,
1961
2028
  null,
1962
2029
  null,
@@ -2834,6 +2901,6 @@
2834
2901
  null
2835
2902
  ]
2836
2903
  },
2837
- "timestamp": 1454871905
2904
+ "timestamp": 1455131667
2838
2905
  }
2839
2906
  }
@@ -0,0 +1,5 @@
1
+ class AddCouponCodeColumnToUsers < ActiveRecord::Migration
2
+ def change
3
+ add_column :users, :coupon_code, :string
4
+ end
5
+ end
@@ -35,14 +35,22 @@ module PaidUp::Mixins
35
35
  subscription.save
36
36
  reload
37
37
  end
38
+ if coupon_code.present?
39
+ stripe_data.coupon = coupon_code
40
+ stripe_data.save
41
+ end
38
42
  subscription.plan = plan_to_set.stripe_id
39
43
  result = subscription.save || ( raise(:could_not_update_subscription.l) && false )
40
44
  else # Totally new subscription
41
- customer = Stripe::Customer.create(
42
- :source => stripeToken,
43
- :plan => plan_to_set.stripe_id,
44
- :email => email
45
- ) || ( raise(:could_not_create_subscription.l) && false )
45
+ args = {
46
+ source: stripeToken,
47
+ plan: plan_to_set.stripe_id,
48
+ email: email
49
+ }
50
+ if coupon_code.present?
51
+ args[:coupon] = coupon_code
52
+ end
53
+ customer = Stripe::Customer.create(args) || ( raise(:could_not_create_subscription.l) && false )
46
54
 
47
55
  if stripe_id != customer.id # There is an update to be made, so we go ahead
48
56
  result = update_attributes(stripe_id: customer.id) || ( raise(:could_not_associate_subscription.l) && false )
data/paid_up.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: paid_up 0.8.1 ruby lib
5
+ # stub: paid_up 0.9.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "paid_up"
9
- s.version = "0.8.1"
9
+ s.version = "0.9.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Karen Lundgren"]
14
- s.date = "2016-02-07"
14
+ s.date = "2016-02-10"
15
15
  s.description = "Allows a model of your choosing (such as users) to subscribe to a plan, which enables features."
16
16
  s.email = "karen.e.lundgren@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -62,6 +62,7 @@ Gem::Specification.new do |s|
62
62
  "db/migrate/20150407110101_create_paid_up_plans_table.rb",
63
63
  "db/migrate/20150519164237_add_stripe_id_column_to_users.rb",
64
64
  "db/migrate/20160207113800_create_paid_up_plan_feature_settings_table.rb",
65
+ "db/migrate/20160210165128_add_coupon_code_column_to_users.rb",
65
66
  "lib/generators/paid_up/install/install_generator.rb",
66
67
  "lib/generators/paid_up/install/templates/ability.rb",
67
68
  "lib/generators/paid_up/install/templates/initializer.rb",
@@ -133,6 +134,7 @@ Gem::Specification.new do |s|
133
134
  "spec/dummy/db/migrate/20160207184112_create_paid_up_plans_table.paid_up.rb",
134
135
  "spec/dummy/db/migrate/20160207184113_add_stripe_id_column_to_users.paid_up.rb",
135
136
  "spec/dummy/db/migrate/20160207184114_create_paid_up_plan_feature_settings_table.paid_up.rb",
137
+ "spec/dummy/db/migrate/20160210165341_add_coupon_code_column_to_users.paid_up.rb",
136
138
  "spec/dummy/db/schema.rb",
137
139
  "spec/dummy/db/seeds.rb",
138
140
  "spec/dummy/db/test.sqlite3",