Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/transbank/sdk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

require 'transbank/sdk/webpay/oneclick/mall_transaction'
require 'transbank/sdk/webpay/oneclick/mall_inscription'
require 'transbank/sdk/webpay/oneclick/mall_bin_info'

require 'transbank/sdk/webpay/transaccion_completa/transaction'
require 'transbank/sdk/webpay/transaccion_completa/mall_transaction'

require 'transbank/sdk/patpass/patpass_comercio/inscription'

48 changes: 48 additions & 0 deletions lib/transbank/sdk/webpay/oneclick/mall_bin_info.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module Transbank
module Webpay
module Oneclick
class MallBinInfo < ::Transbank::Common::BaseTransaction
private_class_method :new
RESOURCES_URL = ::Transbank::Common::ApiConstants::ONECLICK_ENDPOINT
QUERY_BIN_ENDPOINT = (RESOURCES_URL + '/bin_info').freeze

def initialize(options)
super
end

def self.new(options)
super(options)
end

def self.build_for_integration(commerce_code, api_key)
options = Options.new(
commerce_code,
api_key,
:integration
)

new(options)
end

def self.build_for_production(commerce_code, api_key)
options = Options.new(
commerce_code,
api_key,
:production
)
new(options)
end

def query_bin(tbk_user)
Transbank::Common::Validation.has_text_with_max_length(tbk_user, Transbank::Common::ApiConstants::TBK_USER_LENGTH, "tbk_user")

request_service = ::Transbank::Shared::RequestService.new(
@environment, QUERY_BIN_ENDPOINT, @commerce_code, @api_key, @timeout
)
request_service.post({ tbk_user: tbk_user })
end

end
end
end
end
47 changes: 47 additions & 0 deletions test/transbank/oneclick/mall_bin_info_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require 'test_helper'
require 'webmock/minitest'

class MallBinInfoTest < Transbank::WebPayPlus::Test
def setup
@query_bin_url = "https://webpay3gint.transbank.cl/rswebpaytransaction/api/oneclick/v1.2/bin_info"
@tbk_user_valid = "tbk_user_123"
@tbk_user_invalid = "A" * (Transbank::Common::ApiConstants::TBK_USER_LENGTH + 1)


@mock_response = {
bin_issuer: "TEST COMMERCE BANK",
bin_payment_type: "Credito",
bin_brand: "Visa"
}.to_json

stub_request(:post, @query_bin_url)
.with(body: { tbk_user: @tbk_user_valid }.to_json, headers: { 'Content-Type' => 'application/json' })
.to_return(status: 200, body: @mock_response)

WebMock.disable_net_connect!
end

def test_query_bin_success
transaction = Transbank::Webpay::Oneclick::MallBinInfo.build_for_integration(
Transbank::Common::IntegrationCommerceCodes::ONECLICK_MALL,
Transbank::Common::IntegrationApiKeys::WEBPAY
)
response = transaction.query_bin(@tbk_user_valid)
assert_equal "Visa", response["bin_brand"]
assert_equal "Credito", response["bin_payment_type"]
end

def test_query_bin_raises_error_when_tbk_user_is_too_long
transaction = Transbank::Webpay::Oneclick::MallBinInfo.build_for_integration(
Transbank::Common::IntegrationCommerceCodes::ONECLICK_MALL,
Transbank::Common::IntegrationApiKeys::WEBPAY
)

error = assert_raises Transbank::Shared::TransbankError do
transaction.query_bin(@tbk_user_invalid)
end

expected_message = "tbk_user is too long, the maximum length is #{Transbank::Common::ApiConstants::TBK_USER_LENGTH}"
assert_equal expected_message, error.message
end
end