Gem to use Braspag gateway in his REST version.
Add this line to your application's Gemfile:
gem 'braspag-rest'
And then execute:
$ bundle
Or install it yourself as:
$ gem install braspag-rest
The gem looks for a default config/braspag-rest.yml
configuration file, with
environment (RACK_ENV
or RAILS_ENV
) settings for the Braspag API.
# config/braspag-rest.yml
development:
url: 'https://apisandbox.braspag.com.br'
query_url: 'https://apiquerysandbox.braspag.com.br'
merchant_id: 'Your MerchantId here'
merchant_key: 'Your MerchantKey here'
If you want to use a different file or manually set which environment should be
used, you can create an initializer file and use the BraspagRest.config
method
to set your config.
# config/initializers/braspag-rest.rb
BraspagRest.config do |config|
config.config_file_path = 'config/path/here.yml'
config.enviroment = 'production'
end
You can use ERB blocks to interpolate values from your environment variables into the configuration if you are using something like dotenv to handle configuration values that shouldn't be present in the source code.
# config/braspag-rest.yml
development:
url: 'https://apisandbox.braspag.com.br'
query_url: 'https://apiquerysandbox.braspag.com.br'
merchant_id: 'Your MerchantId here'
merchant_key: 'Your MerchantKey here'
production:
url: <%= ENV['BRASPAG_URL'] %>
query_url: <%= ENV['BRASPAG_QUERY_URL'] %>
merchant_id: <%= ENV['BRASPAG_MERCHANT_ID'] %>
merchant_key: <%= ENV['BRASPAG_MERCHANT_KEY'] %>
sale = BraspagRest::Sale.new(
order_id: '123456',
request_id: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
customer: {
name: 'Comprador Teste'
},
payment: {
type: 'CreditCard',
amount: 15700,
provider: 'Simulado',
installments: 1,
credit_card: {
number: '0000000000000001',
holder: 'Teste Holder',
expiration_date: '12/2021',
security_code: '123',
brand: 'Visa'
}
}
)
sale.save
And to create a protected credit card, you should set the credit card saved as true:
credit_card = BraspagRest::CreditCard.new
credit_card.number = '0000000000000001'
credit_card.holder = 'Teste Holder'
credit_card.expiration_date = '12/2021'
credit_card.security_code = '123'
credit_card.brand = 'Visa'
credit_card.saved = true
sale = BraspagRest::Sale.find('REQUEST_ID', 'PAYMENT_ID')
sale.customer.name
=> Maria
sale = BraspagRest::Sale.find('REQUEST_ID', 'PAYMENT_ID')
sale.cancel
sale = BraspagRest::Sale.find('REQUEST_ID', 'PAYMENT_ID')
sale.capture
After checking out the repo, run bin/setup
to install dependencies. Then, run rake rspec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/Dinda-com-br/braspag-rest.
The gem is available as open source under the terms of the MIT License.