This repository was archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
This repository was archived by the owner on Oct 15, 2024. It is now read-only.
Bad Request na criação da conta bancária quando holder.taxDocument.number" == "CNPJ" O mesmo código funciona sim quando o holder.taxDocument.number" == 'CPF' #85
Copy link
Copy link
Open
Description
Issue
Recebo bad request enviando um post request da uma conta bancária com um "holder.taxDocument.number" CNPJ mas recebo 200 com quando o documento é CPF
Error message
#<HTTParty::Response:0x7fa88f649d78 parsed_response=nil, @response=#<Net::HTTPBadRequest 400 Bad Request readbody=true>, @headers={"date"=>["Thu, 30 Aug 2018 13:51:17 GMT"], "server"=>["Apache"], "x-newrelic-app-data"=>["PxQGVFJbCgcTXFdSAwUOVEYdFGQHBDcQUQxLA1tMXV1dORYzVBJHNQFUZAQUFVFQVThOFAVtGAcHUllGDBIQPh8ZWQFbV0FcRyxdHG1OUQMKXVYCBQxNXUQXQUpnfmQyTRMaA0xWT1IeUQxUCwgFBgRJC1UDTREGAVUPUQRaXlIDUVRQVgdWREhXV18RAz4="], "content-type"=>["text/plain; charset=UTF-8"], "content-length"=>["0"], "x-content-type-options"=>["nosniff"], "vary"=>["Origin"], "connection"=>["close"]}>
Code
app/services/moip_api.rb
class MoipApi
def initialize(args = {})
@test = args[:test] || false
@api = Moip.new(args[:store], @test).call
@platform_token = @test ? ENV['MOIP_SANDBOX_ACCESS_TOKEN'] : ENV['MOIP_ACCESS_TOKEN']
end
#[...]
def create_bank(bank_info)
bank_account = api.bank_accounts.create(bank_info.tour_store.moip_id, bank_post_data(bank_info))
bank_info.update(moip_id: bank_account[:id]) unless bank_account[:errors].present?
bank_account
end
#[...]
private
#[...]
def bank_post_data(banking_information)
{
bankNumber: banking_information.bank_code,
agencyNumber: banking_information.bank_ag.to_i,
agencyCheckNumber: banking_information.ag_digit,
accountNumber: banking_information.bank_cc.to_i,
accountCheckNumber: banking_information.cc_digit.to_i,
type: banking_information.account_type,
holder: {
taxDocument: {
type: banking_information.holder_id_type,
number: banking_information.holder_id,
},
fullname: banking_information.holder_name,
}
}
end
endconfig/initializers/moip.rb
class Moip
def initialize(store = nil, test = nil)
@store = store
@test = test || false
@access_token = store_token || platform_token
end
def call
authentication
end
private
def authentication
dummy? ? Moip2::Api.new(moip_sandbox_client) : Moip2::Api.new(moip_client)
end
def moip_client
Moip2::Client.new(:production, moip_auth)
end
def moip_sandbox_client
Moip2::Client.new(:sandbox, moip_auth)
end
def moip_auth
Moip2::Auth::OAuth.new(access_token)
end
def dummy?
@store ? @store.dummy : @test
end
#[...]
endapp/controllers/banking_informations_controller.rb
class BankingInformationsController < ApplicationController
#[...]
def create
@banking_information = BankingInformation.new(set_params)
@banking_information.tour_store = @tour_store
authorize @banking_information
if @banking_information.save && create_moip_bank[:errors].nil?
flash[:notice] = 'Conta bancária criada com sucesso'
redirect_to tour_store_dashboard_path(@tour_store)
else
flash[:alert] = @banking_information.errors.first.second
redirect_back fallback_location: tour_store_bank_path(@tour_store)
end
end
#[...]
private
#[...]
def create_moip_bank
MoipApi.new(store: @tour_store).create_bank(@banking_information)
endapp/models/banking_information.rb
class BankingInformation < ApplicationRecord
#[...]
endPost Request Error
#Método que chama o post request
api.bank_accounts.create(bank_info.tour_store.moip_id, bank_post_data(bank_info))
api #=>
#<Moip2::Api:0x00007fcb0bdf8648
@client=
#<Moip2::Client:0x00007fcb0bdf88f0
@auth=
#<Moip2::Auth::OAuth:0x00007fcb0bdf8918
@oauth=
"da213e99cbcb4638a562dfd34cba3795_v2">,
@env=:production,
@opts=
{:headers=>
{"Content-Type"=>"application/json",
"Authorization"=>
"OAuth da213e99cbcb4638a562dfd34cba3795_v2",
"User-Agent"=>
"MoipRubySDK/1.2.1 (+https://github.com/moip/moip-sdk-ruby)"}},
@uri="https://api.moip.com.br">>
bank_info.tour_store.moip_id #=> "MPA-EA71B0668CA6"
bank_post_data(bank_info) #=>
{:bankNumber=>"033",
:agencyNumber=>4109,
:agencyCheckNumber=>"",
:accountNumber=>13002469,
:accountCheckNumber=>1,
:type=>"CHECKING",
:holder=>
{:taxDocument=>
{:type=>"CNPJ", :number=>"19.870.536/0001-96"},
:fullname=>"Danilo dos Santos Rollo - ME"}}
api.bank_accounts.create(bank_info.tour_store.moip_id, bank_post_data(bank_info)) #=>
#Retorna este erro
=> #<HTTParty::Response:0x7fcb0bde67b8 parsed_response=nil, @response=#<Net::HTTPBadRequest 400 Bad Request readbody=true>, @headers={"date"=>["Thu, 30 Aug 2018 14:25:41 GMT"], "server"=>["Apache"], "x-newrelic-app-data"=>["PxQGVFJbCgcTXFdSAwUOVEYdFGQHBDcQUQxLA1tMXV1dORYzVBJHNQFUZAQUFVFQVThOFAVtGAcHUllGDBIQPh8ZWQFbV0FcRyxdHG1OUQMKXVYCBQxNXUQXQUpnfmQyTRMaA0xWT1IeUQ9RDAgEBx9XDVMdQ1IAVgNVAlQGAVZVAVhRAFcVSgJQWkAHOw=="], "content-type"=>["text/plain; charset=UTF-8"], "content-length"=>["0"], "x-content-type-options"=>["nosniff"], "vary"=>["Origin"], "connection"=>["close"]}>Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels