mymoip 0.7.0 → 0.8.0

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: 53ae6a3acf07d96de7fdeb44ec9f36da4b4d8302
4
- data.tar.gz: 9a35890d9732b300341b60e8184d690b0cf6ca4f
3
+ metadata.gz: f7770df829260624c7e35e953fec04f41bb89a57
4
+ data.tar.gz: ba6208e1363b11bc1e2ed072780ece03459404d5
5
5
  SHA512:
6
- metadata.gz: 4d2460af5d3c904b87d6ebe4f3deec91964e00a68331b191265abdedd9be87ca5fcd2e1df50c021bf83e684c541fea1fceed6e29970fadbb258b4b3c083129ef
7
- data.tar.gz: 39a6d852ca28a90ab3dbfeee666f912c7eb61dd86ea2fd94f869d7b54968bf29dc1907bef22715f1b462e0458011c5a8410ff0dc9586134526bb5fc07dafddde
6
+ metadata.gz: 3db1554c59dc131a3a5b8a682103ffd33acf9d36a65c1019b83bb4330bb6085e05b02803d6c458e35258f21e466fd90832c124af0a6f7f81dec82b893fa21e10
7
+ data.tar.gz: b023b1b7cef15c1be9320016a57e45efe533c2b813b3d3ae5e9bcfd8e8425e4c9a926bcf458c1a8f4098e0a4ce9310a882aabc15b9538de743d5c48174779364
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.8.0
4
+
5
+ * Perform optional extra validations in CreditCard. (by @hugomaiavieira)
6
+ * Fix regex for CreditCard#expiration_date validation. (by @hugomaiavieira)
7
+ * Accept payments by bank debit. (by @hugomaiavieira)
8
+ * Accept payments by payment slip aka boleto. (by @hugomaiavieira)
9
+ * Fix missing forward of PaymentRequest#api_call options to Request's
10
+ implementation. (by @hugomaiavieira)
11
+ * Accept to set invalid owner_birthday in CreditCard. (by @hugomaiavieira)
12
+
3
13
  ## 0.7.0
4
14
 
5
15
  * Allow payments using redirection to Moip's domain. (by @oznek)
data/README.md CHANGED
@@ -85,12 +85,12 @@ purchase = MyMoip::Purchase.new(
85
85
  payer: payer_attrs
86
86
  )
87
87
  purchase.checkout! # => true OR false (succesfull state)
88
- purchase.code # Moip code or nil, depending of the checkout's return
88
+ purchase.code # Moip code or nil, depending of the checkout's return
89
89
  ```
90
90
 
91
91
  ## The hard way
92
92
 
93
- **First request: what and from who**
93
+ ### First request: what and from who
94
94
 
95
95
  ```ruby
96
96
  payer = MyMoip::Payer.new(
@@ -119,33 +119,70 @@ transparent_request = MyMoip::TransparentRequest.new('your_logging_id')
119
119
  transparent_request.api_call(instruction)
120
120
  ```
121
121
 
122
- **Second request: how**
122
+ ### Second request: how
123
+
124
+ #### Credit card
123
125
 
124
126
  ```ruby
125
127
  credit_card = MyMoip::CreditCard.new(
126
- logo: 'visa',
127
- card_number: '4916654211627608',
128
- expiration_date: '06/15',
129
- security_code: '000',
130
- owner_name: 'Juquinha da Rocha',
131
- owner_birthday: '03/11/1984',
132
- owner_phone: '5130405060',
133
- owner_cpf: '52211670695'
128
+ logo: 'visa',
129
+ card_number: '4916654211627608',
130
+ expiration_date: '06/15',
131
+ security_code: '000',
132
+ owner_name: 'Juquinha da Rocha',
133
+ owner_birthday: '03/11/1984',
134
+ owner_phone: '5130405060',
135
+ owner_cpf: '52211670695',
136
+ perform_extra_validation: true # optional: see the next sub section
134
137
  )
135
138
 
136
- credit_card_payment = MyMoip::CreditCardPayment.new(credit_card,
137
- installments: 1)
138
- payment_request = MyMoip::PaymentRequest.new('your_logging_id')
139
- payment_request.api_call(credit_card_payment,
140
- token: transparent_request.token)
139
+ credit_card_payment = MyMoip::CreditCardPayment.new(credit_card, installments: 1)
140
+ payment_request = MyMoip::PaymentRequest.new('your_logging_id')
141
+ payment_request.api_call(credit_card_payment, token: transparent_request.token)
142
+ ```
143
+
144
+ ##### Credit card extra validation
145
+
146
+ There is a already [reported](http://goo.gl/celJIZ) bug that the API don't requires some attributes returning a successful [response](https://gist.github.com/Irio/4032350). To "fix it" you can enable an extra validation with `perform_extra_validation` option. It will require the presence of all credit card attributes.
147
+
148
+
149
+ #### Payment slip (aka boleto)
150
+
151
+ ```ruby
152
+ payment_slip_payment = MyMoip::PaymentSlipPayment.new()
153
+ payment_request = MyMoip::PaymentRequest.new('your_logging_id')
154
+ payment_request.api_call(payment_slip_payment, token: transparent_request.token)
141
155
  ```
142
156
 
143
- **Success?**
157
+ #### Bank debit
158
+
159
+ ```ruby
160
+ bank_debit = MyMoip::BankDebit.new(bank: :itau)
161
+ # you can find the available banks on MyMoip::BankDebit::AVAILABLE_BANKS
162
+
163
+ bank_debit_payment = MyMoip::BankDebitPayment.new(bank_debit)
164
+ payment_request = MyMoip::PaymentRequest.new('your_logging_id')
165
+ payment_request.api_call(bank_debit_payment, token: transparent_request.token)
166
+ ```
167
+
168
+ ### Success?
144
169
 
145
170
  ```ruby
146
171
  payment_request.success?
147
172
  ```
148
173
 
174
+ ### Payment url
175
+
176
+ For **payment slip** and **bank debit**, payment request will have a url. This
177
+ url redirect to:
178
+
179
+ - When **payment slip**: the payment slip to user print and pay
180
+ - When **bank debit**: the bank's specific payment page
181
+
182
+ ```ruby
183
+ payment_request.url
184
+ ```
185
+
149
186
  ## More!
150
187
 
151
188
  Yes, you should read (and help improve!) the docs.
@@ -213,7 +250,7 @@ instruction = MyMoip::Instruction.new(
213
250
  ### Notification and return URLs
214
251
 
215
252
  URLs configured at MoIP account can be overrided by passing new URLs values to the instruction object.
216
- A notification URL is used for MoIP NASP notification system, responsible for transaction changes signals,
253
+ A notification URL is used for MoIP NASP notification system, responsible for transaction changes signals,
217
254
  and a return URL is used to return to your website when a payment is using external websites.
218
255
 
219
256
  ```ruby
@@ -229,7 +266,7 @@ instruction = MyMoip::Instruction.new(
229
266
 
230
267
  ### Payment methods configuration
231
268
 
232
- If you don't need all the payment methods available, you can choose some by configuring
269
+ If you don't need all the payment methods available, you can choose some by configuring
233
270
  PaymentMethods and adding it to the instruction:
234
271
 
235
272
  ```ruby
@@ -238,7 +275,7 @@ payment_methods = MyMoip::PaymentMethods.new(
238
275
  credit_card: true,
239
276
  debit: true,
240
277
  debit_card: true,
241
- financing: true,
278
+ financing: true,
242
279
  moip_wallet: true
243
280
  )
244
281
 
@@ -251,7 +288,7 @@ instruction = MyMoip::Instruction.new(
251
288
  )
252
289
  ```
253
290
 
254
- ### Payment slip (aka boleto) configuration
291
+ ### Payment slip (aka boleto) configuration
255
292
 
256
293
  You can optionally configure your payment slip creating a PaymentSlip and adding to the instruction:
257
294
 
@@ -265,7 +302,7 @@ payment_slip = MyMoip::PaymentSlip.new(
265
302
  instruction_line_3: 'This is a test! :)',
266
303
  logo_url: 'https://example.com/logo.png'
267
304
  )
268
-
305
+
269
306
  instruction = MyMoip::Instruction.new(
270
307
  id: 'instruction_id_defined_by_you',
271
308
  payment_reason: 'Order in Buy Everything Store',
@@ -283,6 +320,22 @@ A payment slip can have the following attributes:
283
320
  * instruction_line_1, instruction_line_2, instruction_line_3: lines of instruction (up to 63 characters each), added to the payment slip.
284
321
  * logo_url: an URL pointing to an image which will be added to the body of the payment slip.
285
322
 
323
+ ### Logger
324
+
325
+ The methods that make api calls to Moip, log request and response informations. The default logger is `Logger.new(STDOUT)`, but you can set the logger you want as `api_call` option. For instance:
326
+
327
+ ``` ruby
328
+ request = MyMoip::PaymentRequest.new('some-id')
329
+ request.api_call(data, token: 'some-token', logger: Rails.logger)
330
+ ```
331
+
332
+ You can configure the logger globally too:
333
+
334
+ ``` ruby
335
+ MyMoip.logger = Rails.logger
336
+ ```
337
+
338
+
286
339
  ## Going alive!
287
340
 
288
341
  If you are ready to get your application using MyMoip approved by MoIP or already have valid production keys, you can read a specific [documentation](https://github.com/Irio/mymoip/wiki/Going-alive).
@@ -0,0 +1,22 @@
1
+ module MyMoip
2
+ class BankDebit
3
+ include ActiveModel::Validations
4
+
5
+ attr_accessor :bank
6
+
7
+ AVAILABLE_BANKS = [:banco_do_brasil, :bradesco, :banrisul, :itau]
8
+
9
+ validates :bank, presence: true, inclusion: AVAILABLE_BANKS
10
+
11
+ def initialize(attrs)
12
+ attrs.each do |attr, value|
13
+ public_send(:"#{attr}=", value)
14
+ end
15
+ end
16
+
17
+ def bank=(value)
18
+ value = value.to_sym unless value.nil?
19
+ @bank = value
20
+ end
21
+ end
22
+ end
@@ -3,7 +3,8 @@ module MyMoip
3
3
  include ActiveModel::Validations
4
4
 
5
5
  attr_accessor :logo, :card_number, :expiration_date, :security_code,
6
- :owner_name, :owner_birthday, :owner_phone, :owner_cpf
6
+ :owner_name, :owner_birthday, :owner_phone, :owner_cpf,
7
+ :perform_extra_validation
7
8
 
8
9
  AVAILABLE_LOGOS = [
9
10
  :american_express, :diners, :hipercard, :mastercard, :visa
@@ -12,8 +13,13 @@ module MyMoip
12
13
  validates_presence_of :logo, :security_code
13
14
  validates_length_of :owner_phone, within: 10..11, allow_nil: true
14
15
  validates_length_of :security_code, within: 3..4
15
- validates_format_of :expiration_date, with: /\A(?:(?:0[1-9])|(?:1[02]))\/\d{2}\Z/ # %m/%y
16
+ validates_format_of :expiration_date, with: /\A(?:(?:0[1-9])|(?:1[0-2]))\/\d{2}\Z/ # %m/%y
16
17
  validates_inclusion_of :logo, in: AVAILABLE_LOGOS
18
+ validate :owner_birthday_format
19
+ validates_presence_of :card_number, :expiration_date, :owner_name,
20
+ :owner_phone, :owner_cpf,
21
+ if: ->(resource) { resource.perform_extra_validation }
22
+
17
23
 
18
24
  def initialize(attrs)
19
25
  attrs.each do |attr, value|
@@ -27,10 +33,9 @@ module MyMoip
27
33
  end
28
34
 
29
35
  def owner_birthday=(value)
30
- unless value.nil?
31
- value = Date.parse(value.to_s)
32
- end
33
- @owner_birthday = value
36
+ value = Date.parse(value.to_s) unless value.nil?
37
+ rescue ArgumentError; ensure
38
+ @owner_birthday = value
34
39
  end
35
40
 
36
41
  def owner_phone=(value)
@@ -55,5 +60,14 @@ module MyMoip
55
60
  end
56
61
  @owner_cpf = value
57
62
  end
63
+
64
+
65
+ private
66
+
67
+ def owner_birthday_format
68
+ Date.parse(owner_birthday.to_s) unless owner_birthday.nil?
69
+ rescue ArgumentError
70
+ errors.add(:owner_birthday)
71
+ end
58
72
  end
59
73
  end
@@ -10,4 +10,6 @@ module MyMoip
10
10
  class InvalidPayer < Error; end
11
11
 
12
12
  class InvalidPaymentSlip < Error; end
13
+
14
+ class InvalidBankDebit < Error; end
13
15
  end
@@ -0,0 +1,10 @@
1
+ module MyMoip
2
+ class Payment
3
+ def self.payment_method
4
+ name.gsub(/^MyMoip::|Payment$/, '').gsub(/([a-z])([A-Z])/,'\1_\2').downcase.to_sym
5
+ end
6
+ end
7
+ end
8
+
9
+ payments = Dir[File.dirname(__FILE__) + "/payments/*.rb"]
10
+ payments.each { |f| require f }
@@ -0,0 +1,27 @@
1
+ module MyMoip
2
+ class BankDebitPayment < Payment
3
+ attr_accessor :bank_debit
4
+
5
+ def initialize(bank_debit)
6
+ @bank_debit = bank_debit
7
+ end
8
+
9
+ def to_json
10
+ raise InvalidBankDebit, "No bank debit information provided." if @bank_debit.nil?
11
+ raise InvalidBankDebit if @bank_debit.invalid?
12
+
13
+ json = {
14
+ Forma: "DebitoBancario",
15
+ }
16
+
17
+ json[:Instituicao] = {
18
+ banco_do_brasil: "BancoDoBrasil",
19
+ bradesco: "Bradesco",
20
+ banrisul: "Banrisul",
21
+ itau: "Itau"
22
+ }.fetch(@bank_debit.bank)
23
+
24
+ json
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  module MyMoip
2
- class CreditCardPayment
2
+ class CreditCardPayment < Payment
3
3
  attr_accessor :credit_card, :installments
4
4
 
5
5
  def initialize(credit_card, opts = {})
@@ -0,0 +1,12 @@
1
+ module MyMoip
2
+ class PaymentSlipPayment < Payment
3
+
4
+ def to_json
5
+ json = {
6
+ Forma: 'BoletoBancario'
7
+ }
8
+
9
+ json
10
+ end
11
+ end
12
+ end
@@ -1,19 +1,24 @@
1
1
  module MyMoip
2
2
  class PaymentRequest < Request
3
3
 
4
- HTTP_METHOD = :get
5
- PATH = "/rest/pagamento?callback=?"
6
- REQUIRES_AUTH = false
7
- FORMAT = :json
4
+ HTTP_METHOD = :get
5
+ PATH = "/rest/pagamento?callback=?"
6
+ REQUIRES_AUTH = false
7
+ FORMAT = :json
8
+ PAYMENT_SLIP_PATH = "/Instrucao.do?token="
9
+
10
+ attr_reader :token
8
11
 
9
12
  def api_call(data, opts)
13
+ @token = opts[:token]
14
+
10
15
  opts[:referer_url] ||= MyMoip.default_referer_url
11
16
  opts[:parser] ||= MyMoip::JsonParser
12
17
 
13
18
  json = JSON.generate({
14
19
  pagamentoWidget: {
15
20
  referer: opts[:referer_url],
16
- token: opts[:token],
21
+ token: token,
17
22
  dadosPagamento: data.to_json
18
23
  }
19
24
  })
@@ -27,13 +32,17 @@ module MyMoip
27
32
  }
28
33
  params[:parser] = opts.delete(:parser) unless opts[:parser].nil?
29
34
 
30
- super(params)
35
+ super(params, opts)
31
36
  end
32
37
 
33
38
  def success?
34
39
  @response && @response["StatusPagamento"] == "Sucesso"
35
40
  end
36
41
 
42
+ def url
43
+ MyMoip.api_url + PAYMENT_SLIP_PATH + token if success?
44
+ end
45
+
37
46
  def code
38
47
  @response["CodigoMoIP"]
39
48
  rescue NoMethodError => e
@@ -1,3 +1,3 @@
1
1
  module MyMoip
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.0'
3
3
  end
@@ -63,7 +63,11 @@ class Fixture
63
63
  instruction_line_3: 'Line 3',
64
64
  logo_url: 'http://www.myurl.com/logo.png'
65
65
  }.merge(params)
66
-
67
66
  MyMoip::PaymentSlip.new(params)
68
67
  end
68
+
69
+ def self.bank_debit(params = {})
70
+ params = { bank: :itau }.merge(params)
71
+ MyMoip::BankDebit.new(params)
72
+ end
69
73
  end
@@ -0,0 +1,32 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://YOUR_MOIP_TOKEN:YOUR_MOIP_KEY@desenvolvedor.moip.com.br/sandbox/rest/pagamento?callback=?&pagamentoWidget=%7B%22pagamentoWidget%22:%7B%22referer%22:%22http://localhost/default%22,%22token%22:%22D2O0U1W2K1P1D1R2C2E3H0N3L5X3A2E4E3X0X030T090T0A1D1V2T8X500E3%22,%22dadosPagamento%22:%7B%22Forma%22:%22BoletoBancario%22%7D%7D%7D
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Date:
16
+ - Tue, 24 Sep 2013 13:46:21 GMT
17
+ Server:
18
+ - Apache
19
+ Content-Length:
20
+ - '92'
21
+ Vary:
22
+ - Accept-Encoding
23
+ Content-Type:
24
+ - application/json
25
+ body:
26
+ encoding: ASCII-8BIT
27
+ string: !binary |-
28
+ Pyh7IkNvZGlnbyI6MCwiU3RhdHVzUGFnYW1lbnRvIjoiU3VjZXNzbyIsIk1l
29
+ bnNhZ2VtIjoiUmVxdWlzaW8gcHJvY2Vzc2FkYSBjb20gc3VjZXNzbyJ9KQ==
30
+ http_version:
31
+ recorded_at: Tue, 24 Sep 2013 13:46:22 GMT
32
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,36 @@
1
+ require_relative '../test_helper'
2
+
3
+ class TestBankDebit < Test::Unit::TestCase
4
+ def test_initialization_and_setters
5
+ subject = MyMoip::BankDebit.new(bank: :itau)
6
+ assert_equal :itau, subject.bank
7
+ end
8
+
9
+ def test_initialization_and_setters_with_string_keys
10
+ subject = MyMoip::BankDebit.new('bank' => :itau)
11
+ assert_equal :itau, subject.bank
12
+ end
13
+
14
+ def test_validate_presence_of_bank_attribute
15
+ subject = Fixture.bank_debit(bank: nil)
16
+ assert subject.invalid? && subject.errors[:bank].present?,
17
+ 'should be invalid without a bank name'
18
+ end
19
+
20
+ def test_converts_bank_string_to_symbol
21
+ subject = Fixture.bank_debit(bank: "itau")
22
+ assert_equal :itau, subject.bank
23
+ end
24
+
25
+ def test_accepts_any_bank_from_available_banks_constant
26
+ MyMoip::BankDebit::AVAILABLE_BANKS.each do |bank|
27
+ subject = Fixture.bank_debit(bank: bank)
28
+ assert subject.valid?, 'should be valid'
29
+ end
30
+ end
31
+
32
+ def test_dont_accept_bank_out_of_available_banks_constant
33
+ subject = Fixture.bank_debit(bank: :unavailable_bank)
34
+ assert subject.invalid? && subject.errors[:bank].present?, 'should not be valid'
35
+ end
36
+ end
@@ -0,0 +1,32 @@
1
+ require_relative '../test_helper'
2
+
3
+ class TestBankDebitPayment < Test::Unit::TestCase
4
+ def test_initialization_and_setters
5
+ bank_debit = Fixture.bank_debit
6
+ subject = MyMoip::BankDebitPayment.new(bank_debit)
7
+ assert_equal bank_debit, subject.bank_debit
8
+ end
9
+
10
+ def test_json_format
11
+ payment = MyMoip::BankDebitPayment.new(Fixture.bank_debit)
12
+ assert_equal "DebitoBancario", payment.to_json[:Forma]
13
+ end
14
+
15
+ def test_to_json_should_accept_any_bank_from_available_banks_constant
16
+ MyMoip::BankDebit::AVAILABLE_BANKS.each do |bank|
17
+ payment = MyMoip::BankDebitPayment.new(Fixture.bank_debit(bank: bank))
18
+ assert_nothing_raised(KeyError) { payment.to_json }
19
+ end
20
+ end
21
+
22
+ def test_to_json_method_raises_an_exception_when_called_without_a_bank_debit
23
+ subject = MyMoip::BankDebitPayment.new(nil)
24
+ assert_raise(MyMoip::InvalidBankDebit) { subject.to_json }
25
+ end
26
+
27
+ def test_to_json_method_raises_an_exception_when_called_with_a_invalid_bank_debit
28
+ subject = MyMoip::BankDebitPayment.new(Fixture.bank_debit)
29
+ MyMoip::BankDebit.any_instance.stubs(:invalid?).returns(true)
30
+ assert_raise(MyMoip::InvalidBankDebit) { subject.to_json }
31
+ end
32
+ end
@@ -10,7 +10,8 @@ class TestCreditCard < Test::Unit::TestCase
10
10
  owner_name: "Juquinha da Rocha",
11
11
  owner_birthday: Date.new(1984, 11, 3),
12
12
  owner_phone: "5130405060",
13
- owner_cpf: "522.116.706-95"
13
+ owner_cpf: "522.116.706-95",
14
+ perform_extra_validation: true
14
15
  )
15
16
 
16
17
  assert_equal :visa, subject.logo
@@ -21,18 +22,20 @@ class TestCreditCard < Test::Unit::TestCase
21
22
  assert_equal Date.new(1984, 11, 3), subject.owner_birthday
22
23
  assert_equal "5130405060", subject.owner_phone
23
24
  assert_equal "52211670695", subject.owner_cpf
25
+ assert_equal true, subject.perform_extra_validation
24
26
  end
25
27
 
26
28
  def test_initialization_and_setters_with_string_keys
27
29
  subject = MyMoip::CreditCard.new(
28
- 'logo' => :visa,
29
- 'card_number' => '4916654211627608',
30
- 'expiration_date' => '06/15',
31
- 'security_code' => '000',
32
- 'owner_name' => 'Juquinha da Rocha',
33
- 'owner_birthday' => Date.new(1984, 11, 3),
34
- 'owner_phone' => '5130405060',
35
- 'owner_cpf' => '522.116.706-95'
30
+ 'logo' => :visa,
31
+ 'card_number' => '4916654211627608',
32
+ 'expiration_date' => '06/15',
33
+ 'security_code' => '000',
34
+ 'owner_name' => 'Juquinha da Rocha',
35
+ 'owner_birthday' => Date.new(1984, 11, 3),
36
+ 'owner_phone' => '5130405060',
37
+ 'owner_cpf' => '522.116.706-95',
38
+ 'perform_extra_validation' => false
36
39
  )
37
40
 
38
41
  assert_equal :visa, subject.logo
@@ -43,6 +46,7 @@ class TestCreditCard < Test::Unit::TestCase
43
46
  assert_equal Date.new(1984, 11, 3), subject.owner_birthday
44
47
  assert_equal "5130405060", subject.owner_phone
45
48
  assert_equal "52211670695", subject.owner_cpf
49
+ assert_equal false, subject.perform_extra_validation
46
50
  end
47
51
 
48
52
  def test_validate_presence_of_logo_attribute
@@ -58,6 +62,19 @@ class TestCreditCard < Test::Unit::TestCase
58
62
  assert_equal Date.new(1980, 12, 20), subject.owner_birthday
59
63
  end
60
64
 
65
+ def test_owner_birthday_accepts_input_of_invalid_dates
66
+ subject = Fixture.credit_card
67
+ subject.owner_birthday = '50/12/1980'
68
+ assert_equal '50/12/1980', subject.owner_birthday
69
+ end
70
+
71
+ def test_validate_format_of_birthday_date
72
+ subject = Fixture.credit_card
73
+ subject.owner_birthday = '50/12/1980'
74
+ assert subject.invalid? && subject.errors[:owner_birthday].present?,
75
+ 'should be valid'
76
+ end
77
+
61
78
  def test_validate_presence_of_security_code_attribute
62
79
  subject = Fixture.credit_card
63
80
  subject.security_code = nil
@@ -81,6 +98,23 @@ class TestCreditCard < Test::Unit::TestCase
81
98
  'should not accept strings with other than 10 or 11 chars'
82
99
  end
83
100
 
101
+ def test_perform_extra_validation
102
+ subject = Fixture.credit_card({
103
+ card_number: nil,
104
+ expiration_date: nil,
105
+ owner_name: nil,
106
+ owner_phone: nil,
107
+ owner_cpf: nil,
108
+ perform_extra_validation: true
109
+ })
110
+ assert subject.invalid?
111
+ assert subject.errors[:card_number], "can't be blank"
112
+ assert subject.errors[:expiration_date], "can't be blank"
113
+ assert subject.errors[:owner_name], "can't be blank"
114
+ assert subject.errors[:owner_phone], "can't be blank"
115
+ assert subject.errors[:owner_cpf], "can't be blank"
116
+ end
117
+
84
118
  def test_remove_left_zeros_from_owner_phone
85
119
  subject = Fixture.credit_card
86
120
  subject.owner_phone = '05130405060'
@@ -0,0 +1,15 @@
1
+ require_relative '../test_helper'
2
+
3
+ class TestPayment < Test::Unit::TestCase
4
+ def test_payment_method_when_payment_split
5
+ assert_equal :payment_slip, MyMoip::PaymentSlipPayment.payment_method
6
+ end
7
+
8
+ def test_payment_method_when_bank_debit
9
+ assert_equal :bank_debit, MyMoip::BankDebitPayment.payment_method
10
+ end
11
+
12
+ def test_payment_method_when_credit_card
13
+ assert_equal :credit_card, MyMoip::CreditCardPayment.payment_method
14
+ end
15
+ end
@@ -93,4 +93,28 @@ class TestPaymentRequest < Test::Unit::TestCase
93
93
  payment_request = MyMoip::PaymentRequest.new("your_own_id")
94
94
  assert_nil payment_request.code
95
95
  end
96
+
97
+ def test_method_to_get_response_url
98
+ instruction = Fixture.instruction(payer: Fixture.payer)
99
+ transparent_request = MyMoip::TransparentRequest.new("your_own_id")
100
+ VCR.use_cassette('transparent_request') do
101
+ transparent_request.api_call(instruction)
102
+ end
103
+ payment_slip_payment = MyMoip::PaymentSlipPayment.new
104
+ payment_request = MyMoip::PaymentRequest.new("your_own_id")
105
+ VCR.use_cassette('payment_request_with_payment_slip') do
106
+ payment_request.api_call(payment_slip_payment, token: transparent_request.token)
107
+ end
108
+ assert_equal "https://desenvolvedor.moip.com.br/sandbox/Instrucao.do?token=#{transparent_request.token}", payment_request.url
109
+ end
110
+
111
+ def test_url_method_should_return_nil_with_blank_response
112
+ instruction = Fixture.instruction(payer: Fixture.payer)
113
+ transparent_request = MyMoip::TransparentRequest.new("your_own_id")
114
+ VCR.use_cassette('transparent_request') do
115
+ transparent_request.api_call(instruction)
116
+ end
117
+ payment_request = MyMoip::PaymentRequest.new("your_own_id")
118
+ assert_nil payment_request.url
119
+ end
96
120
  end
@@ -0,0 +1,8 @@
1
+ require_relative '../test_helper'
2
+
3
+ class TestPaymentSlipPayment < Test::Unit::TestCase
4
+ def test_json_format
5
+ payment = MyMoip::PaymentSlipPayment.new()
6
+ assert_equal 'BoletoBancario', payment.to_json[:Forma]
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mymoip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Irio Irineu Musskopf Junior
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-07 00:00:00.000000000 Z
11
+ date: 2013-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -152,16 +152,20 @@ files:
152
152
  - README.md
153
153
  - Rakefile
154
154
  - lib/mymoip.rb
155
+ - lib/mymoip/bank_debit.rb
155
156
  - lib/mymoip/commission.rb
156
157
  - lib/mymoip/credit_card.rb
157
- - lib/mymoip/credit_card_payment.rb
158
158
  - lib/mymoip/exceptions.rb
159
159
  - lib/mymoip/formatter.rb
160
160
  - lib/mymoip/instruction.rb
161
161
  - lib/mymoip/json_parser.rb
162
162
  - lib/mymoip/payer.rb
163
+ - lib/mymoip/payment.rb
163
164
  - lib/mymoip/payment_methods.rb
164
165
  - lib/mymoip/payment_slip.rb
166
+ - lib/mymoip/payments/bank_debit_payment.rb
167
+ - lib/mymoip/payments/credit_card_payment.rb
168
+ - lib/mymoip/payments/payment_slip_payment.rb
165
169
  - lib/mymoip/purchase.rb
166
170
  - lib/mymoip/request.rb
167
171
  - lib/mymoip/requests/payment_request.rb
@@ -171,8 +175,11 @@ files:
171
175
  - mymoip.gemspec
172
176
  - test/fixtures/fixture.rb
173
177
  - test/fixtures/vcr_cassettes/payment_request.yml
178
+ - test/fixtures/vcr_cassettes/payment_request_with_payment_slip.yml
174
179
  - test/fixtures/vcr_cassettes/transparent_request.yml
175
180
  - test/fixtures/vcr_cassettes/transparent_request_with_commissions.yml
181
+ - test/lib/test_bank_debit.rb
182
+ - test/lib/test_bank_debit_payment.rb
176
183
  - test/lib/test_commission.rb
177
184
  - test/lib/test_credit_card_payment.rb
178
185
  - test/lib/test_creditcard.rb
@@ -180,9 +187,11 @@ files:
180
187
  - test/lib/test_instruction.rb
181
188
  - test/lib/test_mymoip.rb
182
189
  - test/lib/test_payer.rb
190
+ - test/lib/test_payment.rb
183
191
  - test/lib/test_payment_methods.rb
184
192
  - test/lib/test_payment_request.rb
185
193
  - test/lib/test_payment_slip.rb
194
+ - test/lib/test_payment_slip_payment.rb
186
195
  - test/lib/test_purchase.rb
187
196
  - test/lib/test_request.rb
188
197
  - test/lib/test_transparent_request.rb
@@ -209,15 +218,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
218
  version: '0'
210
219
  requirements: []
211
220
  rubyforge_project:
212
- rubygems_version: 2.0.3
221
+ rubygems_version: 2.1.0
213
222
  signing_key:
214
223
  specification_version: 4
215
224
  summary: MoIP transactions in a gem to call your own.
216
225
  test_files:
217
226
  - test/fixtures/fixture.rb
218
227
  - test/fixtures/vcr_cassettes/payment_request.yml
228
+ - test/fixtures/vcr_cassettes/payment_request_with_payment_slip.yml
219
229
  - test/fixtures/vcr_cassettes/transparent_request.yml
220
230
  - test/fixtures/vcr_cassettes/transparent_request_with_commissions.yml
231
+ - test/lib/test_bank_debit.rb
232
+ - test/lib/test_bank_debit_payment.rb
221
233
  - test/lib/test_commission.rb
222
234
  - test/lib/test_credit_card_payment.rb
223
235
  - test/lib/test_creditcard.rb
@@ -225,9 +237,11 @@ test_files:
225
237
  - test/lib/test_instruction.rb
226
238
  - test/lib/test_mymoip.rb
227
239
  - test/lib/test_payer.rb
240
+ - test/lib/test_payment.rb
228
241
  - test/lib/test_payment_methods.rb
229
242
  - test/lib/test_payment_request.rb
230
243
  - test/lib/test_payment_slip.rb
244
+ - test/lib/test_payment_slip_payment.rb
231
245
  - test/lib/test_purchase.rb
232
246
  - test/lib/test_request.rb
233
247
  - test/lib/test_transparent_request.rb