solidus_subscriptions-alpha 0.0.3 → 0.0.4
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/LICENSE +26 -26
- data/README.md +130 -130
- data/Rakefile +28 -28
- data/app/assets/javascripts/spree/backend/solidus_subscriptions.js +1 -1
- data/app/assets/javascripts/spree/frontend/solidus_subscriptions.js +1 -1
- data/app/assets/stylesheets/spree/backend/solidus_subscriptions.css +4 -4
- data/app/assets/stylesheets/spree/frontend/solidus_subscriptions.css +4 -4
- data/app/controllers/solidus_subscriptions/api/v1/line_items_controller.rb +35 -35
- data/app/controllers/solidus_subscriptions/api/v1/subscriptions_controller.rb +44 -44
- data/app/controllers/spree/admin/subscriptions_controller.rb +66 -66
- data/app/decorators/spree/controllers/api/line_items/create_subscription_line_items.rb +28 -28
- data/app/decorators/spree/controllers/orders/create_subscription_line_items.rb +33 -33
- data/app/decorators/spree/line_items/subscription_line_items_association.rb +22 -22
- data/app/decorators/spree/orders/after_create.rb +15 -15
- data/app/decorators/spree/orders/finalize_creates_subscriptions.rb +19 -19
- data/app/decorators/spree/orders/subscription_line_items_association.rb +15 -15
- data/app/decorators/spree/products/subscribable_decorator.rb +11 -11
- data/app/decorators/spree/users/have_many_subscriptions.rb +18 -18
- data/app/decorators/spree/variant_pretty_name.rb +13 -13
- data/app/jobs/solidus_subscriptions/process_installments_job.rb +22 -22
- data/app/models/solidus_subscriptions/checkout.rb +141 -141
- data/app/models/solidus_subscriptions/dispatcher.rb +32 -32
- data/app/models/solidus_subscriptions/failure_dispatcher.rb +19 -19
- data/app/models/solidus_subscriptions/installment.rb +126 -126
- data/app/models/solidus_subscriptions/installment_detail.rb +23 -23
- data/app/models/solidus_subscriptions/interval.rb +24 -24
- data/app/models/solidus_subscriptions/line_item.rb +98 -98
- data/app/models/solidus_subscriptions/line_item_builder.rb +44 -44
- data/app/models/solidus_subscriptions/order_builder.rb +40 -40
- data/app/models/solidus_subscriptions/out_of_stock_dispatcher.rb +19 -19
- data/app/models/solidus_subscriptions/payment_failed_dispatcher.rb +23 -23
- data/app/models/solidus_subscriptions/subscription.rb +217 -217
- data/app/models/solidus_subscriptions/subscription_generator.rb +60 -60
- data/app/models/solidus_subscriptions/subscription_line_item_builder.rb +21 -21
- data/app/models/solidus_subscriptions/subscription_order_promotion_rule.rb +25 -25
- data/app/models/solidus_subscriptions/subscription_promotion_rule.rb +38 -38
- data/app/models/solidus_subscriptions/success_dispatcher.rb +16 -16
- data/app/models/solidus_subscriptions/unsubscribable_error.rb +17 -17
- data/app/models/solidus_subscriptions/user_mismatch_error.rb +15 -15
- data/app/overrides/views/admin_subscribable_checkbox.rb +13 -13
- data/app/overrides/views/admin_subscriptions_menu_link.rb +8 -8
- data/app/overrides/views/subscription_line_item_fields.rb +6 -6
- data/app/views/spree/admin/products/_subscribable_checkbox.html.erb +8 -8
- data/app/views/spree/admin/promotions/rules/_subscription_order_promotion_rule.html.erb +0 -0
- data/app/views/spree/admin/promotions/rules/_subscription_promotion_rule.html.erb +0 -0
- data/app/views/spree/admin/shared/_no_objects_found.html.erb +4 -4
- data/app/views/spree/admin/shared/_subscription_tab.html.erb +3 -3
- data/app/views/spree/admin/solidus_subscriptions/subscriptions/_subscription.html.erb +66 -66
- data/app/views/spree/admin/subscriptions/_form.html.erb +81 -81
- data/app/views/spree/admin/subscriptions/_legacy_form.html.erb +81 -81
- data/app/views/spree/admin/subscriptions/_legacy_sidebar.html.erb +28 -28
- data/app/views/spree/admin/subscriptions/edit.html.erb +21 -21
- data/app/views/spree/admin/subscriptions/index.html.erb +119 -119
- data/app/views/spree/admin/subscriptions/new.html.erb +9 -9
- data/app/views/spree/admin/variants/_subscribable_checkbox.html.erb +6 -6
- data/app/views/spree/frontend/products/_subscription_line_item_fields.html.erb +30 -30
- data/config/locales/en.yml +91 -91
- data/config/routes.rb +25 -25
- data/db/migrate/20160825164850_create_solidus_subscriptions_subscriptions.rb +11 -11
- data/db/migrate/20160825173548_create_solidus_subscriptions_line_items.rb +17 -17
- data/db/migrate/20160825202248_create_solidus_subscriptions_installments.rb +23 -23
- data/db/migrate/20160825211202_create_solidus_subscriptions_installment_details.rb +22 -22
- data/db/migrate/20160825214240_add_subscribable_to_spree_variants.rb +5 -5
- data/db/migrate/20160829201653_change_subscription_line_items_installments_to_max_installments.rb +5 -5
- data/db/migrate/20160902220242_remove_state_from_solidus_susbscriptions_installment_details.rb +5 -5
- data/db/migrate/20160902220604_add_successful_to_solidus_subscriptions_installment_details.rb +5 -5
- data/db/migrate/20160902221218_add_message_to_solidus_subscriptions_installment_details.rb +5 -5
- data/db/migrate/20160922164101_add_interval_length_and_units_to_subscription_line_items.rb +8 -8
- data/db/migrate/20161006191003_add_skip_count_to_solidus_subscriptions_subscriptions.rb +5 -5
- data/db/migrate/20161006191127_add_successive_skip_count_to_solidus_subscriptions_subscriptions.rb +5 -5
- data/db/migrate/20161014212649_allow_spree_line_item_id_to_be_null.rb +5 -5
- data/db/migrate/20161017155749_add_order_id_to_solidus_subscriptions_installment_details.rb +6 -6
- data/db/migrate/20161017175509_remove_order_id_from_solidus_subscriptions_installments.rb +6 -6
- data/db/migrate/20161017201944_add_subscription_order_to_spree_orders.rb +5 -5
- data/db/migrate/20161221155142_add_store_to_solidus_subscriptions_subscriptions.rb +6 -6
- data/db/migrate/20161223152905_add_address_id_to_solidus_subscriptions_subscriptions.rb +7 -7
- data/db/migrate/20170106224713_change_line_item_max_installments_to_end_date.rb +6 -6
- data/db/migrate/20170111224458_change_subscription_actionable_date_to_datetime.rb +5 -5
- data/db/migrate/20170111232801_change_inteval_actionable_date_to_datetime.rb +5 -5
- data/db/migrate/20170112012407_add_config_options_to_subscriptions.rb +7 -7
- data/lib/generators/solidus_subscriptions/install/install_generator.rb +30 -30
- data/lib/solidus_subscriptions.rb +6 -6
- data/lib/solidus_subscriptions/ability.rb +19 -19
- data/lib/solidus_subscriptions/config.rb +97 -97
- data/lib/solidus_subscriptions/engine.rb +56 -56
- data/lib/solidus_subscriptions/permitted_attributes.rb +36 -36
- data/lib/solidus_subscriptions/processor.rb +108 -108
- data/lib/solidus_subscriptions/testing_support/factories.rb +5 -5
- data/lib/solidus_subscriptions/testing_support/factories/installment_detail_factory.rb +7 -7
- data/lib/solidus_subscriptions/testing_support/factories/installment_factory.rb +21 -21
- data/lib/solidus_subscriptions/testing_support/factories/line_item_factory.rb +18 -18
- data/lib/solidus_subscriptions/testing_support/factories/spree/line_item_factory.rb +17 -17
- data/lib/solidus_subscriptions/testing_support/factories/spree/order_factory.rb +18 -18
- data/lib/solidus_subscriptions/testing_support/factories/spree_modification_factory.rb +8 -8
- data/lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb +43 -43
- data/lib/solidus_subscriptions/version.rb +3 -3
- data/lib/tasks/process_subscriptions.rake +6 -6
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 39010b56ff2915edd7261baf34bf1f7f363fd242
|
|
4
|
+
data.tar.gz: 371866a39b718967ba7c974411cb765f2ad1cd13
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 388d726ca96e52d9b011e411b19ef52237c9347f30ee73ecfd01c87bb489cb96f27bd5a50518847854a4c13ba76a936d5fb85ce8bd0470b4fe408b0b779050a0
|
|
7
|
+
data.tar.gz: 66f53e74bd7ae568dc2bbd319457b730bad531f9ab8ca32ef6b5e5464529fe6baa345fd22c6d05ee145aa792aaa83aedc977d14bbec8f3f97eef7b68544e7311
|
data/LICENSE
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
Copyright (c) 2016 [name of plugin creator]
|
|
2
|
-
All rights reserved.
|
|
3
|
-
|
|
4
|
-
Redistribution and use in source and binary forms, with or without modification,
|
|
5
|
-
are permitted provided that the following conditions are met:
|
|
6
|
-
|
|
7
|
-
* Redistributions of source code must retain the above copyright notice,
|
|
8
|
-
this list of conditions and the following disclaimer.
|
|
9
|
-
* Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
-
this list of conditions and the following disclaimer in the documentation
|
|
11
|
-
and/or other materials provided with the distribution.
|
|
12
|
-
* Neither the name Spree nor the names of its contributors may be used to
|
|
13
|
-
endorse or promote products derived from this software without specific
|
|
14
|
-
prior written permission.
|
|
15
|
-
|
|
16
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
17
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
18
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
19
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
20
|
-
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
21
|
-
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
22
|
-
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
23
|
-
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
24
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
25
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1
|
+
Copyright (c) 2016 [name of plugin creator]
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
5
|
+
are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
|
8
|
+
this list of conditions and the following disclaimer.
|
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
|
11
|
+
and/or other materials provided with the distribution.
|
|
12
|
+
* Neither the name Spree nor the names of its contributors may be used to
|
|
13
|
+
endorse or promote products derived from this software without specific
|
|
14
|
+
prior written permission.
|
|
15
|
+
|
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
17
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
20
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
21
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
22
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
23
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
24
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
25
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
CHANGED
|
@@ -1,130 +1,130 @@
|
|
|
1
|
-
This is currently a fork of https://github.com/solidusio-contrib/solidus_subscriptions. It supports the alpha version of the gem on rubygems until such a time that an official gem is released.
|
|
2
|
-
|
|
3
|
-
# SolidusSubscriptions
|
|
4
|
-
|
|
5
|
-
A Solidus extension for subscriptions. **Important note**: this is
|
|
6
|
-
**PRE-RELEASE** software and is currently a work-in-progress. There are **no
|
|
7
|
-
guarantees** this will work for your store!
|
|
8
|
-
|
|
9
|
-
Sponsored by [Goby](https://www.goby.co) - Electrify your routine!
|
|
10
|
-
|
|
11
|
-
## Installation
|
|
12
|
-
|
|
13
|
-
Add solidus_subscriptions to your Gemfile:
|
|
14
|
-
|
|
15
|
-
```ruby
|
|
16
|
-
gem 'solidus_subscriptions-alpha', '~> 0.0.1', require: 'solidus_subscriptions'
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
Bundle your dependencies and run the installation generator:
|
|
20
|
-
|
|
21
|
-
```shell
|
|
22
|
-
bundle
|
|
23
|
-
bundle exec rails g solidus_subscriptions:install
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Configuration
|
|
27
|
-
This gem requires a gateway which supports credit cards in order to process
|
|
28
|
-
subscription orders.
|
|
29
|
-
|
|
30
|
-
Add this to specify the gateway used by the gem:
|
|
31
|
-
an initializer.
|
|
32
|
-
|
|
33
|
-
```ruby
|
|
34
|
-
SolidusSubscriptions::Config.default_gateway { my_gateway }
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## Usage
|
|
38
|
-
|
|
39
|
-
### Purchasing Subscriptions
|
|
40
|
-
By default only Spree::Variants can be subscribed to. To subscribe to a variant, it
|
|
41
|
-
must have the `:subscribable` attribute set to true.
|
|
42
|
-
|
|
43
|
-
To subscribe to a variant include the following parameters when posting to
|
|
44
|
-
`/orders/populate` (The add to cart button on the product page):
|
|
45
|
-
|
|
46
|
-
```js
|
|
47
|
-
{
|
|
48
|
-
// other add to cart params
|
|
49
|
-
subscription_line_item: {
|
|
50
|
-
quantity: 2, // number of units in each subscription order.
|
|
51
|
-
subscribable_id: 1234, // Which variant the subscription is for.
|
|
52
|
-
interval_length: 1, // The time between subscription activations.
|
|
53
|
-
interval_units: "month", // A plural qualifier for length.
|
|
54
|
-
// Can be one of "day", "week", "month", or "year".
|
|
55
|
-
end_date: '2011/12/13' // Stop processing after this date
|
|
56
|
-
// (use null to process the subscription ad nauseam)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
This will associate a `SolidusSubscriptions::LineItem` to the line item
|
|
62
|
-
being added to the cart.
|
|
63
|
-
|
|
64
|
-
The customer will not be charged for the subscription until it is processed. The
|
|
65
|
-
subscription line items should be shown to the user on the cart page by
|
|
66
|
-
looping over `Spree::Order#subscription_line_items`.
|
|
67
|
-
`SolidusSubscriptions::LineItem#dummy_line_item` may be useful to help you display
|
|
68
|
-
the subscription line item with your existing cart infrastructure.
|
|
69
|
-
|
|
70
|
-
When the order is finalized, a `SolidusSubscriptions::Subscription` will be
|
|
71
|
-
created for each group of subscription line items which can be fulfilled by a single
|
|
72
|
-
subscription.
|
|
73
|
-
|
|
74
|
-
#### Example:
|
|
75
|
-
|
|
76
|
-
An order is finalized and has following associated subscription line items:
|
|
77
|
-
|
|
78
|
-
1. { subscribable_id: 1, interval_length: 1, interval_units: 'month'}
|
|
79
|
-
2. { subscribable_id: 2, interval_length: 1, interval_units: 'month' }
|
|
80
|
-
3. { subscribable_id: 1, interval_length: 2, interval_units: 'month' }
|
|
81
|
-
|
|
82
|
-
This will generate 2 Subscriptions objects. The first related to
|
|
83
|
-
subscription_line_items 1 & 2. The second related to line item 3.
|
|
84
|
-
|
|
85
|
-
### Processing Subscriptions
|
|
86
|
-
|
|
87
|
-
To process actionable subscriptions simply run:
|
|
88
|
-
|
|
89
|
-
`bundle exec rake solidus_subscriptions:process`
|
|
90
|
-
|
|
91
|
-
To schedule this task we suggest using the [Whenever](https://github.com/javan/whenever) gem.
|
|
92
|
-
|
|
93
|
-
This task creates ActiveJobs which can be fulfilled by the queue library of your
|
|
94
|
-
choice.
|
|
95
|
-
|
|
96
|
-
### Guest Checkout
|
|
97
|
-
|
|
98
|
-
Subscriptions require a user to be present to allow them to be managed after
|
|
99
|
-
they are purchased.
|
|
100
|
-
|
|
101
|
-
Because of this you must disabling guest checkout for orders
|
|
102
|
-
which contain `subscription_line_items`.
|
|
103
|
-
|
|
104
|
-
An example of this would be adding this to the registration page:
|
|
105
|
-
|
|
106
|
-
```erb
|
|
107
|
-
<%# spree/checkout/registration.html.erb %>
|
|
108
|
-
<% if Spree::Config[:allow_guest_checkout] && current_order.subscription_line_items.empty? %>
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
This allows guests to add subscriptions to their carts as guests, but forces them
|
|
112
|
-
to login or create an account before purchasing them.
|
|
113
|
-
|
|
114
|
-
## Testing
|
|
115
|
-
|
|
116
|
-
First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs, and [Rubocop](https://github.com/bbatsov/rubocop) static code analysis. The dummy app can be regenerated by using `rake test_app`.
|
|
117
|
-
|
|
118
|
-
```shell
|
|
119
|
-
bundle
|
|
120
|
-
bundle exec rake
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
When testing your applications integration with this extension you may use it's factories.
|
|
124
|
-
Simply add this require statement to your spec_helper:
|
|
125
|
-
|
|
126
|
-
```ruby
|
|
127
|
-
require 'solidus_subscriptions/testing_support/factories'
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
Copyright (c) 2016 Stembolt, released under the New BSD License
|
|
1
|
+
This is currently a fork of https://github.com/solidusio-contrib/solidus_subscriptions. It supports the alpha version of the gem on rubygems until such a time that an official gem is released.
|
|
2
|
+
|
|
3
|
+
# SolidusSubscriptions
|
|
4
|
+
|
|
5
|
+
A Solidus extension for subscriptions. **Important note**: this is
|
|
6
|
+
**PRE-RELEASE** software and is currently a work-in-progress. There are **no
|
|
7
|
+
guarantees** this will work for your store!
|
|
8
|
+
|
|
9
|
+
Sponsored by [Goby](https://www.goby.co) - Electrify your routine!
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Add solidus_subscriptions to your Gemfile:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem 'solidus_subscriptions-alpha', '~> 0.0.1', require: 'solidus_subscriptions'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Bundle your dependencies and run the installation generator:
|
|
20
|
+
|
|
21
|
+
```shell
|
|
22
|
+
bundle
|
|
23
|
+
bundle exec rails g solidus_subscriptions:install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Configuration
|
|
27
|
+
This gem requires a gateway which supports credit cards in order to process
|
|
28
|
+
subscription orders.
|
|
29
|
+
|
|
30
|
+
Add this to specify the gateway used by the gem:
|
|
31
|
+
an initializer.
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
SolidusSubscriptions::Config.default_gateway { my_gateway }
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
### Purchasing Subscriptions
|
|
40
|
+
By default only Spree::Variants can be subscribed to. To subscribe to a variant, it
|
|
41
|
+
must have the `:subscribable` attribute set to true.
|
|
42
|
+
|
|
43
|
+
To subscribe to a variant include the following parameters when posting to
|
|
44
|
+
`/orders/populate` (The add to cart button on the product page):
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
{
|
|
48
|
+
// other add to cart params
|
|
49
|
+
subscription_line_item: {
|
|
50
|
+
quantity: 2, // number of units in each subscription order.
|
|
51
|
+
subscribable_id: 1234, // Which variant the subscription is for.
|
|
52
|
+
interval_length: 1, // The time between subscription activations.
|
|
53
|
+
interval_units: "month", // A plural qualifier for length.
|
|
54
|
+
// Can be one of "day", "week", "month", or "year".
|
|
55
|
+
end_date: '2011/12/13' // Stop processing after this date
|
|
56
|
+
// (use null to process the subscription ad nauseam)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
This will associate a `SolidusSubscriptions::LineItem` to the line item
|
|
62
|
+
being added to the cart.
|
|
63
|
+
|
|
64
|
+
The customer will not be charged for the subscription until it is processed. The
|
|
65
|
+
subscription line items should be shown to the user on the cart page by
|
|
66
|
+
looping over `Spree::Order#subscription_line_items`.
|
|
67
|
+
`SolidusSubscriptions::LineItem#dummy_line_item` may be useful to help you display
|
|
68
|
+
the subscription line item with your existing cart infrastructure.
|
|
69
|
+
|
|
70
|
+
When the order is finalized, a `SolidusSubscriptions::Subscription` will be
|
|
71
|
+
created for each group of subscription line items which can be fulfilled by a single
|
|
72
|
+
subscription.
|
|
73
|
+
|
|
74
|
+
#### Example:
|
|
75
|
+
|
|
76
|
+
An order is finalized and has following associated subscription line items:
|
|
77
|
+
|
|
78
|
+
1. { subscribable_id: 1, interval_length: 1, interval_units: 'month'}
|
|
79
|
+
2. { subscribable_id: 2, interval_length: 1, interval_units: 'month' }
|
|
80
|
+
3. { subscribable_id: 1, interval_length: 2, interval_units: 'month' }
|
|
81
|
+
|
|
82
|
+
This will generate 2 Subscriptions objects. The first related to
|
|
83
|
+
subscription_line_items 1 & 2. The second related to line item 3.
|
|
84
|
+
|
|
85
|
+
### Processing Subscriptions
|
|
86
|
+
|
|
87
|
+
To process actionable subscriptions simply run:
|
|
88
|
+
|
|
89
|
+
`bundle exec rake solidus_subscriptions:process`
|
|
90
|
+
|
|
91
|
+
To schedule this task we suggest using the [Whenever](https://github.com/javan/whenever) gem.
|
|
92
|
+
|
|
93
|
+
This task creates ActiveJobs which can be fulfilled by the queue library of your
|
|
94
|
+
choice.
|
|
95
|
+
|
|
96
|
+
### Guest Checkout
|
|
97
|
+
|
|
98
|
+
Subscriptions require a user to be present to allow them to be managed after
|
|
99
|
+
they are purchased.
|
|
100
|
+
|
|
101
|
+
Because of this you must disabling guest checkout for orders
|
|
102
|
+
which contain `subscription_line_items`.
|
|
103
|
+
|
|
104
|
+
An example of this would be adding this to the registration page:
|
|
105
|
+
|
|
106
|
+
```erb
|
|
107
|
+
<%# spree/checkout/registration.html.erb %>
|
|
108
|
+
<% if Spree::Config[:allow_guest_checkout] && current_order.subscription_line_items.empty? %>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
This allows guests to add subscriptions to their carts as guests, but forces them
|
|
112
|
+
to login or create an account before purchasing them.
|
|
113
|
+
|
|
114
|
+
## Testing
|
|
115
|
+
|
|
116
|
+
First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs, and [Rubocop](https://github.com/bbatsov/rubocop) static code analysis. The dummy app can be regenerated by using `rake test_app`.
|
|
117
|
+
|
|
118
|
+
```shell
|
|
119
|
+
bundle
|
|
120
|
+
bundle exec rake
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
When testing your applications integration with this extension you may use it's factories.
|
|
124
|
+
Simply add this require statement to your spec_helper:
|
|
125
|
+
|
|
126
|
+
```ruby
|
|
127
|
+
require 'solidus_subscriptions/testing_support/factories'
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Copyright (c) 2016 Stembolt, released under the New BSD License
|
data/Rakefile
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
require 'bundler'
|
|
2
|
-
|
|
3
|
-
Bundler::GemHelper.install_tasks
|
|
4
|
-
|
|
5
|
-
begin
|
|
6
|
-
require 'spree/testing_support/extension_rake'
|
|
7
|
-
require 'rubocop/rake_task'
|
|
8
|
-
require 'rspec/core/rake_task'
|
|
9
|
-
|
|
10
|
-
RSpec::Core::RakeTask.new(:spec)
|
|
11
|
-
|
|
12
|
-
task default: %i(first_run spec)
|
|
13
|
-
rescue LoadError
|
|
14
|
-
# no rspec available
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
task :first_run do
|
|
18
|
-
if Dir['spec/dummy'].empty?
|
|
19
|
-
Rake::Task[:test_app].invoke
|
|
20
|
-
Dir.chdir('../../')
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
desc 'Generates a dummy app for testing'
|
|
25
|
-
task :test_app do
|
|
26
|
-
ENV['LIB_NAME'] = 'solidus_subscriptions'
|
|
27
|
-
Rake::Task['extension:test_app'].invoke
|
|
28
|
-
end
|
|
1
|
+
require 'bundler'
|
|
2
|
+
|
|
3
|
+
Bundler::GemHelper.install_tasks
|
|
4
|
+
|
|
5
|
+
begin
|
|
6
|
+
require 'spree/testing_support/extension_rake'
|
|
7
|
+
require 'rubocop/rake_task'
|
|
8
|
+
require 'rspec/core/rake_task'
|
|
9
|
+
|
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
11
|
+
|
|
12
|
+
task default: %i(first_run spec)
|
|
13
|
+
rescue LoadError
|
|
14
|
+
# no rspec available
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
task :first_run do
|
|
18
|
+
if Dir['spec/dummy'].empty?
|
|
19
|
+
Rake::Task[:test_app].invoke
|
|
20
|
+
Dir.chdir('../../')
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
desc 'Generates a dummy app for testing'
|
|
25
|
+
task :test_app do
|
|
26
|
+
ENV['LIB_NAME'] = 'solidus_subscriptions'
|
|
27
|
+
Rake::Task['extension:test_app'].invoke
|
|
28
|
+
end
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// Placeholder manifest file.
|
|
1
|
+
// Placeholder manifest file.
|
|
2
2
|
// the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/backend/all.js'
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// Placeholder manifest file.
|
|
1
|
+
// Placeholder manifest file.
|
|
2
2
|
// the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/frontend/all.js'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Placeholder manifest file.
|
|
3
|
-
the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css'
|
|
4
|
-
*/
|
|
1
|
+
/*
|
|
2
|
+
Placeholder manifest file.
|
|
3
|
+
the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css'
|
|
4
|
+
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Placeholder manifest file.
|
|
3
|
-
the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/frontend/all.css'
|
|
4
|
-
*/
|
|
1
|
+
/*
|
|
2
|
+
Placeholder manifest file.
|
|
3
|
+
the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/frontend/all.css'
|
|
4
|
+
*/
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
class SolidusSubscriptions::Api::V1::LineItemsController < Spree::Api::BaseController
|
|
2
|
-
before_action :load_line_item, only: [:update, :destroy]
|
|
3
|
-
wrap_parameters :subscription_line_item
|
|
4
|
-
|
|
5
|
-
def update
|
|
6
|
-
authorize! :crud, @line_item, @order
|
|
7
|
-
if @line_item.update(line_item_params)
|
|
8
|
-
render json: @line_item.to_json
|
|
9
|
-
else
|
|
10
|
-
render json: @line_item.errors.to_json, status: 422
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def destroy
|
|
15
|
-
authorize! :crud, @line_item, @order
|
|
16
|
-
return render json: {}, status: 400 if @line_item.order.complete?
|
|
17
|
-
|
|
18
|
-
@line_item.destroy!
|
|
19
|
-
@line_item.order.update!
|
|
20
|
-
|
|
21
|
-
render json: @line_item.to_json
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
private
|
|
25
|
-
|
|
26
|
-
def line_item_params
|
|
27
|
-
params.require(:subscription_line_item).permit(
|
|
28
|
-
SolidusSubscriptions::PermittedAttributes.subscription_line_item_attributes - [:subscribable_id]
|
|
29
|
-
)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def load_line_item
|
|
33
|
-
@line_item = SolidusSubscriptions::LineItem.find(params[:id])
|
|
34
|
-
end
|
|
35
|
-
end
|
|
1
|
+
class SolidusSubscriptions::Api::V1::LineItemsController < Spree::Api::BaseController
|
|
2
|
+
before_action :load_line_item, only: [:update, :destroy]
|
|
3
|
+
wrap_parameters :subscription_line_item
|
|
4
|
+
|
|
5
|
+
def update
|
|
6
|
+
authorize! :crud, @line_item, @order
|
|
7
|
+
if @line_item.update(line_item_params)
|
|
8
|
+
render json: @line_item.to_json
|
|
9
|
+
else
|
|
10
|
+
render json: @line_item.errors.to_json, status: 422
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def destroy
|
|
15
|
+
authorize! :crud, @line_item, @order
|
|
16
|
+
return render json: {}, status: 400 if @line_item.order.complete?
|
|
17
|
+
|
|
18
|
+
@line_item.destroy!
|
|
19
|
+
@line_item.order.update!
|
|
20
|
+
|
|
21
|
+
render json: @line_item.to_json
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def line_item_params
|
|
27
|
+
params.require(:subscription_line_item).permit(
|
|
28
|
+
SolidusSubscriptions::PermittedAttributes.subscription_line_item_attributes - [:subscribable_id]
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def load_line_item
|
|
33
|
+
@line_item = SolidusSubscriptions::LineItem.find(params[:id])
|
|
34
|
+
end
|
|
35
|
+
end
|