Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Ruby::Daraja
is a Ruby wrapper for the Safaricom Daraja API. It provides a simple interface to the API endpoints and allows for smooth setup in Ruby on Rails
applications or any other Ruby application.
IMPORTANT: This gem is not yet released to rubygems.org. The instructions below are for when the gem is released.
Install the gem and add to the application's Gemfile by executing:
$ bundle add ruby-daraja
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install ruby-daraja
With ruby-daraja
you can easily make requests to the Safaricom Daraja API. The DSL is simple and easy to use. The DSL is divided into two parts:
In order to get started with the DSL, you need to configure the gem with your credentials.
There are two ways to get started with ruby-daraja
:
This is a quick-start mode for the gem. It is meant to get you up and running quickly. It is not recommended for production
applications. To get started with the gem in development
mode, follow the steps below:
# mandatory variables
CONSUMER_KEY='daraja consumer key here'
CONSUMER_SECRET='daraja consumer secret here'
# optional variables
VALIDATION_URL='C2B Validation URL'
CONFIRMATION_URL='C2B Confirmation URL'
IS_SANDBOX='boolean indicating whether you are in sandbox or production'
SHORT_CODE='daraja (paybill /till number) short code here'
B2C_RESULT_URL='B2C Result URL'
INITIATOR_NAME='B2C initiator name'
INITIATOR_PASSWORD='B2C initiator password'
SSL_CERTIFICATE='path to SSL certificate'
BALANCE_RESULT_URL='Balance Result URL'
Daraja::AppConfig
instance. This instance is used to configure the application. It is created as follows:
require 'ruby-daraja'
app_config = Daraja::Default.new._app_config
TODO: Add instructions for production mode
require 'ruby-daraja'
app_config = `Daraja::AppConfig instance here`
responses = app_config.register_urls # array of JSON responses from Safaricom Daraja API
Create a new Daraja::PayBill
instance.
require 'ruby-daraja'
app_config = `Daraja::AppConfig instance here`
paybill_client = Daraja::PayBill.new(config: app_config, pass_key: 'pass key here')
Initiate Payment Request (STK Push) for MPESA PayBill
.
response = paybill_client.initiate_stk_push(
amount: 1,
phone_number: '2547xxxxxxxx',
account_reference: 'account reference',
transaction_description: 'transaction description'
) # JSON response from Safaricom Daraja API
Initiate B2C Request for MPESA PayBill
response = paybill_client.initiate_b2c(
amount: 1,
phone_number: '2547xxxxxxxx',
type: 0, # 0 for business, 1 for salary, 2 for promotion
remarks: 'remarks',
occasion: 'occasion'
) # JSON response from Safaricom Daraja API
Check balance for MPESA PayBill
response = paybill_client.initiate_balance_request(
remarks: 'remarks'
) # JSON response from Safaricom Daraja API
Create a new Daraja::BuyGoods
instance.
require 'ruby-daraja'
app_config = `Daraja::AppConfig instance here`
till_client = Daraja::BuyGoods.new(config: app_config, pass_key: 'pass key here')
Initiate Payment Request (STK Push) for MPESA Buy Goods And Services
.
response = till_client.initiate_stk_push(
amount: 1,
phone_number: '2547xxxxxxxx',
account_reference: 'account reference',
transaction_description: 'transaction description'
) # JSON response from Safaricom Daraja API
Initiate B2C Request for MPESA Buy Goods And Services
response = till_client.initiate_b2c(
amount: 1,
phone_number: '2547xxxxxxxx',
type: 0, # 0 for business, 1 for salary, 2 for promotion
remarks: 'remarks',
occasion: 'occasion'
) # JSON response from Safaricom Daraja API
Check balance for MPESA Buy Goods And Services
response = till_client.initiate_balance_request(
remarks: 'remarks'
) # JSON response from Safaricom Daraja API
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
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 the created tag, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/otsembo/ruby-daraja. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
You can also join the conversation at our discussions page.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Ruby::Daraja project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that ruby-daraja demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.