pixelpay_sdk 1.0.0.pre.beta.2 → 1.0.0.pre.beta.3

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
  SHA256:
3
- metadata.gz: c5f07580ae9e4680a5cea20ae57c4c74bd09fecbe87c4355866d6a49922f8c0c
4
- data.tar.gz: 49a60f57f531f6cd67af47a0b6152817f7d93826635ff34f52ffb29a617628c6
3
+ metadata.gz: 961abbeb4b8500cf6a7b72d56b6e989f9ad272eea07ac70cf84f6358e5770edd
4
+ data.tar.gz: 8d74a9ce9e7cdcebea00c63cbb6b2cee9c80c658cba56a679a8caa4ce94fdff2
5
5
  SHA512:
6
- metadata.gz: 1fdbc16e08e20c37435ea86c2098f3da943e71b8ab11e4f9203a5010126d6aa4b7af044c4bf5c6b6ac7bdf23d56d27e17e586d14b3aee51825face6c032072a3
7
- data.tar.gz: 5be5b2837421a5ab0a39aa3888d5013886e60d3cf15e8b197ccaf63d2a3b928ae6ee956bbc12c892d9746b5dd6b3cd4bf7cca476d1a8d35e0eb83c8014fd5089
6
+ metadata.gz: 572a75320c2523a9ba0a42ec5dfa17da844d1c51381486bc584a1d516b10c5bf617b30cacf55d4eb0b078134a76f6559a5a18d95c619adba1d2d8082aae1487c
7
+ data.tar.gz: efabb3851beab2c6dbc4430a5d54bbafb49418d4ce7e251e08eb34a53fb8129d52effaa247611b8bab34181a9ec2de91ddce97bf7a95a12800756b56cf330935
data/CHANGELOG.md CHANGED
@@ -5,6 +5,20 @@ El formato se basa en [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  y este proyecto se adhiere a [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
  Tipos de cambios: `Added`, `Changed`, `Deprecated`, `Removed`, `Fixed`, `Security`.
7
7
 
8
+ ## [1.0.0-beta.3] - 2023-06-08
9
+ ### Added
10
+ - Se agregan campos de cuotas y puntos.
11
+ - Se agrega firma de transacciones de anulación.
12
+ - Se agrega helper `object_to_hash`.
13
+
14
+ ### Fixed
15
+ - Se corrige asignación de la propiedad `order_content` en la clase `PaymentTransaction`.
16
+ - Se corrige test `test_transaction_with_3ds`.
17
+
18
+ ### Changed
19
+ - Se cambia estructura de helper `object_to_json`.
20
+ - Se cambia estructura de helper `verify_type`.
21
+
8
22
  ## [1.0.0-beta.2] - 2023-05-26
9
23
  ### Added
10
24
  - Se agrega importación de `SaleTransaction` al archivo principal.
data/CONTRIBUTING.md CHANGED
@@ -9,3 +9,19 @@ rake test
9
9
  ```
10
10
  - Agregar al `CHANGELOG.md` las descripciones del cambio.
11
11
  - Crear un commit con los cambios, agregar una etiqueta con el número de versión y hacer push con los tags.
12
+
13
+ ## Pruebas
14
+ Ejecutar todos los unit tests:
15
+ ```bash
16
+ rake test
17
+ ```
18
+
19
+ Ejecutar todos los unit tests de un archivo:
20
+ ```bash
21
+ rake test TEST=test/requests/test_sale_transaction.rb
22
+ ```
23
+
24
+ Ejecutar unit test en particular:
25
+ ```bash
26
+ rake test TEST=test/models/test_billing.rb TESTOPTS="--name=test_empty_billing"
27
+ ```
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pixelpay_sdk (1.0.0.pre.beta.2)
4
+ pixelpay_sdk (1.0.0.pre.beta.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -5,15 +5,15 @@
5
5
  Para obtener la versión del SDK de PixelPay con Ruby puedes utilizar este comando para instalar directamente:
6
6
 
7
7
  ``` bash
8
- gem install pixelpay_sdk-1.0.0-beta.2
8
+ gem install pixelpay_sdk-1.0.0-beta.3
9
9
  ```
10
10
 
11
11
  O puedes colocar en el archivo Gemfile la siguiente línea:
12
12
  ``` bash
13
- gem 'pixelpay_sdk', '~> 1.0.0.pre.beta.2'
13
+ gem 'pixelpay_sdk', '~> 1.0.0.pre.beta.3'
14
14
  ```
15
15
 
16
16
  Y luego ejecutar:
17
17
  ``` bash
18
18
  bundle install
19
- ```
19
+ ```
@@ -6,17 +6,17 @@ require "json"
6
6
  module Helpers
7
7
  # Serialize object to JSON string without empties.
8
8
  # Args:
9
- # value (hash): hash to serialize.
9
+ # value (object): object to serialize.
10
10
  # Returns
11
11
  # string: JSON string.
12
12
  def self.object_to_json(value)
13
- verify_type(TypeError, Object, value.is_a?(Object))
13
+ verify_type(Object, value.is_a?(Object))
14
14
 
15
15
  hash = {}
16
16
  value.instance_variables.each { |var| hash[var.to_s.delete("@")] = value.instance_variable_get(var) }
17
17
 
18
18
  hash.each do |attr_name, attr_value|
19
- if hash[attr_name].nil? || hash[attr_name].to_s.empty? || hash[attr_value].to_s == "[]" || hash[attr_value].to_s == "{}"
19
+ if hash[attr_name].nil? || hash[attr_name].to_s.empty? || (attr_value.is_a?(Array) && attr_value.empty?) || (attr_value.is_a?(Hash) && attr_value.empty?)
20
20
  hash.delete(attr_name)
21
21
  end
22
22
  end
@@ -26,6 +26,18 @@ module Helpers
26
26
  warn("An exception occurred: #{e.message}")
27
27
  end
28
28
 
29
+ # Serialize object to hash.
30
+ # Args:
31
+ # value (object): object to serialize.
32
+ # Returns
33
+ # hash.
34
+ def self.object_to_hash(value)
35
+ hash = {}
36
+ value.instance_variables.each { |var| hash[var.to_s.delete("@")] = value.instance_variable_get(var) }
37
+
38
+ hash
39
+ end
40
+
29
41
  # Hash of a given value using the specified algorithm.
30
42
  # Args:
31
43
  # algorithm (string): algorithm to use (e.g. "MD5", "SHA-1", "SHA-256").
@@ -40,6 +52,8 @@ module Helpers
40
52
  Digest::SHA1.hexdigest(value.to_s)
41
53
  when "SHA-256"
42
54
  Digest::SHA256.hexdigest(value.to_s)
55
+ when "SHA-512"
56
+ Digest::SHA512.hexdigest(value.to_s)
43
57
  else
44
58
  ""
45
59
  end
@@ -74,19 +88,11 @@ module Helpers
74
88
 
75
89
  # Verify type of data.
76
90
  # Args:
77
- # error_type: error type to raise.
78
91
  # expected: data type expected.
79
92
  # flag: condition.
80
93
  # Returns:
81
94
  # throw an error if the condition is met
82
- def self.verify_type(error_type, expected, flag)
83
- case error_type.to_s
84
- when "TypeError"
85
- raise TypeError, "This function only accepts parameters of type #{expected}." unless flag
86
- when "InvalidCredentialsException"
87
- raise InvalidCredentialsException, "This function only accepts parameters of type #{expected}." unless flag
88
- when "InvalidTransactionTypeException"
89
- raise InvalidTransactionTypeException, "This function only accepts parameters of type #{expected}." unless flag
90
- end
95
+ def self.verify_type(expected, flag)
96
+ raise TypeError, "This function only accepts parameters of type #{expected}." unless flag
91
97
  end
92
98
  end
@@ -24,7 +24,7 @@ class ServiceBehaviour
24
24
 
25
25
  # Initialize service.
26
26
  def initialize(settings)
27
- Helpers.verify_type(TypeError, Settings, settings.instance_of?(Settings))
27
+ Helpers.verify_type(Settings, settings.instance_of?(Settings))
28
28
 
29
29
  @settings = settings
30
30
  rescue StandardError => e
@@ -100,7 +100,7 @@ class ServiceBehaviour
100
100
  # Returns:
101
101
  # req: prepared request.
102
102
  def build_request(uri, method, transaction)
103
- Helpers.verify_type(TypeError, RequestBehaviour, transaction.is_a?(RequestBehaviour))
103
+ Helpers.verify_type(RequestBehaviour, transaction.is_a?(RequestBehaviour))
104
104
 
105
105
  if settings.auth_key.nil? || settings.auth_hash.nil?
106
106
  raise InvalidCredentialsException, "The merchant credentials are not definied (key/hash)."
@@ -179,7 +179,7 @@ class ServiceBehaviour
179
179
  # Returns:
180
180
  # response: parsed response.
181
181
  def put(url, body)
182
- Helpers.verify_type(TypeError, RequestBehaviour, body.is_a?(RequestBehaviour))
182
+ Helpers.verify_type(RequestBehaviour, body.is_a?(RequestBehaviour))
183
183
 
184
184
  uri = get_route(url)
185
185
  req = build_request(uri, "PUT", body)
@@ -200,7 +200,7 @@ class ServiceBehaviour
200
200
  # Returns:
201
201
  # response: parsed response.
202
202
  def delete(url, body)
203
- Helpers.verify_type(TypeError, RequestBehaviour, body.is_a?(RequestBehaviour))
203
+ Helpers.verify_type(RequestBehaviour, body.is_a?(RequestBehaviour))
204
204
 
205
205
  uri = get_route(url)
206
206
  req = build_request(uri, "DELETE", body)
@@ -221,7 +221,7 @@ class ServiceBehaviour
221
221
  # Returns:
222
222
  # response: parsed response.
223
223
  def get(url, body)
224
- Helpers.verify_type(TypeError, RequestBehaviour, body.is_a?(RequestBehaviour))
224
+ Helpers.verify_type(RequestBehaviour, body.is_a?(RequestBehaviour))
225
225
 
226
226
  uri = get_route(url)
227
227
  req = build_request(uri, "GET", body)
@@ -50,7 +50,7 @@ class Order
50
50
  # Order: self.
51
51
  def add_item(item)
52
52
  begin
53
- Helpers.verify_type(TypeError, Item, item.instance_of?(Item))
53
+ Helpers.verify_type(Item, item.instance_of?(Item))
54
54
 
55
55
  @content.append(item)
56
56
  totalize
@@ -59,7 +59,7 @@ class CardTokenization < RequestBehaviour
59
59
  # CardTokenization: self.
60
60
  def set_card(card)
61
61
  begin
62
- Helpers.verify_type(TypeError, Card, card.instance_of?(Card))
62
+ Helpers.verify_type(Card, card.instance_of?(Card))
63
63
 
64
64
  @number = Helpers.trim_value(card.number)
65
65
  @cvv2 = card.cvv2
@@ -80,7 +80,7 @@ class CardTokenization < RequestBehaviour
80
80
  # CardTokenization: self.
81
81
  def set_billing(billing)
82
82
  begin
83
- Helpers.verify_type(TypeError, Billing, billing.instance_of?(Billing))
83
+ Helpers.verify_type(Billing, billing.instance_of?(Billing))
84
84
 
85
85
  @address = Helpers.trim_value(billing.address)
86
86
  @country = billing.country
@@ -98,7 +98,7 @@ class PaymentTransaction < RequestBehaviour
98
98
  # PaymentTransaction: self.
99
99
  def set_card(card)
100
100
  begin
101
- Helpers.verify_type(TypeError, Card, card.instance_of?(Card))
101
+ Helpers.verify_type(Card, card.instance_of?(Card))
102
102
 
103
103
  @card_number = Helpers.clean_string(card.number)
104
104
  @card_cvv = card.cvv2
@@ -129,7 +129,7 @@ class PaymentTransaction < RequestBehaviour
129
129
  # PaymentTransaction: self.
130
130
  def set_billing(billing)
131
131
  begin
132
- Helpers.verify_type(TypeError, Billing, billing.instance_of?(Billing))
132
+ Helpers.verify_type(Billing, billing.instance_of?(Billing))
133
133
 
134
134
  @billing_address = Helpers.trim_value(billing.address)
135
135
  @billing_country = billing.country
@@ -151,14 +151,14 @@ class PaymentTransaction < RequestBehaviour
151
151
  # PaymentTransaction: self.
152
152
  def set_order(order)
153
153
  begin
154
- Helpers.verify_type(TypeError, Order, order.instance_of?(Order))
154
+ Helpers.verify_type(Order, order.instance_of?(Order))
155
155
 
156
156
  @order_id = order.id
157
157
  @order_currency = order.currency
158
158
  @order_amount = Helpers.parse_amount(order.amount)
159
159
  @order_tax_amount = Helpers.parse_amount(order.tax_amount)
160
160
  @order_shipping_amount = Helpers.parse_amount(order.shipping_amount)
161
- @order_content = order.content.empty? ? [] : order.content
161
+ @order_content = order.content.map { |item| Helpers.object_to_hash(item) }
162
162
  @order_extras = order.extras.empty? ? {} : order.extras
163
163
  @order_note = Helpers.trim_value(order.note)
164
164
  @order_callback = order.callback_url
@@ -1,7 +1,39 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../base/Helpers"
3
4
  require_relative "./PaymentTransaction"
4
5
 
5
6
  # SaleTransaction defines a sale transaction request.
6
7
  class SaleTransaction < PaymentTransaction
8
+ attr_accessor :installment_type, :installment_months, :points_redeem_amount
9
+
10
+ # Initialize request.
11
+ def initialize
12
+ super()
13
+
14
+ # Transaction installment type
15
+ @installment_type = nil
16
+
17
+ # Transaction installment value
18
+ @installment_months = nil
19
+
20
+ # Transaction total points redeem amount
21
+ @points_redeem_amount = nil
22
+ end
23
+
24
+ # Set Installment service values to transaction
25
+ # Args:
26
+ # months (int): installment months
27
+ # financing_type (str): installment type
28
+ def set_installment(months, financing_type)
29
+ @installment_months = months.to_s
30
+ @installment_type = financing_type.to_s
31
+ end
32
+
33
+ # Set transaction points redeem amount
34
+ # Args:
35
+ # amount (float): points redeem amount
36
+ def with_points_redeem_amount(amount)
37
+ @points_redeem_amount = Helpers.parse_amount(amount.to_f)
38
+ end
7
39
  end
@@ -4,7 +4,7 @@ require_relative "../base/RequestBehaviour"
4
4
 
5
5
  # VoidTransaction defines a void transaction request.
6
6
  class VoidTransaction < RequestBehaviour
7
- attr_accessor :payment_uuid, :void_reason
7
+ attr_accessor :payment_uuid, :void_reason, :void_signature
8
8
 
9
9
  # Initialize request.
10
10
  def initialize
@@ -15,5 +15,8 @@ class VoidTransaction < RequestBehaviour
15
15
 
16
16
  # Reason for void the order
17
17
  @void_reason = nil
18
+
19
+ # Required signature for void authentication
20
+ @void_signature = nil
18
21
  end
19
22
  end
@@ -15,7 +15,7 @@ class Tokenization < ServiceBehaviour
15
15
  # Returns:
16
16
  # Response: processed response.
17
17
  def vault_card(card)
18
- Helpers.verify_type(TypeError, CardTokenization, card.instance_of?(CardTokenization))
18
+ Helpers.verify_type(CardTokenization, card.instance_of?(CardTokenization))
19
19
 
20
20
  post(BASE_CARD_PATH, card)
21
21
  rescue StandardError => e
@@ -29,7 +29,7 @@ class Tokenization < ServiceBehaviour
29
29
  # Returns:
30
30
  # Response: processed response.
31
31
  def update_card(token, card)
32
- Helpers.verify_type(TypeError, CardTokenization, card.instance_of?(CardTokenization))
32
+ Helpers.verify_type(CardTokenization, card.instance_of?(CardTokenization))
33
33
 
34
34
  put("#{BASE_CARD_PATH}/#{token}", card)
35
35
  rescue StandardError => e
@@ -11,7 +11,7 @@ class Transaction < ServiceBehaviour
11
11
  # Args:
12
12
  # transaction (PaymentTransaction) : input.
13
13
  def eval_authentication_transaction(transaction)
14
- Helpers.verify_type(TypeError, PaymentTransaction, transaction.is_a?(PaymentTransaction))
14
+ Helpers.verify_type(PaymentTransaction, transaction.is_a?(PaymentTransaction))
15
15
 
16
16
  if transaction.authentication_request
17
17
  raise InvalidTransactionTypeException, "This platform does not support 3DS transactions."
@@ -26,7 +26,7 @@ class Transaction < ServiceBehaviour
26
26
  # Returns:
27
27
  # Response: processed response.
28
28
  def do_sale(transaction)
29
- Helpers.verify_type(TypeError, SaleTransaction, transaction.instance_of?(SaleTransaction))
29
+ Helpers.verify_type(SaleTransaction, transaction.instance_of?(SaleTransaction))
30
30
 
31
31
  err = eval_authentication_transaction(transaction)
32
32
  raise InvalidTransactionTypeException, err.message if err.instance_of?(InvalidTransactionTypeException)
@@ -42,7 +42,7 @@ class Transaction < ServiceBehaviour
42
42
  # Returns:
43
43
  # Response: processed response.
44
44
  def do_auth(transaction)
45
- Helpers.verify_type(TypeError, AuthTransaction, transaction.instance_of?(AuthTransaction))
45
+ Helpers.verify_type(AuthTransaction, transaction.instance_of?(AuthTransaction))
46
46
 
47
47
  err = eval_authentication_transaction(transaction)
48
48
  raise InvalidTransactionTypeException, err.message if err.instance_of?(InvalidTransactionTypeException)
@@ -58,7 +58,7 @@ class Transaction < ServiceBehaviour
58
58
  # Returns:
59
59
  # Response: processed response.
60
60
  def do_capture(transaction)
61
- Helpers.verify_type(TypeError, CaptureTransaction, transaction.instance_of?(CaptureTransaction))
61
+ Helpers.verify_type(CaptureTransaction, transaction.instance_of?(CaptureTransaction))
62
62
 
63
63
  post("api/v2/transaction/capture", transaction)
64
64
  rescue StandardError => e
@@ -71,7 +71,7 @@ class Transaction < ServiceBehaviour
71
71
  # Returns:
72
72
  # Response: processed response.
73
73
  def do_void(transaction)
74
- Helpers.verify_type(TypeError, VoidTransaction, transaction.instance_of?(VoidTransaction))
74
+ Helpers.verify_type(VoidTransaction, transaction.instance_of?(VoidTransaction))
75
75
 
76
76
  post("api/v2/transaction/void", transaction)
77
77
  rescue StandardError => e
@@ -84,7 +84,7 @@ class Transaction < ServiceBehaviour
84
84
  # Returns:
85
85
  # Response: processed response.
86
86
  def get_status(transaction)
87
- Helpers.verify_type(TypeError, StatusTransaction, transaction.instance_of?(StatusTransaction))
87
+ Helpers.verify_type(StatusTransaction, transaction.instance_of?(StatusTransaction))
88
88
 
89
89
  post("api/v2/transaction/status", transaction)
90
90
  rescue StandardError => e
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PixelpaySdk
4
- VERSION = "1.0.0-beta.2"
4
+ VERSION = "1.0.0-beta.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixelpay_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.beta.2
4
+ version: 1.0.0.pre.beta.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sonia Villeda
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-05-29 00:00:00.000000000 Z
12
+ date: 2023-06-16 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: