cbraspag 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ nbproject
2
+ pkg
3
+ doc
4
+ tags
5
+ *.sw*
6
+ .bundle
7
+ .rvmrc
8
+ Gemfile.lock
9
+
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in cbraspag.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard 'bundler' do
2
+ watch('Gemfile')
3
+ end
4
+
5
+ guard 'rspec', :version => 2, :bundler => false do
6
+ watch(%r{^spec/(.*)_spec\.rb$})
7
+ watch(%r{^lib/cbraspag.rb$}) { "spec" }
8
+ watch(%r{^lib/cbraspag/(.*)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
9
+ watch('spec/spec_helper.rb') { "spec" }
10
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,23 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2012 - Codeminer42 contato(at)codeminer42.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
data/README.md ADDED
@@ -0,0 +1,539 @@
1
+ # cbraspag
2
+
3
+ cbraspag gem to use Braspag gateway
4
+
5
+ - Bult-in crypto server
6
+ - Bult-in fake server
7
+ - Support most operations in gateway
8
+ - Compatible with Active Merchant response object
9
+ - Support multiple connections easy
10
+
11
+
12
+ ## Usage CreditCard
13
+
14
+ This simple example demonstrates how a purchase can be made using a person's
15
+ credit card details.
16
+
17
+ require 'rubygems'
18
+ require 'cbraspag'
19
+
20
+ gateway = Braspag::Connection.new(
21
+ :merchant_id => '{84BE7E7F-698A-6C74-F820-AE359C2A07C2}',
22
+ :environment => :homologation
23
+ )
24
+
25
+ # The card verification value is also known as CVV2, CVC2, or CID
26
+ credit_card = Braspag::CreditCard.new(
27
+ :holder_name => 'Bob Bobsen',
28
+ :number => '4242424242424242',
29
+ :month => '8',
30
+ :year => '2012',
31
+ :verification_value => '123'
32
+ )
33
+
34
+ customer = Braspag::Customer.new(
35
+ :name => 'Bob Dela Bobsen'
36
+ )
37
+
38
+ order = Braspag::Order.new(
39
+ :payment_method => Braspag::PAYMENT_METHOD[:redecard],
40
+ :id => 11,
41
+ :amount => 10.00, # $10.00 (accepts all amounts as Integer values in cents)
42
+ :customer => customer,
43
+ :installments => 1,
44
+ :installments_type => Braspag::INTEREST[:no]
45
+ )
46
+
47
+ # Validating the card automatically detects the card type
48
+ if credit_card.valid?(:purchase) && customer.valid?(:purchase) && order.valid?(:purchase)
49
+ # Capture $10 from the credit card
50
+ response = gateway.purchase(order, credit_card)
51
+
52
+ if response.success?
53
+ puts "Successfully charged $#{sprintf("%.2f", order.amount / 100)} to the credit card #{order.gateway_id}"
54
+ else
55
+ raise StandardError, response.message
56
+ end
57
+ end
58
+
59
+ ## Usage Billet
60
+
61
+ This simple example demonstrates how create billet to a person.
62
+
63
+ require 'rubygems'
64
+ require 'cbraspag'
65
+
66
+ gateway = Braspag::Connection.new(
67
+ :merchant_id => '{84BE7E7F-698A-6C74-F820-AE359C2A07C2}',
68
+ :environment => :homologation
69
+ )
70
+
71
+ billet = Braspag::Billet.new(
72
+ :id => '123456', # (optional if configured in gateway)
73
+ :instructions => 'does not accepted after due date', # (optional)
74
+ :due_date_on => Date.parse('2012-01-01')
75
+ )
76
+
77
+ customer = Braspag::Customer.new(
78
+ :document => '21473696240', # (OPTIONAL)
79
+ :name => 'Bob Dela Bobsen',
80
+ :email => 'bob@mailinator.com' # send email to consumer (OPTIONAL)
81
+ )
82
+
83
+ order = Braspag::Order.new(
84
+ :payment_method => Braspag::PAYMENT_METHOD[:billet_bradesco],
85
+ :id => 11,
86
+ :amount => 10.00, # $10.00 (accepts all amounts as Integer values in cents)
87
+ :customer => customer
88
+ )
89
+
90
+ # Validating the card automatically detects the card type
91
+ if billet.valid?(:generate) && customer.valid?(:generate) && order.valid?(:generate)
92
+ response = gateway.generate_billet(order, billet)
93
+
94
+ if response.success?
95
+ puts "Successfully created billet, open in:#{billet.url}"
96
+ else
97
+ raise StandardError, response.message
98
+ end
99
+ end
100
+
101
+ ## Usage EFT (Eletronic Founds Transfer)
102
+
103
+ This simple example demonstrates how create eft to a person.
104
+
105
+ require 'rubygems'
106
+ require 'cbraspag'
107
+
108
+ gateway = Braspag::Connection.new(
109
+ :merchant_id => '{84BE7E7F-698A-6C74-F820-AE359C2A07C2}',
110
+ :environment => :homologation
111
+ )
112
+
113
+ #USING Braspag Webservice
114
+ eft = Braspag::EFT.new(
115
+ :crypto => Braspag::Crypto::Webservice
116
+ )
117
+
118
+ #USIGN CryptoJAR
119
+ eft = Braspag::EFT.new(
120
+ :crypto => Braspag::Crypto::JarWebservice.new(
121
+ :url => "http://0.0.0.0:9292"
122
+ :key => "123456123456"
123
+ )
124
+ )
125
+
126
+ #Without Crypto
127
+ eft = Braspag::EFT.new(
128
+ :crypto => Braspag::Crypto::NoCrypto
129
+ )
130
+
131
+ customer = Braspag::Customer.new(
132
+ :name => 'Bob Dela Bobsen'
133
+ )
134
+
135
+ order = Braspag::Order.new(
136
+ :payment_method => Braspag::PAYMENT_METHOD[:eft_itau],
137
+ :id => 1234,
138
+ :amount => '1000', # $10.00 (accepts all amounts as Integer values in cents)
139
+ :customer => customer
140
+ )
141
+
142
+ # Validating the card automatically detects the card type
143
+ if eft.valid?(:generate) && customer.valid?(:generate) && order.valid?(:generate)
144
+ response = gateway.generate_eft(order, eft)
145
+
146
+ if response.success?
147
+ puts "Successfully created eft, continue in:#{eft.code}"
148
+ else
149
+ raise StandardError, response.message
150
+ end
151
+ end
152
+
153
+ ## CREDITCARD AUTHORIZE
154
+
155
+ This simple example demonstrates how a authorize can be made using a person's
156
+ credit card details.
157
+
158
+ require 'rubygems'
159
+ require 'cbraspag'
160
+
161
+ gateway = Braspag::Connection.new(
162
+ :merchant_id => '{84BE7E7F-698A-6C74-F820-AE359C2A07C2}',
163
+ :environment => :homologation
164
+ )
165
+
166
+ # The card verification value is also known as CVV2, CVC2, or CID
167
+ credit_card = Braspag::CreditCard.new(
168
+ :holder_name => 'Bob Bobsen',
169
+ :number => '4242424242424242',
170
+ :month => '8',
171
+ :year => '2012',
172
+ :verification_value => '123'
173
+ )
174
+
175
+ customer = Braspag::Customer.new(
176
+ :name => 'Bob Dela Bobsen'
177
+ )
178
+
179
+ order = Braspag::Order.new(
180
+ :payment_method => Braspag::PAYMENT_METHOD[:redecard],
181
+ :id => 11,
182
+ :amount => '1000', # $10.00 (accepts all amounts as Integer values in cents)
183
+ :customer => customer,
184
+ :installments => 1,
185
+ :installments_type => Braspag::INTEREST[:no]
186
+ )
187
+
188
+ # Validating the card automatically detects the card type
189
+ if credit_card.valid?(:authorize) && customer.valid?(:authorize) && order.valid?(:authorize)
190
+ # Authorize $10 from the credit card
191
+ response = gateway.authorize(order, credit_card)
192
+
193
+ if response.success?
194
+ puts "Successfully authorized $#{sprintf("%.2f", order.amount / 100)} to the credit card #{order.gateway_id}"
195
+ else
196
+ raise StandardError, response.message
197
+ end
198
+ end
199
+
200
+ ## CREDITCARD CAPTURE
201
+
202
+ This simple example demonstrates how a capture can be made, after authorize.
203
+
204
+ require 'rubygems'
205
+ require 'cbraspag'
206
+
207
+ gateway = Braspag::Connection.new(
208
+ :merchant_id => '{84BE7E7F-698A-6C74-F820-AE359C2A07C2}',
209
+ :environment => :homologation
210
+ )
211
+
212
+ order = Braspag::Order.new(
213
+ :id => 11
214
+ )
215
+
216
+ # Capture $10 from the credit card
217
+ response = gateway.capture(order)
218
+
219
+ if response.success?
220
+ puts "Successfully charged #{order.id}"
221
+ else
222
+ raise StandardError, response.message
223
+ end
224
+
225
+ ## CREDITCARD VOID
226
+
227
+ This simple example demonstrates how a void transaction can be made.
228
+
229
+ require 'rubygems'
230
+ require 'cbraspag'
231
+
232
+ gateway = Braspag::Connection.new(
233
+ :merchant_id => '{84BE7E7F-698A-6C74-F820-AE359C2A07C2}',
234
+ :environment => :homologation
235
+ )
236
+
237
+ order = Braspag::Order.new(
238
+ :id => 11
239
+ )
240
+
241
+ response = gateway.void(order)
242
+
243
+ if response.success?
244
+ puts "Successfully charged #{order.id}"
245
+ else
246
+ raise StandardError, response.message
247
+ end
248
+
249
+ ### Partial Void
250
+
251
+ If need specify partial amount
252
+
253
+
254
+ response = gateway.void(order, '500')
255
+
256
+
257
+
258
+ ## ORDER INFO
259
+
260
+ Sometimes your need get status in braspag
261
+
262
+ > order = Order.new(:id => "1234")
263
+ > response = gateway.get(order)
264
+
265
+ > if response.success?
266
+ > puts order.authorization
267
+ > "148519"
268
+
269
+ > puts order.payment_method_name
270
+ > "Boleto Santander"
271
+
272
+ > puts order.payment_method
273
+ > "06"
274
+
275
+ > puts Braspag::Converter.payment_method_name?(order.payment_method)
276
+ > :billet_bradesco
277
+
278
+ > puts order.installments
279
+ > 1
280
+
281
+ > puts order.status
282
+ > 4
283
+
284
+ > puts Braspag::Converter.status_name?(order.status)
285
+ > :cancelled
286
+
287
+ > puts order.amount
288
+ > 500
289
+
290
+ > # Kind a datetime
291
+ > puts order.gateway_cancelled_at
292
+ > 2012-10-13 03:30:15 -0300
293
+
294
+ > # Kind a datetime
295
+ > puts order.gateway_paid_at
296
+ > 2012-10-12 13:42:30 -0300
297
+
298
+ > # Kind a datetime
299
+ > puts order.gateway_created_at
300
+ > 2012-10-11 17:44:23 -0300
301
+
302
+ > puts order.transaction_id
303
+ > "342818"
304
+
305
+ > puts order.gateway_id
306
+ > "02ff02e2-f1ce-4c2b-a874-a20bb98fb97e<"
307
+
308
+ > else
309
+ > puts response.code
310
+ > "XPTO"
311
+
312
+ > puts response.message
313
+ > puts "ERROR XPTO"
314
+ > end
315
+
316
+
317
+
318
+ ### CREDITCARD DETAILS
319
+
320
+ If order is a credit card, extras fields returning:
321
+
322
+ > order = Order.new(:id => "1234")
323
+ > response = gateway.get(order)
324
+
325
+ > puts order.credit_card.checking_number
326
+ > "342818"
327
+
328
+ > puts order.credit_card.avs
329
+ > false
330
+
331
+ > puts order.credit_card.autorization_number
332
+ > "148519"
333
+
334
+ > puts order.credit_card.card_number
335
+ > "345678*****0007"
336
+
337
+ > puts order.credit_card.transaction_number
338
+ > "101014343175"
339
+
340
+ > puts order.credit_card.avs_response
341
+ > "XPX RESPONSE"
342
+
343
+ > puts order.credit_card.issuing
344
+ > "XPX"
345
+
346
+ > puts order.credit_card.authenticated_number
347
+ > "112934"
348
+
349
+
350
+ ### BILL DETAILS
351
+
352
+ If order is a billet, extras fields returning:
353
+
354
+ > order = Order.new(:id => "1234")
355
+ > response = gateway.get(order)
356
+
357
+ > puts order.customer.name
358
+ > "Teste"
359
+
360
+ > puts order.billet.id
361
+ > "00070475"
362
+
363
+ > puts order.billet.code
364
+ > "35690.00361 03962.030007 00000.704759 6 54930000010000"
365
+
366
+ > # Kind a date
367
+ > puts order.billet.created_at
368
+ > 2012-10-11
369
+
370
+ > # Kind a date
371
+ > puts order.billet.due_date_on
372
+ > 2012-10-13
373
+
374
+ > puts order.billet.transferor
375
+ > "Codeminer42"
376
+
377
+ > puts order.billet.bank
378
+ > "356-5"
379
+
380
+ > puts order.billet.agency
381
+ > "0003"
382
+
383
+ > puts order.billet.account
384
+ > "6039620"
385
+
386
+ > puts order.billet.wallet
387
+ > "57"
388
+
389
+ > puts order.billet.amount
390
+ > 100.00
391
+
392
+ > puts order.billet.amount_paid
393
+ > 100.00
394
+
395
+ > # Kind a date
396
+ > puts order.billet.paid_at
397
+ > 2012-10-12
398
+
399
+ ## CREDITCARD RECURRING SAVE
400
+
401
+ Save credit card in Braspag PCI Compliant
402
+
403
+ require 'rubygems'
404
+ require 'cbraspag'
405
+
406
+ gateway = Braspag::Connection.new(
407
+ :merchant_id => '{84BE7E7F-698A-6C74-F820-AE359C2A07C2}',
408
+ :environment => :homologation
409
+ )
410
+
411
+ # The card verification value is also known as CVV2, CVC2, or CID
412
+ credit_card = Braspag::CreditCard.new(
413
+ :holder_name => 'Bob Bobsen',
414
+ :number => '4242424242424242',
415
+ :month => '8',
416
+ :year => '2012',
417
+ :alias => 'Card Visa' #(OPTIONAL)
418
+ )
419
+
420
+ customer = Braspag::Customer.new(
421
+ :name => 'Bob Dela Bobsen'
422
+ :document => '21473696240' #(OPTIONAL)
423
+ )
424
+
425
+ # Validating the card automatically detects the card type
426
+ if credit_card.valid?(:archive) && customer.valid?(:archive)
427
+ response = gateway.archive(credit_card, customer, "00000000-0000-0000-0000-000000000044")
428
+
429
+ if response.success?
430
+ puts "Successfully saved credit_card! The just key #{credit_card.id}"
431
+ else
432
+ raise StandardError, response.message
433
+ end
434
+ end
435
+
436
+ ## CREDITCARD RECURRING GET
437
+
438
+ Request the credit card info in Braspag PCI Compliant
439
+
440
+ require 'rubygems'
441
+ require 'cbraspag'
442
+
443
+ gateway = Braspag::Connection.new(
444
+ :merchant_id => '{84BE7E7F-698A-6C74-F820-AE359C2A07C2}',
445
+ :environment => :homologation
446
+ )
447
+
448
+ # The card verification value is also known as CVV2, CVC2, or CID
449
+ credit_card = Braspag::CreditCard.new(
450
+ :id => '123123123123123',
451
+ :alias => 'Card Visa' #(OPTIONAL)
452
+ )
453
+
454
+ # Validating the card automatically detects the card type
455
+ if credit_card.valid?(:get_recurrency)
456
+ response = gateway.get_recurrency(credit_card)
457
+
458
+ if response.success?
459
+ puts "Successfully get credit!"
460
+ puts "Holder: #{credit_card.holder_name}"
461
+ puts "Number: #{credit_card.number}"
462
+ puts "Month: #{credit_card.month}"
463
+ puts "Year: #{credit_card.year}"
464
+ else
465
+ raise StandardError, response.message
466
+ end
467
+ end
468
+
469
+
470
+ ## CREDITCARD RECURRING PURCHASE
471
+
472
+ Purchase order using recurrence
473
+
474
+ require 'rubygems'
475
+ require 'cbraspag'
476
+
477
+ gateway = Braspag::Connection.new(
478
+ :merchant_id => '{84BE7E7F-698A-6C74-F820-AE359C2A07C2}',
479
+ :environment => :homologation
480
+ )
481
+
482
+ # The card verification value is also known as CVV2, CVC2, or CID
483
+ credit_card = Braspag::CreditCard.new(
484
+ :id => '123415',
485
+ :verification_value => '123',
486
+ :alias => 'Card Visa' #(OPTIONAL)
487
+ )
488
+
489
+ customer = Braspag::Customer.new(
490
+ :name => 'Bob Dela Bobsen'
491
+ )
492
+
493
+ order = Braspag::Order.new(
494
+ :payment_method => Braspag::PAYMENT_METHOD[:redecard],
495
+ :id => 11,
496
+ :amount => 10.00, # $10.00 (accepts all amounts as Integer values in cents)
497
+ :customer => customer,
498
+ :installments => 1,
499
+ :installments_type => Braspag::INTEREST[:no]
500
+ )
501
+
502
+ # Validating the card automatically detects the card type
503
+ if credit_card.valid?(:recurrency) && customer.valid?(:recurrency) && order.valid?(:recurrency)
504
+ # Capture $10 from the credit card
505
+ response = gateway.recurrency(order, credit_card, "00000000-0000-0000-0000-000000000044")
506
+
507
+ if response.success?
508
+ puts "Successfully charged $#{sprintf("%.2f", order.amount / 100)} to the credit card #{credit_card.id}"
509
+ else
510
+ raise StandardError, response.message
511
+ end
512
+ en
513
+
514
+
515
+ # License
516
+
517
+ (The MIT License)
518
+
519
+ Copyright (c) 2012 - Codeminer42 contato(at)codeminer42.com
520
+
521
+ Permission is hereby granted, free of charge, to any person obtaining
522
+ a copy of this software and associated documentation files (the
523
+ 'Software'), to deal in the Software without restriction, including
524
+ without limitation the rights to use, copy, modify, merge, publish,
525
+ distribute, sublicense, and/or sell copies of the Software, and to
526
+ permit persons to whom the Software is furnished to do so, subject to
527
+ the following conditions:
528
+
529
+ The above copyright notice and this permission notice shall be
530
+ included in all copies or substantial portions of the Software.
531
+
532
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
533
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
534
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
535
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
536
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
537
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
538
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
539
+