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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e648ad18b726f5416e960a14097eae8bcb3525a
4
- data.tar.gz: a466c2092e532bb98ba9cd33ed4af537ca8d1660
3
+ metadata.gz: c3e7d039fcb376a8409cdad3aa79e65068dee59b
4
+ data.tar.gz: 565f4e85f4652699598bc1dfecde84425ce3a9ac
5
5
  SHA512:
6
- metadata.gz: 5d7f6425ac42d2644dd0336445e71721791aeda754747a46c7aa61ee42aa28a219d07c0da89301c929f921ea85793b420878d2a583da38c66a56b9425c1c70de
7
- data.tar.gz: 2b6399c4a3e09153d0202d46403dec82b3a0c4d16872e3830af0f0396baa2aaedf07b528ac5699e6287595e46e9208f06f27a4b4ca3aae7156ab56bd3b717df4
6
+ metadata.gz: 13b823a99b2704f8f73dfd053789de2431984dc6d6ec92eb0e53b75a12d3a09a46c0931285d61f2a097fcc0e0c7d2376a8100a0b27e7b07b47bd37af31aac7f9
7
+ data.tar.gz: 578023dc0df271b972d0452e368a4363c7b5effa8dc94e0aa22276fdb8ebf303bdd3bd808ec64054ae897c690047cc91627a22d90b68bfffb4c76ae002ea0027
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- multibanco_ifthenpay (1.1.0)
4
+ multibanco_ifthenpay (1.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/multibanco_ifthenpay.svg)](https://badge.fury.io/rb/multibanco_ifthenpay)
4
4
  [![Build Status](https://travis-ci.org/rafaelcpalmeida/multibanco_ifthenpay.svg?branch=master)](https://travis-ci.org/rafaelcpalmeida/multibanco_ifthenpay)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/rafaelcpalmeida/multibanco_ifthenpay/badge.svg?branch=master)](https://coveralls.io/github/rafaelcpalmeida/multibanco_ifthenpay?branch=master)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/ea8d1dd7e3ca818b621d/maintainability)](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
 
@@ -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
- raise ArgumentError, 'Not a valid entity' unless entity.length == 5
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
- chk_str = if sub_entity.length == 1
31
- # only the 6 order_id right most digits are going to be used
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
@@ -1,3 +1,3 @@
1
1
  module MultibancoIfthenpay
2
- VERSION = '1.1.1'.freeze
2
+ VERSION = '1.1.2'.freeze
3
3
  end
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.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-06 00:00:00.000000000 Z
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.13
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