tbk-sdk-ruby 4.0.0.pre.1

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.
@@ -0,0 +1,56 @@
1
+ module Transbank
2
+ module Patpass
3
+ module PatpassComercio
4
+ class Inscription < ::Transbank::Common::BaseTransaction
5
+ DEFAULT_ENVIRONMENT = :integration
6
+ RESOURCES_URL = ::Transbank::Common::ApiConstants::PATPASS_ENDPOINT
7
+ START_ENDPOINT = (RESOURCES_URL + '/patInscription').freeze
8
+ STATUS_ENDPOINT = (RESOURCES_URL + '/status').freeze
9
+
10
+ ENVIRONMENTS = {
11
+ production: 'https://www.pagoautomaticocontarjetas.cl',
12
+ integration: 'https://pagoautomaticocontarjetasint.transbank.cl/'
13
+ }
14
+
15
+ def initialize(commerce_code = ::Transbank::Common::IntegrationCommerceCodes::PATPASS_COMERCIO, api_key = ::Transbank::Common::IntegrationApiKeys::PATPASS_COMERCIO, environment = DEFAULT_ENVIRONMENT)
16
+ super(commerce_code, api_key, environment)
17
+ end
18
+
19
+ def start(url, name, last_name, second_last_name, rut, service_id, final_url, max_amount, phone, cell_phone, patpass_name, person_email, commerce_email, address, city)
20
+ request_service = ::Transbank::Shared::RequestService.new(
21
+ ENVIRONMENTS[@environment] + START_ENDPOINT, @commerce_code, @api_key
22
+ )
23
+ request_service.set_patpass();
24
+ request_service.post({
25
+ url: url,
26
+ nombre: name,
27
+ pApellido: last_name,
28
+ sApellido: second_last_name,
29
+ rut: rut,
30
+ serviceId: service_id,
31
+ finalUrl: final_url,
32
+ commerceCode: @commerce_code,
33
+ montoMaximo: max_amount,
34
+ telefonoFijo: phone,
35
+ telefonoCelular: cell_phone,
36
+ nombrePatPass: patpass_name,
37
+ correoPersona: person_email,
38
+ correoComercio: commerce_email,
39
+ direccion: address,
40
+ ciudad: city
41
+ })
42
+
43
+ end
44
+
45
+ def status(token)
46
+ request_service = ::Transbank::Shared::RequestService.new(
47
+ ENVIRONMENTS[@environment] + format(STATUS_ENDPOINT, token: token), @commerce_code, @api_key
48
+ )
49
+ request_service.set_patpass();
50
+ request_service.post({token: token})
51
+ end
52
+
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,99 @@
1
+ module Transbank
2
+ module Shared
3
+ class RequestService
4
+ ENVIRONMENTS = {
5
+ production: 'https://webpay3g.transbank.cl/',
6
+ integration: 'https://webpay3gint.transbank.cl/'
7
+ }
8
+
9
+ def initialize(environment=nil, endpoint, commerce_code, api_key)
10
+ @commerce_code = commerce_code
11
+ @api_key = api_key
12
+ if environment.nil?
13
+ @url = endpoint
14
+ else
15
+ @url = ENVIRONMENTS[environment] + endpoint
16
+ end
17
+ @headers = headers(@commerce_code, @api_key)
18
+ end
19
+
20
+ def set_patpass()
21
+ @headers = headers_patpass(@commerce_code, @api_key)
22
+ end
23
+
24
+ def post(body)
25
+ build_http_request('post', body)
26
+ end
27
+
28
+ def put(body)
29
+ build_http_request('put', body)
30
+ end
31
+
32
+ def get
33
+ build_http_request('get')
34
+ end
35
+
36
+ def delete(body)
37
+ build_http_request('delete', body)
38
+ end
39
+
40
+ private
41
+
42
+ def build_http_request(method, body = nil)
43
+ # raise TransbankError, 'Transbank Error: Incorrect Request type' unless %w[put post].include?(method.downcase)
44
+
45
+ uri, http = build_client
46
+ http_method = build_method(method, uri, body)
47
+
48
+ response = http.request(http_method)
49
+
50
+ if response.is_a? Net::HTTPSuccess
51
+ return nil if response.body.nil? || response.body.empty?
52
+ return JSON.parse(response.body)
53
+ end
54
+
55
+ if !response.body.to_s.empty?
56
+ body = JSON.parse(response.body)
57
+ if body.key?("description")
58
+ raise TransbankError, "Transbank Error: #{body['code']} - #{body['description']}"
59
+ else
60
+ raise TransbankError, "Transbank Error: #{body['error_message']}"
61
+ end
62
+ end
63
+
64
+ raise TransbankError, "Transbank Error: HTTP-STATUS #{response&.code}"
65
+ end
66
+
67
+ def build_client
68
+ uri = URI.parse(@url)
69
+ http = Net::HTTP.new(uri.host, uri.port)
70
+ http.use_ssl = uri.scheme == 'https'
71
+ [uri, http]
72
+ end
73
+
74
+ def build_method(method, uri, body = nil)
75
+ http_method = Object.const_get("Net::HTTP::#{method.capitalize}").new(uri.path, @headers)
76
+ if !body.nil?
77
+ http_method.body = body.to_json
78
+ end
79
+ http_method
80
+ end
81
+
82
+ def headers(commerce_code, api_key)
83
+ {
84
+ 'Tbk-Api-Key-Id' => commerce_code.to_s,
85
+ 'Tbk-Api-Key-Secret' => api_key,
86
+ 'Content-Type' => 'application/json'
87
+ }
88
+ end
89
+
90
+ def headers_patpass(commerce_code, api_key)
91
+ {
92
+ 'commercecode' => commerce_code.to_s,
93
+ 'Authorization' => api_key,
94
+ 'Content-Type' => 'application/json'
95
+ }
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,5 @@
1
+ module Transbank
2
+ module Shared
3
+ class TransbankError < StandardError; end
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Transbank
2
+ module Sdk
3
+ VERSION = '4.0.0-1'
4
+ end
5
+ end
@@ -0,0 +1,52 @@
1
+ module Transbank
2
+ module Webpay
3
+ module Oneclick
4
+ class MallInscription < ::Transbank::Common::BaseTransaction
5
+ DEFAULT_ENVIRONMENT = :integration
6
+ RESOURCES_URL = ::Transbank::Common::ApiConstants::ONECLICK_ENDPOINT
7
+ START_ENDPOINT = (RESOURCES_URL + '/inscriptions').freeze
8
+ FINISH_ENDPOINT = (RESOURCES_URL + '/inscriptions/%{token}').freeze
9
+ DELETE_ENDPOINT = (RESOURCES_URL + '/inscriptions').freeze
10
+
11
+ def initialize(commerce_code = ::Transbank::Common::IntegrationCommerceCodes::ONECLICK_MALL, api_key = ::Transbank::Common::IntegrationApiKeys::WEBPAY, environment = DEFAULT_ENVIRONMENT)
12
+ super
13
+ end
14
+
15
+ def start(username, email, response_url)
16
+
17
+ Transbank::Common::Validation.has_text_with_max_length(username, Transbank::Common::ApiConstants::USER_NAME_LENGTH, "username")
18
+ Transbank::Common::Validation.has_text_with_max_length(email, Transbank::Common::ApiConstants::EMAIL_LENGTH, "email")
19
+ Transbank::Common::Validation.has_text_with_max_length(response_url, Transbank::Common::ApiConstants::RETURN_URL_LENGTH, "response_url")
20
+
21
+ request_service = ::Transbank::Shared::RequestService.new(
22
+ @environment, START_ENDPOINT, @commerce_code, @api_key
23
+ )
24
+ request_service.post({
25
+ username: username, email: email, response_url: response_url
26
+ })
27
+ end
28
+
29
+ def finish(token)
30
+
31
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
32
+
33
+ request_service = ::Transbank::Shared::RequestService.new(
34
+ @environment, format(FINISH_ENDPOINT, token: token), @commerce_code, @api_key
35
+ )
36
+ request_service.put({})
37
+ end
38
+
39
+ def delete(tbk_user, username)
40
+
41
+ Transbank::Common::Validation.has_text_with_max_length(tbk_user, Transbank::Common::ApiConstants::TBK_USER_LENGTH, "tbk_user")
42
+ Transbank::Common::Validation.has_text_with_max_length(username, Transbank::Common::ApiConstants::USER_NAME_LENGTH, "username")
43
+
44
+ request_service = ::Transbank::Shared::RequestService.new(
45
+ @environment, DELETE_ENDPOINT, @commerce_code, @api_key
46
+ )
47
+ request_service.delete({tbk_user: tbk_user, username: username})
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,66 @@
1
+ module Transbank
2
+ module Webpay
3
+ module Oneclick
4
+ class MallTransaction < ::Transbank::Common::BaseTransaction
5
+ DEFAULT_ENVIRONMENT = :integration
6
+ RESOURCES_URL = ::Transbank::Common::ApiConstants::ONECLICK_ENDPOINT
7
+ AUTHORIZE_ENDPOINT = (RESOURCES_URL + '/transactions').freeze
8
+ STATUS_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}').freeze
9
+ REFUND_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/refunds').freeze
10
+ CAPTURE_ENDPOINT = (RESOURCES_URL + '/transactions/capture').freeze
11
+
12
+ def initialize(commerce_code = ::Transbank::Common::IntegrationCommerceCodes::ONECLICK_MALL, api_key = ::Transbank::Common::IntegrationApiKeys::WEBPAY, environment = DEFAULT_ENVIRONMENT)
13
+ super(commerce_code, api_key, environment)
14
+ end
15
+
16
+ def authorize(username, tbk_user, parent_buy_order, details)
17
+
18
+ Transbank::Common::Validation.has_text_with_max_length(username, Transbank::Common::ApiConstants::USER_NAME_LENGTH, "username")
19
+ Transbank::Common::Validation.has_text_with_max_length(tbk_user, Transbank::Common::ApiConstants::TBK_USER_LENGTH, "tbk_user")
20
+ Transbank::Common::Validation.has_text_with_max_length(parent_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "parent_buy_order")
21
+
22
+ request_service = ::Transbank::Shared::RequestService.new(
23
+ @environment, AUTHORIZE_ENDPOINT, @commerce_code, @api_key
24
+ )
25
+ request_service.post({
26
+ username: username, tbk_user: tbk_user, buy_order: parent_buy_order, details: details
27
+ })
28
+ end
29
+
30
+ def capture(child_commerce_code, child_buy_order, authorization_code, amount)
31
+
32
+ Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
33
+ Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")
34
+ Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")
35
+
36
+ request_service = ::Transbank::Shared::RequestService.new(
37
+ @environment, CAPTURE_ENDPOINT, @commerce_code, @api_key
38
+ )
39
+ request_service.put(commerce_code: child_commerce_code, buy_order: child_buy_order, authorization_code: authorization_code, capture_amount: amount)
40
+ end
41
+
42
+ def status(buy_order)
43
+
44
+ Transbank::Common::Validation.has_text_with_max_length(buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "buy_order")
45
+
46
+ request_service = ::Transbank::Shared::RequestService.new(
47
+ @environment, format(STATUS_ENDPOINT, token: buy_order), @commerce_code, @api_key
48
+ )
49
+ request_service.get
50
+ end
51
+
52
+ def refund(buy_order, child_commerce_code, child_buy_order, amount)
53
+
54
+ Transbank::Common::Validation.has_text_with_max_length(buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "buy_order")
55
+ Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
56
+ Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")
57
+
58
+ request_service = ::Transbank::Shared::RequestService.new(
59
+ @environment, format(REFUND_ENDPOINT, token: buy_order), @commerce_code, @api_key
60
+ )
61
+ request_service.post(detail_buy_order: child_buy_order, commerce_code: child_commerce_code, amount: amount)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,67 @@
1
+ module Transbank
2
+ module Webpay
3
+ module TransaccionCompleta
4
+ class MallTransaction < ::Transbank::Common::BaseTransaction
5
+ DEFAULT_ENVIRONMENT = :integration
6
+ RESOURCES_URL = ::Transbank::Common::ApiConstants::WEBPAY_ENDPOINT
7
+ CREATE_ENDPOINT = (RESOURCES_URL + '/transactions/').freeze
8
+ INSTALLMENTS_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/installments').freeze
9
+ COMMIT_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}').freeze
10
+ STATUS_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}').freeze
11
+ REFUND_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/refunds').freeze
12
+ CAPTURE_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/capture').freeze
13
+
14
+ def initialize(commerce_code = ::Transbank::Common::IntegrationCommerceCodes::TRANSACCION_COMPLETA_MALL, api_key = ::Transbank::Common::IntegrationApiKeys::WEBPAY, environment = DEFAULT_ENVIRONMENT)
15
+ super(commerce_code, api_key, environment)
16
+ end
17
+
18
+ def create(buy_order, session_id, card_number, card_expiration_date, details, cvv = nil)
19
+ request_service = ::Transbank::Shared::RequestService.new(
20
+ @environment, CREATE_ENDPOINT, @commerce_code, @api_key
21
+ )
22
+ request_service.post({
23
+ buy_order: buy_order, session_id: session_id, card_number: card_number, card_expiration_date: card_expiration_date, details: details, cvv: cvv
24
+ })
25
+ end
26
+
27
+ def installments(token, details)
28
+ request_service = ::Transbank::Shared::RequestService.new(
29
+ @environment, format(INSTALLMENTS_ENDPOINT, token: token), @commerce_code, @api_key
30
+ )
31
+ details.map {
32
+ |detail|
33
+ request_service.post({commerce_code: detail['commerce_code'], buy_order: detail['buy_order'], installments_number: detail['installments_number']})
34
+ }
35
+ end
36
+
37
+ def commit(token, details)
38
+ request_service = ::Transbank::Shared::RequestService.new(
39
+ @environment, format(COMMIT_ENDPOINT, token: token), @commerce_code, @api_key
40
+ )
41
+ request_service.put({details: details})
42
+ end
43
+
44
+ def status(token)
45
+ request_service = ::Transbank::Shared::RequestService.new(
46
+ @environment, format(STATUS_ENDPOINT, token: token), @commerce_code, @api_key
47
+ )
48
+ request_service.get
49
+ end
50
+
51
+ def refund(token, buy_order, commerce_code_child, amount)
52
+ request_service = ::Transbank::Shared::RequestService.new(
53
+ @environment, format(REFUND_ENDPOINT, token: token), @commerce_code, @api_key
54
+ )
55
+ request_service.post(buy_order: buy_order, commerce_code: commerce_code_child, amount: amount)
56
+ end
57
+
58
+ def capture(token, commerce_code, buy_order, authorization_code, amount)
59
+ request_service = ::Transbank::Shared::RequestService.new(
60
+ @environment, format(CAPTURE_ENDPOINT, token: token), @commerce_code, @api_key
61
+ )
62
+ request_service.put(buy_order: buy_order, commerce_code: commerce_code, authorization_code: authorization_code, capture_amount: amount)
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,70 @@
1
+ module Transbank
2
+ module Webpay
3
+ module TransaccionCompleta
4
+ class Transaction < ::Transbank::Common::BaseTransaction
5
+ DEFAULT_ENVIRONMENT = :integration
6
+ RESOURCES_URL = ::Transbank::Common::ApiConstants::WEBPAY_ENDPOINT
7
+ CREATE_ENDPOINT = (RESOURCES_URL + '/transactions/').freeze
8
+ INSTALLMENTS_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/installments').freeze
9
+ COMMIT_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}').freeze
10
+ STATUS_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}').freeze
11
+ REFUND_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/refunds').freeze
12
+ CAPTURE_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/capture').freeze
13
+
14
+ def initialize(commerce_code = ::Transbank::Common::IntegrationCommerceCodes::TRANSACCION_COMPLETA, api_key = ::Transbank::Common::IntegrationApiKeys::WEBPAY, environment = DEFAULT_ENVIRONMENT)
15
+ super
16
+ end
17
+
18
+ def create(buy_order, session_id, amount, cvv, card_number, card_expiration_date)
19
+
20
+ Transbank::Common::Validation.has_text_with_max_length(buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "buy_order")
21
+ Transbank::Common::Validation.has_text_with_max_length(session_id, Transbank::Common::ApiConstants::SESSION_ID_LENGTH, "session_id")
22
+ Transbank::Common::Validation.has_text_with_max_length(card_number, Transbank::Common::ApiConstants::CARD_NUMBER_LENGTH, "card_number")
23
+ Transbank::Common::Validation.has_text_with_max_length(card_expiration_date, Transbank::Common::ApiConstants::CARD_EXPIRATION_DATE_LENGTH, "card_expiration_date")
24
+
25
+ request_service = ::Transbank::Shared::RequestService.new(
26
+ @environment, CREATE_ENDPOINT, @commerce_code, @api_key
27
+ )
28
+ request_service.post({
29
+ buy_order: buy_order, session_id: session_id, amount: amount, cvv: cvv, card_number: card_number, card_expiration_date: card_expiration_date
30
+ })
31
+ end
32
+
33
+ def installments(token, installments_number)
34
+ request_service = ::Transbank::Shared::RequestService.new(
35
+ @environment, format(INSTALLMENTS_ENDPOINT, token: token), @commerce_code, @api_key
36
+ )
37
+ request_service.post({installments_number: installments_number})
38
+ end
39
+
40
+ def commit(token, id_query_installments, deferred_period_index, grace_period)
41
+ request_service = ::Transbank::Shared::RequestService.new(
42
+ @environment, format(COMMIT_ENDPOINT, token: token), @commerce_code, @api_key
43
+ )
44
+ request_service.put({id_query_installments: id_query_installments, deferred_period_index: deferred_period_index, grace_period: grace_period})
45
+ end
46
+
47
+ def status(token)
48
+ request_service = ::Transbank::Shared::RequestService.new(
49
+ @environment, format(STATUS_ENDPOINT, token: token), @commerce_code, @api_key
50
+ )
51
+ request_service.get
52
+ end
53
+
54
+ def refund(token, amount)
55
+ request_service = ::Transbank::Shared::RequestService.new(
56
+ @environment, format(REFUND_ENDPOINT, token: token), @commerce_code, @api_key
57
+ )
58
+ request_service.post(amount: amount)
59
+ end
60
+
61
+ def capture(token, buy_order, authorization_code, amount)
62
+ request_service = ::Transbank::Shared::RequestService.new(
63
+ @environment, format(CAPTURE_ENDPOINT, token: token), @commerce_code, @api_key
64
+ )
65
+ request_service.put(buy_order: buy_order, authorization_code: authorization_code, capture_amount: amount)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,79 @@
1
+ module Transbank
2
+ module Webpay
3
+ module WebpayPlus
4
+ class MallTransaction < ::Transbank::Common::BaseTransaction
5
+ DEFAULT_ENVIRONMENT = :integration
6
+ RESOURCES_URL = ::Transbank::Common::ApiConstants::WEBPAY_ENDPOINT
7
+ CREATE_ENDPOINT = (RESOURCES_URL + '/transactions/').freeze
8
+ COMMIT_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}').freeze
9
+ STATUS_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}').freeze
10
+ REFUND_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/refunds').freeze
11
+ CAPTURE_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/capture').freeze
12
+
13
+ def initialize(commerce_code = ::Transbank::Common::IntegrationCommerceCodes::WEBPAY_PLUS_MALL, api_key = ::Transbank::Common::IntegrationApiKeys::WEBPAY, environment = DEFAULT_ENVIRONMENT)
14
+ super
15
+ end
16
+
17
+ def create(buy_order, session_id, return_url, details)
18
+
19
+ Transbank::Common::Validation.has_text_with_max_length(buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "buy_order")
20
+ Transbank::Common::Validation.has_text_with_max_length(session_id, Transbank::Common::ApiConstants::SESSION_ID_LENGTH, "session_id")
21
+ Transbank::Common::Validation.has_text_with_max_length(return_url, Transbank::Common::ApiConstants::RETURN_URL_LENGTH, "return_url")
22
+
23
+ request_service = ::Transbank::Shared::RequestService.new(
24
+ @environment, CREATE_ENDPOINT, @commerce_code, @api_key
25
+ )
26
+ request_service.post({
27
+ buy_order: buy_order, session_id: session_id, return_url: return_url, details: details
28
+ })
29
+ end
30
+
31
+ def commit(token)
32
+
33
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
34
+
35
+ request_service = ::Transbank::Shared::RequestService.new(
36
+ @environment, format(COMMIT_ENDPOINT, token: token), @commerce_code, @api_key
37
+ )
38
+ request_service.put({})
39
+ end
40
+
41
+ def status(token)
42
+
43
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
44
+
45
+ request_service = ::Transbank::Shared::RequestService.new(
46
+ @environment, format(STATUS_ENDPOINT, token: token), @commerce_code, @api_key
47
+ )
48
+ request_service.get
49
+ end
50
+
51
+ def refund(token, buy_order, child_commerce_code, amount)
52
+
53
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
54
+ Transbank::Common::Validation.has_text_with_max_length(buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "buy_order")
55
+ Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
56
+
57
+ request_service = ::Transbank::Shared::RequestService.new(
58
+ @environment, format(REFUND_ENDPOINT, token: token), @commerce_code, @api_key
59
+ )
60
+ request_service.post(buy_order: buy_order, commerce_code: child_commerce_code, amount: amount)
61
+ end
62
+
63
+ def capture(child_commerce_code, token, buy_order, authorization_code, capture_amount)
64
+
65
+
66
+ Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
67
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
68
+ Transbank::Common::Validation.has_text_with_max_length(buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "buy_order")
69
+ Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")
70
+
71
+ request_service = ::Transbank::Shared::RequestService.new(
72
+ @environment, format(CAPTURE_ENDPOINT, token: token), @commerce_code, @api_key
73
+ )
74
+ request_service.put(commerce_code: child_commerce_code, buy_order: buy_order, authorization_code: authorization_code, capture_amount: capture_amount)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,76 @@
1
+ module Transbank
2
+ module Webpay
3
+ module WebpayPlus
4
+ class Transaction < ::Transbank::Common::BaseTransaction
5
+ DEFAULT_ENVIRONMENT = :integration
6
+ RESOURCES_URL = ::Transbank::Common::ApiConstants::WEBPAY_ENDPOINT
7
+ CREATE_ENDPOINT = (RESOURCES_URL + '/transactions/').freeze
8
+ COMMIT_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}').freeze
9
+ STATUS_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}').freeze
10
+ REFUND_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/refunds').freeze
11
+ CAPTURE_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/capture').freeze
12
+
13
+
14
+ def initialize(commerce_code = ::Transbank::Common::IntegrationCommerceCodes::WEBPAY_PLUS, api_key = ::Transbank::Common::IntegrationApiKeys::WEBPAY, environment = DEFAULT_ENVIRONMENT)
15
+ super(commerce_code, api_key, environment)
16
+ end
17
+
18
+ def create(buy_order, session_id, amount, return_url)
19
+
20
+ Transbank::Common::Validation.has_text_with_max_length(buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "buy_order")
21
+ Transbank::Common::Validation.has_text_with_max_length(session_id, Transbank::Common::ApiConstants::SESSION_ID_LENGTH, "session_id")
22
+ Transbank::Common::Validation.has_text_with_max_length(return_url, Transbank::Common::ApiConstants::RETURN_URL_LENGTH, "return_url")
23
+
24
+ request_service = ::Transbank::Shared::RequestService.new(
25
+ @environment, CREATE_ENDPOINT, @commerce_code, @api_key
26
+ )
27
+ request_service.post({
28
+ buy_order: buy_order, session_id: session_id, amount: amount, return_url: return_url
29
+ })
30
+ end
31
+
32
+ def commit(token)
33
+
34
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
35
+
36
+ request_service = ::Transbank::Shared::RequestService.new(
37
+ @environment, format(COMMIT_ENDPOINT, token: token), @commerce_code, @api_key
38
+ )
39
+ request_service.put({})
40
+ end
41
+
42
+ def status(token)
43
+
44
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
45
+
46
+ request_service = ::Transbank::Shared::RequestService.new(
47
+ @environment, format(STATUS_ENDPOINT, token: token), @commerce_code, @api_key
48
+ )
49
+ request_service.get
50
+ end
51
+
52
+ def refund(token, amount)
53
+
54
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
55
+
56
+ request_service = ::Transbank::Shared::RequestService.new(
57
+ @environment, format(REFUND_ENDPOINT, token: token), @commerce_code, @api_key
58
+ )
59
+ request_service.post(amount: amount)
60
+ end
61
+
62
+ def capture(token, buy_order, authorization_code, amount)
63
+
64
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
65
+ Transbank::Common::Validation.has_text_with_max_length(buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "buy_order")
66
+ Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")
67
+
68
+ request_service = ::Transbank::Shared::RequestService.new(
69
+ @environment, format(CAPTURE_ENDPOINT, token: token), @commerce_code, @api_key
70
+ )
71
+ request_service.put(buy_order: buy_order, authorization_code: authorization_code, capture_amount: amount)
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,62 @@
1
+ module Transbank
2
+ module Webpay
3
+ module WebpayPlusModal
4
+ class Transaction < ::Transbank::Common::BaseTransaction
5
+ DEFAULT_ENVIRONMENT = :integration
6
+ RESOURCES_URL = ::Transbank::Common::ApiConstants::WEBPAY_ENDPOINT
7
+ CREATE_ENDPOINT = (RESOURCES_URL + '/transactions/').freeze
8
+ COMMIT_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}').freeze
9
+ STATUS_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}').freeze
10
+ REFUND_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/refunds').freeze
11
+
12
+ def initialize(commerce_code = ::Transbank::Common::IntegrationCommerceCodes::WEBPAY_PLUS_MODAL, api_key = ::Transbank::Common::IntegrationApiKeys::WEBPAY, environment = DEFAULT_ENVIRONMENT)
13
+ super(commerce_code, api_key, environment)
14
+ end
15
+
16
+ def create(buy_order, session_id, amount)
17
+
18
+ Transbank::Common::Validation.has_text_with_max_length(buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "buy_order")
19
+ Transbank::Common::Validation.has_text_with_max_length(session_id, Transbank::Common::ApiConstants::SESSION_ID_LENGTH, "session_id")
20
+
21
+ request_service = ::Transbank::Shared::RequestService.new(
22
+ @environment, CREATE_ENDPOINT, @commerce_code, @api_key
23
+ )
24
+ request_service.post({
25
+ buy_order: buy_order, session_id: session_id, amount: amount
26
+ })
27
+ end
28
+
29
+ def commit(token)
30
+
31
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
32
+
33
+ request_service = ::Transbank::Shared::RequestService.new(
34
+ @environment, format(COMMIT_ENDPOINT, token: token), @commerce_code, @api_key
35
+ )
36
+ request_service.put({})
37
+ end
38
+
39
+ def status(token)
40
+
41
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
42
+
43
+ request_service = ::Transbank::Shared::RequestService.new(
44
+ @environment, format(STATUS_ENDPOINT, token: token), @commerce_code, @api_key
45
+ )
46
+ request_service.get
47
+ end
48
+
49
+ def refund(token, amount)
50
+
51
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
52
+
53
+ request_service = ::Transbank::Shared::RequestService.new(
54
+ @environment, format(REFUND_ENDPOINT, token: token), @commerce_code, @api_key
55
+ )
56
+ request_service.post(amount: amount)
57
+ end
58
+
59
+ end
60
+ end
61
+ end
62
+ end