multibanco_ifthenpay 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/lib/multibanco_ifthenpay.rb +8 -4
- data/lib/multibanco_ifthenpay/calculator.rb +4 -21
- data/lib/multibanco_ifthenpay/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c3e7d039fcb376a8409cdad3aa79e65068dee59b
|
|
4
|
+
data.tar.gz: 565f4e85f4652699598bc1dfecde84425ce3a9ac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 13b823a99b2704f8f73dfd053789de2431984dc6d6ec92eb0e53b75a12d3a09a46c0931285d61f2a097fcc0e0c7d2376a8100a0b27e7b07b47bd37af31aac7f9
|
|
7
|
+
data.tar.gz: 578023dc0df271b972d0452e368a4363c7b5effa8dc94e0aa22276fdb8ebf303bdd3bd808ec64054ae897c690047cc91627a22d90b68bfffb4c76ae002ea0027
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
[](https://badge.fury.io/rb/multibanco_ifthenpay)
|
|
4
4
|
[](https://travis-ci.org/rafaelcpalmeida/multibanco_ifthenpay)
|
|
5
5
|
[](https://coveralls.io/github/rafaelcpalmeida/multibanco_ifthenpay?branch=master)
|
|
6
|
+
[](https://codeclimate.com/github/rafaelcpalmeida/multibanco_ifthenpay/maintainability)
|
|
6
7
|
|
|
7
8
|
Multibanco is a Portuguese payment method that allows the customer to pay by bank reference. This gem aims to provide a simple way to integrate Ifthenpay's multibanco gateway into your Ruby / Ruby on Rails projects.
|
|
8
9
|
|
data/lib/multibanco_ifthenpay.rb
CHANGED
|
@@ -11,10 +11,7 @@ module MultibancoIfthenpay
|
|
|
11
11
|
# @param [String] order_id
|
|
12
12
|
# @param [Float] order_value
|
|
13
13
|
def initialize(entity, sub_entity, order_id, order_value)
|
|
14
|
-
|
|
15
|
-
raise ArgumentError, 'Not a valid sub-entity' unless
|
|
16
|
-
!sub_entity.empty? && sub_entity.length < 4
|
|
17
|
-
raise ArgumentError, 'Not a valid order value' unless order_value >= 1
|
|
14
|
+
validate!(entity, sub_entity, order_value)
|
|
18
15
|
|
|
19
16
|
@entity = entity
|
|
20
17
|
@sub_entity = sub_entity
|
|
@@ -22,6 +19,13 @@ module MultibancoIfthenpay
|
|
|
22
19
|
@order_value = order_value
|
|
23
20
|
end
|
|
24
21
|
|
|
22
|
+
def validate!(entity, sub_entity, order_value)
|
|
23
|
+
raise ArgumentError, 'Not a valid entity' unless entity.length == 5
|
|
24
|
+
raise ArgumentError, 'Not a valid sub-entity' unless
|
|
25
|
+
!sub_entity.empty? && sub_entity.length < 4
|
|
26
|
+
raise ArgumentError, 'Not a valid order value' unless order_value >= 1
|
|
27
|
+
end
|
|
28
|
+
|
|
25
29
|
# @param [BooleanMatcher] prettify
|
|
26
30
|
# @return [String]
|
|
27
31
|
def print_multibanco_reference(prettify = false)
|
|
@@ -27,32 +27,15 @@ module MultibancoIfthenpay
|
|
|
27
27
|
# @param [Float] order_value
|
|
28
28
|
# @return [String]
|
|
29
29
|
def self.get_chk_string(entity, sub_entity, order_id, order_value)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
entity + sub_entity + order_id[-6..-1] +
|
|
33
|
-
format('%08.0f', (order_value.to_f * 100))
|
|
34
|
-
elsif sub_entity.length == 2
|
|
35
|
-
# only the 5 order_id right most digits are going to be used
|
|
36
|
-
entity + sub_entity + order_id[-5..-1] +
|
|
37
|
-
format('%08.0f', (order_value.to_f * 100))
|
|
38
|
-
else
|
|
39
|
-
entity + sub_entity + order_id[-4..-1] +
|
|
40
|
-
format('%08.0f', (order_value.to_f * 100))
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
chk_str
|
|
30
|
+
entity + sub_entity + order_id[-(7 - sub_entity.length)..-1] +
|
|
31
|
+
format('%08.0f', (order_value.to_f * 100))
|
|
44
32
|
end
|
|
45
33
|
|
|
46
34
|
# @param [String] chk_str
|
|
47
35
|
# @return [String]
|
|
48
36
|
def self.get_chk_digits(chk_str)
|
|
49
|
-
chk_val = 0
|
|
50
|
-
|
|
51
|
-
chk_array_size = CHK_ARRAY.length
|
|
52
|
-
|
|
53
|
-
CHK_ARRAY.each do |chk_item|
|
|
54
|
-
chk_val += (chk_str[chk_array_size - 1].to_i % 10) * chk_item
|
|
55
|
-
chk_array_size -= 1
|
|
37
|
+
chk_val = CHK_ARRAY.each_with_index.reduce(0) do |val, (chk_item, index)|
|
|
38
|
+
val + (chk_str[CHK_ARRAY.length - index - 1].to_i % 10) * chk_item
|
|
56
39
|
end
|
|
57
40
|
|
|
58
41
|
chk_val %= 97
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: multibanco_ifthenpay
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rafael Almeida
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-04-
|
|
11
|
+
date: 2018-04-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
110
110
|
version: '0'
|
|
111
111
|
requirements: []
|
|
112
112
|
rubyforge_project:
|
|
113
|
-
rubygems_version: 2.6.
|
|
113
|
+
rubygems_version: 2.6.14
|
|
114
114
|
signing_key:
|
|
115
115
|
specification_version: 4
|
|
116
116
|
summary: This gem aims to provide a simple way to integrate Ifthenpay's multibanco
|