solidus_subscriptions 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +41 -0
  3. data/.gem_release.yml +5 -0
  4. data/.github/stale.yml +17 -0
  5. data/.github_changelog_generator +2 -0
  6. data/.gitignore +20 -0
  7. data/.rspec +2 -0
  8. data/.rubocop.yml +12 -0
  9. data/.rubocop_todo.yml +86 -0
  10. data/CHANGELOG.md +191 -0
  11. data/Gemfile +33 -0
  12. data/LICENSE +26 -0
  13. data/README.md +221 -0
  14. data/Rakefile +6 -0
  15. data/app/assets/javascripts/spree/backend/solidus_subscriptions.js +1 -0
  16. data/app/assets/javascripts/spree/backend/solidus_subscriptions/edit_subscription_payment.js +32 -0
  17. data/app/controllers/solidus_subscriptions/api/v1/base_controller.rb +13 -0
  18. data/app/controllers/solidus_subscriptions/api/v1/line_items_controller.rb +48 -0
  19. data/app/controllers/solidus_subscriptions/api/v1/subscriptions_controller.rb +100 -0
  20. data/app/controllers/spree/admin/installments_controller.rb +25 -0
  21. data/app/controllers/spree/admin/subscription_events_controller.rb +37 -0
  22. data/app/controllers/spree/admin/subscription_orders_controller.rb +35 -0
  23. data/app/controllers/spree/admin/subscriptions_controller.rb +100 -0
  24. data/app/controllers/spree/admin/users/subscriptions_controller.rb +17 -0
  25. data/app/decorators/controllers/solidus_subscriptions/spree/api/line_items_controller/create_subscription_line_items.rb +36 -0
  26. data/app/decorators/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items.rb +35 -0
  27. data/app/decorators/models/solidus_subscriptions/spree/line_item/subscription_line_items_association.rb +26 -0
  28. data/app/decorators/models/solidus_subscriptions/spree/order/after_create.rb +19 -0
  29. data/app/decorators/models/solidus_subscriptions/spree/order/finalize_creates_subscriptions.rb +23 -0
  30. data/app/decorators/models/solidus_subscriptions/spree/order/installment_details_association.rb +15 -0
  31. data/app/decorators/models/solidus_subscriptions/spree/order/subscription_association.rb +15 -0
  32. data/app/decorators/models/solidus_subscriptions/spree/order/subscription_line_items_association.rb +19 -0
  33. data/app/decorators/models/solidus_subscriptions/spree/product/delegate_subscribable.rb +17 -0
  34. data/app/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions.rb +30 -0
  35. data/app/decorators/models/solidus_subscriptions/spree/variant/auto_delete_from_subscriptions.rb +20 -0
  36. data/app/decorators/models/solidus_subscriptions/spree/variant/variant_pretty_name.rb +17 -0
  37. data/app/decorators/models/solidus_subscriptions/spree/wallet_payment_source/report_default_change_to_subscriptions.rb +28 -0
  38. data/app/jobs/solidus_subscriptions/process_installment_job.rb +13 -0
  39. data/app/jobs/solidus_subscriptions/process_subscription_job.rb +31 -0
  40. data/app/models/solidus_subscriptions/installment.rb +135 -0
  41. data/app/models/solidus_subscriptions/installment_detail.rb +28 -0
  42. data/app/models/solidus_subscriptions/interval.rb +26 -0
  43. data/app/models/solidus_subscriptions/line_item.rb +42 -0
  44. data/app/models/solidus_subscriptions/promotion/rules/subscription_creation_order.rb +44 -0
  45. data/app/models/solidus_subscriptions/promotion/rules/subscription_installment_order.rb +31 -0
  46. data/app/models/solidus_subscriptions/subscription.rb +392 -0
  47. data/app/models/solidus_subscriptions/subscription_event.rb +11 -0
  48. data/app/overrides/views/admin_subscribable_product_checkbox.rb +8 -0
  49. data/app/overrides/views/admin_subscribable_variant_checkbox.rb +8 -0
  50. data/app/overrides/views/admin_subscriptions_menu_link.rb +10 -0
  51. data/app/overrides/views/admin_users_subscriptions_tab.rb +8 -0
  52. data/app/overrides/views/subscription_line_item_fields.rb +8 -0
  53. data/app/subscribers/solidus_subscriptions/churn_buster_subscriber.rb +39 -0
  54. data/app/subscribers/solidus_subscriptions/event_storage_subscriber.rb +64 -0
  55. data/app/views/spree/admin/installments/_state_pill.html.erb +8 -0
  56. data/app/views/spree/admin/installments/index.html.erb +42 -0
  57. data/app/views/spree/admin/products/_subscribable_checkbox.html.erb +8 -0
  58. data/app/views/spree/admin/promotions/rules/_subscription_creation_order.html.erb +0 -0
  59. data/app/views/spree/admin/promotions/rules/_subscription_installment_order.html.erb +0 -0
  60. data/app/views/spree/admin/shared/_subscription_actions.html.erb +35 -0
  61. data/app/views/spree/admin/shared/_subscription_breadcrumbs.html.erb +4 -0
  62. data/app/views/spree/admin/shared/_subscription_sidebar.html.erb +18 -0
  63. data/app/views/spree/admin/shared/_subscription_tab.html.erb +3 -0
  64. data/app/views/spree/admin/shared/_subscription_tabs.html.erb +18 -0
  65. data/app/views/spree/admin/subscription_events/_state_pill.html.erb +8 -0
  66. data/app/views/spree/admin/subscription_events/index.html.erb +42 -0
  67. data/app/views/spree/admin/subscription_orders/index.html.erb +93 -0
  68. data/app/views/spree/admin/subscriptions/_form.html.erb +150 -0
  69. data/app/views/spree/admin/subscriptions/_processing_state_pill.html.erb +9 -0
  70. data/app/views/spree/admin/subscriptions/_state_pill.html.erb +10 -0
  71. data/app/views/spree/admin/subscriptions/edit.html.erb +10 -0
  72. data/app/views/spree/admin/subscriptions/index.html.erb +176 -0
  73. data/app/views/spree/admin/subscriptions/new.html.erb +5 -0
  74. data/app/views/spree/admin/users/_subscription_tab.html.erb +5 -0
  75. data/app/views/spree/admin/users/subscriptions/index.html.erb +44 -0
  76. data/app/views/spree/admin/variants/_subscribable_checkbox.html.erb +6 -0
  77. data/app/views/spree/frontend/products/_subscription_line_item_fields.html.erb +30 -0
  78. data/bin/console +17 -0
  79. data/bin/rails +7 -0
  80. data/bin/rails-engine +13 -0
  81. data/bin/rails-sandbox +16 -0
  82. data/bin/rake +7 -0
  83. data/bin/sandbox +86 -0
  84. data/bin/setup +8 -0
  85. data/config/initializers/permission_sets.rb +11 -0
  86. data/config/initializers/subscribers.rb +9 -0
  87. data/config/locales/en.yml +129 -0
  88. data/config/routes.rb +34 -0
  89. data/db/migrate/20160825164850_create_solidus_subscriptions_subscriptions.rb +11 -0
  90. data/db/migrate/20160825173548_create_solidus_subscriptions_line_items.rb +17 -0
  91. data/db/migrate/20160825202248_create_solidus_subscriptions_installments.rb +23 -0
  92. data/db/migrate/20160825211202_create_solidus_subscriptions_installment_details.rb +22 -0
  93. data/db/migrate/20160825214240_add_subscribable_to_spree_variants.rb +5 -0
  94. data/db/migrate/20160829201653_change_subscription_line_items_installments_to_max_installments.rb +5 -0
  95. data/db/migrate/20160902220242_remove_state_from_solidus_susbscriptions_installment_details.rb +5 -0
  96. data/db/migrate/20160902220604_add_successful_to_solidus_subscriptions_installment_details.rb +5 -0
  97. data/db/migrate/20160902221218_add_message_to_solidus_subscriptions_installment_details.rb +5 -0
  98. data/db/migrate/20160922164101_add_interval_length_and_units_to_subscription_line_items.rb +8 -0
  99. data/db/migrate/20161006191003_add_skip_count_to_solidus_subscriptions_subscriptions.rb +5 -0
  100. data/db/migrate/20161006191127_add_successive_skip_count_to_solidus_subscriptions_subscriptions.rb +5 -0
  101. data/db/migrate/20161014212649_allow_spree_line_item_id_to_be_null.rb +5 -0
  102. data/db/migrate/20161017155749_add_order_id_to_solidus_subscriptions_installment_details.rb +6 -0
  103. data/db/migrate/20161017175509_remove_order_id_from_solidus_subscriptions_installments.rb +5 -0
  104. data/db/migrate/20161017201944_add_subscription_order_to_spree_orders.rb +5 -0
  105. data/db/migrate/20161221155142_add_store_to_solidus_subscriptions_subscriptions.rb +6 -0
  106. data/db/migrate/20161223152905_add_address_id_to_solidus_subscriptions_subscriptions.rb +7 -0
  107. data/db/migrate/20170106224713_change_line_item_max_installments_to_end_date.rb +6 -0
  108. data/db/migrate/20170111224458_change_subscription_actionable_date_to_datetime.rb +5 -0
  109. data/db/migrate/20170111232801_change_inteval_actionable_date_to_datetime.rb +5 -0
  110. data/db/migrate/20170112012407_add_config_options_to_subscriptions.rb +7 -0
  111. data/db/migrate/20200617102749_add_billing_address_to_subscriptions.rb +11 -0
  112. data/db/migrate/20200617155042_add_payment_source_to_subscriptions.rb +6 -0
  113. data/db/migrate/20200618092951_add_payment_method_to_subscriptions.rb +11 -0
  114. data/db/migrate/20200730101242_create_solidus_subscriptions_subscription_events.rb +22 -0
  115. data/db/migrate/20200917072152_add_subscription_reference_to_orders.rb +11 -0
  116. data/db/migrate/20201007140032_add_guest_token_to_subscriptions.rb +6 -0
  117. data/db/migrate/20201123171026_change_actionable_date_to_date.rb +15 -0
  118. data/db/migrate/20210205140422_add_currency_to_subscription.rb +5 -0
  119. data/db/migrate/20210323165714_update_promotion_rule_names.rb +22 -0
  120. data/lib/generators/solidus_subscriptions/install/install_generator.rb +32 -0
  121. data/lib/generators/solidus_subscriptions/install/templates/initializer.rb +99 -0
  122. data/lib/solidus_subscriptions.rb +49 -0
  123. data/lib/solidus_subscriptions/checkout.rb +74 -0
  124. data/lib/solidus_subscriptions/churn_buster/client.rb +48 -0
  125. data/lib/solidus_subscriptions/churn_buster/order_serializer.rb +19 -0
  126. data/lib/solidus_subscriptions/churn_buster/serializer.rb +23 -0
  127. data/lib/solidus_subscriptions/churn_buster/subscription_customer_serializer.rb +28 -0
  128. data/lib/solidus_subscriptions/churn_buster/subscription_payment_method_serializer.rb +37 -0
  129. data/lib/solidus_subscriptions/churn_buster/subscription_serializer.rb +17 -0
  130. data/lib/solidus_subscriptions/configuration.rb +84 -0
  131. data/lib/solidus_subscriptions/dispatcher/base.rb +18 -0
  132. data/lib/solidus_subscriptions/dispatcher/failure_dispatcher.rb +13 -0
  133. data/lib/solidus_subscriptions/dispatcher/out_of_stock_dispatcher.rb +11 -0
  134. data/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher.rb +19 -0
  135. data/lib/solidus_subscriptions/dispatcher/success_dispatcher.rb +17 -0
  136. data/lib/solidus_subscriptions/engine.rb +56 -0
  137. data/lib/solidus_subscriptions/permission_sets/default_customer.rb +19 -0
  138. data/lib/solidus_subscriptions/permission_sets/subscription_management.rb +12 -0
  139. data/lib/solidus_subscriptions/permitted_attributes.rb +20 -0
  140. data/lib/solidus_subscriptions/processor.rb +17 -0
  141. data/lib/solidus_subscriptions/subscription_generator.rb +77 -0
  142. data/lib/solidus_subscriptions/subscription_line_item_builder.rb +23 -0
  143. data/lib/solidus_subscriptions/testing_support/factories/installment_detail_factory.rb +11 -0
  144. data/lib/solidus_subscriptions/testing_support/factories/installment_factory.rb +29 -0
  145. data/lib/solidus_subscriptions/testing_support/factories/line_item_factory.rb +20 -0
  146. data/lib/solidus_subscriptions/testing_support/factories/spree/line_item_factory.rb +17 -0
  147. data/lib/solidus_subscriptions/testing_support/factories/spree/order_factory.rb +17 -0
  148. data/lib/solidus_subscriptions/testing_support/factories/spree_modification_factory.rb +10 -0
  149. data/lib/solidus_subscriptions/testing_support/factories/subscription_event_factory.rb +8 -0
  150. data/lib/solidus_subscriptions/testing_support/factories/subscription_factory.rb +56 -0
  151. data/lib/solidus_subscriptions/version.rb +5 -0
  152. data/lib/tasks/process_subscriptions.rake +8 -0
  153. data/reference/solidus_subscriptions.v1.yaml +290 -0
  154. data/solidus_subscriptions.gemspec +47 -0
  155. data/spec/controllers/spree/admin/subscriptions_controller_spec.rb +202 -0
  156. data/spec/controllers/spree/api/line_items_controller_spec.rb +103 -0
  157. data/spec/controllers/spree/api/orders_controller_spec.rb +57 -0
  158. data/spec/controllers/spree/api/users_controller_spec.rb +48 -0
  159. data/spec/decorators/controllers/solidus_subscriptions/spree/orders_controller/create_subscription_line_items_spec.rb +80 -0
  160. data/spec/decorators/models/solidus_subscriptions/spree/line_item/subscription_line_items_association_spec.rb +10 -0
  161. data/spec/decorators/models/solidus_subscriptions/spree/order/finalize_creates_subscriptions_spec.rb +32 -0
  162. data/spec/decorators/models/solidus_subscriptions/spree/order/installment_details_association_spec.rb +9 -0
  163. data/spec/decorators/models/solidus_subscriptions/spree/order/subscription_line_items_association_spec.rb +9 -0
  164. data/spec/decorators/models/solidus_subscriptions/spree/user/have_many_subscriptions_spec.rb +22 -0
  165. data/spec/decorators/models/solidus_subscriptions/spree/variant/auto_delete_from_subscriptions_spec.rb +25 -0
  166. data/spec/features/admin/subscription_orders_spec.rb +35 -0
  167. data/spec/features/admin/subscriptions_spec.rb +63 -0
  168. data/spec/features/admin_users_subscription_tabs_spec.rb +61 -0
  169. data/spec/fixtures/cassettes/churn_buster.yml +229 -0
  170. data/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb +38 -0
  171. data/spec/jobs/solidus_subscriptions/process_subscription_job_spec.rb +83 -0
  172. data/spec/lib/solidus_subscriptions/checkout_spec.rb +125 -0
  173. data/spec/lib/solidus_subscriptions/churn_buster/client_spec.rb +59 -0
  174. data/spec/lib/solidus_subscriptions/dispatcher/failure_dispatcher_spec.rb +29 -0
  175. data/spec/lib/solidus_subscriptions/dispatcher/out_of_stock_dispatcher_spec.rb +15 -0
  176. data/spec/lib/solidus_subscriptions/dispatcher/payment_failed_dispatcher_spec.rb +44 -0
  177. data/spec/lib/solidus_subscriptions/dispatcher/success_dispatcher_spec.rb +30 -0
  178. data/spec/lib/solidus_subscriptions/permission_sets/default_customer_spec.rb +95 -0
  179. data/spec/lib/solidus_subscriptions/permission_sets/subscription_management_spec.rb +26 -0
  180. data/spec/lib/solidus_subscriptions/processor_spec.rb +34 -0
  181. data/spec/lib/solidus_subscriptions/promotion/rules/subscription_creation_order_spec.rb +57 -0
  182. data/spec/lib/solidus_subscriptions/promotion/rules/subscription_installment_order_spec.rb +39 -0
  183. data/spec/lib/solidus_subscriptions/subscription_generator_spec.rb +83 -0
  184. data/spec/lib/solidus_subscriptions_spec.rb +30 -0
  185. data/spec/models/solidus_subscriptions/installment_detail_spec.rb +23 -0
  186. data/spec/models/solidus_subscriptions/installment_spec.rb +201 -0
  187. data/spec/models/solidus_subscriptions/line_item_spec.rb +29 -0
  188. data/spec/models/solidus_subscriptions/subscription_spec.rb +814 -0
  189. data/spec/models/spree/variant_spec.rb +16 -0
  190. data/spec/models/spree/wallet_payment_source_spec.rb +20 -0
  191. data/spec/requests/api/v1/line_items_spec.rb +116 -0
  192. data/spec/requests/api/v1/subscriptions_spec.rb +255 -0
  193. data/spec/spec_helper.rb +30 -0
  194. data/spec/subscribers/solidus_subscriptions/churn_buster_subscriber_spec.rb +76 -0
  195. data/spec/support/active_model_mocks.rb +1 -0
  196. data/spec/support/cancancan.rb +1 -0
  197. data/spec/support/factories.rb +1 -0
  198. data/spec/support/helpers/checkout_infrastructure.rb +18 -0
  199. data/spec/support/helpers/config.rb +13 -0
  200. data/spec/support/shoulda.rb +7 -0
  201. data/spec/support/timecop.rb +1 -0
  202. data/spec/support/vcr.rb +10 -0
  203. data/spec/support/version_cake.rb +8 -0
  204. metadata +498 -0
@@ -0,0 +1,150 @@
1
+ <div data-hook="new_subscription">
2
+ <fieldset class="no-border-bottom">
3
+ <legend><%= t('.subscription') %></legend>
4
+
5
+ <div data-hook="admin_subscription_form_fields">
6
+ <% if f.object.new_record? %>
7
+ <div class="field">
8
+ <%= f.label :user_id, I18n.t('spree.user'), class: "required" %>
9
+ <%= f.collection_select :user_id, Spree.user_class.all, :id, :email, {}, class: "select2 fullwidth" %>
10
+ </div>
11
+ <% end %>
12
+
13
+ <div class="field">
14
+ <%= f.label :actionable_date %>
15
+ <%= f.text_field :actionable_date, class: "form-control fullwidth datepicker" %>
16
+ </div>
17
+
18
+ <div class="row">
19
+ <div class="col-6">
20
+ <div class="field">
21
+ <%= f.label :interval_length %>
22
+ <%= f.number_field :interval_length, class: "form-control fullwidth" %>
23
+ </div>
24
+ </div>
25
+
26
+ <div class="col-6">
27
+ <div class="field">
28
+ <%
29
+ unit_values = SolidusSubscriptions::LineItem.interval_units.keys
30
+ units = unit_values.map do |unit|
31
+ [
32
+ SolidusSubscriptions::LineItem.human_attribute_name("interval_units.#{unit}"),
33
+ unit,
34
+ ]
35
+ end
36
+ %>
37
+
38
+ <%= f.label :interval_units %>
39
+ <%= f.select(:interval_units, units, {}, class: 'fullwidth select2') %>
40
+ </div>
41
+ </div>
42
+ </div>
43
+
44
+ <div class="field">
45
+ <%= f.label :end_date %>
46
+ <%= f.text_field :end_date, class: "fullwidth datepicker" %>
47
+ </div>
48
+
49
+ <div class="field">
50
+ <%= f.label :store_id %>
51
+ <%= f.collection_select :store_id, Spree::Store.all, :id, :name, {}, class: 'fullwidth select2' %>
52
+ </div>
53
+ </div>
54
+ </fieldset>
55
+
56
+ <% if @subscription.persisted? && @subscription.user %>
57
+ <div class="js-edit-subscription-payment">
58
+ <fieldset class="no-border-bottom">
59
+ <legend><%= t('spree.admin.subscriptions.edit.payment') %></legend>
60
+
61
+ <div class="field">
62
+ <%= f.label :payment_method %>
63
+ <%= f.select :payment_method_id, @payment_methods.map { |pm| [pm.name, pm.id] }, { include_blank: true }, class: 'select2 fullwidth' %>
64
+ </div>
65
+
66
+ <div class="field">
67
+ <%= f.label :payment_source %>
68
+ <%= f.select :payment_source_id, nil, {}, class: 'select2 fullwidth' do %>
69
+ <option<% if @subscription.payment_source.nil? %> selected<% end %>></option>
70
+ <% @subscription.user.wallet_payment_sources.select { |wps| wps.payment_source.reusable? }.each do |wps| %>
71
+ <option
72
+ value="<%= wps.payment_source_id %>"
73
+ data-js-payment-method-id="<%= wps.payment_source.payment_method.id %>"
74
+ <% if @subscription.payment_source == wps.payment_source %> selected<% end %>
75
+ >
76
+ <% if wps.payment_source.respond_to?(:display_number) %>
77
+ <%= wps.payment_source.display_number %> (<%= wps.payment_source.gateway_customer_profile_id %>)
78
+ <% else %>
79
+ <%= wps.payment_source.gateway_customer_profile_id %>
80
+ <% end %>
81
+ </option>
82
+ <% end %>
83
+ <% end %>
84
+ </div>
85
+ </fieldset>
86
+ </div>
87
+ <% end %>
88
+
89
+ <div class="js-customer-details">
90
+ <div class="row">
91
+ <div class="col-6">
92
+ <fieldset class="no-border-bottom">
93
+ <legend align="center"><%= t('spree.shipping_address') %></legend>
94
+
95
+ <div class="js-shipping-address">
96
+ <%= f.fields_for :shipping_address do |sa_form| %>
97
+ <%= render partial: 'spree/admin/shared/address_form', locals: { f: sa_form, type: "shipping" } %>
98
+ <% end %>
99
+ </div>
100
+ </fieldset>
101
+ </div>
102
+
103
+ <div class="col-6">
104
+ <fieldset class="no-border-bottom">
105
+ <legend align="center"><%= t('spree.billing_address') %></legend>
106
+ <div class="js-billing-address">
107
+ <%= f.fields_for :billing_address do |ba_form| %>
108
+ <%= render partial: 'spree/admin/shared/address_form', locals: { f: ba_form, type: "billing" } %>
109
+ <% end %>
110
+ </div>
111
+ </fieldset>
112
+ </div>
113
+ </div>
114
+ </div>
115
+
116
+ <fieldset>
117
+ <legend><%= t('.subscription_line_items') %></legend>
118
+
119
+ <%= f.fields_for :line_items do |lf| %>
120
+ <div class="row">
121
+ <div class="col-8">
122
+ <div class="field">
123
+ <%= lf.label :subscribable_id %>
124
+ <%= lf.collection_select :subscribable_id, Spree::Variant.where(subscribable: true), :id, :pretty_name, {}, { class: "fullwidth select2" } %>
125
+ </div>
126
+ </div>
127
+
128
+ <div class="col-2">
129
+ <div class="field">
130
+ <%= lf.label :quantity %>
131
+ <%= lf.number_field :quantity, min: 1, class: "form-control fullwidth" %>
132
+ </div>
133
+ </div>
134
+
135
+ <div class="col-2">
136
+ <div class="field align-center">
137
+ <%= lf.label :_destroy %>
138
+ <%= lf.check_box :_destroy, class: "form-control", disabled: lf.object.new_record? %>
139
+ </div>
140
+ </div>
141
+ </div>
142
+ <% end %>
143
+
144
+ <% if f.object.new_record? %>
145
+ <%= render partial: 'spree/admin/shared/new_resource_links' %>
146
+ <% else %>
147
+ <%= render partial: 'spree/admin/shared/edit_resource_links' %>
148
+ <% end %>
149
+ </fieldset>
150
+ </div>
@@ -0,0 +1,9 @@
1
+ <% state_class = {
2
+ success: 'active',
3
+ failed: 'error',
4
+ pending: 'inactive',
5
+ }[subscription.processing_state.to_sym] %>
6
+
7
+ <span class="pill pill-<%= state_class %>">
8
+ <%= subscription.class.human_attribute_name("processing_state.#{subscription.processing_state}") %>
9
+ </span>
@@ -0,0 +1,10 @@
1
+ <% state_class = {
2
+ active: 'active',
3
+ canceled: 'error',
4
+ pending_cancellation: 'warning',
5
+ inactive: 'inactive',
6
+ }[subscription.state.to_sym] %>
7
+
8
+ <span class="pill pill-<%= state_class %>">
9
+ <%= subscription.human_state_name %>
10
+ </span>
@@ -0,0 +1,10 @@
1
+ <% content_for(:page_title) { t('.title') } %>
2
+
3
+ <%= render 'spree/admin/shared/subscription_breadcrumbs', subscription: @subscription %>
4
+ <%= render 'spree/admin/shared/subscription_sidebar', subscription: @subscription %>
5
+ <%= render 'spree/admin/shared/subscription_tabs', current: :details, subscription: @subscription %>
6
+ <%= render 'spree/admin/shared/subscription_actions', subscription: @subscription %>
7
+
8
+ <%= form_for @subscription, url: spree.admin_subscription_path(@subscription) do |f| %>
9
+ <%= render "form", f: f %>
10
+ <% end %>
@@ -0,0 +1,176 @@
1
+ <% admin_breadcrumb(plural_resource_name(SolidusSubscriptions::Subscription)) %>
2
+
3
+ <% content_for :page_actions do %>
4
+ <li><%= link_to t('.new_subscription'), new_admin_subscription_path, class: 'btn btn-primary' %></li>
5
+ <% end %>
6
+
7
+ <% content_for :table_filter_title do %>
8
+ <%= I18n.t('spree.search') %>
9
+ <% end %>
10
+
11
+ <% content_for :table_filter do %>
12
+ <div data-hook="admin_subscriptions_index_search">
13
+ <%= search_form_for [:admin, @search] do |f| %>
14
+ <div class="row">
15
+ <div class="field-block col-6">
16
+ <div class="date-range-filter field">
17
+ <%= label_tag :q_created_at_gt, I18n.t('spree.date_range') %>
18
+ <div class="date-range-fields input-group">
19
+ <%= f.text_field :created_at_gt, class: 'datepicker form-control datepicker-from', placeholder: I18n.t('spree.start') %>
20
+
21
+ <div class="input-group-prepend input-group-append">
22
+ <span class="input-group-text range-divider">
23
+ <i class="fa fa-arrow-right"></i>
24
+ </span>
25
+ </div>
26
+
27
+ <%= f.text_field :created_at_lt, class: 'datepicker form-control datepicker-to', placeholder: I18n.t('spree.stop') %>
28
+ </div>
29
+ </div>
30
+ </div>
31
+
32
+ <div class="field-block col-6">
33
+ <div class="date-range-filter field">
34
+ <%= label_tag :q_actionable_date_gt, SolidusSubscriptions::Subscription.human_attribute_name(:actionable_date) %>
35
+ <div class="date-range-fields input-group">
36
+ <%= f.text_field :actionable_date_gt, class: 'datepicker form-control datepicker-from', placeholder: I18n.t('spree.start') %>
37
+
38
+ <div class="input-group-prepend input-group-append">
39
+ <span class="input-group-text range-divider">
40
+ <i class="fa fa-arrow-right"></i>
41
+ </span>
42
+ </div>
43
+
44
+ <%= f.text_field :actionable_date_lt, class: 'datepicker form-control datepicker-to', placeholder: I18n.t('spree.stop') %>
45
+ </div>
46
+ </div>
47
+ </div>
48
+ </div>
49
+
50
+ <div class="row">
51
+ <div class="field-block col-4">
52
+ <div class="field">
53
+ <%= label_tag :q_user_email_cont, Spree.user_class.human_attribute_name(:email) %>
54
+ <%= f.text_field :user_email_cont, size: 25 %>
55
+ </div>
56
+ </div>
57
+
58
+ <div class="field-block col-4">
59
+ <div class="field">
60
+ <%= label_tag :q_state_eq, SolidusSubscriptions::Subscription.human_attribute_name(:state) %>
61
+ <%= f.select :state_eq, SolidusSubscriptions::Subscription.state_machines[:state].states.map {|s| [s.human_name, s.value]}, {include_blank: true}, class: 'select2 fullwidth' %>
62
+ </div>
63
+ </div>
64
+
65
+ <div class="field-block col-4">
66
+ <div class="field">
67
+ <%= label_tag :q_processing_state_eq, SolidusSubscriptions::Subscription.human_attribute_name(:processing_state) %>
68
+
69
+ <%
70
+ processing_states = SolidusSubscriptions::Subscription.processing_states.map do |state|
71
+ [
72
+ SolidusSubscriptions::Subscription.human_attribute_name("processing_state.#{ state }"),
73
+ state
74
+ ]
75
+ end
76
+ %>
77
+
78
+ <%=
79
+ f.select(
80
+ :in_processing_state,
81
+ options_for_select(processing_states, params.dig(:q, :in_processing_state)),
82
+ { include_blank: true },
83
+ class: 'select2 fullwidth'
84
+ )
85
+ %>
86
+ </div>
87
+ </div>
88
+ </div>
89
+
90
+ <div class="clearfix"></div>
91
+
92
+ <div class="actions filter-actions">
93
+ <div data-hook="admin_subscriptions_index_search_buttons">
94
+ <%= button_tag I18n.t('spree.filter_results'), class: 'btn btn-primary' %>
95
+ </div>
96
+ </div>
97
+ <% end %>
98
+ </div>
99
+ <% end %>
100
+
101
+ <%= paginate @subscriptions, theme: 'solidus_admin' %>
102
+
103
+ <% if @subscriptions.any? %>
104
+ <table id="listing_subscriptions" class="index">
105
+ <thead>
106
+ <tr data-hook="admin_subscriptions_index_headers">
107
+ <th><%= sort_link(@search, :created_at, SolidusSubscriptions::Subscription.human_attribute_name(:created_at)) %></th>
108
+ <th><%= sort_link(@search, :user_email, SolidusSubscriptions::Subscription.human_attribute_name(:user)) %></th>
109
+ <th><%= sort_link(@search, :actionable_date, [:actionable_date, 'id asc'], SolidusSubscriptions::Subscription.human_attribute_name(:actionable_date)) %></th>
110
+ <th><%= sort_link(@search, :line_item_interval_length, SolidusSubscriptions::Subscription.human_attribute_name(:interval)) %></th>
111
+ <th><%= sort_link(@search, :state, [:state, 'id asc'], SolidusSubscriptions::Subscription.human_attribute_name(:state)) %></th>
112
+ <th><%= sort_link(@search, :processing_state, [:processing_state, 'id asc'], SolidusSubscriptions::Subscription.human_attribute_name(:processing_state)) %></th>
113
+ <th data-hook="admin_subscriptions_index_header_actions" class="actions"></th>
114
+ </tr>
115
+ </thead>
116
+
117
+ <tbody>
118
+ <% @subscriptions.each do |subscription| %>
119
+ <tr>
120
+ <td><%= l(subscription.created_at.to_date) %></td>
121
+ <td><%= link_to subscription.user.email, admin_user_path(subscription.user) %></td>
122
+ <td><%= subscription.actionable_date ? l(subscription.actionable_date) : '-' %></td>
123
+ <td><%= subscription.interval.inspect %></td>
124
+ <td><%= render 'state_pill', subscription: subscription %></td>
125
+ <td><%= render 'processing_state_pill', subscription: subscription %></td>
126
+ <td class="actions">
127
+ <% if subscription.state_events.include?(:cancel) %>
128
+ <%=
129
+ link_to_with_icon(
130
+ :stop,
131
+ t('spree.admin.subscriptions.actions.cancel'),
132
+ spree.cancel_admin_subscription_path(subscription),
133
+ no_text: true,
134
+ method: :delete,
135
+ data: { confirm: t('spree.admin.subscriptions.actions.cancel_alert') }
136
+ )
137
+ %>
138
+ <% end %>
139
+
140
+ <% if subscription.state_events.include?(:activate) %>
141
+ <%=
142
+ link_to_with_icon(
143
+ :play,
144
+ t('spree.admin.subscriptions.actions.activate'),
145
+ spree.activate_admin_subscription_path(subscription),
146
+ no_text: true,
147
+ method: :post
148
+ )
149
+ %>
150
+ <% end %>
151
+
152
+ <% if subscription.active? %>
153
+ <%=
154
+ link_to_with_icon(
155
+ :'fast-forward',
156
+ t('spree.admin.subscriptions.actions.skip'),
157
+ spree.skip_admin_subscription_path(subscription),
158
+ no_text: true,
159
+ method: :post
160
+ )
161
+ %>
162
+ <% end %>
163
+
164
+ <%= link_to_edit(subscription, no_text: true) %>
165
+ </td>
166
+ </tr>
167
+ <% end %>
168
+ </tbody>
169
+ </table>
170
+ <% else %>
171
+ <div class="no-objects-found">
172
+ <%= render 'spree/admin/shared/no_objects_found',
173
+ resource: SolidusSubscriptions::Subscription,
174
+ new_resource_url: spree.new_admin_subscription_path %>
175
+ </div>
176
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <% content_for(:page_title) { t('.title') } %>
2
+
3
+ <%= form_for @subscription, url: spree.admin_subscriptions_url, class: "row" do |f| %>
4
+ <%= render "form", f: f %>
5
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <% if can? :admin, SolidusSubscriptions::Subscription.new(user: @user) %>
2
+ <li<%== ' class="active"' if current == :subscriptions %>>
3
+ <%= link_to t("spree.admin.user.subscriptions"), spree.admin_user_subscriptions_path(@user) %>
4
+ </li>
5
+ <% end %>
@@ -0,0 +1,44 @@
1
+ <% admin_breadcrumb(link_to plural_resource_name(Spree::LegacyUser), spree.admin_users_path) %>
2
+ <% admin_breadcrumb(link_to @user.email, edit_admin_user_url(@user)) %>
3
+ <% admin_breadcrumb(plural_resource_name(SolidusSubscriptions::Subscription)) %>
4
+
5
+ <%= render 'spree/admin/users/sidebar' %>
6
+ <%= render 'spree/admin/users/tabs', current: :subscriptions %>
7
+
8
+ <fieldset>
9
+ <legend><%= plural_resource_name(SolidusSubscriptions::Subscription) %></legend>
10
+
11
+ <% if @subscriptions.any? %>
12
+ <table id="subscriptions-table" class="index">
13
+ <thead>
14
+ <tr>
15
+ <th><%= SolidusSubscriptions::Subscription.human_attribute_name(:created_at) %></th>
16
+ <th><%= SolidusSubscriptions::Subscription.human_attribute_name(:actionable_date) %></th>
17
+ <th><%= SolidusSubscriptions::Subscription.human_attribute_name(:interval) %></th>
18
+ <th><%= SolidusSubscriptions::Subscription.human_attribute_name(:state) %></th>
19
+ <th><%= SolidusSubscriptions::Subscription.human_attribute_name(:processing_state) %></th>
20
+ <th class="actions"></th>
21
+ </tr>
22
+ </thead>
23
+
24
+ <tbody>
25
+ <% @subscriptions.each do |subscription| %>
26
+ <tr>
27
+ <td><%= l(subscription.created_at.to_date) %></td>
28
+ <td><%= subscription.actionable_date ? l(subscription.actionable_date) : '-' %></td>
29
+ <td><%= subscription.interval.inspect %></td>
30
+ <td><%= render 'spree/admin/subscriptions/state_pill', subscription: subscription %></td>
31
+ <td><%= render 'spree/admin/subscriptions/processing_state_pill', subscription: subscription %></td>
32
+ <td class="actions">
33
+ <%= link_to_edit(subscription, no_text: true, url: edit_admin_subscription_path(subscription)) %>
34
+ </td>
35
+ </tr>
36
+ <% end %>
37
+ </tbody>
38
+ </table>
39
+ <% else %>
40
+ <div class="no-objects-found">
41
+ <%= render 'spree/admin/shared/no_objects_found', resource: SolidusSubscriptions::Subscription %>
42
+ </div>
43
+ <% end %>
44
+ </fieldset>
@@ -0,0 +1,6 @@
1
+ <div class="field checkbox" data-hook="subscribable">
2
+ <%= f.label :subscribable do %>
3
+ <%= f.check_box :subscribable %>
4
+ <%= Spree::Variant.human_attribute_name(:subscribable) %>
5
+ <% end %>
6
+ </div>
@@ -0,0 +1,30 @@
1
+ <%= content_tag :h3, t('.subscription_fields') %>
2
+ <%= fields_for :'subscription_line_item', SolidusSubscriptions::LineItem.new do |ff| %>
3
+ <div>
4
+ <%= ff.label :quantity, t('.quantity') %>
5
+ <%= ff.number_field :quantity %>
6
+ <%= ff.label :quantity, t('.quantity_suffix') %>
7
+ </div>
8
+
9
+ <div>
10
+ <%= ff.label :interval_length, t('.interval_length') %>
11
+ <%= ff.number_field :interval_length %>
12
+
13
+ <%= ff.collection_radio_buttons :interval_units, SolidusSubscriptions::LineItem.interval_units.to_a, :first, :first %>
14
+ </div>
15
+
16
+ <%= ff.hidden_field :subscribable_id %>
17
+ <% end %>
18
+
19
+ <script>
20
+ document.addEventListener("DOMContentLoaded", function(e) {
21
+ var cartForm = document.querySelector('#cart-form form');
22
+ cartForm.addEventListener('submit', function(e) {
23
+ var quantityInput = e.target.querySelector('[name*="quantity"]');
24
+ var subscriptionQuantityInput = e.target.querySelector('[name*="subscribable_id"]');
25
+
26
+ subscriptionQuantityInput.value = quantityInput.value;
27
+ return true;
28
+ });
29
+ });
30
+ </script>