Class: Serialize

Inherits:
Object
  • Object
show all
Defined in:
lib/compropago_sdk/factory/serialize.rb

Class Method Summary collapse

Class Method Details

.cp_order_info(data = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/compropago_sdk/factory/serialize.rb', line 23

def self.cp_order_info(data=nil)
  puts JSON.pretty_generate(data)
  if data.nil?
    return CpOrderInfo.new
  else
    obj = CpOrderInfo.new

    obj.id = data['id']
    obj.short_id = data['short_id']
    obj.type = data['type']
    obj.object = data['object']
    obj.created_at = data['created_at']
    obj.accepted_at = data['accepted_at']
    obj.expires_at = data['expires_at']
    obj.paid = data['paid']
    obj.amount = data['amount']
    obj.livemode = data['livemode']
    obj.currency = data['currency']
    obj.refunded = data['refunded']
    obj.fee = data['fee']
    obj.fee_details = Serialize::fee_details(data['fee_details'])
    obj.order_info = Serialize::order_info(data['order_info'])
    obj.customer = Serialize::customer(data['customer'])
    obj.api_version = data['']

    return obj
  end
end

.customer(data = nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/compropago_sdk/factory/serialize.rb', line 52

def self.customer(data=nil)
  if data.nil?
    Customer.new
  else
    obj = Customer.new

    obj.customer_name = data['customer_name']
    obj.customer_email = data['customer_email']
    obj.customer_phone = data['customer_phone']

    return obj
  end
end

.eval_auth_info(data = nil) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/compropago_sdk/factory/serialize.rb', line 66

def self.eval_auth_info(data=nil)
  if data.nil?
    return EvalAuthInfo.new
  else
    obj = EvalAuthInfo.new

    obj.type = data['type']
    obj.livemode = data['livemode']
    obj.mode_key = data['mode_key']
    obj.message = data['message']
    obj.code = data['code']

    return obj
  end
end

.exchange(data = nil) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/compropago_sdk/factory/serialize.rb', line 192

def self.exchange(data=nil)
  if data.nil?
    return Exchange.new
  else
    obj = Exchange.new

    obj.rate = data['rate'] ? data['rate'] : nil
    obj.request = data['request'] ? data['request'] : nil
    obj.origin_amount = data['origin_amount'] ? data['origin_amount'] : nil
    obj.final_amount = data['final_amount'] ? data['final_amount'] : nil
    obj.origin_currency = data['origin_currency'] ? data['origin_currency'] : nil
    obj.final_currency = data['final_currency'] ? data['final_currency'] : nil
    obj.exchange_id = data['exchange_id'] ? data['exchange_id'] : nil

    return obj
  end
end

.fee_details(data = nil) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/compropago_sdk/factory/serialize.rb', line 82

def self.fee_details(data=nil)
  if data.nil?
    return FeeDetails.new
  else
    obj = FeeDetails.new

    obj.amount = data['amount']
    obj.currency = data['currency']
    obj.type = data['type']
    obj.application = data['application']
    obj.amount_refunded = data['amount_refunded']
    obj.tax = data['tax']

    return obj
  end
end

.instruction_details(data = nil) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/compropago_sdk/factory/serialize.rb', line 99

def self.instruction_details(data=nil)
  if data.nil?
    return InstructionDetails.new
  else
    obj = InstructionDetails.new

    obj.payment_amount = data['payment_amount'] ? data['payment_amount'] : nil
    obj.payment_store = data['payment_store'] ? data['payment_store'] : nil
    obj.amount = data['amount'] ? data['amount'] : nil
    obj.store = data['store'] ? data['store'] : nil
    obj. = data['bank_account_number'] ? data['bank_account_number'] : nil
    obj.company_reference_name = data['company_reference_name'] ? data['company_reference_name'] : nil
    obj.company_reference_number = data['company_reference_number'] ? data['company_reference_number'] : nil
    obj.company_bank_number = data['company_bank_number'] ? data['company_bank_number'] : nil
    obj.order_reference_number = data['order_reference_number'] ? data['order_reference_number'] : nil
    obj. = data['bank_account_holder_name'] ? data['bank_account_holder_name'] : nil
    obj.bank_reference = data['bank_reference'] ? data['bank_reference'] : nil
    obj.bank_name = data['bank_name'] ? data['bank_name'] : nil

    return obj
  end
end

.instructions(data = nil) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/compropago_sdk/factory/serialize.rb', line 122

def self.instructions(data=nil)
  if data.nil?
    return Instructions.new
  else
    obj = Instructions.new

    obj.description = data['description']
    obj.step_1 = data['step_1']
    obj.step_2 = data['step_2']
    obj.step_3 = data['step_3']
    obj.note_extra_comition = data['note_extra_comition']
    obj.note_expiration_date = data['note_expiration_date']
    obj.note_confirmation = data['note_confirmation']

    obj.details = Serialize::instruction_details(data['details'])

    return obj
  end
end

.new_order_info(data = nil) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/compropago_sdk/factory/serialize.rb', line 142

def self.new_order_info(data=nil)
  if data.nil?
    return NewOrderInfo.new
  else
    obj = NewOrderInfo.new

    obj.id = data['id']
    obj.short_id = data['short_id']
    obj.type = data['type']
    obj.object = data['object']
    obj.created_at = data['created_at']
    obj.accepted_at = data['accepted_at']
    obj.expires_at = data['expires_at']
    obj.paid = data['paid']
    obj.amount = data['amount']
    obj.livemode = data['livemode']
    obj.currency = data['currency']
    obj.refunded = data['refunded']
    obj.fee = data['fee']
    obj.fee_details = Serialize::fee_details(data['fee_details'])
    obj.order_info = Serialize::order_info(data['order_info'])
    obj.customer = Serialize::customer(data['customer'])
    obj.instructions = Serialize::instructions(data['instructions'])
    obj.api_version = data['api_version']

    return obj
  end
end

.order_info(data = nil) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/compropago_sdk/factory/serialize.rb', line 171

def self.order_info(data=nil)
  if data.nil?
    return OrderInfo.new
  else
    obj = OrderInfo.new

    obj.order_id = data['order_id']
    obj.order_price = data['order_price']
    obj.order_name = data['order_name']
    obj.payment_method = data['payment_method']
    obj.store = data['store']
    obj.country = data['country']
    obj.image_url = data['image_url']
    obj.success_url = data['success_url']
    obj.fialed_url = data['failed_url']
    obj.exchange = Serialize::exchange(data['exchange'])

    return obj
  end
end

.place_order_info(data = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/compropago_sdk/factory/serialize.rb', line 3

def self.place_order_info(data=nil)
  if data.nil?
    return PlaceOrderInfo.new(nil, nil, nil, nil, nil)
  else
    return PlaceOrderInfo.new(
        data[:order_id],
        data[:order_name],
        data[:order_price],
        data[:customer_name],
        data[:customer_email],
        data[:payment_type] ? data[:payment_type] : 'OXXO',
        data[:currency] ? data[:currency] : 'MXN',
        data[:expiration_time] ? data[:expiration_time] : nil,
        data[:image_url] ? data[:image_url] : '',
        data[:app_client_name] ? data[:app_client_name] : 'sdk-ruby',
        data[:app_client_version] ? data[:app_client_version] : Client::VERSION,
    )
  end
end

.provider(data = nil) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/compropago_sdk/factory/serialize.rb', line 210

def self.provider(data=nil)
  if data.nil?
    return Provider.new
  else
    obj = Provider.new

    obj.name = data['name']
    obj.store_image = data['store_image']
    obj.availability = data['availability']
    obj.is_active = data['is_active']
    obj.internal_name = data['internal_name']
    obj.image_small = data['image_small']
    obj.image_medium = data['image_medium']
    obj.image_large = data['image_large']
    obj.transaction_limit = data['transaction_limit']
    obj.rank = data['rank']

    return obj
  end
end

.sms_data(data = nil) ⇒ Object



245
246
247
248
249
250
251
252
253
254
255
# File 'lib/compropago_sdk/factory/serialize.rb', line 245

def self.sms_data(data=nil)
  if data.nil?
    return SmsData.new
  else
    obj = SmsData.new

    obj.object = Serialize::sms_object(data['object'])

    return obj
  end
end

.sms_info(data = nil) ⇒ Object



257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/compropago_sdk/factory/serialize.rb', line 257

def self.sms_info(data=nil)
  if data.nil?
    return SmsInfo.new
  else
    obj = SmsInfo.new

    obj.type = data['type']
    obj.object = data['object']
    obj.data = Serialize::sms_data(data['data'])

    return obj
  end
end

.sms_object(data = nil) ⇒ Object



231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/compropago_sdk/factory/serialize.rb', line 231

def self.sms_object(data=nil)
  if data.nil?
    return SmsObject.new
  else
    obj = SmsObject.new

    obj.id = data['id']
    obj.object = data['object']
    obj.short_id = data['short_id']

    return obj
  end
end

.webhook(data = nil) ⇒ Object



271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/compropago_sdk/factory/serialize.rb', line 271

def self.webhook(data=nil)
  if data.nil?
    return Webhook.new
  else
    obj = Webhook.new

    obj.id = data['id'] ? data['id'] : nil
    obj.url = data['url'] ? data['url'] : nil
    obj.mode = data['mode'] ? data['mode'] : nil
    obj.status = data['status'] ? data['status'] : nil

    return obj
  end
end