workarea-gift_cards 3.4.10 → 4.0.3

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.
Files changed (76) hide show
  1. checksums.yaml +5 -5
  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 +40 -20
  7. data/Gemfile +3 -5
  8. data/README.md +25 -1
  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 +72 -0
  15. data/app/models/workarea/fulfillment/policies/create_gift_card.rb +30 -0
  16. data/app/models/workarea/payment.decorator +25 -7
  17. data/app/models/workarea/payment/authorize/gift_card.rb +7 -20
  18. data/app/models/workarea/payment/capture/gift_card.rb +5 -7
  19. data/app/models/workarea/payment/gift_card.rb +1 -1
  20. data/app/models/workarea/payment/gift_card_operation.rb +9 -0
  21. data/app/models/workarea/payment/purchase/gift_card.rb +24 -1
  22. data/app/models/workarea/payment/refund/gift_card.rb +9 -14
  23. data/app/models/workarea/payment/tender/gift_card.rb +3 -10
  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.rb +9 -0
  41. data/lib/workarea/gift_cards/gateway.rb +128 -0
  42. data/lib/workarea/gift_cards/version.rb +1 -1
  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 +131 -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 +32 -25
  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
@@ -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
@@ -1,161 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Workarea
4
- if Plugin.installed?(:api)
5
- module Api
6
- module Storefront
7
- class CheckoutIntegrationTest < Workarea::IntegrationTest
8
- setup :tax, :product, :shipping_service, :gift_card
9
-
10
- def tax
11
- @tax ||= create_tax_category(
12
- name: 'Sales Tax',
13
- code: '001',
14
- rates: [{ percentage: 0.07, country: 'US', region: 'PA' }]
15
- )
16
- end
17
-
18
- def product
19
- @product ||= create_product(
20
- name: 'Integration Product',
21
- variants: [
22
- { sku: 'SKU1',
23
- regular: 6.to_m,
24
- tax_code: '001',
25
- on_sale: true,
26
- sale: 5.to_m }
27
- ]
28
- )
29
- end
30
-
31
- def shipping_service
32
- @shipping_service ||= create_shipping_service(
33
- name: 'Ground',
34
- tax_code: '001',
35
- rates: [{ price: 7.to_m }]
36
- )
37
- end
38
-
39
- def gift_card
40
- @gift_card ||= create_gift_card(amount: 5.to_m)
41
- end
42
-
43
- def complete_checkout
44
- post storefront_api.carts_path
45
- order_id = JSON.parse(response.body)['id']
46
-
47
- post storefront_api.cart_items_path(order_id),
48
- params: {
49
- product_id: product.id,
50
- sku: product.skus.first,
51
- quantity: 2
52
- }
53
-
54
- patch storefront_api.checkout_path(order_id),
55
- params: {
56
- email: 'bcrouse@workarea.com',
57
- billing_address: {
58
- first_name: 'Ben',
59
- last_name: 'Crouse',
60
- street: '12 N. 3rd St.',
61
- city: 'Philadelphia',
62
- region: 'PA',
63
- postal_code: '19106',
64
- country: 'US',
65
- phone_number: '2159251800'
66
- },
67
- shipping_address: {
68
- first_name: 'Ben',
69
- last_name: 'Crouse',
70
- street: '22 S. 3rd St.',
71
- city: 'Philadelphia',
72
- region: 'PA',
73
- postal_code: '19106',
74
- country: 'US',
75
- phone_number: '2159251800'
76
- }
77
- }
78
-
79
- patch storefront_api.add_gift_card_checkout_path(order_id),
80
- params: { gift_card_number: gift_card.token }
81
-
82
- post storefront_api.complete_checkout_path(order_id),
83
- params: {
84
- payment: 'new_card',
85
- credit_card: {
86
- number: '1',
87
- month: '1',
88
- year: Time.now.year + 1,
89
- cvv: '999'
90
- }
91
- }
92
- end
93
-
94
- def test_saves_order_info
95
- complete_checkout
96
-
97
- order = Order.first
98
-
99
- assert_equal('bcrouse@workarea.com', order.email)
100
- assert(order.placed_at.present?)
101
- assert_equal(1, order.items.length)
102
-
103
- assert_equal(product.id, order.items.first.product_id)
104
- assert_equal(product.skus.first, order.items.first.sku)
105
- assert_equal(2, order.items.first.quantity)
106
-
107
- assert_equal(10.to_m, order.items.first.total_price)
108
- assert_equal(1, order.items.first.price_adjustments.length)
109
- assert_equal(10.to_m, order.items.first.price_adjustments.first.amount)
110
-
111
- assert(order.items.first.on_sale?)
112
- assert(order.items.first.product_attributes.present?)
113
-
114
- payment = Payment.find(order.id)
115
- assert_equal('Ben', payment.first_name)
116
- assert_equal('Crouse', payment.last_name)
117
- assert_equal('Ben', payment.address.first_name)
118
- assert_equal('Crouse', payment.address.last_name)
119
- assert_equal('12 N. 3rd St.', payment.address.street)
120
- assert_equal('Philadelphia', payment.address.city)
121
- assert_equal('PA', payment.address.region)
122
- assert_equal('19106', payment.address.postal_code)
123
- assert_equal('US', payment.address.country.alpha2)
124
- assert_equal('2159251800', payment.address.phone_number)
125
-
126
- assert_equal('Test Card', payment.credit_card.issuer)
127
- assert_equal('XXXX-XXXX-XXXX-1', payment.credit_card.display_number)
128
- assert_equal(1, payment.credit_card.month)
129
- assert(payment.credit_card.year.present?)
130
- assert_equal(13.19.to_m, payment.credit_card.amount)
131
- assert(payment.credit_card.token.present?)
132
- assert(payment.credit_card.saved_card_id.blank?)
133
-
134
- assert_equal(1, payment.credit_card.transactions.length)
135
- assert(payment.credit_card.transactions.first.response.present?)
136
- assert_equal(13.19.to_m, payment.credit_card.transactions.first.amount)
137
-
138
- assert_equal(gift_card.token, payment.gift_card.number)
139
- assert_equal(5.to_m, payment.gift_card.amount)
140
- assert_equal(1, payment.gift_card.transactions.length)
141
- assert_equal(5.to_m, payment.gift_card.transactions.first.amount)
142
- end
143
-
144
- def test_reduces_balance_on_gift_card
145
- complete_checkout
146
-
147
- gift_card.reload
148
- assert_equal(0.to_m, gift_card.balance)
149
- assert_equal(5.to_m, gift_card.amount)
150
- assert_equal(5.to_m, gift_card.used)
151
-
152
- order = Order.first
153
- redemption = gift_card.redemptions.first
154
- assert_equal(order.placed_at, redemption.redeemed_at)
155
- assert_equal(5.to_m, redemption.amount)
156
- end
157
- end
158
- end
159
- end
160
- end
161
- end
@@ -1,226 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Workarea
4
- module Storefront
5
- class GiftCardIntegrationTest < Workarea::IntegrationTest
6
- setup :tax, :product, :shipping_service, :gift_card
7
-
8
- def next_year
9
- 1.year.from_now.year
10
- end
11
-
12
- def tax
13
- @tax ||= create_tax_category(
14
- name: 'Sales Tax',
15
- code: '001',
16
- rates: [{ percentage: 0.07, country: 'US', region: 'PA' }]
17
- )
18
- end
19
-
20
- def product
21
- @product ||= create_product(
22
- name: 'Integration Product',
23
- variants: [
24
- { sku: 'SKU1',
25
- regular: 6.to_m,
26
- tax_code: '001',
27
- on_sale: true,
28
- sale: 5.to_m }
29
- ]
30
- )
31
- end
32
-
33
- def shipping_service
34
- @shipping_service ||= create_shipping_service(
35
- name: 'Ground',
36
- tax_code: '001',
37
- rates: [{ price: 7.to_m }]
38
- )
39
- end
40
-
41
- def gift_card
42
- @gift_card ||= create_gift_card(amount: 5.to_m)
43
- end
44
-
45
- def complete_checkout
46
- post storefront.cart_items_path,
47
- params: {
48
- product_id: product.id,
49
- sku: product.skus.first,
50
- quantity: 2
51
- }
52
-
53
- patch storefront.checkout_addresses_path,
54
- params: {
55
- email: 'bcrouse@workarea.com',
56
- billing_address: {
57
- first_name: 'Ben',
58
- last_name: 'Crouse',
59
- street: '12 N. 3rd St.',
60
- city: 'Philadelphia',
61
- region: 'PA',
62
- postal_code: '19106',
63
- country: 'US',
64
- phone_number: '2159251800'
65
- },
66
- shipping_address: {
67
- first_name: 'Ben',
68
- last_name: 'Crouse',
69
- street: '22 S. 3rd St.',
70
- city: 'Philadelphia',
71
- region: 'PA',
72
- postal_code: '19106',
73
- country: 'US',
74
- phone_number: '2159251800'
75
- }
76
- }
77
-
78
- patch storefront.checkout_add_gift_card_path,
79
- params: { gift_card_number: gift_card.token }
80
-
81
- patch storefront.checkout_place_order_path,
82
- params: {
83
- payment: 'new_card',
84
- credit_card: {
85
- number: '1',
86
- month: 1,
87
- year: next_year,
88
- cvv: '999'
89
- }
90
- }
91
- end
92
-
93
- def test_saves_order_info
94
- complete_checkout
95
-
96
- order = Order.first
97
-
98
- assert_equal('bcrouse@workarea.com', order.email)
99
- assert(order.placed_at.present?)
100
- assert_equal(1, order.items.length)
101
-
102
- assert_equal(product.id, order.items.first.product_id)
103
- assert_equal(product.skus.first, order.items.first.sku)
104
- assert_equal(2, order.items.first.quantity)
105
-
106
- assert_equal(10.to_m, order.items.first.total_price)
107
- assert_equal(1, order.items.first.price_adjustments.length)
108
- assert_equal(10.to_m, order.items.first.price_adjustments.first.amount)
109
-
110
- assert(order.items.first.on_sale?)
111
- assert(order.items.first.product_attributes.present?)
112
-
113
- payment = Payment.find(order.id)
114
- assert_equal('Ben', payment.first_name)
115
- assert_equal('Crouse', payment.last_name)
116
- assert_equal('Ben', payment.address.first_name)
117
- assert_equal('Crouse', payment.address.last_name)
118
- assert_equal('12 N. 3rd St.', payment.address.street)
119
- assert_equal('Philadelphia', payment.address.city)
120
- assert_equal('PA', payment.address.region)
121
- assert_equal('19106', payment.address.postal_code)
122
- assert_equal('US', payment.address.country.alpha2)
123
- assert_equal('2159251800', payment.address.phone_number)
124
-
125
- assert_equal('Test Card', payment.credit_card.issuer)
126
- assert_equal('XXXX-XXXX-XXXX-1', payment.credit_card.display_number)
127
- assert_equal(1, payment.credit_card.month)
128
- assert_equal(next_year, payment.credit_card.year)
129
- assert_equal(13.19.to_m, payment.credit_card.amount)
130
- assert(payment.credit_card.token.present?)
131
- assert(payment.credit_card.saved_card_id.blank?)
132
-
133
- assert_equal(1, payment.credit_card.transactions.length)
134
- assert(payment.credit_card.transactions.first.response.present?)
135
- assert_equal(13.19.to_m, payment.credit_card.transactions.first.amount)
136
-
137
- assert_equal(gift_card.token, payment.gift_card.number)
138
- assert_equal(5.to_m, payment.gift_card.amount)
139
- assert_equal(1, payment.gift_card.transactions.length)
140
- assert_equal(5.to_m, payment.gift_card.transactions.first.amount)
141
- end
142
-
143
- def test_reduces_balance_on_gift_card
144
- complete_checkout
145
-
146
- gift_card.reload
147
- assert_equal(0.to_m, gift_card.balance)
148
- assert_equal(5.to_m, gift_card.amount)
149
- assert_equal(5.to_m, gift_card.used)
150
-
151
- order = Order.first
152
- redemption = gift_card.redemptions.first
153
- assert_equal(order.placed_at, redemption.redeemed_at)
154
- assert_equal(5.to_m, redemption.amount)
155
- end
156
-
157
- def test_generates_gift_card
158
- product = create_product(
159
- name: 'Gift Card',
160
- gift_card: true,
161
- digital: true,
162
- customizations: 'gift_card',
163
- variants: [{ sku: 'GIFTCARD', regular: 10.to_m }]
164
- )
165
-
166
- post storefront.cart_items_path,
167
- params: {
168
- product_id: product.id,
169
- sku: product.skus.first,
170
- email: 'recipient@workarea.com',
171
- from: 'from@workarea.com',
172
- message: 'this is a message',
173
- quantity: 1
174
- }
175
-
176
- patch storefront.checkout_addresses_path,
177
- params: {
178
- email: 'bcrouse@workarea.com',
179
- billing_address: {
180
- first_name: 'Ben',
181
- last_name: 'Crouse',
182
- street: '12 N. 3rd St.',
183
- city: 'Philadelphia',
184
- region: 'PA',
185
- postal_code: '19106',
186
- country: 'US',
187
- phone_number: '2159251800'
188
- }
189
- }
190
-
191
- patch storefront.checkout_place_order_path,
192
- params: {
193
- payment: 'new_card',
194
- credit_card: {
195
- number: '1',
196
- month: 1,
197
- year: next_year,
198
- cvv: '999'
199
- }
200
- }
201
-
202
- assert_equal(2, Payment::GiftCard.count)
203
-
204
- card = Payment::GiftCard.desc(:created_at).first
205
- assert_equal(10.to_m, card.amount)
206
- assert_equal(0.to_m, card.used)
207
- assert_equal(10.to_m, card.balance)
208
- assert(card.order_id.present?)
209
-
210
- assert_equal(2, ActionMailer::Base.deliveries.length)
211
-
212
- assert(card.purchased?)
213
-
214
- gift_card_email = ActionMailer::Base.deliveries.detect do |email|
215
- assert_includes(email.to, 'recipient@workarea.com')
216
- end
217
-
218
- gift_card_email.parts.each do |part|
219
- assert_includes(part.body, card.token)
220
- assert_includes(part.body, 'from@workarea.com')
221
- assert_includes(part.body, 'this is a message')
222
- end
223
- end
224
- end
225
- end
226
- end