edools_mymoip 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +15 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +128 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.md +3 -0
- data/Rakefile +10 -0
- data/lib/mymoip.rb +57 -0
- data/lib/mymoip/bank_debit.rb +22 -0
- data/lib/mymoip/commission.rb +54 -0
- data/lib/mymoip/credit_card.rb +73 -0
- data/lib/mymoip/exceptions.rb +15 -0
- data/lib/mymoip/formatter.rb +23 -0
- data/lib/mymoip/instruction.rb +134 -0
- data/lib/mymoip/json_parser.rb +11 -0
- data/lib/mymoip/payer.rb +75 -0
- data/lib/mymoip/payment.rb +10 -0
- data/lib/mymoip/payment_methods.rb +46 -0
- data/lib/mymoip/payment_slip.rb +74 -0
- data/lib/mymoip/payments/bank_debit_payment.rb +27 -0
- data/lib/mymoip/payments/credit_card_payment.rb +53 -0
- data/lib/mymoip/payments/payment_slip_payment.rb +12 -0
- data/lib/mymoip/purchase.rb +40 -0
- data/lib/mymoip/request.rb +34 -0
- data/lib/mymoip/requests/payment_request.rb +53 -0
- data/lib/mymoip/requests/transparent_request.rb +36 -0
- data/lib/mymoip/validators.rb +12 -0
- data/lib/mymoip/version.rb +3 -0
- data/mymoip.gemspec +30 -0
- data/test/fixtures/fixture.rb +73 -0
- data/test/fixtures/vcr_cassettes/payment_request.yml +37 -0
- data/test/fixtures/vcr_cassettes/payment_request_with_payment_slip.yml +32 -0
- data/test/fixtures/vcr_cassettes/transparent_request.yml +34 -0
- data/test/fixtures/vcr_cassettes/transparent_request_with_commissions.yml +35 -0
- data/test/lib/test_bank_debit.rb +36 -0
- data/test/lib/test_bank_debit_payment.rb +32 -0
- data/test/lib/test_commission.rb +121 -0
- data/test/lib/test_credit_card_payment.rb +107 -0
- data/test/lib/test_creditcard.rb +206 -0
- data/test/lib/test_formatter.rb +49 -0
- data/test/lib/test_instruction.rb +243 -0
- data/test/lib/test_mymoip.rb +79 -0
- data/test/lib/test_payer.rb +249 -0
- data/test/lib/test_payment.rb +15 -0
- data/test/lib/test_payment_methods.rb +54 -0
- data/test/lib/test_payment_request.rb +120 -0
- data/test/lib/test_payment_slip.rb +78 -0
- data/test/lib/test_payment_slip_payment.rb +8 -0
- data/test/lib/test_purchase.rb +109 -0
- data/test/lib/test_request.rb +88 -0
- data/test/lib/test_transparent_request.rb +71 -0
- data/test/lib/test_validators.rb +13 -0
- data/test/live_test.rb +4 -0
- data/test/test_helper.rb +17 -0
- metadata +251 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fadf859fc323eedb44d2c704ba9392f9764d7887
|
4
|
+
data.tar.gz: 2b1f9b90f2e3fc91944ea036ff54a5a070732188
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a2f5619801ccc432b4c32f01bce46ac9796bb8b030406f5bea1718e98f191a878f9375122fbfd36ce0812060e7bec0bbe7481968ea5f0d90f68b42a9e7e9b1a4
|
7
|
+
data.tar.gz: 84a66fa25b95073c6c36f8a7541b9ace498c206fc5d58c4a00b51e22c6119cfb8443ce1a0f15ea481d336bd7f4356b817cc789da6711c4aeaa7f9ef6f247baa5
|
data/.document
ADDED
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# CHANGELOG
|
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
|
+
|
13
|
+
## 0.7.0
|
14
|
+
|
15
|
+
* Allow payments using redirection to Moip's domain. (by @oznek)
|
16
|
+
* Include PaymentSlip configuration class. (by @oznek)
|
17
|
+
* Remove backward compatibility with CreditCardPayment w/o options hash.
|
18
|
+
|
19
|
+
## 0.6.2
|
20
|
+
|
21
|
+
* Removed development dependency of jeweler. Gems are now managed
|
22
|
+
directly in .gemspec file.
|
23
|
+
* Offer a easier way to manage purchase implementations that don't have
|
24
|
+
many customizations over passing some attribute list, making the
|
25
|
+
checkout and getting a successful (or not) response. Through
|
26
|
+
MyMoip::Purchase.
|
27
|
+
* Accept string keys in initializers of CreditCard and Payer classes.
|
28
|
+
|
29
|
+
## 0.6.1
|
30
|
+
|
31
|
+
* Send 2 decimal place numbers in fixed and percentage values nodes of
|
32
|
+
Comission's XML. Percentage values are required to be in a 0 to 100 range.
|
33
|
+
Reported by @zangrandi.
|
34
|
+
|
35
|
+
## 0.6.0
|
36
|
+
|
37
|
+
* Add support for Ruby 2.0.
|
38
|
+
* Improved installments option for Instructions.
|
39
|
+
|
40
|
+
## 0.5.0
|
41
|
+
|
42
|
+
* Breaking backward compatibility with exceptions raised. ArgumentError
|
43
|
+
is not used anymore. New MyMoip::InvalidComission, MyMoip::InvalidCreditCard,
|
44
|
+
MyMoip::InvalidInstruction and MyMoip::InvalidPayer exceptions inherited from
|
45
|
+
MyMoip::Error.
|
46
|
+
|
47
|
+
## 0.4.1
|
48
|
+
|
49
|
+
* Simultaneous setters for sandbox and production token/keys.
|
50
|
+
* DEPRECATE MyMoip.key and MyMoip.token methods over new environment specific setters.
|
51
|
+
* Going alive instructions added to README file.
|
52
|
+
* Add reference to new my_moip-rails gem.
|
53
|
+
|
54
|
+
## 0.4.0
|
55
|
+
|
56
|
+
* Accept multiple receivers for each instruction.
|
57
|
+
* Can set a fixed value (e.g. R$ 50,00).
|
58
|
+
* Can set a percentage value (e.g. 10%).
|
59
|
+
* Define which one will take the fees.
|
60
|
+
* Accept payments to any MoIP users, even those without API keys.
|
61
|
+
|
62
|
+
## 0.3.1
|
63
|
+
|
64
|
+
* Re-releasing 0.3.0 after some Rubygems issues.
|
65
|
+
|
66
|
+
## 0.3.0
|
67
|
+
|
68
|
+
* Add dependency of active_model gem for validations.
|
69
|
+
* Try always to store the plain value of attributes. While the previous version would require you to provide phones in the `"(51)93040-5060"` format, now works even with `"051930405060"`.
|
70
|
+
* Payer accepts address_state and address_country downcased.
|
71
|
+
* CreditCard accept a valid string date as owner_birthday.
|
72
|
+
* Extract conversions of attributes' formats to a new Formatter class.
|
73
|
+
* Prevent use of CreditCardPayment#to_json with a invalid CreditCard.
|
74
|
+
* Prevent use of Instruction#to_xml with invalid attributes by itself or a invalid Payer.
|
75
|
+
|
76
|
+
New validations:
|
77
|
+
* **CreditCard**
|
78
|
+
* Require a logo and a security_code.
|
79
|
+
* Validate length of owner_phone (accepts 8 and 9 digit phones with its DDD code).
|
80
|
+
* Validate length of security_code (American Express has 4 digits, others 3).
|
81
|
+
* Validate format of expiration_date using `%m/%y`.
|
82
|
+
* Limit logos in the available at AVAILABLE_LOGOS constant.
|
83
|
+
* **Instruction**
|
84
|
+
* Require an id, payment_reason, values and a payer.
|
85
|
+
* **Payer**
|
86
|
+
* Require and id, name, email, address_street, address_street_number, address_neighbourhood, address_city, address_state, address_country, address_cep and an address_phone.
|
87
|
+
* Validate length of address_state in 2 chars.
|
88
|
+
* Validate length of address_country in 3 chars.
|
89
|
+
* Validate length of address_cep in 8 chars.
|
90
|
+
* Validate length of address_phone (accepts 8 and 9 digit phones with its DDD code).
|
91
|
+
|
92
|
+
## 0.2.6
|
93
|
+
|
94
|
+
* DEPRECATE owner_rg attribute of MyMoip::CreditCard; you should provide a owner_cpf from now on. Should explain issues with Visa's risk analysis.
|
95
|
+
|
96
|
+
## 0.2.5
|
97
|
+
|
98
|
+
* Request's log messages moved to debug level.
|
99
|
+
* Make CreditCard class accept string and symbol logos.
|
100
|
+
* Create MyMoip::CreditCard::AVAILABLE_LOGOS constant.
|
101
|
+
* Standardise Request#api_call parameters.
|
102
|
+
|
103
|
+
## 0.2.4
|
104
|
+
|
105
|
+
* Fix American Express logo format expected by Moip.
|
106
|
+
|
107
|
+
## 0.2.3
|
108
|
+
|
109
|
+
* Remove .rvmrc
|
110
|
+
* CreditCardPayment's initialization can now receive a hash of options.
|
111
|
+
* lib/requests folder created.
|
112
|
+
* Requests has methods to return its response id.
|
113
|
+
|
114
|
+
## 0.2.2
|
115
|
+
|
116
|
+
* Explicitly require order for Requests classes.
|
117
|
+
|
118
|
+
## 0.2.1
|
119
|
+
|
120
|
+
* Bugfix related to explicitly require MyMoip class being needed.
|
121
|
+
|
122
|
+
## 0.2.0
|
123
|
+
|
124
|
+
* Update production url from `https://desenvolvedor.moip.com.br` to `https://www.moip.com.br`.
|
125
|
+
|
126
|
+
## 0.1.0
|
127
|
+
|
128
|
+
* First version of the gem.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Irio Irineu Musskopf Junior
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/lib/mymoip.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
require 'builder'
|
3
|
+
require 'logger'
|
4
|
+
require 'httparty'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module MyMoip
|
8
|
+
class << self
|
9
|
+
attr_accessor :production_key, :production_token,
|
10
|
+
:sandbox_key, :sandbox_token,
|
11
|
+
:environment, :logger, :default_referer_url
|
12
|
+
|
13
|
+
def api_url
|
14
|
+
if environment == "sandbox"
|
15
|
+
"https://desenvolvedor.moip.com.br/sandbox"
|
16
|
+
else
|
17
|
+
"https://www.moip.com.br"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def key=(value)
|
22
|
+
warn "[DEPRECATION] `key=` is deprecated. Please use `sandbox_key` or `production_key` instead."
|
23
|
+
@production_key = @sandbox_key = value
|
24
|
+
end
|
25
|
+
|
26
|
+
def token=(value)
|
27
|
+
warn "[DEPRECATION] `token=` is deprecated. Please use `sandbox_token` or `production_token` instead."
|
28
|
+
@production_token = @sandbox_token = value
|
29
|
+
end
|
30
|
+
|
31
|
+
def key
|
32
|
+
send(:"#{environment}_key")
|
33
|
+
end
|
34
|
+
|
35
|
+
def token
|
36
|
+
send(:"#{environment}_token")
|
37
|
+
end
|
38
|
+
|
39
|
+
def ensure_key_and_token_set!
|
40
|
+
if MyMoip.key.blank?
|
41
|
+
raise StandardError, "Invalid MyMoip.#{environment}_key set."
|
42
|
+
elsif MyMoip.token.blank?
|
43
|
+
raise StandardError, "Invalid MyMoip.#{environment}_token set."
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
$LOAD_PATH << "./lib/mymoip"
|
50
|
+
|
51
|
+
require File.dirname(__FILE__) + "/mymoip/validators.rb"
|
52
|
+
|
53
|
+
files = Dir[File.dirname(__FILE__) + "/mymoip/*.rb"]
|
54
|
+
files.each { |f| require f }
|
55
|
+
|
56
|
+
MyMoip.environment = "sandbox"
|
57
|
+
MyMoip.logger = Logger.new(STDOUT)
|
@@ -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
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module MyMoip
|
2
|
+
class Commission
|
3
|
+
include ActiveModel::Validations
|
4
|
+
|
5
|
+
attr_accessor :reason, :receiver_login, :fixed_value, :percentage_value
|
6
|
+
|
7
|
+
validates_presence_of :reason, :receiver_login
|
8
|
+
validates_presence_of :fixed_value, if: -> { percentage_value.nil? }
|
9
|
+
validates_presence_of :percentage_value, if: -> { fixed_value.nil? }
|
10
|
+
validates_numericality_of :fixed_value, greater_than_or_equal_to: 0,
|
11
|
+
allow_nil: true
|
12
|
+
validates_numericality_of :percentage_value, greater_than_or_equal_to: 0,
|
13
|
+
less_than_or_equal_to: 1,
|
14
|
+
allow_nil: true
|
15
|
+
|
16
|
+
def initialize(attrs)
|
17
|
+
attrs.each do |attr, value|
|
18
|
+
public_send(:"#{attr}=", value)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def gross_amount(instruction)
|
23
|
+
if fixed_value
|
24
|
+
fixed_value
|
25
|
+
elsif percentage_value
|
26
|
+
percentage_value * instruction.gross_amount
|
27
|
+
else
|
28
|
+
raise InvalidComission, 'Cannot give gross_amount without fixed_value or percentage_value.'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_xml(root = nil)
|
33
|
+
raise InvalidComission if invalid?
|
34
|
+
|
35
|
+
if root.nil?
|
36
|
+
xml = ""
|
37
|
+
root ||= Builder::XmlMarkup.new(target: xml)
|
38
|
+
end
|
39
|
+
|
40
|
+
root.Comissionamento do |n1|
|
41
|
+
n1.Razao(reason)
|
42
|
+
n1.Comissionado {|n2| n2.LoginMoIP(receiver_login)}
|
43
|
+
if fixed_value
|
44
|
+
n1.ValorFixo(sprintf('%.2f', fixed_value))
|
45
|
+
end
|
46
|
+
if percentage_value
|
47
|
+
n1.ValorPercentual(sprintf('%.2f', percentage_value * 100))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
xml
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module MyMoip
|
2
|
+
class CreditCard
|
3
|
+
include ActiveModel::Validations
|
4
|
+
|
5
|
+
attr_accessor :logo, :card_number, :expiration_date, :security_code,
|
6
|
+
:owner_name, :owner_birthday, :owner_phone, :owner_cpf,
|
7
|
+
:perform_extra_validation
|
8
|
+
|
9
|
+
AVAILABLE_LOGOS = [
|
10
|
+
:american_express, :diners, :hipercard, :mastercard, :visa
|
11
|
+
]
|
12
|
+
|
13
|
+
validates_presence_of :logo, :security_code
|
14
|
+
validates_length_of :owner_phone, within: 10..11, allow_nil: true
|
15
|
+
validates_length_of :security_code, within: 3..4
|
16
|
+
validates_format_of :expiration_date, with: /\A(?:(?:0[1-9])|(?:1[0-2]))\/\d{2}\Z/ # %m/%y
|
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
|
+
|
23
|
+
|
24
|
+
def initialize(attrs)
|
25
|
+
attrs.each do |attr, value|
|
26
|
+
public_send(:"#{attr}=", value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def logo=(value)
|
31
|
+
value = value.to_sym unless value.nil?
|
32
|
+
@logo = value
|
33
|
+
end
|
34
|
+
|
35
|
+
def owner_birthday=(value)
|
36
|
+
value = Date.parse(value.to_s) unless value.nil?
|
37
|
+
rescue ArgumentError; ensure
|
38
|
+
@owner_birthday = value
|
39
|
+
end
|
40
|
+
|
41
|
+
def owner_phone=(value)
|
42
|
+
unless value.nil?
|
43
|
+
# Removes non-digits
|
44
|
+
value.gsub!(/\D*/, '')
|
45
|
+
# Removes zeros in the beginning
|
46
|
+
value.gsub!(/\A0*/, '')
|
47
|
+
end
|
48
|
+
@owner_phone = value
|
49
|
+
end
|
50
|
+
|
51
|
+
def owner_rg=(value)
|
52
|
+
warn "[DEPRECATION] `owner_rg` is deprecated. Please use `owner_cpf` instead."
|
53
|
+
self.owner_cpf = value
|
54
|
+
end
|
55
|
+
|
56
|
+
def owner_cpf=(value)
|
57
|
+
unless value.nil?
|
58
|
+
# Removes dashes and dots
|
59
|
+
value.gsub!(/\-|\./, '')
|
60
|
+
end
|
61
|
+
@owner_cpf = value
|
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
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MyMoip
|
2
|
+
class Error < StandardError; end
|
3
|
+
|
4
|
+
class InvalidComission < Error; end
|
5
|
+
|
6
|
+
class InvalidCreditCard < Error; end
|
7
|
+
|
8
|
+
class InvalidInstruction < Error; end
|
9
|
+
|
10
|
+
class InvalidPayer < Error; end
|
11
|
+
|
12
|
+
class InvalidPaymentSlip < Error; end
|
13
|
+
|
14
|
+
class InvalidBankDebit < Error; end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module MyMoip
|
2
|
+
class Formatter
|
3
|
+
def self.cep(plain_cep)
|
4
|
+
raise ArgumentError, 'Cannot format CEP nil' if plain_cep.nil?
|
5
|
+
plain_cep.gsub(/(\d{5})/, '\1-')
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.phone(plain_phone)
|
9
|
+
raise ArgumentError, 'Cannot format phone nil' if plain_phone.nil?
|
10
|
+
plain_phone.gsub(/(\d{2})(\d)?(\d{4})(\d{4})/, '(\1)\2\3-\4')
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.date(plain_date)
|
14
|
+
raise ArgumentError, 'Cannot format date nil' if plain_date.nil?
|
15
|
+
plain_date.strftime("%d/%m/%Y")
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.cpf(plain_cpf)
|
19
|
+
raise ArgumentError, 'Cannot format CPF nil' if plain_cpf.nil?
|
20
|
+
plain_cpf.gsub(/(\d{3})(\d{3})(\d{3})(\d{2})/, '\1.\2.\3-\4')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|