spree_emerchantpay_genesis 0.1.6 → 0.1.7
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/CHANGELOG.md +9 -0
- data/app/helpers/spree_emerchantpay_genesis/mappers/genesis.rb +14 -2
- data/app/helpers/spree_emerchantpay_genesis/mappers/transaction.rb +60 -0
- data/app/helpers/spree_emerchantpay_genesis/payment_method_helper.rb +19 -0
- data/app/models/spree/gateway/emerchantpay_checkout.rb +1 -1
- data/app/repositories/spree_emerchantpay_genesis/spree_payments_repository.rb +29 -3
- data/config/locales/en.yml +7 -0
- data/lib/spree_emerchantpay_genesis/version.rb +1 -1
- metadata +15 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15b5e5ed86841d728dddc6749dd6829a422e915c9ddca396d3da9f63f8d0cf48
|
4
|
+
data.tar.gz: 31f819b12ba869f0ea706fbec6b55d1d2f77064862f5602c879a04d67317bc1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e9a3a9dd894f4f26f78ded9c05e7d0bd1e7ee9e9339e8abc5c4d8244c1f7be0605959df1fea55f9797e8c7b69b6f8d0e807314441770998acc32d586744e20f
|
7
|
+
data.tar.gz: cce74188db70045556aea1bcdba4516f4f508a40dd6b3d0fdaa0b3e368dcda7ebcadc79f7bc698c830d031ff77c92c0ad2c90f808bfd8ee17d8021df090df9ff
|
data/CHANGELOG.md
CHANGED
@@ -214,8 +214,7 @@ module SpreeEmerchantpayGenesis
|
|
214
214
|
|
215
215
|
# Map WPF Transaction Types
|
216
216
|
def transaction_types_attributes(options, source)
|
217
|
-
custom_attributes = source
|
218
|
-
transaction_types = PaymentMethodHelper.select_options_value options, :transaction_types
|
217
|
+
transaction_types, custom_attributes = wpf_selected_transaction_types options, source
|
219
218
|
|
220
219
|
transaction_types.each do |type|
|
221
220
|
next if type.empty?
|
@@ -248,6 +247,19 @@ module SpreeEmerchantpayGenesis
|
|
248
247
|
@context.locale = locale.delete_prefix('\'').delete_suffix('\'')
|
249
248
|
end
|
250
249
|
|
250
|
+
# Map WPF transaction types selected in the Payment Method Options
|
251
|
+
def wpf_selected_transaction_types(options, source)
|
252
|
+
transaction_types = PaymentMethodHelper.select_options_value options, :transaction_types
|
253
|
+
mobile_types = PaymentMethodHelper.fetch_wpf_mobile_types transaction_types
|
254
|
+
|
255
|
+
custom_attributes = source.public_metadata.merge mobile_types
|
256
|
+
transaction_types = (transaction_types - Mappers::Transaction.mobile_types_with_payment_sub_types).push(
|
257
|
+
*mobile_types.keys
|
258
|
+
)
|
259
|
+
|
260
|
+
[transaction_types, custom_attributes]
|
261
|
+
end
|
262
|
+
|
251
263
|
end
|
252
264
|
end
|
253
265
|
end
|
@@ -16,6 +16,16 @@ module SpreeEmerchantpayGenesis
|
|
16
16
|
GenesisRuby::Api::Constants::Transactions::VOID
|
17
17
|
].freeze
|
18
18
|
|
19
|
+
MOBILE_TYPES = [
|
20
|
+
GenesisRuby::Api::Constants::Transactions::GOOGLE_PAY,
|
21
|
+
GenesisRuby::Api::Constants::Transactions::APPLE_PAY,
|
22
|
+
GenesisRuby::Api::Constants::Transactions::PAY_PAL
|
23
|
+
].freeze
|
24
|
+
|
25
|
+
MOBILE_PAYMENT_SUB_TYPE_AUTHORIZE = 'authorize'.freeze
|
26
|
+
MOBILE_PAYMENT_SUB_TYPE_SALE = 'sale'.freeze
|
27
|
+
MOBILE_PAYMENT_SUB_TYPE_EXPRESS = 'express'.freeze
|
28
|
+
|
19
29
|
# Provide transaction class object from the given type
|
20
30
|
def self.for(transaction_type)
|
21
31
|
object_class = nil
|
@@ -40,6 +50,56 @@ module SpreeEmerchantpayGenesis
|
|
40
50
|
"GenesisRuby::Api::Requests::Financial::#{transaction_type.capitalize}".constantize
|
41
51
|
end
|
42
52
|
|
53
|
+
# Map Web Payment Form Mobile transaction types
|
54
|
+
def self.map_wpf_config_mobile_types(types)
|
55
|
+
MOBILE_TYPES.each { |type| types.delete type }
|
56
|
+
|
57
|
+
types.push(*mobile_types_with_payment_sub_types)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Provides Mobile payment types|subtypes
|
61
|
+
def self.mobile_payment_sub_types
|
62
|
+
%W[
|
63
|
+
_#{Mappers::Transaction::MOBILE_PAYMENT_SUB_TYPE_AUTHORIZE}
|
64
|
+
_#{Mappers::Transaction::MOBILE_PAYMENT_SUB_TYPE_SALE}
|
65
|
+
_#{Mappers::Transaction::MOBILE_PAYMENT_SUB_TYPE_EXPRESS}
|
66
|
+
]
|
67
|
+
end
|
68
|
+
|
69
|
+
# Provides all Mobile payment types with their subtypes
|
70
|
+
def self.mobile_types_with_payment_sub_types
|
71
|
+
%W[
|
72
|
+
#{GenesisRuby::Api::Constants::Transactions::GOOGLE_PAY}_#{MOBILE_PAYMENT_SUB_TYPE_SALE}
|
73
|
+
#{GenesisRuby::Api::Constants::Transactions::GOOGLE_PAY}_#{MOBILE_PAYMENT_SUB_TYPE_AUTHORIZE}
|
74
|
+
#{GenesisRuby::Api::Constants::Transactions::APPLE_PAY}_#{MOBILE_PAYMENT_SUB_TYPE_SALE}
|
75
|
+
#{GenesisRuby::Api::Constants::Transactions::APPLE_PAY}_#{MOBILE_PAYMENT_SUB_TYPE_AUTHORIZE}
|
76
|
+
#{GenesisRuby::Api::Constants::Transactions::PAY_PAL}_#{MOBILE_PAYMENT_SUB_TYPE_SALE}
|
77
|
+
#{GenesisRuby::Api::Constants::Transactions::PAY_PAL}_#{MOBILE_PAYMENT_SUB_TYPE_AUTHORIZE}
|
78
|
+
#{GenesisRuby::Api::Constants::Transactions::PAY_PAL}_#{MOBILE_PAYMENT_SUB_TYPE_EXPRESS}
|
79
|
+
]
|
80
|
+
end
|
81
|
+
|
82
|
+
# Extract mobile type from the sub type and return the WPF custom attribute structure
|
83
|
+
def self.extract_mobile_type_with_sub_type(mobile_with_sub_type)
|
84
|
+
mobile_type = mobile_with_sub_type.gsub(/#{Mappers::Transaction.mobile_payment_sub_types.join("|")}/, '')
|
85
|
+
|
86
|
+
Hash[mobile_type, Hash[mobile_subtype_key(mobile_type), mobile_with_sub_type.gsub(/#{mobile_type}_/, '')]]
|
87
|
+
end
|
88
|
+
|
89
|
+
# Returns the Mobile Sub/Type WFP custom attribute
|
90
|
+
def self.mobile_subtype_key(mobile_type)
|
91
|
+
google_pay = GenesisRuby::Api::Constants::Transactions::GOOGLE_PAY
|
92
|
+
apple_pay = GenesisRuby::Api::Constants::Transactions::APPLE_PAY
|
93
|
+
pay_pal = GenesisRuby::Api::Constants::Transactions::PAY_PAL
|
94
|
+
|
95
|
+
case mobile_type
|
96
|
+
when google_pay, apple_pay
|
97
|
+
'payment_subtype'
|
98
|
+
when pay_pal
|
99
|
+
'payment_type'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
43
103
|
end
|
44
104
|
end
|
45
105
|
end
|
@@ -35,6 +35,25 @@ module SpreeEmerchantpayGenesis
|
|
35
35
|
options[key]
|
36
36
|
end
|
37
37
|
|
38
|
+
# Provide a list of the available transaction types for the checkout payment method configuration
|
39
|
+
def fetch_wpf_transaction_types
|
40
|
+
Mappers::Transaction.map_wpf_config_mobile_types GenesisRuby::Utils::Transactions::WpfTypes.all
|
41
|
+
end
|
42
|
+
|
43
|
+
# Extract Custom Attributes defined along with the transaction types
|
44
|
+
def fetch_wpf_mobile_types(selected_transaction_types)
|
45
|
+
attributes = {}
|
46
|
+
selected_mobile_types = selected_transaction_types.intersection(
|
47
|
+
Mappers::Transaction.mobile_types_with_payment_sub_types
|
48
|
+
)
|
49
|
+
|
50
|
+
selected_mobile_types.each do |type|
|
51
|
+
attributes.merge! Mappers::Transaction.extract_mobile_type_with_sub_type type
|
52
|
+
end
|
53
|
+
|
54
|
+
attributes
|
55
|
+
end
|
56
|
+
|
38
57
|
end
|
39
58
|
|
40
59
|
end
|
@@ -4,7 +4,7 @@ module Spree
|
|
4
4
|
|
5
5
|
preference :transaction_types, :multi_select, default: lambda {
|
6
6
|
{
|
7
|
-
values:
|
7
|
+
values: SpreeEmerchantpayGenesis::PaymentMethodHelper.fetch_wpf_transaction_types,
|
8
8
|
selected: [GenesisRuby::Api::Constants::Transactions::SALE_3D]
|
9
9
|
}
|
10
10
|
}
|
@@ -35,11 +35,9 @@ module SpreeEmerchantpayGenesis
|
|
35
35
|
|
36
36
|
# Update the Spree Payment status from GenesisRuby::Api::Response object
|
37
37
|
def update_payment_status(payment, response, transaction_type)
|
38
|
-
capturable_types = GenesisRuby::Utils::Transactions::References::CapturableTypes
|
39
|
-
|
40
38
|
if response.approved?
|
41
39
|
action = :complete
|
42
|
-
action = :pend if
|
40
|
+
action = :pend if capturable_type? payment, transaction_type
|
43
41
|
|
44
42
|
payment.public_send(action)
|
45
43
|
end
|
@@ -48,6 +46,34 @@ module SpreeEmerchantpayGenesis
|
|
48
46
|
payment.void if response.voided?
|
49
47
|
end
|
50
48
|
|
49
|
+
# Determine if the given transaction type need capture reference action
|
50
|
+
def capturable_type?(payment, transaction_type)
|
51
|
+
capturable_types = GenesisRuby::Utils::Transactions::References::CapturableTypes
|
52
|
+
|
53
|
+
if SpreeEmerchantpayGenesis::Mappers::Transaction::MOBILE_TYPES.include? transaction_type
|
54
|
+
return mobile_authorize_type? payment, transaction_type
|
55
|
+
end
|
56
|
+
|
57
|
+
capturable_types.allowed_reference? transaction_type
|
58
|
+
end
|
59
|
+
|
60
|
+
# Determine if the given mobile type is authorize or not
|
61
|
+
def mobile_authorize_type?(payment, transaction_type)
|
62
|
+
transaction_helper = SpreeEmerchantpayGenesis::Mappers::Transaction
|
63
|
+
selected_mobile_types = SpreeEmerchantpayGenesis::PaymentMethodHelper.fetch_wpf_mobile_types(
|
64
|
+
payment.payment_method.preferred_transaction_types
|
65
|
+
)
|
66
|
+
|
67
|
+
if selected_mobile_types.is_a?(Hash) && selected_mobile_types.key?(transaction_type)
|
68
|
+
custom_attribute = selected_mobile_types[transaction_type.to_s]
|
69
|
+
custom_attribute_key = transaction_helper.mobile_subtype_key transaction_type
|
70
|
+
|
71
|
+
return custom_attribute[custom_attribute_key.to_s] == transaction_helper::MOBILE_PAYMENT_SUB_TYPE_AUTHORIZE
|
72
|
+
end
|
73
|
+
|
74
|
+
false
|
75
|
+
end
|
76
|
+
|
51
77
|
end
|
52
78
|
|
53
79
|
end
|
data/config/locales/en.yml
CHANGED
@@ -75,6 +75,13 @@ en:
|
|
75
75
|
webmoney: Webmoney
|
76
76
|
webpay: Webpay
|
77
77
|
wechat: Wechat
|
78
|
+
google_pay_authorize: Google Pay (Authorize)
|
79
|
+
google_pay_sale: Google Pay (Sale)
|
80
|
+
apple_pay_authorize: Apple Pay (Authorize)
|
81
|
+
apple_pay_sale: Apple Pay (Sale)
|
82
|
+
pay_pal_authorize: Pay Pal (Authorize)
|
83
|
+
pay_pal_sale: Pay Pal (Sale)
|
84
|
+
pay_pal_express: Pay Pal (Express)
|
78
85
|
ar: Arabic
|
79
86
|
bg: Bulgarian
|
80
87
|
de: German
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_emerchantpay_genesis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- emerchantpay ltd.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: genesis_ruby
|
@@ -45,6 +45,9 @@ dependencies:
|
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 4.4.0
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 4.8.0
|
48
51
|
type: :runtime
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -52,6 +55,9 @@ dependencies:
|
|
52
55
|
- - ">="
|
53
56
|
- !ruby/object:Gem::Version
|
54
57
|
version: 4.4.0
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 4.8.0
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: spree_core
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,6 +65,9 @@ dependencies:
|
|
59
65
|
- - ">="
|
60
66
|
- !ruby/object:Gem::Version
|
61
67
|
version: 4.4.0
|
68
|
+
- - "<"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 4.8.0
|
62
71
|
type: :runtime
|
63
72
|
prerelease: false
|
64
73
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -66,6 +75,9 @@ dependencies:
|
|
66
75
|
- - ">="
|
67
76
|
- !ruby/object:Gem::Version
|
68
77
|
version: 4.4.0
|
78
|
+
- - "<"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 4.8.0
|
69
81
|
- !ruby/object:Gem::Dependency
|
70
82
|
name: spree_extension
|
71
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -401,7 +413,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
401
413
|
version: '0'
|
402
414
|
requirements:
|
403
415
|
- none
|
404
|
-
rubygems_version: 3.
|
416
|
+
rubygems_version: 3.2.33
|
405
417
|
signing_key:
|
406
418
|
specification_version: 4
|
407
419
|
summary: emerchantpay Gateway Module for Spree
|