mastercard_merchant_checkout 2.0.0

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.
@@ -0,0 +1,215 @@
1
+ require 'date'
2
+ require 'roxml'
3
+ require_relative '../../mastercard_merchant_checkout/models/address'
4
+ require_relative '../../mastercard_merchant_checkout/models/authentication_options'
5
+ require_relative '../../mastercard_merchant_checkout/models/card'
6
+ require_relative '../../mastercard_merchant_checkout/models/personal_info'
7
+
8
+
9
+ module MastercardMerchantCheckout
10
+ # This class contains various methods to get paymentData response parameters returned by paymentDataApi.
11
+ class PaymentData
12
+ include ROXML
13
+
14
+ xml_name "PaymentData"
15
+
16
+ # @!attribute card
17
+ # @return [Card] the card details.
18
+ xml_accessor :card, :from =>"card",:as => Card
19
+
20
+ # @!attribute shipping_address
21
+ # @return [Address] the shipping address details.
22
+ xml_accessor :shipping_address, :from =>"shippingAddress",:as => Address
23
+
24
+ # @!attribute personal_info
25
+ # @return [PersonalInfo] the recipient's personal information.
26
+ xml_accessor :personal_info, :from =>"personalInfo",:as => PersonalInfo
27
+
28
+ # @!attribute wallet_id
29
+ # @return [String] the value which helps to identify origin wallet.
30
+ xml_accessor :wallet_id, :from =>"walletId"
31
+
32
+ # @!attribute authentication_options
33
+ # @return [AuthenticationOptions] the authentication information.
34
+ xml_accessor :authentication_options, :from =>"authenticationOptions",:as => AuthenticationOptions
35
+
36
+
37
+ # Attribute mapping from ruby-style variable name to JSON key.
38
+ def self.attribute_map
39
+ {
40
+ :card => :card ,
41
+ :shipping_address => :shippingAddress ,
42
+ :personal_info => :personalInfo ,
43
+ :wallet_id => :walletId ,
44
+ :authentication_options => :authenticationOptions
45
+
46
+ }
47
+ end
48
+
49
+ def initialize(attributes = {})
50
+ return unless attributes.is_a?(Hash)
51
+
52
+ # convert string to symbol for hash key
53
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
54
+
55
+
56
+ if attributes.has_key?(:card)
57
+ self.card = attributes[:card]
58
+ end
59
+
60
+ if attributes.has_key?(:shipping_address)
61
+ self.shipping_address = attributes[:shipping_address]
62
+ end
63
+
64
+ if attributes.has_key?(:personal_info)
65
+ self.personal_info = attributes[:personal_info]
66
+ end
67
+
68
+ if attributes.has_key?(:wallet_id)
69
+ self.wallet_id = attributes[:wallet_id]
70
+ end
71
+
72
+ if attributes.has_key?(:authentication_options)
73
+ self.authentication_options = attributes[:authentication_options]
74
+ end
75
+
76
+ end
77
+
78
+
79
+
80
+
81
+ # Check equality by comparing each attribute.
82
+ def ==(o)
83
+ return true if self.equal?(o)
84
+ self.class == o.class &&
85
+ card == o.card &&
86
+ shipping_address == o.shipping_address &&
87
+ personal_info == o.personal_info &&
88
+ wallet_id == o.wallet_id &&
89
+ authentication_options == o.authentication_options
90
+ end
91
+
92
+ # @see the `==` method
93
+ def eql?(o)
94
+ self == o
95
+ end
96
+
97
+ # Calculate hash code according to all attributes.
98
+ def hash
99
+ [card, shipping_address, personal_info, wallet_id, authentication_options].hash
100
+ end
101
+
102
+ # build the object from hash
103
+ def build_from_hash(attributes)
104
+ return nil unless attributes.is_a?(Hash)
105
+ self.class.datatype_map.each_pair do |key, type|
106
+ if type =~ /^Array<(.*)>/i
107
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
108
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
109
+ else
110
+ #TODO show warning in debug mode
111
+ end
112
+ elsif !attributes[self.class.attribute_map[key]].nil?
113
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
114
+ else
115
+ # data not found in attributes(hash), not an issue as the data can be optional
116
+ end
117
+ end
118
+
119
+ self
120
+ end
121
+
122
+ def _deserialize(type, value)
123
+ case type.to_sym
124
+ when :DateTime
125
+ DateTime.parse(value)
126
+ when :Date
127
+ Date.parse(value)
128
+ when :String
129
+ value.to_s
130
+ when :Integer
131
+ value.to_i
132
+ when :Float
133
+ value.to_f
134
+ when :BOOLEAN
135
+ if value =~ /^(true|t|yes|y|1)$/i
136
+ true
137
+ else
138
+ false
139
+ end
140
+ when /\AArray<(?<inner_type>.+)>\z/
141
+ inner_type = Regexp.last_match[:inner_type]
142
+ value.map { |v| _deserialize(inner_type, v) }
143
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
144
+ k_type = Regexp.last_match[:k_type]
145
+ v_type = Regexp.last_match[:v_type]
146
+ {}.tap do |hash|
147
+ value.each do |k, v|
148
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
149
+ end
150
+ end
151
+ else # model
152
+ _model = MastercardMerchantCheckout.const_get(type).new
153
+ _model.build_from_hash(value)
154
+ end
155
+ end
156
+
157
+ def to_s
158
+ to_hash.to_s
159
+ end
160
+
161
+ # to_body is an alias to to_body (backward compatibility))
162
+ def to_body
163
+ to_hash
164
+ end
165
+
166
+ # return the object in the form of hash
167
+ def to_hash(include_root = false)
168
+ attributes_hash = {}
169
+ hash = {}
170
+ self.class.attribute_map.each_pair do |attr, param|
171
+ value = self.send(attr)
172
+ next if value.nil?
173
+ hash[param] = _to_hash(value)
174
+ end
175
+ attributes_hash = include_root ? { "PaymentData" => hash } : hash
176
+ return attributes_hash
177
+ end
178
+
179
+ # Method to output non-array value in the form of hash
180
+ # For object, use to_hash. Otherwise, just return the value
181
+ def _to_hash(value)
182
+ if value.is_a?(Array)
183
+ value.compact.map{ |v| _to_hash(v) }
184
+ elsif value.is_a?(Hash)
185
+ {}.tap do |hash|
186
+ value.each { |k, v| hash[k] = _to_hash(v) }
187
+ end
188
+ elsif value.respond_to? :to_hash
189
+ value.to_hash
190
+ else
191
+ value
192
+ end
193
+ end
194
+
195
+
196
+ private
197
+ def after_parse
198
+ self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
199
+ end
200
+
201
+ # Attribute datatype mapping.
202
+ def self.datatype_map
203
+ {
204
+ :card => 'Card',
205
+ :shipping_address => 'Address',
206
+ :personal_info => 'PersonalInfo',
207
+ :wallet_id => 'String',
208
+ :authentication_options => 'AuthenticationOptions'
209
+
210
+ }
211
+ end
212
+ end
213
+
214
+
215
+ end
@@ -0,0 +1,189 @@
1
+ require 'date'
2
+ require 'roxml'
3
+
4
+
5
+ module MastercardMerchantCheckout
6
+ # This class contains methods to get the recipient's personal details.
7
+ class PersonalInfo
8
+ include ROXML
9
+
10
+ xml_name "PersonalInfo"
11
+
12
+ # @!attribute recipient_name
13
+ # @return [String] the recipient's name.
14
+ xml_accessor :recipient_name, :from =>"recipientName"
15
+
16
+ # @!attribute recipient_phone
17
+ # @return [String] the recipient's phone number.
18
+ xml_accessor :recipient_phone, :from =>"recipientPhone"
19
+
20
+ # @!attribute recipient_email_address
21
+ # @return [String] the recipient's email address.
22
+ xml_accessor :recipient_email_address, :from =>"recipientEmailAddress"
23
+
24
+
25
+ # Attribute mapping from ruby-style variable name to JSON key.
26
+ def self.attribute_map
27
+ {
28
+ :recipient_name => :recipientName ,
29
+ :recipient_phone => :recipientPhone ,
30
+ :recipient_email_address => :recipientEmailAddress
31
+
32
+ }
33
+ end
34
+
35
+ def initialize(attributes = {})
36
+ return unless attributes.is_a?(Hash)
37
+
38
+ # convert string to symbol for hash key
39
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
40
+
41
+
42
+ if attributes.has_key?(:recipient_name)
43
+ self.recipient_name = attributes[:recipient_name]
44
+ end
45
+
46
+ if attributes.has_key?(:recipient_phone)
47
+ self.recipient_phone = attributes[:recipient_phone]
48
+ end
49
+
50
+ if attributes.has_key?(:recipient_email_address)
51
+ self.recipient_email_address = attributes[:recipient_email_address]
52
+ end
53
+
54
+ end
55
+
56
+
57
+
58
+
59
+ # Check equality by comparing each attribute.
60
+ def ==(o)
61
+ return true if self.equal?(o)
62
+ self.class == o.class &&
63
+ recipient_name == o.recipient_name &&
64
+ recipient_phone == o.recipient_phone &&
65
+ recipient_email_address == o.recipient_email_address
66
+ end
67
+
68
+ # @see the `==` method
69
+ def eql?(o)
70
+ self == o
71
+ end
72
+
73
+ # Calculate hash code according to all attributes.
74
+ def hash
75
+ [recipient_name, recipient_phone, recipient_email_address].hash
76
+ end
77
+
78
+ # build the object from hash
79
+ def build_from_hash(attributes)
80
+ return nil unless attributes.is_a?(Hash)
81
+ self.class.datatype_map.each_pair do |key, type|
82
+ if type =~ /^Array<(.*)>/i
83
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
84
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
85
+ else
86
+ #TODO show warning in debug mode
87
+ end
88
+ elsif !attributes[self.class.attribute_map[key]].nil?
89
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
90
+ else
91
+ # data not found in attributes(hash), not an issue as the data can be optional
92
+ end
93
+ end
94
+
95
+ self
96
+ end
97
+
98
+ def _deserialize(type, value)
99
+ case type.to_sym
100
+ when :DateTime
101
+ DateTime.parse(value)
102
+ when :Date
103
+ Date.parse(value)
104
+ when :String
105
+ value.to_s
106
+ when :Integer
107
+ value.to_i
108
+ when :Float
109
+ value.to_f
110
+ when :BOOLEAN
111
+ if value =~ /^(true|t|yes|y|1)$/i
112
+ true
113
+ else
114
+ false
115
+ end
116
+ when /\AArray<(?<inner_type>.+)>\z/
117
+ inner_type = Regexp.last_match[:inner_type]
118
+ value.map { |v| _deserialize(inner_type, v) }
119
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
120
+ k_type = Regexp.last_match[:k_type]
121
+ v_type = Regexp.last_match[:v_type]
122
+ {}.tap do |hash|
123
+ value.each do |k, v|
124
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
125
+ end
126
+ end
127
+ else # model
128
+ _model = MastercardMerchantCheckout.const_get(type).new
129
+ _model.build_from_hash(value)
130
+ end
131
+ end
132
+
133
+ def to_s
134
+ to_hash.to_s
135
+ end
136
+
137
+ # to_body is an alias to to_body (backward compatibility))
138
+ def to_body
139
+ to_hash
140
+ end
141
+
142
+ # return the object in the form of hash
143
+ def to_hash(include_root = false)
144
+ attributes_hash = {}
145
+ hash = {}
146
+ self.class.attribute_map.each_pair do |attr, param|
147
+ value = self.send(attr)
148
+ next if value.nil?
149
+ hash[param] = _to_hash(value)
150
+ end
151
+ attributes_hash = include_root ? { "PersonalInfo" => hash } : hash
152
+ return attributes_hash
153
+ end
154
+
155
+ # Method to output non-array value in the form of hash
156
+ # For object, use to_hash. Otherwise, just return the value
157
+ def _to_hash(value)
158
+ if value.is_a?(Array)
159
+ value.compact.map{ |v| _to_hash(v) }
160
+ elsif value.is_a?(Hash)
161
+ {}.tap do |hash|
162
+ value.each { |k, v| hash[k] = _to_hash(v) }
163
+ end
164
+ elsif value.respond_to? :to_hash
165
+ value.to_hash
166
+ else
167
+ value
168
+ end
169
+ end
170
+
171
+
172
+ private
173
+ def after_parse
174
+ self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
175
+ end
176
+
177
+ # Attribute datatype mapping.
178
+ def self.datatype_map
179
+ {
180
+ :recipient_name => 'String',
181
+ :recipient_phone => 'String',
182
+ :recipient_email_address => 'String'
183
+
184
+ }
185
+ end
186
+ end
187
+
188
+
189
+ end
@@ -0,0 +1,222 @@
1
+ require 'date'
2
+ require 'roxml'
3
+
4
+
5
+ module MastercardMerchantCheckout
6
+ # This class contains different methods to send transaction details to Masterpass using PostbackApi.
7
+ class Postback
8
+ include ROXML
9
+
10
+ xml_name "Postback"
11
+
12
+ # @!attribute transaction_id
13
+ # @return [String] the transaction Id.
14
+ xml_accessor :transaction_id, :from =>"transactionId"
15
+
16
+ # @!attribute currency
17
+ # @return [String] the currency for the transaction; for example, USD.
18
+ xml_accessor :currency, :from =>"currency"
19
+
20
+ # @!attribute amount
21
+ # @return [Float] the transaction order amount.
22
+ xml_accessor :amount, :from =>"amount"
23
+
24
+ # @!attribute payment_successful
25
+ # @return [BOOLEAN] the payment status indicator. It is set to true if payment successful with PSP else false.
26
+ xml_accessor :payment_successful, :from =>"paymentSuccessful"
27
+
28
+ # @!attribute payment_code
29
+ # @return [String] the six-digit approval code returned by payment API.
30
+ xml_accessor :payment_code, :from =>"paymentCode"
31
+
32
+ # @!attribute payment_date
33
+ # @return [DateTime] the date of purchase.
34
+ xml_accessor :payment_date, :from =>"paymentDate"
35
+
36
+
37
+ # Attribute mapping from ruby-style variable name to JSON key.
38
+ def self.attribute_map
39
+ {
40
+ :transaction_id => :transactionId ,
41
+ :currency => :currency ,
42
+ :amount => :amount ,
43
+ :payment_successful => :paymentSuccessful ,
44
+ :payment_code => :paymentCode ,
45
+ :payment_date => :paymentDate
46
+
47
+ }
48
+ end
49
+
50
+ def initialize(attributes = {})
51
+ return unless attributes.is_a?(Hash)
52
+
53
+ # convert string to symbol for hash key
54
+ attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
55
+
56
+
57
+ if attributes.has_key?(:transaction_id)
58
+ self.transaction_id = attributes[:transaction_id]
59
+ end
60
+
61
+ if attributes.has_key?(:currency)
62
+ self.currency = attributes[:currency]
63
+ end
64
+
65
+ if attributes.has_key?(:amount)
66
+ self.amount = attributes[:amount]
67
+ end
68
+
69
+ if attributes.has_key?(:payment_successful)
70
+ self.payment_successful = attributes[:payment_successful]
71
+ end
72
+
73
+ if attributes.has_key?(:payment_code)
74
+ self.payment_code = attributes[:payment_code]
75
+ end
76
+
77
+ if attributes.has_key?(:payment_date)
78
+ self.payment_date = attributes[:payment_date]
79
+ end
80
+
81
+ end
82
+
83
+
84
+
85
+
86
+ # Check equality by comparing each attribute.
87
+ def ==(o)
88
+ return true if self.equal?(o)
89
+ self.class == o.class &&
90
+ transaction_id == o.transaction_id &&
91
+ currency == o.currency &&
92
+ amount == o.amount &&
93
+ payment_successful == o.payment_successful &&
94
+ payment_code == o.payment_code &&
95
+ payment_date == o.payment_date
96
+ end
97
+
98
+ # @see the `==` method
99
+ def eql?(o)
100
+ self == o
101
+ end
102
+
103
+ # Calculate hash code according to all attributes.
104
+ def hash
105
+ [transaction_id, currency, amount, payment_successful, payment_code, payment_date].hash
106
+ end
107
+
108
+ # build the object from hash
109
+ def build_from_hash(attributes)
110
+ return nil unless attributes.is_a?(Hash)
111
+ self.class.datatype_map.each_pair do |key, type|
112
+ if type =~ /^Array<(.*)>/i
113
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
114
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
115
+ else
116
+ #TODO show warning in debug mode
117
+ end
118
+ elsif !attributes[self.class.attribute_map[key]].nil?
119
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
120
+ else
121
+ # data not found in attributes(hash), not an issue as the data can be optional
122
+ end
123
+ end
124
+
125
+ self
126
+ end
127
+
128
+ def _deserialize(type, value)
129
+ case type.to_sym
130
+ when :DateTime
131
+ DateTime.parse(value)
132
+ when :Date
133
+ Date.parse(value)
134
+ when :String
135
+ value.to_s
136
+ when :Integer
137
+ value.to_i
138
+ when :Float
139
+ value.to_f
140
+ when :BOOLEAN
141
+ if value =~ /^(true|t|yes|y|1)$/i
142
+ true
143
+ else
144
+ false
145
+ end
146
+ when /\AArray<(?<inner_type>.+)>\z/
147
+ inner_type = Regexp.last_match[:inner_type]
148
+ value.map { |v| _deserialize(inner_type, v) }
149
+ when /\AHash<(?<k_type>.+), (?<v_type>.+)>\z/
150
+ k_type = Regexp.last_match[:k_type]
151
+ v_type = Regexp.last_match[:v_type]
152
+ {}.tap do |hash|
153
+ value.each do |k, v|
154
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
155
+ end
156
+ end
157
+ else # model
158
+ _model = MastercardMerchantCheckout.const_get(type).new
159
+ _model.build_from_hash(value)
160
+ end
161
+ end
162
+
163
+ def to_s
164
+ to_hash.to_s
165
+ end
166
+
167
+ # to_body is an alias to to_body (backward compatibility))
168
+ def to_body
169
+ to_hash
170
+ end
171
+
172
+ # return the object in the form of hash
173
+ def to_hash(include_root = false)
174
+ attributes_hash = {}
175
+ hash = {}
176
+ self.class.attribute_map.each_pair do |attr, param|
177
+ value = self.send(attr)
178
+ next if value.nil?
179
+ hash[param] = _to_hash(value)
180
+ end
181
+ attributes_hash = include_root ? { "Postback" => hash } : hash
182
+ return attributes_hash
183
+ end
184
+
185
+ # Method to output non-array value in the form of hash
186
+ # For object, use to_hash. Otherwise, just return the value
187
+ def _to_hash(value)
188
+ if value.is_a?(Array)
189
+ value.compact.map{ |v| _to_hash(v) }
190
+ elsif value.is_a?(Hash)
191
+ {}.tap do |hash|
192
+ value.each { |k, v| hash[k] = _to_hash(v) }
193
+ end
194
+ elsif value.respond_to? :to_hash
195
+ value.to_hash
196
+ else
197
+ value
198
+ end
199
+ end
200
+
201
+
202
+ private
203
+ def after_parse
204
+ self.send(:remove_instance_variable, :@roxml_references) if defined? self.roxml_references
205
+ end
206
+
207
+ # Attribute datatype mapping.
208
+ def self.datatype_map
209
+ {
210
+ :transaction_id => 'String',
211
+ :currency => 'String',
212
+ :amount => 'Float',
213
+ :payment_successful => 'BOOLEAN',
214
+ :payment_code => 'String',
215
+ :payment_date => 'DateTime'
216
+
217
+ }
218
+ end
219
+ end
220
+
221
+
222
+ end