-
-
Save luispimenta/e702b088ffa618305c0dfaa7d5c5dc0c to your computer and use it in GitHub Desktop.
create marketplace account on iugu (iugu-ruby)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using the iugu-ruby gem's fork from https://github.com/jnettome/iugu-ruby | |
module IuguConcerns | |
extend ActiveSupport::Concern | |
included do | |
def generate_iugu_subaccount! | |
return iugu_receiver_id if iugu_receiver_id | |
account = Iugu::Account.create(name: name, commission_percent: 0) | |
return fail account.errors.to_s if account.errors | |
self.iugu_receiver_id = account.account_id | |
self.iugu_live_api_token = account.live_api_token | |
self.iugu_test_api_token = account.test_api_token | |
self.iugu_user_token = account.user_token | |
self.save! | |
iugu_receiver_id | |
end | |
def send_documents_to_iugu | |
data_params = { | |
price_range: 'Mais que R$ 500,00', | |
physical_products: false, | |
business_type: 'Prestador de serviços de TI', | |
person_type: have_cnpj? ? 'Pessoa Jurídica' : 'Pessoa Física', | |
automatic_transfer: true, | |
cnpj: document_cnpj, | |
cpf: document_cpf, | |
company_name: 'razao social', | |
name: name, | |
address: addresses.first.address, | |
cep: addresses.first.zipcode, | |
city: addresses.first.city, | |
state: addresses.first.state, | |
telephone: cellphone, | |
resp_name: name, | |
resp_cpf: document_cpf, | |
bank: bank_accounts.first.bank, | |
bank_ag: bank_accounts.first.agency, | |
account_type: bank_accounts.first.account_type, | |
bank_cc: bank_accounts.first.number | |
} | |
file_params = { | |
id: nil, | |
cpf: nil, | |
activity: nil | |
} | |
params = { data: data_params, file: file_params } | |
verification = Iugu::Account.verify(params, iugu_receiver_id, iugu_user_token) | |
# Iugu::RequestWithErrors: Iugu::RequestWithErrors | |
# {"account"=>["já existe uma verificação pendente para essa conta."]} | |
end | |
def self.configure_iugu | |
config_file = YAML.load_file("#{Rails.root.to_s}/config/iugu_settings.yml") | |
config = JSON.parse(config_file.to_json, object_class: OpenStruct) | |
config | |
data_params = { | |
commission_percent: config.commission_percent, | |
auto_withdraw: config.auto_withdraw, | |
credit_card: { | |
active: config.credit_card.active, | |
soft_descriptor: config.credit_card.soft_descriptor, | |
two_step_transaction: config.credit_card.two_step_transaction | |
}, | |
bank_slip: { | |
active: config.bank_slip.active | |
}, | |
id: iugu_receiver_id | |
} | |
Iugu::Account.configuration(data_params) | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commission_percent: 0 | |
auto_withdraw: true | |
fines: true | |
per_day_interest: true | |
late_payment_fine: 2 | |
auto_advance: false | |
auto_advance_type: false | |
bank_slip: | |
active: true | |
extra_due: 1 | |
reprint_extra_due: 1 | |
credit_card: | |
active: true | |
soft_descriptor: NomeDaEmpresa | |
# Descrição que apareça na Fatura do Cartão do Cliente (Máx: 12 Caractéres) | |
installments: true | |
installments_pass_interest: true | |
max_installments: 12 | |
max_installments_without_interest: 2 | |
two_step_transaction: false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment