workarea-gift_cards 3.4.11 → 4.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/{.eslintrc → .eslintrc.json} +12 -1
  3. data/.github/workflows/ci.yml +10 -8
  4. data/.rubocop.yml +2 -197
  5. data/.stylelintrc.json +8 -0
  6. data/CHANGELOG.md +0 -71
  7. data/Gemfile +3 -5
  8. data/Rakefile +5 -4
  9. data/app/controllers/workarea/api/admin/gift_cards_controller.rb +309 -0
  10. data/app/controllers/workarea/api/storefront/checkouts_controller.decorator +6 -0
  11. data/app/controllers/workarea/api/storefront/gift_cards_controller.rb +2 -8
  12. data/app/controllers/workarea/storefront/checkout/gift_cards_controller.rb +32 -0
  13. data/app/controllers/workarea/storefront/gift_cards_controller.rb +15 -16
  14. data/app/models/workarea/checkout/steps/gift_card.rb +71 -0
  15. data/app/models/workarea/fulfillment/policies/create_gift_card.rb +30 -0
  16. data/app/models/workarea/payment/authorize/gift_card.rb +7 -20
  17. data/app/models/workarea/payment/capture/gift_card.rb +5 -7
  18. data/app/models/workarea/payment/gift_card.rb +1 -1
  19. data/app/models/workarea/payment/gift_card_operation.rb +9 -0
  20. data/app/models/workarea/payment/purchase/gift_card.rb +24 -1
  21. data/app/models/workarea/payment/refund/gift_card.rb +9 -14
  22. data/app/models/workarea/payment/tender/gift_card.rb +3 -10
  23. data/app/models/workarea/payment.decorator +25 -7
  24. data/app/models/workarea/search/admin/order.decorator +2 -4
  25. data/app/seeds/workarea/gift_card_seeds.rb +7 -7
  26. data/app/view_models/workarea/storefront/gift_card_order_pricing.rb +19 -20
  27. data/app/view_models/workarea/storefront/order_view_model.decorator +2 -22
  28. data/app/views/workarea/admin/payment_gift_cards/_menu.html.haml +2 -1
  29. data/app/views/workarea/storefront/checkouts/_gift_card_error.html.haml +8 -6
  30. data/app/views/workarea/storefront/checkouts/_gift_card_payment.html.haml +20 -12
  31. data/app/views/workarea/storefront/gift_card_mailer/created.html.haml +1 -1
  32. data/app/views/workarea/storefront/order_mailer/_gift_card_summary.html.haml +6 -5
  33. data/app/views/workarea/storefront/orders/_gift_card_summary.html.haml +2 -2
  34. data/app/views/workarea/storefront/products/templates/_gift_card.html.haml +5 -5
  35. data/app/workers/workarea/log_gift_card_redemption.rb +16 -9
  36. data/config/initializers/configuration.rb +7 -4
  37. data/config/initializers/fields.rb +14 -0
  38. data/config/locales/en.yml +14 -4
  39. data/config/routes.rb +9 -2
  40. data/lib/workarea/gift_cards/gateway.rb +128 -0
  41. data/lib/workarea/gift_cards/version.rb +1 -1
  42. data/lib/workarea/gift_cards.rb +9 -0
  43. data/test/documentation/workarea/api/admin/gift_cards_documentation_test.rb +24 -10
  44. data/test/documentation/workarea/api/storefront/gift_cards_documentation_test.rb +57 -50
  45. data/test/dummy/config/initializers/session_store.rb +1 -1
  46. data/test/integration/workarea/api/admin/gift_card_integration_test.rb +13 -5
  47. data/test/integration/workarea/api/storefront/checkout_gift_cards_integration_test.rb +120 -0
  48. data/test/integration/workarea/api/storefront/{balance_integration_test.rb → gift_cards_integration_test.rb} +1 -1
  49. data/test/integration/workarea/storefront/checkout_gift_cards_integration_test.rb +116 -0
  50. data/test/integration/workarea/storefront/gift_cards_integration_test.rb +48 -0
  51. data/test/integration/workarea/storefront/purchase_gift_cards_integration_test.rb +55 -0
  52. data/test/lib/workarea/gift_cards/gateway_test.rb +97 -0
  53. data/test/models/workarea/checkout/steps/gift_card_test.rb +104 -0
  54. data/test/models/workarea/fulfillment/policies/create_gift_card_test.rb +47 -0
  55. data/test/models/workarea/gift_card_payment_test.rb +15 -3
  56. data/test/models/workarea/payment/purchase/gift_card_test.rb +11 -8
  57. data/test/queries/workarea/admin_redemptions_export_test.rb +31 -35
  58. data/test/system/workarea/storefront/gift_cards_system_test.rb +8 -2
  59. data/test/view_models/workarea/storefront/gift_card_order_pricing_test.rb +113 -0
  60. data/test/workers/workarea/log_gift_card_redemption_test.rb +1 -1
  61. data/workarea-gift_cards.gemspec +4 -4
  62. metadata +26 -30
  63. data/.eslintignore +0 -2
  64. data/.scss-lint.yml +0 -188
  65. data/app/controllers/workarea/api/admin/payment_gift_cards_controller.rb +0 -49
  66. data/app/controllers/workarea/storefront/checkouts_controller.decorator +0 -24
  67. data/app/services/workarea/checkout/steps/gift_card.rb +0 -49
  68. data/app/view_models/workarea/storefront/checkout/payment_view_model.decorator +0 -32
  69. data/app/view_models/workarea/storefront/checkout/summary_view_model.decorator +0 -11
  70. data/app/workers/workarea/create_ordered_gift_cards.rb +0 -47
  71. data/config/initializers/jump_to_navigation.rb +0 -3
  72. data/test/integration/workarea/api/storefront/checkout_integration_test.rb +0 -161
  73. data/test/integration/workarea/storefront/gift_card_integration_test.rb +0 -226
  74. data/test/services/workarea/checkout/steps/gift_card_test.rb +0 -87
  75. data/test/view_models/workarea/storefront/checkout/gift_card_payment_view_model_test.rb +0 -65
  76. data/test/workers/workarea/create_ordered_gift_cards_test.rb +0 -39
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workarea-gift_cards
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.11
4
+ version: 4.0.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - bcrouse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-02 00:00:00.000000000 Z
11
+ date: 2019-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: workarea
@@ -18,9 +18,6 @@ dependencies:
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.x
20
20
  - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 3.3.x
23
- - - "<"
24
21
  - !ruby/object:Gem::Version
25
22
  version: 3.5.x
26
23
  type: :runtime
@@ -31,28 +28,24 @@ dependencies:
31
28
  - !ruby/object:Gem::Version
32
29
  version: 3.x
33
30
  - - ">="
34
- - !ruby/object:Gem::Version
35
- version: 3.3.x
36
- - - "<"
37
31
  - !ruby/object:Gem::Version
38
32
  version: 3.5.x
39
- description: Adds built-in gift cards to the Workarea commerce platform.
33
+ description: Adds built-in digital gift cards to the Workarea Commerce Platform.
40
34
  email:
41
- - bcrouse@weblinc.com
35
+ - bcrouse@workarea.com
42
36
  executables: []
43
37
  extensions: []
44
38
  extra_rdoc_files: []
45
39
  files:
46
40
  - ".editorconfig"
47
- - ".eslintignore"
48
- - ".eslintrc"
41
+ - ".eslintrc.json"
49
42
  - ".github/ISSUE_TEMPLATE/bug_report.md"
50
43
  - ".github/ISSUE_TEMPLATE/documentation-request.md"
51
44
  - ".github/ISSUE_TEMPLATE/feature_request.md"
52
45
  - ".github/workflows/ci.yml"
53
46
  - ".gitignore"
54
47
  - ".rubocop.yml"
55
- - ".scss-lint.yml"
48
+ - ".stylelintrc.json"
56
49
  - ".yardopts"
57
50
  - CHANGELOG.md
58
51
  - CODE_OF_CONDUCT.md
@@ -65,20 +58,23 @@ files:
65
58
  - app/assets/images/workarea/storefront/payment_icons/gift_card.svg
66
59
  - app/controllers/workarea/admin/data_file_exports_controller.decorator
67
60
  - app/controllers/workarea/admin/payment_gift_cards_controller.rb
68
- - app/controllers/workarea/api/admin/payment_gift_cards_controller.rb
61
+ - app/controllers/workarea/api/admin/gift_cards_controller.rb
69
62
  - app/controllers/workarea/api/storefront/checkouts_controller.decorator
70
63
  - app/controllers/workarea/api/storefront/gift_cards_controller.rb
71
- - app/controllers/workarea/storefront/checkouts_controller.decorator
64
+ - app/controllers/workarea/storefront/checkout/gift_cards_controller.rb
72
65
  - app/controllers/workarea/storefront/gift_cards_controller.rb
73
66
  - app/mailers/workarea/storefront/gift_card_mailer.rb
74
67
  - app/models/workarea/catalog/customizations/gift_card.rb
75
68
  - app/models/workarea/catalog/product.decorator
69
+ - app/models/workarea/checkout/steps/gift_card.rb
70
+ - app/models/workarea/fulfillment/policies/create_gift_card.rb
76
71
  - app/models/workarea/order/item.decorator
77
72
  - app/models/workarea/payment.decorator
78
73
  - app/models/workarea/payment/authorize/gift_card.rb
79
74
  - app/models/workarea/payment/capture/gift_card.rb
80
75
  - app/models/workarea/payment/gift_card.rb
81
76
  - app/models/workarea/payment/gift_card/redemption.rb
77
+ - app/models/workarea/payment/gift_card_operation.rb
82
78
  - app/models/workarea/payment/purchase/gift_card.rb
83
79
  - app/models/workarea/payment/refund/gift_card.rb
84
80
  - app/models/workarea/payment/tender/gift_card.rb
@@ -88,10 +84,7 @@ files:
88
84
  - app/queries/workarea/order_item_details.decorator
89
85
  - app/queries/workarea/search/admin_gift_cards.rb
90
86
  - app/seeds/workarea/gift_card_seeds.rb
91
- - app/services/workarea/checkout/steps/gift_card.rb
92
87
  - app/view_models/workarea/admin/payment_gift_card_view_model.rb
93
- - app/view_models/workarea/storefront/checkout/payment_view_model.decorator
94
- - app/view_models/workarea/storefront/checkout/summary_view_model.decorator
95
88
  - app/view_models/workarea/storefront/gift_card_order_pricing.rb
96
89
  - app/view_models/workarea/storefront/order_view_model.decorator
97
90
  - app/view_models/workarea/storefront/product_templates/gift_card_view_model.rb
@@ -121,17 +114,17 @@ files:
121
114
  - app/views/workarea/storefront/orders/_gift_card_summary.html.haml
122
115
  - app/views/workarea/storefront/orders/tenders/_gift_card.html.haml
123
116
  - app/views/workarea/storefront/products/templates/_gift_card.html.haml
124
- - app/workers/workarea/create_ordered_gift_cards.rb
125
117
  - app/workers/workarea/log_gift_card_redemption.rb
126
118
  - app/workers/workarea/send_gift_card_notifications.rb
127
119
  - bin/rails
128
120
  - config/initializers/append_points.rb
129
121
  - config/initializers/configuration.rb
130
- - config/initializers/jump_to_navigation.rb
122
+ - config/initializers/fields.rb
131
123
  - config/locales/en.yml
132
124
  - config/routes.rb
133
125
  - lib/workarea/gift_cards.rb
134
126
  - lib/workarea/gift_cards/engine.rb
127
+ - lib/workarea/gift_cards/gateway.rb
135
128
  - lib/workarea/gift_cards/version.rb
136
129
  - lib/workarea/mailer_previews/storefront/gift_card_mailer_preview.rb
137
130
  - test/documentation/workarea/api/admin/gift_cards_documentation_test.rb
@@ -191,22 +184,25 @@ files:
191
184
  - test/integration/workarea/admin/gift_card_integration_test.rb
192
185
  - test/integration/workarea/admin/gift_card_redemptions_export_integration_test.rb
193
186
  - test/integration/workarea/api/admin/gift_card_integration_test.rb
194
- - test/integration/workarea/api/storefront/balance_integration_test.rb
195
- - test/integration/workarea/api/storefront/checkout_integration_test.rb
196
- - test/integration/workarea/storefront/gift_card_integration_test.rb
187
+ - test/integration/workarea/api/storefront/checkout_gift_cards_integration_test.rb
188
+ - test/integration/workarea/api/storefront/gift_cards_integration_test.rb
189
+ - test/integration/workarea/storefront/checkout_gift_cards_integration_test.rb
190
+ - test/integration/workarea/storefront/gift_cards_integration_test.rb
191
+ - test/integration/workarea/storefront/purchase_gift_cards_integration_test.rb
192
+ - test/lib/workarea/gift_cards/gateway_test.rb
197
193
  - test/models/workarea/catalog/gift_card_product_test.rb
194
+ - test/models/workarea/checkout/steps/gift_card_test.rb
195
+ - test/models/workarea/fulfillment/policies/create_gift_card_test.rb
198
196
  - test/models/workarea/gift_card_payment_test.rb
199
197
  - test/models/workarea/payment/gift_card_test.rb
200
198
  - test/models/workarea/payment/purchase/gift_card_test.rb
201
199
  - test/models/workarea/payment/refund/gift_card_test.rb
202
200
  - test/queries/workarea/admin_redemptions_export_test.rb
203
201
  - test/queries/workarea/gift_card_order_item_details_test.rb
204
- - test/services/workarea/checkout/steps/gift_card_test.rb
205
202
  - test/system/workarea/admin/gift_cards_system_test.rb
206
203
  - test/system/workarea/storefront/gift_cards_system_test.rb
207
204
  - test/test_helper.rb
208
- - test/view_models/workarea/storefront/checkout/gift_card_payment_view_model_test.rb
209
- - test/workers/workarea/create_ordered_gift_cards_test.rb
205
+ - test/view_models/workarea/storefront/gift_card_order_pricing_test.rb
210
206
  - test/workers/workarea/log_gift_card_redemption_test.rb
211
207
  - workarea-gift_cards.gemspec
212
208
  homepage: https://github.com/workarea-commerce/workarea-gift-cards
@@ -224,12 +220,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
224
220
  version: 2.3.0
225
221
  required_rubygems_version: !ruby/object:Gem::Requirement
226
222
  requirements:
227
- - - ">="
223
+ - - ">"
228
224
  - !ruby/object:Gem::Version
229
- version: '0'
225
+ version: 1.3.1
230
226
  requirements: []
231
- rubygems_version: 3.0.3
227
+ rubygems_version: 3.0.6
232
228
  signing_key:
233
229
  specification_version: 4
234
- summary: Gift Cards plugin for the Workarea commerce platform
230
+ summary: Gift Cards plugin for the Workarea Commerce Platform
235
231
  test_files: []
data/.eslintignore DELETED
@@ -1,2 +0,0 @@
1
- **/test/**/*.js
2
- testing/**/spec_helper.js
data/.scss-lint.yml DELETED
@@ -1,188 +0,0 @@
1
- # Extension of the default configuration:
2
- # https://github.com/causes/scss-lint/blob/master/config/default.yml
3
-
4
- linters:
5
- Comment:
6
- enabled: false
7
-
8
- DeclarationOrder:
9
- enabled: true
10
-
11
- ElsePlacement:
12
- enabled: true
13
- style: new_line
14
-
15
- EmptyRule:
16
- enabled: false
17
-
18
- HexLength:
19
- enabled: true
20
- style: long
21
-
22
- Indentation:
23
- enabled: true
24
- allow_non_nested_indentation: true
25
- character: space
26
- width: 4
27
-
28
- LeadingZero:
29
- enabled: true
30
- style: include_zero
31
-
32
- MergeableSelector:
33
- enabled: true
34
- force_nesting: false
35
-
36
- PropertySortOrder:
37
- enabled: true
38
- ignore_unspecified: false
39
- separate_groups: false
40
- order:
41
- - display
42
- -
43
- - position
44
- - top
45
- - right
46
- - bottom
47
- - left
48
- - z-index
49
- -
50
- - margin
51
- - margin-top
52
- - margin-right
53
- - margin-bottom
54
- - margin-left
55
- -
56
- - margin-collapse
57
- - margin-top-collapse
58
- - margin-right-collapse
59
- - margin-bottom-collapse
60
- - margin-left-collapse
61
- -
62
- - padding
63
- - padding-top
64
- - padding-right
65
- - padding-bottom
66
- - padding-left
67
- -
68
- - width
69
- - height
70
- - max-width
71
- - max-height
72
- - min-width
73
- - min-height
74
- -
75
- - float
76
- - clear
77
- -
78
- - color
79
- -
80
- - font
81
- - font-size
82
- - font-style
83
- - font-family
84
- - font-weight
85
- - font-variant
86
- - font-smoothing
87
- -
88
- - line-height
89
- - letter-spacing
90
- - word-spacing
91
- -
92
- - text-align
93
- - text-indent
94
- - text-shadow
95
- - text-overflow
96
- - text-rendering
97
- - text-transform
98
- - text-decoration
99
- - text-size-adjust
100
- -
101
- - word-break
102
- - word-wrap
103
- -
104
- - white-space
105
- -
106
- - background
107
- - background-size
108
- - background-color
109
- - background-image
110
- - background-repeat
111
- - background-position
112
- - background-attachment
113
- -
114
- - border
115
- - border-top
116
- - border-right
117
- - border-bottom
118
- - border-left
119
- -
120
- - border-image
121
- - border-spacing
122
- - border-collapse
123
- -
124
- - border-color
125
- - border-top-color
126
- - border-right-color
127
- - border-bottom-color
128
- - border-left-color
129
- -
130
- - border-style
131
- - border-top-style
132
- - border-right-style
133
- - border-bottom-style
134
- - border-left-style
135
- -
136
- - border-width
137
- - border-top-width
138
- - border-right-width
139
- - border-bottom-width
140
- - border-left-width
141
- -
142
- - border-radius
143
- - border-top-right-radius
144
- - border-bottom-right-radius
145
- - border-bottom-left-radius
146
- - border-top-left-radius
147
- - border-radius-topright
148
- - border-radius-bottomright
149
- - border-radius-bottomleft
150
- - border-radius-topleft
151
- -
152
- - box-shadow
153
-
154
- SelectorFormat:
155
- enabled: true
156
- convention: hyphenated_BEM
157
-
158
- SingleLinePerSelector:
159
- enabled: false
160
-
161
- SpaceAfterPropertyColon:
162
- enabled: true
163
- style: at_least_one_space
164
-
165
- SpaceBeforeBrace:
166
- enabled: true
167
- style: space
168
- allow_single_line_padding: true
169
-
170
- VariableForProperty:
171
- enabled: true
172
- properties:
173
- - color
174
- - font-family
175
- - background-color
176
-
177
- # These default settings may be problematic to implementors. They are not
178
- # ommitted so that they may be adjusted as needed during an implementation.
179
- #
180
- # For documentation:
181
- # https://github.com/causes/scss-lint/blob/master/lib/scss_lint/linter/README.md
182
-
183
- DuplicateProperty:
184
- enabled: true
185
-
186
- PropertySpelling:
187
- enabled: true
188
- extra_properties: [] # Add experimental CSS to this array, if needed
@@ -1,49 +0,0 @@
1
- module Workarea
2
- if Plugin.installed?(:api)
3
- module Api
4
- module Admin
5
- class PaymentGiftCardsController < Admin::ApplicationController
6
- before_action :find_gift_card, except: [:index, :create]
7
-
8
- def index
9
- @gift_cards = Payment::GiftCard
10
- .all
11
- .order_by(sort_field => sort_direction)
12
- .page(params[:page])
13
-
14
- respond_with gift_cards: @gift_cards
15
- end
16
-
17
- def show
18
- respond_with gift_card: @gift_card
19
- end
20
-
21
- def update
22
- @gift_card.update_attributes!(params[:gift_card])
23
- respond_with gift_card: @gift_card
24
- end
25
-
26
- def create
27
- @gift_card = Payment::GiftCard.create!(params[:gift_card])
28
- respond_with(
29
- { gift_card: @gift_card },
30
- { status: :created,
31
- location: payment_gift_card_path(@gift_card) }
32
- )
33
- end
34
-
35
- def destroy
36
- @gift_card.destroy
37
- head :no_content
38
- end
39
-
40
- private
41
-
42
- def find_gift_card
43
- @gift_card = Payment::GiftCard.find(params[:id])
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,24 +0,0 @@
1
- module Workarea
2
- decorate Storefront::CheckoutsController, with: 'gift_cards' do
3
- def add_gift_card
4
- step = Checkout::Steps::GiftCard.new(current_checkout)
5
-
6
- if step.update(params)
7
- flash[:success] = 'Your gift card has been applied.'
8
- redirect_to checkout_payment_path
9
- else
10
- flash[:error] = <<-string
11
- We couldn't add this gift card number.
12
- Please ensure you have entered the correct number.
13
- string
14
-
15
- @step = Storefront::Checkout::PaymentViewModel.new(
16
- step,
17
- view_model_options
18
- )
19
-
20
- render :payment
21
- end
22
- end
23
- end
24
- end
@@ -1,49 +0,0 @@
1
- module Workarea
2
- class Checkout
3
- module Steps
4
- class GiftCard < Base
5
- # Updates the checkout to use a gift card as one of
6
- # its tenders.
7
- #
8
- # Sets pricing and reconciles tenders so the checkout
9
- # can know whether we need more payment.
10
- #
11
- # @param [Hash] params
12
- # @option params [String] :gift_card_number The gift card number to apply
13
- #
14
- # @return [Boolean] whether the update succeeded (payment were saved)
15
- #
16
- def update(params = {})
17
- return false unless params[:gift_card_number].present?
18
- gift_card_number = params[:gift_card_number].to_s.gsub(/\s+/, '')
19
-
20
- return false unless valid_number?(gift_card_number)
21
- payment.set_gift_card(number: gift_card_number)
22
-
23
- Pricing.perform(order, shippings)
24
- payment.adjust_tender_amounts(order.total_price)
25
- end
26
-
27
- # Whether this update to use a gift card succeeded.
28
- # If true, this was no gift card or a valid gift card applied,
29
- # false means the gift card number was invalid or expired.
30
- #
31
- # @return [Boolean]
32
- #
33
- def complete?
34
- !payment.gift_card? || (
35
- payment.gift_card.valid? &&
36
- valid_number?(payment.gift_card.number)
37
- )
38
- end
39
-
40
- private
41
-
42
- def valid_number?(number)
43
- return false unless number.present?
44
- Workarea::Payment::GiftCard.find_balance(number) > 0
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,32 +0,0 @@
1
- module Workarea
2
- decorate Storefront::Checkout::PaymentViewModel, with: 'gift_cards' do
3
- # Whether or not to show current gift card information.
4
- # True if the current payment is a valid gift card.
5
- #
6
- # @return [Boolean]
7
- #
8
- def show_gift_card?
9
- payment.gift_card?
10
- end
11
-
12
- # Can the current gift card cover the entire order
13
- # total? Used for rendering gift card messaging.
14
- #
15
- # @return [Boolean]
16
- #
17
- def order_covered_by_gift_card?
18
- gift_card_balance >= total_after_store_credit
19
- end
20
-
21
- # Can store credit or gift card cover the entire
22
- # order total? Override this method in order to prevent
23
- # a default credit card from being selected if
24
- # not necessary to complete the order.
25
- #
26
- # @return [Boolean]
27
- #
28
- def order_covered_by_advance_payments?
29
- super || order_covered_by_gift_card?
30
- end
31
- end
32
- end
@@ -1,11 +0,0 @@
1
- module Workarea
2
- decorate Storefront::Checkout::SummaryViewModel, with: 'gift_cards' do
3
- # Whether this checkout is using a gift card.
4
- #
5
- # @return [Boolean]
6
- #
7
- def gift_card?
8
- gift_card_amount > 0
9
- end
10
- end
11
- end
@@ -1,47 +0,0 @@
1
- module Workarea
2
- class CreateOrderedGiftCards
3
- include Sidekiq::Worker
4
- include Sidekiq::CallbacksWorker
5
-
6
- sidekiq_options enqueue_on: { Fulfillment => :create }
7
-
8
- def perform(order_id)
9
- order = Order.find(order_id)
10
- fulfillment = Fulfillment.find(order.id)
11
-
12
- gift_cards = order.items.select do |item|
13
- item.digital? && item.gift_card?
14
- end
15
-
16
- gift_cards.each do |item|
17
- unit_adjustment = item.price_adjustments.first
18
- unit_amount = unit_adjustment.amount / item.quantity
19
-
20
- item.quantity.times do
21
- Payment::GiftCard.create!(
22
- amount: unit_amount,
23
- order_id: order.id,
24
- to: item.customizations['email'],
25
- from: item.customizations['from'],
26
- message: item.customizations['message'],
27
- notify: true,
28
- purchased: true
29
- )
30
- end
31
-
32
- update_fulfillment(fulfillment, item)
33
- end
34
- end
35
-
36
- private
37
-
38
- def update_fulfillment(fulfillment, item)
39
- # Ensure item is there to ship
40
- fulfillment.items.detect { |i| i.order_item_id == item.id.to_s } ||
41
- fulfillment.items.build(order_item_id: item.id, quantity: item.quantity)
42
-
43
- fulfillment.mark_item_shipped(id: item.id.to_s, quantity: item.quantity)
44
- fulfillment.save!
45
- end
46
- end
47
- end
@@ -1,3 +0,0 @@
1
- Workarea.configure do |config|
2
- config.jump_to_navigation.merge!('Gift Cards' => :payment_gift_cards_path)
3
- end