spree_cm_commissioner 1.18.1.pre.pre2 → 1.18.1
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/Gemfile.lock +5 -1
- data/app/controllers/spree/api/v2/storefront/dynamic_field_options_controller.rb +1 -1
- data/app/controllers/spree/api/v2/tenant/checkout_controller.rb +0 -2
- data/app/controllers/spree_cm_commissioner/api/v2/storefront/checkout_controller_decorator.rb +0 -11
- data/app/controllers/spree_cm_commissioner/well_known_controller.rb +9 -21
- data/app/interactors/spree_cm_commissioner/universal_link_fetcher.rb +54 -0
- data/app/models/spree_cm_commissioner/dynamic_field.rb +0 -2
- data/app/models/spree_cm_commissioner/dynamic_field_option.rb +0 -2
- data/app/models/spree_cm_commissioner/pin_code.rb +2 -3
- data/app/models/spree_cm_commissioner/vendor_decorator.rb +0 -1
- data/app/serializers/spree_cm_commissioner/v2/storefront/dynamic_field_option_serializer.rb +1 -1
- data/config/locales/en.yml +0 -1
- data/lib/spree_cm_commissioner/version.rb +1 -1
- metadata +5 -14
- data/app/interactors/spree_cm_commissioner/apple_app_site_association_fetcher.rb +0 -27
- data/app/interactors/spree_cm_commissioner/asset_links_fetcher.rb +0 -27
- data/app/interactors/spree_cm_commissioner/telegram_chats_auto_finder.rb +0 -144
- data/app/models/spree_cm_commissioner/pin_code_telegram.rb +0 -28
- data/app/models/spree_cm_commissioner/promotion_category_decorator.rb +0 -11
- data/app/models/spree_cm_commissioner/telegram_chat.rb +0 -6
- data/db/migrate/20250630103536_create_cm_telegram_chats.rb +0 -13
- data/db/migrate/20250707032008_add_vendor_id_to_spree_category.rb +0 -7
- data/db/migrate/20250711092937_add_position_to_cm_dynamic_fields.rb +0 -11
- data/db/migrate/20250711093045_add_position_to_cm_dynamic_field_options.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60a9ca64e7401f96f8cb7e220a28a12ca89d7bc84ce724b0e7751e1c0abf1d0e
|
4
|
+
data.tar.gz: cb4e4fbfd87c785a73c23ee8fd3a02fadacf864d5c905df5a654c56069a79769
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0db6f0473e7663f28e179e51cc68034c6b96315d402a38bb49fef0669ba23ae46cc615d7ee350ec551b1c7fd1686a724a1aef0057ce2b4f637913766c8cdd8c9
|
7
|
+
data.tar.gz: bf5d35d082edc126bcead686c1d1de3e74f2a2bed22a1cbdd62e60dea23679c007ff1fb523f0a3447a3b598b1e3c66838b28f35e408b82024de877c5da237657
|
data/Gemfile.lock
CHANGED
@@ -34,7 +34,7 @@ GIT
|
|
34
34
|
PATH
|
35
35
|
remote: .
|
36
36
|
specs:
|
37
|
-
spree_cm_commissioner (1.18.1
|
37
|
+
spree_cm_commissioner (1.18.1)
|
38
38
|
activerecord-multi-tenant
|
39
39
|
activerecord_json_validator (~> 2.1, >= 2.1.3)
|
40
40
|
aws-sdk-cloudfront
|
@@ -572,6 +572,10 @@ GEM
|
|
572
572
|
nokogiri (1.15.4)
|
573
573
|
mini_portile2 (~> 2.8.2)
|
574
574
|
racc (~> 1.4)
|
575
|
+
nokogiri (1.15.4-x86_64-darwin)
|
576
|
+
racc (~> 1.4)
|
577
|
+
nokogiri (1.15.4-x86_64-linux)
|
578
|
+
racc (~> 1.4)
|
575
579
|
noticed (1.6.3)
|
576
580
|
http (>= 4.0.0)
|
577
581
|
rails (>= 5.2.0)
|
@@ -8,7 +8,7 @@ module Spree
|
|
8
8
|
return @collection if defined?(@collection)
|
9
9
|
return SpreeCmCommissioner::DynamicFieldOption.none if params[:dynamic_field_id].blank?
|
10
10
|
|
11
|
-
@collection = SpreeCmCommissioner::DynamicFieldOption.where(dynamic_field_id: params[:dynamic_field_id])
|
11
|
+
@collection = SpreeCmCommissioner::DynamicFieldOption.where(dynamic_field_id: params[:dynamic_field_id])
|
12
12
|
@collection = @collection.where('value LIKE ?', "%#{params[:query]}%") if params[:query].present?
|
13
13
|
@collection
|
14
14
|
end
|
@@ -27,8 +27,6 @@ module Spree
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def complete
|
30
|
-
return render_serialized_payload { serialized_current_order } if spree_current_order.confirm? || spree_current_order.complete?
|
31
|
-
|
32
30
|
spree_authorize! :update, spree_current_order, order_token
|
33
31
|
|
34
32
|
result = complete_service.call(order: spree_current_order)
|
data/app/controllers/spree_cm_commissioner/api/v2/storefront/checkout_controller_decorator.rb
CHANGED
@@ -6,17 +6,6 @@ module SpreeCmCommissioner
|
|
6
6
|
def self.prepended(base)
|
7
7
|
base.include SpreeCmCommissioner::OrderConcern
|
8
8
|
end
|
9
|
-
|
10
|
-
# Override Spree's default behavior:
|
11
|
-
# By default, Spree raises an error if `complete` is called on a completed or confirmed order.
|
12
|
-
# We want to allow this call to succeed, so the API can be used both to:
|
13
|
-
# - complete the order (if it's not yet complete), or
|
14
|
-
# - return the latest state of a confirmed or completed order without raising a forbidden error.
|
15
|
-
def complete
|
16
|
-
return render_serialized_payload { serialized_current_order } if spree_current_order.confirm? || spree_current_order.complete?
|
17
|
-
|
18
|
-
super
|
19
|
-
end
|
20
9
|
end
|
21
10
|
end
|
22
11
|
end
|
@@ -4,37 +4,25 @@ module SpreeCmCommissioner
|
|
4
4
|
rescue_from StandardError, with: :handle_error
|
5
5
|
|
6
6
|
def assetlinks_json
|
7
|
-
|
7
|
+
render_universal_link('assetlinks.json')
|
8
8
|
end
|
9
9
|
|
10
10
|
def apple_app_site_association
|
11
|
-
|
11
|
+
render_universal_link('apple-app-site-association')
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
result = fetcher_class.call(
|
16
|
+
def render_universal_link(universal_link)
|
17
|
+
result = SpreeCmCommissioner::UniversalLinkFetcher.new(
|
18
|
+
universal_link: universal_link,
|
20
19
|
store: @store,
|
21
20
|
tenant: @tenant,
|
22
|
-
|
23
|
-
)
|
24
|
-
|
25
|
-
if result.success? && result.contents.present?
|
26
|
-
render json: result.contents
|
27
|
-
else
|
28
|
-
render_not_found
|
29
|
-
end
|
30
|
-
end
|
21
|
+
refresh: params[:_refresh].to_s == 'true'
|
22
|
+
).call
|
31
23
|
|
32
|
-
|
33
|
-
|
34
|
-
when :android
|
35
|
-
SpreeCmCommissioner::AssetLinksFetcher
|
36
|
-
when :ios
|
37
|
-
SpreeCmCommissioner::AppleAppSiteAssociationFetcher
|
24
|
+
if result[:success]
|
25
|
+
render json: result[:data]
|
38
26
|
else
|
39
27
|
render_not_found
|
40
28
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module SpreeCmCommissioner
|
2
|
+
class UniversalLinkFetcher < BaseInteractor
|
3
|
+
delegate :universal_link, :store, :tenant, :refresh, to: :context
|
4
|
+
|
5
|
+
def call
|
6
|
+
return not_found unless resource
|
7
|
+
|
8
|
+
data = load_cached_preference(resource)
|
9
|
+
return not_found if data.blank?
|
10
|
+
|
11
|
+
{ success: true, data: data }
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def resource
|
17
|
+
@resource ||= store.presence || tenant
|
18
|
+
end
|
19
|
+
|
20
|
+
def load_cached_preference(resource)
|
21
|
+
preference_key = preference_key_for(universal_link)
|
22
|
+
return nil unless preference_key && resource.respond_to?(preference_key)
|
23
|
+
|
24
|
+
updated_at = resource.try(:updated_at)&.to_i || 'no_updated_at'
|
25
|
+
cache_key = build_cache_key(universal_link, resource, updated_at)
|
26
|
+
|
27
|
+
CmAppLogger.log(label: 'LOOKING_UP_CACHE', data: { cache_key: cache_key })
|
28
|
+
|
29
|
+
Rails.cache.delete(cache_key) if refresh
|
30
|
+
|
31
|
+
Rails.cache.fetch(cache_key, expires_in: 1.day, force: refresh) do
|
32
|
+
CmAppLogger.log(label: 'CACHE_MISS', data: { cache_key: cache_key })
|
33
|
+
resource.public_send(preference_key).presence
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def build_cache_key(universal_link, resource, updated_at)
|
38
|
+
"well_known:#{universal_link}:#{resource.class.name}:#{resource.id}:#{updated_at}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def preference_key_for(universal_link)
|
42
|
+
case universal_link
|
43
|
+
when 'assetlinks.json'
|
44
|
+
:preferred_assetlinks
|
45
|
+
when 'apple-app-site-association'
|
46
|
+
:preferred_apple_app_site_association
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def not_found
|
51
|
+
{ success: false, error: 'Not found' }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
module SpreeCmCommissioner
|
2
2
|
class DynamicField < SpreeCmCommissioner::Base
|
3
|
-
acts_as_list column: :position, scope: :vendor_id
|
4
|
-
|
5
3
|
belongs_to :vendor, class_name: 'Spree::Vendor', optional: false
|
6
4
|
|
7
5
|
has_many :dynamic_field_options, class_name: 'SpreeCmCommissioner::DynamicFieldOption', dependent: :destroy
|
@@ -1,7 +1,5 @@
|
|
1
1
|
module SpreeCmCommissioner
|
2
2
|
class DynamicFieldOption < SpreeCmCommissioner::Base
|
3
|
-
acts_as_list column: :position, scope: :dynamic_field_id
|
4
|
-
|
5
3
|
belongs_to :dynamic_field, class_name: 'SpreeCmCommissioner::DynamicField', optional: false
|
6
4
|
has_many :guest_dynamic_fields, class_name: 'SpreeCmCommissioner::GuestDynamicField', dependent: :restrict_with_error
|
7
5
|
|
@@ -2,7 +2,7 @@ module SpreeCmCommissioner
|
|
2
2
|
class PinCode < SpreeCmCommissioner::Base
|
3
3
|
has_secure_token
|
4
4
|
|
5
|
-
enum contact_type: { 'phone_number' => 0, 'email' => 1
|
5
|
+
enum contact_type: { 'phone_number' => 0, 'email' => 1 }
|
6
6
|
|
7
7
|
validates :code, length: { maximum: 6 }
|
8
8
|
validates :contact, presence: true
|
@@ -130,8 +130,7 @@ module SpreeCmCommissioner
|
|
130
130
|
'SpreeCmCommissioner::PinCodeMobileConfirm' => I18n.t('pincode.readable_type.confirmation_code'),
|
131
131
|
'SpreeCmCommissioner::PinCodeUpdateUserLogin' => I18n.t('pincode.readable_type.update_user_login'),
|
132
132
|
'SpreeCmCommissioner::PinCodeEmailConfirm' => I18n.t('pincode.readable_type.confirmation_code'),
|
133
|
-
'SpreeCmCommissioner::OtpCode' => I18n.t('pincode.readable_type.otp_code')
|
134
|
-
'SpreeCmCommissioner::PinCodeTelegram' => I18n.t('pincode.readable_type.telegram_verification')
|
133
|
+
'SpreeCmCommissioner::OtpCode' => I18n.t('pincode.readable_type.otp_code')
|
135
134
|
}
|
136
135
|
end
|
137
136
|
|
@@ -78,7 +78,6 @@ module SpreeCmCommissioner
|
|
78
78
|
base.has_many :invoices, class_name: 'SpreeCmCommissioner::Invoice', dependent: :destroy
|
79
79
|
base.has_many :subscriptions, through: :customers, class_name: 'SpreeCmCommissioner::Subscription'
|
80
80
|
base.has_many :subscription_orders, through: :subscriptions, class_name: 'Spree::Order', source: :orders
|
81
|
-
base.has_many :promotion_categories, class_name: 'Spree::PromotionCategory', foreign_key: :vendor_id, dependent: :destroy
|
82
81
|
|
83
82
|
base.has_many :homepage_section_relatables,
|
84
83
|
class_name: 'SpreeCmCommissioner::HomepageSectionRelatable',
|
@@ -2,7 +2,7 @@ module SpreeCmCommissioner
|
|
2
2
|
module V2
|
3
3
|
module Storefront
|
4
4
|
class DynamicFieldOptionSerializer < BaseSerializer
|
5
|
-
attributes :id, :value, :dynamic_field_id, :status, :created_at, :updated_at
|
5
|
+
attributes :id, :value, :dynamic_field_id, :status, :created_at, :updated_at
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
data/config/locales/en.yml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_cm_commissioner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.18.1
|
4
|
+
version: 1.18.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- You
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-07-
|
11
|
+
date: 2025-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree
|
@@ -1038,9 +1038,7 @@ files:
|
|
1038
1038
|
- app/interactors/spree_cm_commissioner/account_linkage.rb
|
1039
1039
|
- app/interactors/spree_cm_commissioner/account_recover.rb
|
1040
1040
|
- app/interactors/spree_cm_commissioner/account_updater.rb
|
1041
|
-
- app/interactors/spree_cm_commissioner/apple_app_site_association_fetcher.rb
|
1042
1041
|
- app/interactors/spree_cm_commissioner/apply_service_availability.rb
|
1043
|
-
- app/interactors/spree_cm_commissioner/asset_links_fetcher.rb
|
1044
1042
|
- app/interactors/spree_cm_commissioner/base_interactor.rb
|
1045
1043
|
- app/interactors/spree_cm_commissioner/bib_number_swapper.rb
|
1046
1044
|
- app/interactors/spree_cm_commissioner/chatrace_order_creator.rb
|
@@ -1109,7 +1107,6 @@ files:
|
|
1109
1107
|
- app/interactors/spree_cm_commissioner/subscriptions_order_creator.rb
|
1110
1108
|
- app/interactors/spree_cm_commissioner/subscriptions_order_cron_executor.rb
|
1111
1109
|
- app/interactors/spree_cm_commissioner/subscriptions_prepaid_order_creator.rb
|
1112
|
-
- app/interactors/spree_cm_commissioner/telegram_chats_auto_finder.rb
|
1113
1110
|
- app/interactors/spree_cm_commissioner/telegram_chats_finder.rb
|
1114
1111
|
- app/interactors/spree_cm_commissioner/telegram_debug_pin_code_sender.rb
|
1115
1112
|
- app/interactors/spree_cm_commissioner/telegram_notification_sender.rb
|
@@ -1119,6 +1116,7 @@ files:
|
|
1119
1116
|
- app/interactors/spree_cm_commissioner/telegram_web_app_vendor_user_checker.rb
|
1120
1117
|
- app/interactors/spree_cm_commissioner/transactional_email_sender.rb
|
1121
1118
|
- app/interactors/spree_cm_commissioner/unique_device_token_cron_executor.rb
|
1119
|
+
- app/interactors/spree_cm_commissioner/universal_link_fetcher.rb
|
1122
1120
|
- app/interactors/spree_cm_commissioner/update_payment_gateway_status.rb
|
1123
1121
|
- app/interactors/spree_cm_commissioner/user_contact_updater.rb
|
1124
1122
|
- app/interactors/spree_cm_commissioner/user_device_token_deregister.rb
|
@@ -1304,7 +1302,6 @@ files:
|
|
1304
1302
|
- app/models/spree_cm_commissioner/pin_code_mobile_confirm.rb
|
1305
1303
|
- app/models/spree_cm_commissioner/pin_code_otp.rb
|
1306
1304
|
- app/models/spree_cm_commissioner/pin_code_registration.rb
|
1307
|
-
- app/models/spree_cm_commissioner/pin_code_telegram.rb
|
1308
1305
|
- app/models/spree_cm_commissioner/pin_code_update_user_login.rb
|
1309
1306
|
- app/models/spree_cm_commissioner/place.rb
|
1310
1307
|
- app/models/spree_cm_commissioner/product_completion_step.rb
|
@@ -1324,7 +1321,6 @@ files:
|
|
1324
1321
|
- app/models/spree_cm_commissioner/promotion/rules/guest_occupations.rb
|
1325
1322
|
- app/models/spree_cm_commissioner/promotion/rules/vendors.rb
|
1326
1323
|
- app/models/spree_cm_commissioner/promotion/rules/weekend.rb
|
1327
|
-
- app/models/spree_cm_commissioner/promotion_category_decorator.rb
|
1328
1324
|
- app/models/spree_cm_commissioner/promotion_decorator.rb
|
1329
1325
|
- app/models/spree_cm_commissioner/property_decorator.rb
|
1330
1326
|
- app/models/spree_cm_commissioner/prototype_decorator.rb
|
@@ -1359,7 +1355,6 @@ files:
|
|
1359
1355
|
- app/models/spree_cm_commissioner/taxon_web_banner.rb
|
1360
1356
|
- app/models/spree_cm_commissioner/taxonomy_decorator.rb
|
1361
1357
|
- app/models/spree_cm_commissioner/telegram_bot.rb
|
1362
|
-
- app/models/spree_cm_commissioner/telegram_chat.rb
|
1363
1358
|
- app/models/spree_cm_commissioner/tenant.rb
|
1364
1359
|
- app/models/spree_cm_commissioner/transactional_email.rb
|
1365
1360
|
- app/models/spree_cm_commissioner/trip.rb
|
@@ -2523,13 +2518,9 @@ files:
|
|
2523
2518
|
- db/migrate/20250611023548_add_country_code_to_guests.rb
|
2524
2519
|
- db/migrate/20250612035937_add_intel_phone_number_to_guests.rb
|
2525
2520
|
- db/migrate/20250616084219_add_description_to_cm_vendor_place.rb
|
2526
|
-
- db/migrate/20250630103536_create_cm_telegram_chats.rb
|
2527
2521
|
- db/migrate/20250701093203_add_configurations_to_cm_dynamic_field.rb
|
2528
2522
|
- db/migrate/20250702091305_add_dynamic_field_option_to_guest_dynamic_field.rb
|
2529
2523
|
- db/migrate/20250702091935_add_status_to_dynamic_field_option.rb
|
2530
|
-
- db/migrate/20250707032008_add_vendor_id_to_spree_category.rb
|
2531
|
-
- db/migrate/20250711092937_add_position_to_cm_dynamic_fields.rb
|
2532
|
-
- db/migrate/20250711093045_add_position_to_cm_dynamic_field_options.rb
|
2533
2524
|
- docker-compose.yml
|
2534
2525
|
- docs/option_types/attr_types.md
|
2535
2526
|
- docs/private_key.pem
|
@@ -2682,9 +2673,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
2682
2673
|
version: '2.7'
|
2683
2674
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
2684
2675
|
requirements:
|
2685
|
-
- - "
|
2676
|
+
- - ">="
|
2686
2677
|
- !ruby/object:Gem::Version
|
2687
|
-
version:
|
2678
|
+
version: '0'
|
2688
2679
|
requirements:
|
2689
2680
|
- none
|
2690
2681
|
rubygems_version: 3.4.1
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
class AppleAppSiteAssociationFetcher < BaseInteractor
|
3
|
-
delegate :store, :tenant, :refreshed, to: :context
|
4
|
-
|
5
|
-
def call
|
6
|
-
key = cache_key
|
7
|
-
|
8
|
-
CmAppLogger.log(label: 'LOOKING_UP_CACHE', data: { cache_key: key })
|
9
|
-
|
10
|
-
Rails.cache.delete(key) if refreshed
|
11
|
-
|
12
|
-
context.contents = Rails.cache.fetch(key) do
|
13
|
-
CmAppLogger.log(label: 'CACHE_MISS', data: { cache_key: key })
|
14
|
-
resource.preferred_apple_app_site_association
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def cache_key
|
19
|
-
updated_at = tenant&.updated_at || store&.updated_at
|
20
|
-
"well_known:apple-app-site-association:#{resource.class.name}:#{resource.id}:#{updated_at}"
|
21
|
-
end
|
22
|
-
|
23
|
-
def resource
|
24
|
-
tenant || store
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
class AssetLinksFetcher < BaseInteractor
|
3
|
-
delegate :store, :tenant, :refreshed, to: :context
|
4
|
-
|
5
|
-
def call
|
6
|
-
key = cache_key
|
7
|
-
|
8
|
-
CmAppLogger.log(label: 'LOOKING_UP_CACHE', data: { cache_key: key })
|
9
|
-
|
10
|
-
Rails.cache.delete(key) if refreshed
|
11
|
-
|
12
|
-
context.contents = Rails.cache.fetch(key) do
|
13
|
-
CmAppLogger.log(label: 'CACHE_MISS', data: { cache_key: key })
|
14
|
-
resource.preferred_assetlinks
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def cache_key
|
19
|
-
updated_at = tenant&.updated_at || store&.updated_at
|
20
|
-
"well_known:assetlinks.json:#{resource.class.name}:#{resource.id}:#{updated_at}"
|
21
|
-
end
|
22
|
-
|
23
|
-
def resource
|
24
|
-
tenant || store
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,144 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
class TelegramChatsAutoFinder < BaseInteractor
|
3
|
-
delegate :contact, :pin_code, to: :context
|
4
|
-
|
5
|
-
def call
|
6
|
-
context.chats = []
|
7
|
-
context.verified_chat_ids = []
|
8
|
-
|
9
|
-
updates = fetch_updates
|
10
|
-
|
11
|
-
if updates['result'].any?
|
12
|
-
updates['result'].sort_by { |u| u['update_id'] }.reverse.each do |update|
|
13
|
-
handle_message_update(update) if update['message']
|
14
|
-
handle_channel_post_update(update) if update['channel_post']
|
15
|
-
handle_chat_member_update(update) if update['my_chat_member']
|
16
|
-
end
|
17
|
-
end
|
18
|
-
context.fail!(message: 'No pin codes verified') if context.verified_chat_ids.empty?
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def handle_chat_member_update(update)
|
24
|
-
chat = update.dig('my_chat_member', 'chat')
|
25
|
-
return unless chat
|
26
|
-
|
27
|
-
chat_data = {
|
28
|
-
id: chat['id'],
|
29
|
-
title: chat['title'] || 'Unnamed Chat',
|
30
|
-
type: chat['type']
|
31
|
-
}
|
32
|
-
|
33
|
-
return if context.chats.any? { |c| c[:id] == chat_data[:id] }
|
34
|
-
|
35
|
-
db_chat = SpreeCmCommissioner::TelegramChat.find_or_initialize_by(chat_id: chat_data[:id])
|
36
|
-
is_new_chat = db_chat.new_record?
|
37
|
-
db_chat.update(chat_title: chat_data[:title], chat_type: chat_data[:type])
|
38
|
-
context.chats << chat_data
|
39
|
-
message = "👋Hello! This is Bookme+ bot.\n\nPlease enter the 6-digit PIN code displayed in your portal."
|
40
|
-
send_message(chat_data[:id], message) if is_new_chat
|
41
|
-
end
|
42
|
-
|
43
|
-
def handle_channel_post_update(update)
|
44
|
-
message = update['channel_post']
|
45
|
-
process_pin_code_message(message)
|
46
|
-
end
|
47
|
-
|
48
|
-
def handle_message_update(update)
|
49
|
-
message = update['message']
|
50
|
-
process_pin_code_message(message)
|
51
|
-
end
|
52
|
-
|
53
|
-
def process_pin_code_message(message)
|
54
|
-
chat_id = message.dig('chat', 'id')
|
55
|
-
text = message['text']&.strip
|
56
|
-
|
57
|
-
return unless valid_pin_code?(text, chat_id)
|
58
|
-
|
59
|
-
pin_code_record = find_pin_code_record
|
60
|
-
return unless pin_code_record
|
61
|
-
|
62
|
-
vendor = find_vendor
|
63
|
-
return unless vendor
|
64
|
-
|
65
|
-
chat = update_telegram_chat(message, chat_id)
|
66
|
-
return unless chat
|
67
|
-
|
68
|
-
handle_successful_verification(chat, vendor, pin_code_record)
|
69
|
-
end
|
70
|
-
|
71
|
-
def valid_pin_code?(text, chat_id)
|
72
|
-
text && chat_id && text == pin_code
|
73
|
-
end
|
74
|
-
|
75
|
-
def find_pin_code_record
|
76
|
-
pin_code_record = SpreeCmCommissioner::PinCodeTelegram.find_by(code: pin_code, contact: contact)
|
77
|
-
unless pin_code_record
|
78
|
-
context.fail!(message: "Pin code #{pin_code} not found for contact #{contact}")
|
79
|
-
return nil
|
80
|
-
end
|
81
|
-
pin_code_record
|
82
|
-
end
|
83
|
-
|
84
|
-
def find_vendor
|
85
|
-
vendor = Spree::Vendor.find_by(id: contact)
|
86
|
-
unless vendor
|
87
|
-
context.fail!(message: "Vendor not found for contact #{contact}")
|
88
|
-
return nil
|
89
|
-
end
|
90
|
-
vendor
|
91
|
-
end
|
92
|
-
|
93
|
-
def update_telegram_chat(message, chat_id)
|
94
|
-
chat = SpreeCmCommissioner::TelegramChat.find_or_initialize_by(chat_id: chat_id)
|
95
|
-
unless chat.update(
|
96
|
-
chat_title: message.dig('chat', 'title') || 'Unnamed Chat',
|
97
|
-
chat_type: message.dig('chat', 'type')
|
98
|
-
)
|
99
|
-
context.fail!(message: "Failed to update chat: #{chat.errors.full_messages.join(', ')}")
|
100
|
-
return nil
|
101
|
-
end
|
102
|
-
|
103
|
-
context.chats << { id: chat.chat_id, title: chat.chat_title, type: chat.chat_type }
|
104
|
-
chat
|
105
|
-
end
|
106
|
-
|
107
|
-
def handle_successful_verification(chat, vendor, pin_code_record)
|
108
|
-
return if chat.vendor && chat.vendor != vendor
|
109
|
-
|
110
|
-
update_vendor_preferences(vendor, chat)
|
111
|
-
chat.update(active: true, vendor: vendor)
|
112
|
-
expire_pin_code(pin_code_record)
|
113
|
-
send_success_message(chat.chat_id, vendor.name)
|
114
|
-
context.verified_chat_ids << chat.chat_id
|
115
|
-
end
|
116
|
-
|
117
|
-
def update_vendor_preferences(vendor, chat)
|
118
|
-
vendor.update(
|
119
|
-
preferred_telegram_chat_id: chat.chat_id,
|
120
|
-
preferred_telegram_chat_name: chat.chat_title,
|
121
|
-
preferred_telegram_chat_type: chat.chat_type
|
122
|
-
)
|
123
|
-
end
|
124
|
-
|
125
|
-
def expire_pin_code(pin_code_record)
|
126
|
-
pin_code_record.expire
|
127
|
-
pin_code_record.save
|
128
|
-
end
|
129
|
-
|
130
|
-
def send_success_message(chat_id, vendor_name)
|
131
|
-
message = "✅ PIN code verified successfully! This chat is now connected to <b>#{vendor_name}</b>.\n\n" \
|
132
|
-
'All completed orders will be sent to this chat.'
|
133
|
-
send_message(chat_id, message)
|
134
|
-
end
|
135
|
-
|
136
|
-
def fetch_updates
|
137
|
-
::Telegram.bot.get_updates
|
138
|
-
end
|
139
|
-
|
140
|
-
def send_message(chat_id, text)
|
141
|
-
::Telegram.bot.send_message(chat_id: chat_id, text: text, parse_mode: 'HTML')
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
class PinCodeTelegram < PinCode
|
3
|
-
before_validation :set_telegram_attrs, on: :create
|
4
|
-
validates :contact, presence: true, numericality: { only_integer: true }, if: :telegram?
|
5
|
-
|
6
|
-
belongs_to :vendor, class_name: 'Spree::Vendor', foreign_key: 'contact', primary_key: 'id'
|
7
|
-
|
8
|
-
def telegram?
|
9
|
-
true
|
10
|
-
end
|
11
|
-
|
12
|
-
def expires_in_seconds
|
13
|
-
5 * 60
|
14
|
-
end
|
15
|
-
|
16
|
-
def expired?
|
17
|
-
expired_at < Time.zone.now
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def set_telegram_attrs
|
23
|
-
self.contact_type = :telegram
|
24
|
-
self.type = 'SpreeCmCommissioner::PinCodeTelegram'
|
25
|
-
self.expired_at = Time.zone.now + expires_in_seconds unless expired_at
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module SpreeCmCommissioner
|
2
|
-
module PromotionCategoryDecorator
|
3
|
-
def self.prepended(base)
|
4
|
-
base.belongs_to :vendor, class_name: 'Spree::Vendor', optional: true
|
5
|
-
end
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
unless Spree::PromotionCategory.included_modules.include?(SpreeCmCommissioner::PromotionCategoryDecorator)
|
10
|
-
Spree::PromotionCategory.prepend(SpreeCmCommissioner::PromotionCategoryDecorator)
|
11
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class CreateCmTelegramChats < ActiveRecord::Migration[7.0]
|
2
|
-
def change
|
3
|
-
create_table :cm_telegram_chats, if_not_exists: true do |t|
|
4
|
-
t.bigint :chat_id, null: false
|
5
|
-
t.string :chat_title
|
6
|
-
t.string :chat_type
|
7
|
-
t.boolean :active, default: false
|
8
|
-
t.references :vendor, foreign_key: { to_table: :spree_vendors }
|
9
|
-
t.timestamps
|
10
|
-
end
|
11
|
-
add_index :cm_telegram_chats, :chat_id, unique: true, if_not_exists: true
|
12
|
-
end
|
13
|
-
end
|
@@ -1,7 +0,0 @@
|
|
1
|
-
class AddVendorIdToSpreeCategory < ActiveRecord::Migration[7.0]
|
2
|
-
def change
|
3
|
-
unless column_exists?(:spree_promotion_categories, :vendor_id)
|
4
|
-
add_reference :spree_promotion_categories, :vendor, index: true, foreign_key: { to_table: :spree_vendors }
|
5
|
-
end
|
6
|
-
end
|
7
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
class AddPositionToCmDynamicFields < ActiveRecord::Migration[7.0]
|
2
|
-
def change
|
3
|
-
unless column_exists?(:cm_dynamic_fields, :position)
|
4
|
-
add_column :cm_dynamic_fields, :position, :integer, default: 0, null: false
|
5
|
-
end
|
6
|
-
|
7
|
-
unless index_exists?(:cm_dynamic_fields, :position, name: 'index_dynamic_fields_on_position')
|
8
|
-
add_index :cm_dynamic_fields, :position, name: 'index_dynamic_fields_on_position'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
class AddPositionToCmDynamicFieldOptions < ActiveRecord::Migration[7.0]
|
2
|
-
def change
|
3
|
-
unless column_exists?(:cm_dynamic_field_options, :position)
|
4
|
-
add_column :cm_dynamic_field_options, :position, :integer, default: 0, null: false
|
5
|
-
end
|
6
|
-
|
7
|
-
unless index_exists?(:cm_dynamic_field_options, :position, name: 'index_dynamic_field_options_on_position')
|
8
|
-
add_index :cm_dynamic_field_options, :position, name: 'index_dynamic_field_options_on_position'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|