Easily generate declarations for SUNAT, Peru's state tax collection entity.
Add this line to your application's Gemfile:
gem 'sunat'
And then execute:
$ bundle
Or install it yourself as:
$ gem install sunat
Prepare the SUNAT library by defining the configuration somewhere in your project as follows:
SUNAT.configure do |config| config.credentials do |c| # Regular credentials provided by SUNAT c.ruc = "123456780" c.username = "USERNAME" c.password = "PASSWORD" end
config.signature do |s|
# A company ID (Should be RUC)
s.party_id = "20100454523"
# The name of the company
s.party_name = "SOPORTE TECNOLOGICO EIRL"
# SUNAT validated certificate
s.cert_file = File.join(Dir.pwd, 'config', 'keys', 'sunat.crt')
# Password-less private key used to sign certificate
s.pk_file = File.join(Dir.pwd, 'config', 'keys', 'sunat.key')
end
# General Company details to be included in every document generated.
# Only used if no alternative is provided.
config.supplier do |s|
s.ruc = "20100454523"
s.name = "SOPORTE TECNOLOGICO EIRL"
s.address_id = "070101"
s.street = "Calle los Olivos 234"
s.city = "Lima"
s.district = "Callao"
s.country = "PE"
end
end
Set the next ENV variables: SUNAT_RUC, SUNAT_USERNAME and SUNAT_PASSWORD. They must be secret!
In Fish:
set -gx SUNAT_RUC ruc # ruc set -gx SUNAT_USERNAME username # sol user set -gx SUNAT_PASSWORD password # sol password
In Bash:
export SUNAT_RUC=ruc # ruc export SUNAT_USERNAME=username # sol user export SUNAT_PASSWORD=password # sol password
Every model can be serialized and de-serialized from JSON. This is extremely useful for storing a declaration a more readily usable form.
SUNAT requires that all clients of their system first go through a homolgation process to test all possible combinations of invoices, receipts, credit and debit notes, and summary documents.
Its an increadibly teadious process made more frustrating by the fact you probably only need a couple of standard documents for your project. Fortunately, this library makes the process a bit simpler by including the default set of test cases. Simply enter the homologation
directory, create your own config.rb
file, and call rake. All of the available yaml definitions in the cases
directory will be compiled and sent to SUNAT using your own details.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Creation of the sunay-ruby library was sponsored by Cabify.