transbank-sdk 1.1.0 → 1.2.0
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/.github/ISSUE_TEMPLATE/reporte-de-error.md +40 -0
- data/.gitignore +3 -1
- data/.travis.yml +2 -0
- data/CHANGELOG.md +4 -0
- data/Makefile +1 -1
- data/lib/transbank/sdk.rb +5 -5
- data/lib/transbank/sdk/oneclick/errors/oneclick_error.rb +16 -0
- data/lib/transbank/sdk/oneclick/inscription/errors/mall_inscription_delete_error.rb +16 -0
- data/lib/transbank/sdk/oneclick/inscription/errors/mall_inscription_finish_error.rb +16 -0
- data/lib/transbank/sdk/oneclick/inscription/errors/mall_inscription_start_error.rb +16 -0
- data/lib/transbank/sdk/oneclick/inscription/errors/oneclick_mall_inscription_errors.rb +3 -0
- data/lib/transbank/sdk/oneclick/inscription/inscription.rb +3 -0
- data/lib/transbank/sdk/oneclick/inscription/responses/mall_inscription_delete_response.rb +18 -0
- data/lib/transbank/sdk/oneclick/inscription/responses/mall_inscription_finish_response.rb +15 -0
- data/lib/transbank/sdk/oneclick/inscription/responses/mall_inscription_start_response.rb +14 -0
- data/lib/transbank/sdk/oneclick/inscription/responses/oneclick_mall_inscription_responses.rb +3 -0
- data/lib/transbank/sdk/oneclick/mall/base.rb +51 -0
- data/lib/transbank/sdk/oneclick/mall/errors/mall_transaction_authorize_error.rb +16 -0
- data/lib/transbank/sdk/oneclick/mall/errors/mall_transaction_refund_error.rb +16 -0
- data/lib/transbank/sdk/oneclick/mall/errors/mall_transaction_status_error.rb +16 -0
- data/lib/transbank/sdk/oneclick/mall/errors/oneclick_mall_errors.rb +3 -0
- data/lib/transbank/sdk/oneclick/mall/mall_inscription.rb +73 -0
- data/lib/transbank/sdk/oneclick/mall/mall_transaction.rb +97 -0
- data/lib/transbank/sdk/oneclick/mall/oneclick_mall.rb +5 -0
- data/lib/transbank/sdk/oneclick/mall/responses/mall_transaction_authorize_response.rb +16 -0
- data/lib/transbank/sdk/oneclick/mall/responses/mall_transaction_refund_response.rb +16 -0
- data/lib/transbank/sdk/oneclick/mall/responses/mall_transaction_status_response.rb +15 -0
- data/lib/transbank/sdk/oneclick/mall/responses/oneclick_mall_responses.rb +3 -0
- data/lib/transbank/sdk/oneclick/oneclick.rb +3 -0
- data/lib/transbank/sdk/onepay/models/item.rb +1 -1
- data/lib/transbank/sdk/onepay/models/refund.rb +4 -5
- data/lib/transbank/sdk/onepay/models/shopping_cart.rb +1 -1
- data/lib/transbank/sdk/onepay/models/transaction.rb +11 -9
- data/lib/transbank/sdk/onepay/requests/request.rb +1 -1
- data/lib/transbank/sdk/onepay/responses/response.rb +1 -1
- data/lib/transbank/sdk/transaccion_completa/base.rb +49 -0
- data/lib/transbank/sdk/transaccion_completa/errors/transaccion_completa_error.rb +16 -0
- data/lib/transbank/sdk/transaccion_completa/errors/transaccion_completa_errors.rb +6 -0
- data/lib/transbank/sdk/transaccion_completa/errors/transaction_commit_error.rb +14 -0
- data/lib/transbank/sdk/transaccion_completa/errors/transaction_create_error.rb +14 -0
- data/lib/transbank/sdk/transaccion_completa/errors/transaction_installments_error.rb +14 -0
- data/lib/transbank/sdk/transaccion_completa/errors/transaction_refund_error.rb +14 -0
- data/lib/transbank/sdk/transaccion_completa/errors/transaction_status_error.rb +14 -0
- data/lib/transbank/sdk/transaccion_completa/options.rb +7 -0
- data/lib/transbank/sdk/transaccion_completa/responses/transaccion_completa_responses.rb +5 -0
- data/lib/transbank/sdk/transaccion_completa/responses/transaction_commit_response.rb +16 -0
- data/lib/transbank/sdk/transaccion_completa/responses/transaction_create_response.rb +10 -0
- data/lib/transbank/sdk/transaccion_completa/responses/transaction_installments_response.rb +13 -0
- data/lib/transbank/sdk/transaccion_completa/responses/transaction_refund_response.rb +14 -0
- data/lib/transbank/sdk/transaccion_completa/responses/transaction_status_response.rb +16 -0
- data/lib/transbank/sdk/transaccion_completa/transaccion_completa.rb +5 -0
- data/lib/transbank/sdk/transaccion_completa/transaction.rb +117 -0
- data/lib/transbank/sdk/transbank_error.rb +6 -0
- data/lib/transbank/sdk/utils/json_utils.rb +75 -0
- data/lib/transbank/sdk/utils/net_helper.rb +82 -0
- data/lib/transbank/sdk/{onepay/utils → utils}/request_builder.rb +0 -0
- data/lib/transbank/sdk/{onepay/utils → utils}/signature_utils.rb +0 -0
- data/lib/transbank/sdk/utils/utils.rb +9 -0
- data/lib/transbank/sdk/version.rb +1 -1
- data/lib/transbank/sdk/webpay/errors/integration_type_error.rb +8 -0
- data/lib/transbank/sdk/webpay/errors/webpay_error.rb +14 -0
- data/transbank-sdk.gemspec +1 -1
- metadata +56 -10
- data/lib/transbank/sdk/onepay/utils/json_utils.rb +0 -77
- data/lib/transbank/sdk/onepay/utils/net_helper.rb +0 -38
- data/lib/transbank/sdk/onepay/utils/utils.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c8e254a610d8744915cc56245533ad60f94a1c1a37c786c9eaefe458deaedb4
|
4
|
+
data.tar.gz: '029809591bbd27cdefc7a1dad7f5411f592387dddc430fc81c819fcde135031a'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0756ef91caee98a6d29c144c779650c788b31653758f0190a96746e6d63cdb4946fddbaf66bca329c4feb34f63288e0fd255d3bb2ba99b3c8f6fed61d5b445f
|
7
|
+
data.tar.gz: 33ffe901ec9592015658878761eed5b263cc6b955a7870c964092dae68f62f7965d062ea0a3415c0ee4306dd641eeb95f862748c506bdf77ca8583e8515084bb
|
@@ -0,0 +1,40 @@
|
|
1
|
+
---
|
2
|
+
name: Reporte de Error
|
3
|
+
about: Crea un reporte para ayudarnos a mejorar
|
4
|
+
title: ''
|
5
|
+
labels: bug
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Describe el bug**
|
11
|
+
|
12
|
+
Una descripción concisa sobre el bug.
|
13
|
+
|
14
|
+
**Para reproducir**
|
15
|
+
|
16
|
+
1. Configura '...'
|
17
|
+
2. Crea un objeto '...'
|
18
|
+
3. Ejecuta el método '...'
|
19
|
+
4. Se ve el error en '...'
|
20
|
+
|
21
|
+
**Comportamiento observado**
|
22
|
+
|
23
|
+
Describe de forma concisa lo que observaste siguiendo los pasos para reproducir el error.
|
24
|
+
|
25
|
+
**Comportamiento esperado**
|
26
|
+
|
27
|
+
Una explicación concisa y clara de qué es lo que esperas que ocurra.
|
28
|
+
|
29
|
+
**Capturas de pantalla**
|
30
|
+
|
31
|
+
Si aplica, agrega aquí capturas de pantalla que ayuden a explicar tu problema.
|
32
|
+
|
33
|
+
**Versiones (por favor agrega aquí la siguiente información):**
|
34
|
+
- SDK: [e.g. 1.1.0]
|
35
|
+
- Ruby: [e.g. 2.5.2]
|
36
|
+
- Bundler: [e.g. 2.0.1]
|
37
|
+
|
38
|
+
**Contexto adicional**
|
39
|
+
|
40
|
+
Agrega cualquier otro información sobre el problema aquí.
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@ Todos los cambios notables a este proyecto serán documentados en este archivo.
|
|
4
4
|
El formato está basado en [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
y este proyecto adhiere a [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [1.2.0] - 2019-12-26
|
8
|
+
### Added
|
9
|
+
- Se agrega soporte para Oneclick Mall y Transacción Completa en sus versiones REST.
|
10
|
+
|
7
11
|
## [1.1.0] - 2018-04-08
|
8
12
|
### Added
|
9
13
|
- Se agregaron los parámetros `qr_width_height` y `commerce_logo_url` a Options, para definir el tamaño del QR generado para la transacción, y especificar la ubicación del logo de comercio para ser mostrado en la aplicación móvil de Onepay. Puedes configurar estos parámetros globalmente o por transacción.
|
data/Makefile
CHANGED
data/lib/transbank/sdk.rb
CHANGED
@@ -7,9 +7,10 @@ require 'base64'
|
|
7
7
|
|
8
8
|
require "transbank/sdk/version"
|
9
9
|
|
10
|
+
require 'transbank/sdk/transbank_error'
|
10
11
|
require 'transbank/sdk/onepay/errors/errors'
|
11
12
|
|
12
|
-
require 'transbank/sdk/
|
13
|
+
require 'transbank/sdk/utils/utils'
|
13
14
|
|
14
15
|
require 'transbank/sdk/onepay/requests/requests'
|
15
16
|
require 'transbank/sdk/onepay/responses/responses'
|
@@ -17,7 +18,6 @@ require 'transbank/sdk/onepay/responses/responses'
|
|
17
18
|
require 'transbank/sdk/onepay/models/models'
|
18
19
|
require 'transbank/sdk/onepay/base'
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
21
|
+
require 'transbank/sdk/oneclick/oneclick'
|
22
|
+
|
23
|
+
require 'transbank/sdk/transaccion_completa/transaccion_completa'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
module Errors
|
5
|
+
class OneclickError < StandardError
|
6
|
+
attr_accessor :code, :message
|
7
|
+
def initialize(message, code)
|
8
|
+
@code = code
|
9
|
+
@message = message
|
10
|
+
super(message)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
module Errors
|
5
|
+
class MallInscriptionDeleteError < OneclickError
|
6
|
+
attr_accessor :code, :message
|
7
|
+
def initialize(message, code)
|
8
|
+
@code = code
|
9
|
+
@message = message
|
10
|
+
super(message, code)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
module Errors
|
5
|
+
class MallInscriptionFinishError < OneclickError
|
6
|
+
attr_accessor :code, :message
|
7
|
+
def initialize(message, code)
|
8
|
+
@code = code
|
9
|
+
@message = message
|
10
|
+
super(message, code)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
module Errors
|
5
|
+
class MallInscriptionStartError < OneclickError
|
6
|
+
attr_accessor :code, :message
|
7
|
+
def initialize(message, code)
|
8
|
+
@code = code
|
9
|
+
@message = message
|
10
|
+
super(message, code)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
class MallInscriptionDeleteResponse
|
5
|
+
attr_accessor :status, :code
|
6
|
+
def initialize(code)
|
7
|
+
code = code.to_i
|
8
|
+
@code = code
|
9
|
+
if code == 204
|
10
|
+
@status = 'OK'
|
11
|
+
elsif code == 404
|
12
|
+
@status = 'Not found'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
class MallInscriptionFinishResponse
|
5
|
+
FIELDS = [:response_code, :tbk_user, :authorization_code,
|
6
|
+
:card_type, :card_number]
|
7
|
+
attr_accessor *FIELDS
|
8
|
+
def initialize(json)
|
9
|
+
FIELDS.each {|field| send("#{field}=", json["#{field}"]) }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
class Base
|
5
|
+
DEFAULT_API_KEY = '579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C'.freeze
|
6
|
+
|
7
|
+
DEFAULT_ONECLICK_MALL_COMMERCE_CODE = '597055555541'.freeze
|
8
|
+
DEFAULT_ONECLICK_MALL_CHILD_COMMERCE_CODES = ['597055555542'.freeze,
|
9
|
+
'597055555543'.freeze].freeze
|
10
|
+
|
11
|
+
@api_key = DEFAULT_API_KEY
|
12
|
+
@commerce_code = DEFAULT_ONECLICK_MALL_COMMERCE_CODE
|
13
|
+
@integration_type = :TEST
|
14
|
+
@integration_types = {
|
15
|
+
LIVE: "https://webpay3g.transbank.cl/",
|
16
|
+
TEST: "https://webpay3gint.transbank.cl/"
|
17
|
+
}
|
18
|
+
|
19
|
+
class << self
|
20
|
+
attr_reader :integration_types
|
21
|
+
attr_accessor :api_key, :integration_type, :commerce_code
|
22
|
+
|
23
|
+
def integration_type_url(integration_type)
|
24
|
+
type = integration_type.upcase.to_sym
|
25
|
+
return @integration_types[type] unless @integration_types[type].nil?
|
26
|
+
valid_values = @integration_types.keys.join(', ')
|
27
|
+
raise Transbank::Webpay::Errors::IntegrationTypeError, "Invalid integration type, valid values are #{valid_values}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def current_integration_type_url
|
31
|
+
@integration_types[@integration_type]
|
32
|
+
end
|
33
|
+
|
34
|
+
def integration_type=(integration_type)
|
35
|
+
type = integration_type.upcase.to_sym
|
36
|
+
return @integration_type = type unless @integration_types[type].nil?
|
37
|
+
valid_values = @integration_types.keys.join(', ')
|
38
|
+
raise Transbank::Webpay::Errors::IntegrationTypeError, "Invalid integration type, valid values are #{valid_values}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def configure_mall_for_testing
|
42
|
+
@api_key = DEFAULT_API_KEY
|
43
|
+
@commerce_code = DEFAULT_ONECLICK_MALL_COMMERCE_CODE
|
44
|
+
self.integration_type = :TEST
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
module Errors
|
5
|
+
class MallTransactionAuthorizeError < OneclickError
|
6
|
+
attr_accessor :code, :message
|
7
|
+
def initialize(message, code)
|
8
|
+
@code = code
|
9
|
+
@message = message
|
10
|
+
super(message, code)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
module Errors
|
5
|
+
class MallTransactionRefundError < OneclickError
|
6
|
+
attr_accessor :code, :message
|
7
|
+
def initialize(message, code)
|
8
|
+
@code = code
|
9
|
+
@message = message
|
10
|
+
super(message, code)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
module Errors
|
5
|
+
class MallTransactionStatusError < OneclickError
|
6
|
+
attr_accessor :code, :message
|
7
|
+
def initialize(message, code)
|
8
|
+
@code = code
|
9
|
+
@message = message
|
10
|
+
super(message, code)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
class MallInscription
|
5
|
+
extend Transbank::Utils::NetHelper
|
6
|
+
|
7
|
+
INSCRIPTION_START_ENDPOINT = 'rswebpaytransaction/api/oneclick/v1.0/inscriptions'.freeze
|
8
|
+
INSCRIPTION_FINISH_ENDPOINT = 'rswebpaytransaction/api/oneclick/v1.0/inscriptions/:token'.freeze
|
9
|
+
INSCRIPTION_DELETE_ENDPOINT = 'rswebpaytransaction/api/oneclick/v1.0/inscriptions'.freeze
|
10
|
+
class << self
|
11
|
+
def start(user_name:, email:, response_url:, options: nil)
|
12
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
13
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
14
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
15
|
+
base_url = integration_type.nil? ? Oneclick::Base::integration_type[:TEST] : Oneclick::Base.integration_type_url(integration_type)
|
16
|
+
|
17
|
+
url = base_url + INSCRIPTION_START_ENDPOINT
|
18
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
19
|
+
|
20
|
+
body = {
|
21
|
+
username: user_name,
|
22
|
+
email: email,
|
23
|
+
response_url: response_url
|
24
|
+
}
|
25
|
+
resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
|
26
|
+
body = JSON.parse(resp.body)
|
27
|
+
return ::Transbank::Webpay::Oneclick::MallInscriptionStartResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
28
|
+
raise Oneclick::Errors::MallInscriptionStartError.new(body['error_message'], resp.code)
|
29
|
+
end
|
30
|
+
|
31
|
+
def finish(token:, options: nil)
|
32
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
33
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
34
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
35
|
+
base_url = integration_type.nil? ? Oneclick::Base::integration_type[:TEST] : Oneclick::Base.integration_type_url(integration_type)
|
36
|
+
|
37
|
+
url = base_url + INSCRIPTION_FINISH_ENDPOINT.gsub(':token', token)
|
38
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
39
|
+
|
40
|
+
resp = http_put(uri_string: url, headers: headers)
|
41
|
+
body = JSON.parse(resp.body)
|
42
|
+
return ::Transbank::Webpay::Oneclick::MallInscriptionFinishResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
43
|
+
raise Oneclick::Errors::MallInscriptionFinishError.new(body['error_message'], resp.code)
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete(tbk_user:, user_name:, options: nil)
|
47
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
48
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
49
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
50
|
+
base_url = integration_type.nil? ? Oneclick::Base::integration_type[:TEST] : Oneclick::Base.integration_type_url(integration_type)
|
51
|
+
|
52
|
+
url = base_url + INSCRIPTION_DELETE_ENDPOINT
|
53
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
54
|
+
body = {tbk_user: tbk_user, username: user_name}
|
55
|
+
resp = http_delete(uri_string: url, body: body, headers: headers)
|
56
|
+
code = resp.code
|
57
|
+
return ::Transbank::Webpay::Oneclick::MallInscriptionDeleteResponse.new(code) if resp.kind_of? Net::HTTPSuccess
|
58
|
+
raise Oneclick::Errors::MallInscriptionDeleteError.new(body['error_message'], resp.code)
|
59
|
+
end
|
60
|
+
|
61
|
+
def default_integration_params
|
62
|
+
{
|
63
|
+
api_key: Oneclick::Base::DEFAULT_API_KEY,
|
64
|
+
commerce_code: Oneclick::Base::DEFAULT_ONECLICK_MALL_COMMERCE_CODE,
|
65
|
+
integration_type: Oneclick::Base::integration_type,
|
66
|
+
base_url: Oneclick::Base::current_integration_type_url
|
67
|
+
}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Transbank
|
2
|
+
module Webpay
|
3
|
+
module Oneclick
|
4
|
+
class MallTransaction
|
5
|
+
extend Transbank::Utils::NetHelper
|
6
|
+
|
7
|
+
AUTHORIZE_TRANSACTION_ENDPOINT = 'rswebpaytransaction/api/oneclick/v1.0/transactions'.freeze
|
8
|
+
TRANSACTION_STATUS_ENDPOINT = 'rswebpaytransaction/api/oneclick/v1.0/transactions/:buy_order'.freeze
|
9
|
+
TRANSACTION_REFUND_ENDPOINT = 'rswebpaytransaction/api/oneclick/v1.0/transactions/:buy_order/refunds'.freeze
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
def authorize(username:, tbk_user:, parent_buy_order:, details:,
|
14
|
+
options: nil)
|
15
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
16
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
17
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
18
|
+
base_url = integration_type.nil? ? Oneclick::Base::integration_type[:TEST] : Oneclick::Base.integration_type_url(integration_type)
|
19
|
+
|
20
|
+
url = base_url + AUTHORIZE_TRANSACTION_ENDPOINT
|
21
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
22
|
+
|
23
|
+
details_array = details.map do |det|
|
24
|
+
hash = det.reduce({}) do |acc, (k, v)|
|
25
|
+
acc[k.to_s] = v
|
26
|
+
acc
|
27
|
+
end
|
28
|
+
# We need to make sure the hash's keys are strings (or symbols)
|
29
|
+
# since Ruby doesnt have hahes with indifferent access
|
30
|
+
# I chose to make them strings
|
31
|
+
details_hash = {}
|
32
|
+
details_hash[:amount] = hash.fetch('amount')
|
33
|
+
details_hash[:buy_order] = hash.fetch('buy_order')
|
34
|
+
details_hash[:commerce_code] = hash.fetch('commerce_code')
|
35
|
+
details_hash[:installments_number] = hash.fetch('installments_number')
|
36
|
+
details_hash
|
37
|
+
end
|
38
|
+
|
39
|
+
body = {
|
40
|
+
username: username,
|
41
|
+
tbk_user: tbk_user,
|
42
|
+
buy_order: parent_buy_order,
|
43
|
+
details: details_array
|
44
|
+
}
|
45
|
+
resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
|
46
|
+
body = JSON.parse(resp.body)
|
47
|
+
return ::Transbank::Webpay::Oneclick::MallTransactionAuthorizeResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
48
|
+
raise Oneclick::Errors::MallTransactionAuthorizeError.new(body['error_message'], resp.code)
|
49
|
+
end
|
50
|
+
|
51
|
+
def status(buy_order:, options: nil)
|
52
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
53
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
54
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
55
|
+
base_url = integration_type.nil? ? Oneclick::Base::integration_type[:TEST] : Oneclick::Base.integration_type_url(integration_type)
|
56
|
+
|
57
|
+
url = base_url + TRANSACTION_STATUS_ENDPOINT.gsub(':buy_order', buy_order)
|
58
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
59
|
+
resp = http_get(uri_string: url, headers: headers)
|
60
|
+
body = JSON.parse(resp.body)
|
61
|
+
return ::Transbank::Webpay::Oneclick::MallTransactionStatusResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
62
|
+
raise Oneclick::Errors::MallTransactionStatusError.new(body['error_message'], resp.code)
|
63
|
+
end
|
64
|
+
|
65
|
+
def refund(buy_order:, child_commerce_code:, child_buy_order:, amount:,
|
66
|
+
options: nil)
|
67
|
+
api_key = options&.api_key || default_integration_params[:api_key]
|
68
|
+
commerce_code = options&.commerce_code || default_integration_params[:commerce_code]
|
69
|
+
integration_type = options&.integration_type || default_integration_params[:integration_type]
|
70
|
+
base_url = integration_type.nil? ? Oneclick::Base::integration_type[:TEST] : Oneclick::Base.integration_type_url(integration_type)
|
71
|
+
|
72
|
+
url = base_url + TRANSACTION_REFUND_ENDPOINT.gsub(':buy_order', buy_order)
|
73
|
+
headers = webpay_headers(commerce_code: commerce_code, api_key: api_key)
|
74
|
+
body = {
|
75
|
+
detail_buy_order: child_buy_order,
|
76
|
+
commerce_code: child_commerce_code,
|
77
|
+
amount: amount
|
78
|
+
}
|
79
|
+
resp = http_post(uri_string: url, body: body, headers: headers, camel_case_keys: false)
|
80
|
+
body = JSON.parse(resp.body)
|
81
|
+
return ::Transbank::Webpay::Oneclick::MallTransactionRefundResponse.new(body) if resp.kind_of? Net::HTTPSuccess
|
82
|
+
raise Oneclick::Errors::MallTransactionRefundError.new(body['error_message'], resp.code)
|
83
|
+
end
|
84
|
+
|
85
|
+
def default_integration_params
|
86
|
+
{
|
87
|
+
api_key: Oneclick::Base::DEFAULT_API_KEY,
|
88
|
+
commerce_code: Oneclick::Base::DEFAULT_ONECLICK_MALL_COMMERCE_CODE,
|
89
|
+
integration_type: Oneclick::Base::integration_type,
|
90
|
+
base_url: Oneclick::Base::current_integration_type_url
|
91
|
+
}
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|