mvarlic-ruby-sdk 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/.github/ISSUE_TEMPLATE/reporte-de-error.md +40 -0
  3. data/.github/workflows/publish-sdk.yml +58 -0
  4. data/.gitignore +16 -0
  5. data/CHANGELOG.md +104 -0
  6. data/Dockerfile +5 -0
  7. data/Gemfile +6 -0
  8. data/LICENSE.md +11 -0
  9. data/Makefile +24 -0
  10. data/README.md +85 -0
  11. data/Rakefile +10 -0
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  14. data/docker-compose.yml +20 -0
  15. data/lib/transbank/sdk/common/api_constants.rb +23 -0
  16. data/lib/transbank/sdk/common/base_transaction.rb +18 -0
  17. data/lib/transbank/sdk/common/integration_api_keys.rb +9 -0
  18. data/lib/transbank/sdk/common/integration_commerce_codes.rb +82 -0
  19. data/lib/transbank/sdk/common/validation.rb +19 -0
  20. data/lib/transbank/sdk/patpass/patpass_by_webpay/transaction.rb +41 -0
  21. data/lib/transbank/sdk/patpass/patpass_comercio/inscription.rb +56 -0
  22. data/lib/transbank/sdk/shared/request_service.rb +93 -0
  23. data/lib/transbank/sdk/shared/transbank_error.rb +5 -0
  24. data/lib/transbank/sdk/version.rb +5 -0
  25. data/lib/transbank/sdk/webpay/oneclick/mall_inscription.rb +52 -0
  26. data/lib/transbank/sdk/webpay/oneclick/mall_transaction.rb +118 -0
  27. data/lib/transbank/sdk/webpay/transaccion_completa/mall_transaction.rb +122 -0
  28. data/lib/transbank/sdk/webpay/transaccion_completa/transaction.rb +120 -0
  29. data/lib/transbank/sdk/webpay/webpay_plus/mall_transaction.rb +134 -0
  30. data/lib/transbank/sdk/webpay/webpay_plus/transaction.rb +127 -0
  31. data/lib/transbank/sdk/webpay/webpay_plus_modal/transaction.rb +62 -0
  32. data/lib/transbank/sdk.rb +27 -0
  33. data/mvarlic-ruby-sdk.gemspec +35 -0
  34. data/sdk_test.sh +2 -0
  35. metadata +216 -0
@@ -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,93 @@
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
+ if response.is_a? Net::HTTPSuccess
50
+ return nil if response.body.empty?
51
+ return JSON.parse(response.body)
52
+ end
53
+ body = JSON.parse(response.body)
54
+ if body.key?("description")
55
+ raise TransbankError, "Transbank Error: #{body['code']} - #{body['description']}"
56
+ else
57
+ raise TransbankError, "Transbank Error: #{body['error_message']}"
58
+ end
59
+ end
60
+
61
+ def build_client
62
+ uri = URI.parse(@url)
63
+ http = Net::HTTP.new(uri.host, uri.port)
64
+ http.use_ssl = uri.scheme == 'https'
65
+ [uri, http]
66
+ end
67
+
68
+ def build_method(method, uri, body = nil)
69
+ http_method = Object.const_get("Net::HTTP::#{method.capitalize}").new(uri.path, @headers)
70
+ if !body.nil?
71
+ http_method.body = body.to_json
72
+ end
73
+ http_method
74
+ end
75
+
76
+ def headers(commerce_code, api_key)
77
+ {
78
+ 'Tbk-Api-Key-Id' => commerce_code.to_s,
79
+ 'Tbk-Api-Key-Secret' => api_key,
80
+ 'Content-Type' => 'application/json'
81
+ }
82
+ end
83
+
84
+ def headers_patpass(commerce_code, api_key)
85
+ {
86
+ 'commercecode' => commerce_code.to_s,
87
+ 'Authorization' => api_key,
88
+ 'Content-Type' => 'application/json'
89
+ }
90
+ end
91
+ end
92
+ end
93
+ 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 = '3.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,118 @@
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
+ INCREASE_AMOUNT_ENDPOINT = (RESOURCES_URL + '/transactions/amount').freeze
12
+ INCREASE_AUTHORIZATION_DATE_ENDPOINT = (RESOURCES_URL + '/transactions/authorization_date').freeze
13
+ REVERSE_PRE_AUTHORIZED_AMOUNT_ENDPOINT = (RESOURCES_URL + '/transactions/reverse/amount').freeze
14
+ DEFERRED_CAPTURE_HISTORY_ENDPOINT = (RESOURCES_URL + '/transactions/details').freeze
15
+
16
+ def initialize(commerce_code = ::Transbank::Common::IntegrationCommerceCodes::ONECLICK_MALL, api_key = ::Transbank::Common::IntegrationApiKeys::WEBPAY, environment = DEFAULT_ENVIRONMENT)
17
+ super(commerce_code, api_key, environment)
18
+ end
19
+
20
+ def authorize(username, tbk_user, parent_buy_order, details)
21
+
22
+ Transbank::Common::Validation.has_text_with_max_length(username, Transbank::Common::ApiConstants::USER_NAME_LENGTH, "username")
23
+ Transbank::Common::Validation.has_text_with_max_length(tbk_user, Transbank::Common::ApiConstants::TBK_USER_LENGTH, "tbk_user")
24
+ Transbank::Common::Validation.has_text_with_max_length(parent_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "parent_buy_order")
25
+
26
+ request_service = ::Transbank::Shared::RequestService.new(
27
+ @environment, AUTHORIZE_ENDPOINT, @commerce_code, @api_key
28
+ )
29
+ request_service.post({
30
+ username: username, tbk_user: tbk_user, buy_order: parent_buy_order, details: details
31
+ })
32
+ end
33
+
34
+ def capture(child_commerce_code, child_buy_order, authorization_code, amount)
35
+
36
+ Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
37
+ Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")
38
+ Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")
39
+
40
+ request_service = ::Transbank::Shared::RequestService.new(
41
+ @environment, CAPTURE_ENDPOINT, @commerce_code, @api_key
42
+ )
43
+ request_service.put(commerce_code: child_commerce_code, buy_order: child_buy_order, authorization_code: authorization_code, capture_amount: amount)
44
+ end
45
+
46
+ def status(buy_order)
47
+
48
+ Transbank::Common::Validation.has_text_with_max_length(buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "buy_order")
49
+
50
+ request_service = ::Transbank::Shared::RequestService.new(
51
+ @environment, format(STATUS_ENDPOINT, token: buy_order), @commerce_code, @api_key
52
+ )
53
+ request_service.get
54
+ end
55
+
56
+ def refund(buy_order, child_commerce_code, child_buy_order, amount)
57
+
58
+ Transbank::Common::Validation.has_text_with_max_length(buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "buy_order")
59
+ Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
60
+ Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")
61
+
62
+ request_service = ::Transbank::Shared::RequestService.new(
63
+ @environment, format(REFUND_ENDPOINT, token: buy_order), @commerce_code, @api_key
64
+ )
65
+ request_service.post(detail_buy_order: child_buy_order, commerce_code: child_commerce_code, amount: amount)
66
+ end
67
+
68
+ def increase_amount(child_commerce_code, child_buy_order, authorization_code, amount)
69
+
70
+ Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
71
+ Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")
72
+ Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")
73
+
74
+ request_service = ::Transbank::Shared::RequestService.new(
75
+ @environment, INCREASE_AMOUNT_ENDPOINT, @commerce_code, @api_key
76
+ )
77
+ request_service.put(commerce_code: child_commerce_code, buy_order: child_buy_order, authorization_code: authorization_code, amount: amount)
78
+ end
79
+
80
+ def increase_authorization_date(child_commerce_code, child_buy_order, authorization_code)
81
+
82
+ Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
83
+ Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")
84
+ Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")
85
+
86
+ request_service = ::Transbank::Shared::RequestService.new(
87
+ @environment, INCREASE_AUTHORIZATION_DATE_ENDPOINT, @commerce_code, @api_key
88
+ )
89
+ request_service.put(commerce_code: child_commerce_code, buy_order: child_buy_order, authorization_code: authorization_code)
90
+ end
91
+
92
+ def reverse_pre_authorized_amount(child_commerce_code, child_buy_order, authorization_code, amount)
93
+
94
+ Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
95
+ Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")
96
+ Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")
97
+
98
+ request_service = ::Transbank::Shared::RequestService.new(
99
+ @environment, REVERSE_PRE_AUTHORIZED_AMOUNT_ENDPOINT, @commerce_code, @api_key
100
+ )
101
+ request_service.put(commerce_code: child_commerce_code, buy_order: child_buy_order, authorization_code: authorization_code, amount: amount)
102
+ end
103
+
104
+ def deferred_capture_history(child_commerce_code, child_buy_order, authorization_code)
105
+
106
+ Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
107
+ Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")
108
+ Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")
109
+
110
+ request_service = ::Transbank::Shared::RequestService.new(
111
+ @environment, DEFERRED_CAPTURE_HISTORY_ENDPOINT, @commerce_code, @api_key
112
+ )
113
+ request_service.post(commerce_code: child_commerce_code, buy_order: child_buy_order, authorization_code: authorization_code)
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,122 @@
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
+ INCREASE_AMOUNT_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/amount').freeze
14
+ INCREASE_AUTHORIZATION_DATE_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/authorization_date').freeze
15
+ REVERSE_PRE_AUTHORIZED_AMOUNT_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/reverse/amount').freeze
16
+ DEFERRED_CAPTURE_HISTORY_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/details').freeze
17
+
18
+ def initialize(commerce_code = ::Transbank::Common::IntegrationCommerceCodes::TRANSACCION_COMPLETA_MALL, api_key = ::Transbank::Common::IntegrationApiKeys::WEBPAY, environment = DEFAULT_ENVIRONMENT)
19
+ super(commerce_code, api_key, environment)
20
+ end
21
+
22
+ def create(buy_order, session_id, card_number, card_expiration_date, details, cvv = nil)
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, card_number: card_number, card_expiration_date: card_expiration_date, details: details, cvv: cvv
28
+ })
29
+ end
30
+
31
+ def installments(token, details)
32
+ request_service = ::Transbank::Shared::RequestService.new(
33
+ @environment, format(INSTALLMENTS_ENDPOINT, token: token), @commerce_code, @api_key
34
+ )
35
+ details.map {
36
+ |detail|
37
+ request_service.post({commerce_code: detail['commerce_code'], buy_order: detail['buy_order'], installments_number: detail['installments_number']})
38
+ }
39
+ end
40
+
41
+ def commit(token, details)
42
+ request_service = ::Transbank::Shared::RequestService.new(
43
+ @environment, format(COMMIT_ENDPOINT, token: token), @commerce_code, @api_key
44
+ )
45
+ request_service.put({details: details})
46
+ end
47
+
48
+ def status(token)
49
+ request_service = ::Transbank::Shared::RequestService.new(
50
+ @environment, format(STATUS_ENDPOINT, token: token), @commerce_code, @api_key
51
+ )
52
+ request_service.get
53
+ end
54
+
55
+ def refund(token, buy_order, commerce_code_child, amount)
56
+ request_service = ::Transbank::Shared::RequestService.new(
57
+ @environment, format(REFUND_ENDPOINT, token: token), @commerce_code, @api_key
58
+ )
59
+ request_service.post(buy_order: buy_order, commerce_code: commerce_code_child, amount: amount)
60
+ end
61
+
62
+ def capture(token, commerce_code, buy_order, authorization_code, amount)
63
+ request_service = ::Transbank::Shared::RequestService.new(
64
+ @environment, format(CAPTURE_ENDPOINT, token: token), @commerce_code, @api_key
65
+ )
66
+ request_service.put(buy_order: buy_order, commerce_code: commerce_code, authorization_code: authorization_code, capture_amount: amount)
67
+ end
68
+
69
+ def increase_amount(token, child_commerce_code, child_buy_order, authorization_code, amount)
70
+
71
+ Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
72
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
73
+ Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")
74
+ Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")
75
+
76
+ request_service = ::Transbank::Shared::RequestService.new(
77
+ @environment, format(INCREASE_AMOUNT_ENDPOINT, token: token), @commerce_code, @api_key
78
+ )
79
+ request_service.put(commerce_code: child_commerce_code, buy_order: child_buy_order, authorization_code: authorization_code, amount: amount)
80
+ end
81
+
82
+ def increase_authorization_date(token, child_commerce_code, child_buy_order, authorization_code)
83
+
84
+ Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
85
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
86
+ Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")
87
+ Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")
88
+
89
+ request_service = ::Transbank::Shared::RequestService.new(
90
+ @environment, format(INCREASE_AUTHORIZATION_DATE_ENDPOINT, token: token), @commerce_code, @api_key
91
+ )
92
+ request_service.put(commerce_code: child_commerce_code, buy_order: child_buy_order, authorization_code: authorization_code)
93
+ end
94
+
95
+ def reverse_pre_authorized_amount(token, child_commerce_code, child_buy_order, authorization_code, amount)
96
+
97
+ Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
98
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
99
+ Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")
100
+ Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")
101
+
102
+ request_service = ::Transbank::Shared::RequestService.new(
103
+ @environment, format(REVERSE_PRE_AUTHORIZED_AMOUNT_ENDPOINT, token: token), @commerce_code, @api_key
104
+ )
105
+ request_service.put(commerce_code: child_commerce_code, buy_order: child_buy_order, authorization_code: authorization_code, amount: amount)
106
+ end
107
+
108
+ def deferred_capture_history(token, child_commerce_code, child_buy_order)
109
+
110
+ Transbank::Common::Validation.has_text_with_max_length(child_commerce_code, Transbank::Common::ApiConstants::COMMERCE_CODE_LENGTH, "child_commerce_code")
111
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
112
+ Transbank::Common::Validation.has_text_with_max_length(child_buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "child_buy_order")
113
+
114
+ request_service = ::Transbank::Shared::RequestService.new(
115
+ @environment, format(DEFERRED_CAPTURE_HISTORY_ENDPOINT, token: token), @commerce_code, @api_key
116
+ )
117
+ request_service.post(commerce_code: child_commerce_code, buy_order: child_buy_order)
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,120 @@
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
+ INCREASE_AMOUNT_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/amount').freeze
14
+ INCREASE_AUTHORIZATION_DATE_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/authorization_date').freeze
15
+ REVERSE_PRE_AUTHORIZED_AMOUNT_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/reverse/amount').freeze
16
+ DEFERRED_CAPTURE_HISTORY_ENDPOINT = (RESOURCES_URL + '/transactions/%{token}/details').freeze
17
+
18
+ def initialize(commerce_code = ::Transbank::Common::IntegrationCommerceCodes::TRANSACCION_COMPLETA, api_key = ::Transbank::Common::IntegrationApiKeys::WEBPAY, environment = DEFAULT_ENVIRONMENT)
19
+ super
20
+ end
21
+
22
+ def create(buy_order, session_id, amount, cvv, card_number, card_expiration_date)
23
+
24
+ Transbank::Common::Validation.has_text_with_max_length(buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "buy_order")
25
+ Transbank::Common::Validation.has_text_with_max_length(session_id, Transbank::Common::ApiConstants::SESSION_ID_LENGTH, "session_id")
26
+ Transbank::Common::Validation.has_text_with_max_length(card_number, Transbank::Common::ApiConstants::CARD_NUMBER_LENGTH, "card_number")
27
+ Transbank::Common::Validation.has_text_with_max_length(card_expiration_date, Transbank::Common::ApiConstants::CARD_EXPIRATION_DATE_LENGTH, "card_expiration_date")
28
+
29
+ request_service = ::Transbank::Shared::RequestService.new(
30
+ @environment, CREATE_ENDPOINT, @commerce_code, @api_key
31
+ )
32
+ request_service.post({
33
+ buy_order: buy_order, session_id: session_id, amount: amount, cvv: cvv, card_number: card_number, card_expiration_date: card_expiration_date
34
+ })
35
+ end
36
+
37
+ def installments(token, installments_number)
38
+ request_service = ::Transbank::Shared::RequestService.new(
39
+ @environment, format(INSTALLMENTS_ENDPOINT, token: token), @commerce_code, @api_key
40
+ )
41
+ request_service.post({installments_number: installments_number})
42
+ end
43
+
44
+ def commit(token, id_query_installments, deferred_period_index, grace_period)
45
+ request_service = ::Transbank::Shared::RequestService.new(
46
+ @environment, format(COMMIT_ENDPOINT, token: token), @commerce_code, @api_key
47
+ )
48
+ request_service.put({id_query_installments: id_query_installments, deferred_period_index: deferred_period_index, grace_period: grace_period})
49
+ end
50
+
51
+ def status(token)
52
+ request_service = ::Transbank::Shared::RequestService.new(
53
+ @environment, format(STATUS_ENDPOINT, token: token), @commerce_code, @api_key
54
+ )
55
+ request_service.get
56
+ end
57
+
58
+ def refund(token, amount)
59
+ request_service = ::Transbank::Shared::RequestService.new(
60
+ @environment, format(REFUND_ENDPOINT, token: token), @commerce_code, @api_key
61
+ )
62
+ request_service.post(amount: amount)
63
+ end
64
+
65
+ def capture(token, buy_order, authorization_code, amount)
66
+ request_service = ::Transbank::Shared::RequestService.new(
67
+ @environment, format(CAPTURE_ENDPOINT, token: token), @commerce_code, @api_key
68
+ )
69
+ request_service.put(buy_order: buy_order, authorization_code: authorization_code, capture_amount: amount)
70
+ end
71
+
72
+ def increase_amount(token, buy_order, authorization_code, amount)
73
+
74
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
75
+ Transbank::Common::Validation.has_text_with_max_length(buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "buy_order")
76
+ Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")
77
+
78
+ request_service = ::Transbank::Shared::RequestService.new(
79
+ @environment, format(INCREASE_AMOUNT_ENDPOINT, token: token), @commerce_code, @api_key
80
+ )
81
+ request_service.put(commerce_code: @commerce_code, buy_order: buy_order, authorization_code: authorization_code, amount: amount)
82
+ end
83
+
84
+ def increase_authorization_date(token, buy_order, authorization_code)
85
+
86
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
87
+ Transbank::Common::Validation.has_text_with_max_length(buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "buy_order")
88
+ Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")
89
+
90
+ request_service = ::Transbank::Shared::RequestService.new(
91
+ @environment, format(INCREASE_AUTHORIZATION_DATE_ENDPOINT, token: token), @commerce_code, @api_key
92
+ )
93
+ request_service.put(commerce_code: @commerce_code, buy_order: buy_order, authorization_code: authorization_code)
94
+ end
95
+
96
+ def reverse_pre_authorized_amount(token, buy_order, authorization_code, amount)
97
+
98
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
99
+ Transbank::Common::Validation.has_text_with_max_length(buy_order, Transbank::Common::ApiConstants::BUY_ORDER_LENGTH, "buy_order")
100
+ Transbank::Common::Validation.has_text_with_max_length(authorization_code, Transbank::Common::ApiConstants::AUTHORIZATION_CODE_LENGTH, "authorization_code")
101
+
102
+ request_service = ::Transbank::Shared::RequestService.new(
103
+ @environment, format(REVERSE_PRE_AUTHORIZED_AMOUNT_ENDPOINT, token: token), @commerce_code, @api_key
104
+ )
105
+ request_service.put(commerce_code: @commerce_code, buy_order: buy_order, authorization_code: authorization_code, amount: amount)
106
+ end
107
+
108
+ def deferred_capture_history(token)
109
+
110
+ Transbank::Common::Validation.has_text_with_max_length(token, Transbank::Common::ApiConstants::TOKEN_LENGTH, "token")
111
+
112
+ request_service = ::Transbank::Shared::RequestService.new(
113
+ @environment, format(DEFERRED_CAPTURE_HISTORY_ENDPOINT, token: token), @commerce_code, @api_key
114
+ )
115
+ request_service.get
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end