pagarme 1.9.6 → 1.9.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cd543f3e64ed61f404f6278c9bca1b74b216601
4
- data.tar.gz: 7e7bbab3994f861d6dea16952aac5ad1701ac442
3
+ metadata.gz: 07ef72a9ab3e1f21d8898baed73a8a239baed97d
4
+ data.tar.gz: 0d764d6aed23814807f143cf186369523f6df64b
5
5
  SHA512:
6
- metadata.gz: d08104c2256b4007d2638607e8505b7dd780cf60a29bd3a821b92b3ae41574efbaf387674f4c537941f6226ab5d6be77160e4d07c47b4b0d1ec418b9fcdb239a
7
- data.tar.gz: 4148ea215f0ac10197485d45b5a2a326ddae91f33cd0486dd6af4eac0edac96ad4bede64bc654a55804ee2d37cdf4b7568733f9d9b675ac865519422110e8bf5
6
+ metadata.gz: c4320d518446fc9749187ee5828743b077d2bb5910d4f03eb46bf175b0af166dfd2d7e58238c0ffcc9b813063007a08a8ef87b881d9e3fd18deb425c838e65d8
7
+ data.tar.gz: 77e7e2b622c6e5510e689292971b39eb1ce49b0a9a4512f2ae091b084275086fed672b8798c1690b0bbf3e8c22420b5ffc33f823f5e0d9aea1aae315c2903117
@@ -8,6 +8,7 @@ require 'pagarme/phone'
8
8
  require 'pagarme/address'
9
9
  require 'pagarme/subscription'
10
10
  require 'pagarme/transaction'
11
+ require 'pagarme/card'
11
12
  require 'pagarme/plan'
12
13
  require 'pagarme/request'
13
14
  require 'pagarme/errors'
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ require File.join(File.dirname(__FILE__), '..', 'pagarme')
3
+
4
+ module PagarMe
5
+ class Card < TransactionCommon
6
+ end
7
+ end
@@ -4,44 +4,71 @@ require File.join(File.dirname(__FILE__), '..', 'pagarme')
4
4
  module PagarMe
5
5
  class TransactionCommon < Model
6
6
 
7
- def initialize(response = {})
8
- super(response)
9
- self.payment_method = 'credit_card' unless self.payment_method
10
- self.installments = 1 unless self.installments
11
- self.status = 'local' unless self.status
12
- end
13
-
14
- def create
15
- self.card_hash = generate_card_hash unless self.card_hash
16
- self.card_number = nil
17
- self.card_holder_name = nil
18
- self.card_expiration_year = nil
19
- self.card_expiration_month = nil
20
- self.card_cvv = nil
21
- super
22
- end
23
-
24
- def card_data_parameters
25
- {
26
- :card_number => self.card_number,
27
- :card_holder_name => self.card_holder_name,
28
- :card_expiration_date => "#{self.card_expiration_month}#{self.card_expiration_year}",
29
- :card_cvv => self.card_cvv
30
- }
31
- end
32
-
33
- def generate_card_hash
34
- request = PagarMe::Request.new("/transactions/card_hash_key", 'GET')
35
- response = request.run
36
- card_data = {
37
- :card_number => self.card_number,
38
- :card_holder_name => self.card_holder_name,
39
- :card_expiration_date => "#{self.card_expiration_month}#{self.card_expiration_year}",
40
- :card_cvv => self.card_cvv
41
- }
42
-
43
- public_key = OpenSSL::PKey::RSA.new(response['public_key'])
44
- ret = "#{response['id']}_#{Base64.strict_encode64(public_key.public_encrypt(card_data.to_params))}"
45
- end
7
+ def initialize(response = {})
8
+ super(response)
9
+ self.payment_method = 'credit_card' unless self.payment_method
10
+ self.installments = 1 unless self.installments
11
+ self.status = 'local' unless self.status
12
+ end
13
+
14
+ def create
15
+ check_card_object
16
+ clear_card_data
17
+ super
18
+ end
19
+
20
+ def save
21
+ check_card_object
22
+ clear_card_data
23
+ super
24
+ end
25
+
26
+ def card_data_parameters
27
+ {
28
+ :card_number => self.card_number,
29
+ :card_holder_name => self.card_holder_name,
30
+ :card_expiration_date => "#{self.card_expiration_month}#{self.card_expiration_year}",
31
+ :card_cvv => self.card_cvv
32
+ }
33
+ end
34
+
35
+ def generate_card_hash
36
+ request = PagarMe::Request.new("/transactions/card_hash_key", 'GET')
37
+ response = request.run
38
+
39
+ public_key = OpenSSL::PKey::RSA.new(response['public_key'])
40
+ ret = "#{response['id']}_#{Base64.strict_encode64(public_key.public_encrypt(card_data_parameters.to_params))}"
41
+ end
42
+
43
+ def should_generate_card_hash
44
+ true
45
+ end
46
+
47
+ private
48
+ def check_card_object
49
+ if self.card
50
+ if self.card.id
51
+ self.card_id = self.card.id
52
+ else
53
+ self.card_number = self.card.card_number
54
+ self.card_holder_name = self.card.card_holder_name
55
+ self.card_expiration_year = self.card.card_expiration_year
56
+ self.card_expiration_month = self.card.card_expiration_month
57
+ self.card_cvv = self.card.card_cvv
58
+ end
59
+ self.card = nil
60
+ end
61
+ end
62
+
63
+ def clear_card_data
64
+ if self.should_generate_card_hash
65
+ self.card_hash = generate_card_hash unless self.card_hash || self.card_id
66
+ self.card_number = nil
67
+ self.card_holder_name = nil
68
+ self.card_expiration_year = nil
69
+ self.card_expiration_month = nil
70
+ self.card_cvv = nil
71
+ end
72
+ end
46
73
  end
47
74
  end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "pagarme"
7
- spec.version = "1.9.6"
7
+ spec.version = "1.9.7"
8
8
  spec.authors = ["Pedro Franceschi", "Henrique Dubugras"]
9
9
  spec.email = ["pedrohfranceschi@gmail.com", "henrique@pagar.me"]
10
10
  spec.description = %q{Pagar.me's ruby gem}
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ require_relative '../test_helper'
3
+
4
+ module PagarMe
5
+ class CardTest < Test::Unit::TestCase
6
+ should 'be able to create' do
7
+ card = test_card
8
+ card.create
9
+
10
+ assert card.id
11
+ assert card.first_digits == '411111'
12
+ assert card.last_digits = '1111'
13
+ end
14
+
15
+ should 'be able to find by id' do
16
+ card = test_card
17
+ card.create
18
+
19
+ card2 = PagarMe::Card.find_by_id(card.id)
20
+
21
+ assert card.id == card2.id
22
+ assert card.first_digits == card2.first_digits
23
+ assert card.last_digits == card2.last_digits
24
+ end
25
+ end
26
+ end
@@ -13,6 +13,49 @@ module PagarMe
13
13
  test_transaction_with_customer(subscription)
14
14
  end
15
15
 
16
+ should 'be able to create subscription with plan and unsaved card' do
17
+ plan = test_plan
18
+ plan.create
19
+
20
+ card = test_card
21
+
22
+ subscription = PagarMe::Subscription.new({
23
+ :postback_url => 'http://test.com/postback',
24
+ :payment_method => 'credit_card',
25
+ :card => card,
26
+ :plan => plan,
27
+ :customer => {
28
+ :email => 'customer@pagar.me'
29
+ }
30
+ })
31
+ subscription.create
32
+
33
+ assert subscription.id
34
+ assert subscription.plan.id == plan.id
35
+ end
36
+
37
+ should 'be able to create subscription with plan and saved card' do
38
+ plan = test_plan
39
+ plan.create
40
+
41
+ card = test_card
42
+ card.create
43
+
44
+ subscription = PagarMe::Subscription.new({
45
+ :postback_url => 'http://test.com/postback',
46
+ :payment_method => 'credit_card',
47
+ :card => card,
48
+ :plan => plan,
49
+ :customer => {
50
+ :email => 'customer@pagar.me'
51
+ }
52
+ })
53
+ subscription.create
54
+
55
+ assert subscription.id
56
+ assert subscription.plan.id == plan.id
57
+ end
58
+
16
59
  should 'be able to create subscription without plan' do
17
60
  subscription = test_subscription({:amount => 2000})
18
61
  subscription.create
@@ -11,6 +11,40 @@ module PagarMe
11
11
  test_transaction_response(transaction)
12
12
  end
13
13
 
14
+ should 'be able to charge with a saved card' do
15
+ card = test_card
16
+ card.create
17
+
18
+ transaction = PagarMe::Transaction.new({
19
+ :card => card,
20
+ :amount => 1000,
21
+ :payment_method => 'credit_card'
22
+ })
23
+
24
+ transaction.charge
25
+ assert transaction.status == 'paid'
26
+ end
27
+
28
+ should 'be able to charge with an unsaved card' do
29
+ card = test_card
30
+ transaction = PagarMe::Transaction.new({
31
+ :card => card,
32
+ :amount => 1000,
33
+ :payment_method => 'credit_card'
34
+ })
35
+
36
+ transaction.charge
37
+ assert transaction.status == 'paid'
38
+ end
39
+
40
+ should 'return a card object' do
41
+ transaction = test_transaction
42
+ transaction.create
43
+ assert transaction.card.id
44
+ assert transaction.card.first_digits == '490172'
45
+ assert transaction.card.last_digits == '4448'
46
+ end
47
+
14
48
  should 'be able to refund' do
15
49
  transaction = test_transaction
16
50
  transaction.charge
@@ -69,8 +103,7 @@ module PagarMe
69
103
 
70
104
  transaction2 = PagarMe::Transaction.new({
71
105
  :payment_method => 'boleto',
72
- :amount => '1000',
73
- :postback_url => 'http://url.com/postback'
106
+ :amount => '1000'
74
107
  })
75
108
 
76
109
  transaction.charge
@@ -82,7 +115,7 @@ module PagarMe
82
115
  transaction2.status = 'paid'
83
116
  transaction2.save
84
117
 
85
- transaction.refund({:bank_account => {:bank_code => '399', :agencia => '1234', :conta => '1234567', :conta_dv => '1', :legal_name => 'Jose da silva', :document_number => '68782915423'}})
118
+ transaction.refund({bank_account: {:bank_code => '399', :agencia => '1234', :conta => '1234567', :conta_dv => '1', :legal_name => 'Jose da silva', :document_number => '68782915423'}})
86
119
  assert transaction.status == 'pending_refund'
87
120
  end
88
121
 
@@ -13,6 +13,16 @@ def test_transaction(params = {})
13
13
  }.merge(params))
14
14
  end
15
15
 
16
+ def test_card(params = {})
17
+ return PagarMe::Card.new({
18
+ :card_number => '4111111111111111',
19
+ :card_holder_name => 'Jose da Silva',
20
+ :card_expiration_month => '10',
21
+ :card_expiration_year => '15',
22
+ :card_cvv => '314'
23
+ }.merge(params))
24
+ end
25
+
16
26
  def test_subscription_without_plan(params = {})
17
27
  return PagarMe::Subscription.new({
18
28
  :payment_method => 'credit_card',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pagarme
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.6
4
+ version: 1.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Franceschi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-25 00:00:00.000000000 Z
12
+ date: 2014-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -111,6 +111,7 @@ files:
111
111
  - certs/public_key.pem
112
112
  - lib/pagarme.rb
113
113
  - lib/pagarme/address.rb
114
+ - lib/pagarme/card.rb
114
115
  - lib/pagarme/customer.rb
115
116
  - lib/pagarme/errors.rb
116
117
  - lib/pagarme/model.rb
@@ -124,6 +125,7 @@ files:
124
125
  - lib/pagarme/util.rb
125
126
  - pagarme.gemspec
126
127
  - pagarme.rb
128
+ - test/pagarme/card.rb
127
129
  - test/pagarme/object.rb
128
130
  - test/pagarme/pagarme.rb
129
131
  - test/pagarme/plan.rb
@@ -154,6 +156,7 @@ signing_key:
154
156
  specification_version: 4
155
157
  summary: Allows integration with Pagar.me
156
158
  test_files:
159
+ - test/pagarme/card.rb
157
160
  - test/pagarme/object.rb
158
161
  - test/pagarme/pagarme.rb
159
162
  - test/pagarme/plan.rb