项目作者: nukturnal

项目描述 :
Bygpay Payment Gateway Ruby SDK. Irrespective of your BygPay private installation, this wrapper should work flawlessly with it.
高级语言: Ruby
项目地址: git://github.com/nukturnal/bygpay_ruby.git
创建时间: 2017-05-16T21:41:29Z
项目社区:https://github.com/nukturnal/bygpay_ruby

开源协议:MIT License

下载


Gem Version Code Climate FOSSA Status Issue Count codebeat badge Codacy Badge Build Status

Bygpay Ruby SDK

Ruby wrapper around Bygpay Payment Gateway. Bygpay is a self hosted payment processing gateway which gives merchants / business better flexiblity and control when it comes to payment processing.

Installation

Add this line to your application’s Gemfile:

  1. gem 'bygpay'

And then execute:

  1. $ bundle

Or install it yourself as:

  1. $ gem install bygpay

Usage

Setup few configs before use. If you using Rails you can put this in your initializers directory eg initializers/bygpay.rb

  1. Bygpay.configure do |config|
  2. config.base_url = 'http://gateway.bygpay-server.com/api'
  3. config.api_key = '8b4e5a9c-6eba-4cdd-94b6-65e6b514'
  4. # Optional Configurations (Every code below this line)
  5. # (In case you've changed routes in your Bygpay Installation)
  6. config.deposit_mobile_path = '/deposits/mobile'
  7. config.deposit_card_path = '/deposits/card'
  8. config.deposit_status_overide_path = '/deposits/status-overide'
  9. config.deposit_status_path = '/deposits'
  10. config.withdraw_mobile_path = '/withdrawals/mobile'
  11. config.withdraw_status_overide_path = '/withdrawals/status-overide'
  12. config.withdraw_status_path = '/withdrawals'
  13. end

Transaction Statuses

Bygpay gateway uses four types of status messages to mark transactions.

  • accepted A transaction is marked as accepted when it’s initially receives the request from a client
  • pending A transaction is marked a pending when the Gateway begins processing
  • success A final status message success is used when processing completes successfully
  • fail A final status message `fail’ is used when the processing completes unsuccessfully

Deposit Requests

Mobile Money

Currently SDK supports MTN, AIRTEL, TIGO, VODAFONE, you may refer to your Bygpay Gateway documentations for more provider options.

Mobile Money transactions are not onetime requests because of their inherent nature, need to rely on checking the transaction status or callback POST from Bygpay Gateway to verify the status of the transaction.

  1. # Making a Mobile Money Deposit Request
  2. deposit = Bygpay::Deposit::Mobile.new
  3. mobile_payload = {
  4. walletno: '0244124550',
  5. provider: 'MTN',
  6. currency: 'USD', # optional
  7. token: '23571', # Optional (Only required for Vodafone Payments)
  8. extrnx_code: nil, # optional
  9. meta_data: { name: "Alfred Rowe" } # pass an optional arbitary meta_data which will be returned later
  10. }
  11. result = deposit.charge(1.99, mobile_payload)
  12. if result
  13. puts deposit.uuid
  14. puts deposit.status # accepted, :pending, :fail, :success
  15. puts deposit.transaction_id
  16. else
  17. puts deposit.response_text
  18. puts deposit.status
  19. end

Debit/Credit Card

Supports VISA, MasterCard and any other cards based on the processors available on Bygpay Gateway. This is a onetime transaction and immediate response is the final status of the transaction. However transaction status request is still available

  1. # Making a Mobile Money Deposit Request
  2. # Please note that some of the optional fields might be required base on
  3. # which processors the BygPay Gateway is using.
  4. deposit = Bygpay::Deposit::Card.new
  5. card_data = {
  6. card_number: '4111111111111111',
  7. amount: 0.10,
  8. expiry_month: 6,
  9. expiry_year: 2017,
  10. cvv: 123,
  11. country: 'GH', # Optional country ISO code
  12. currency: 'USD', # Optional currency ISO code
  13. card_name: 'Gifty Cobbinah', # Optional Card Hold Name
  14. meta_data: { store: "Gifty's Thrifts" } # pass an optional arbitary meta_data which will be returned later
  15. }
  16. result = deposit.charge(1.99, card_data)
  17. if result
  18. puts deposit.uuid
  19. puts deposit.status # accepted, :pending, :fail, :success
  20. puts deposit.transaction_id
  21. else
  22. puts deposit.response_text
  23. puts deposit.status
  24. end

Query Transaction status

  1. # Checking transaction status
  2. # You always need the transaction UUID to get status response
  3. deposit = Bygpay::Deposits.new
  4. result = deposit.transaction_status('e81216aa-9ef7-4c5c-aed0-6e5ff1fe')
  5. if result
  6. puts deposit.uuid
  7. puts deposit.status # accepted, :pending, :fail, :success
  8. puts deposit.transaction_id
  9. puts deposit.meta_data # retrieve meta_data
  10. else
  11. puts deposit.response_text
  12. puts deposit.status
  13. end

Withdraw Requests

Mobile Money

Currently SDK supports MTN, AIRTEL, TIGO, VODAFONE, you may refer to your Bygpay Gateway documentations for more provider options.

  1. # Making a Mobile Money Withdrawal Request
  2. withdraw = Bygpay::Withdraw::Mobile.new
  3. result = withdraw.sendmoney(1.99,{walletno: '0244124550', provider: 'MTN'})
  4. if result
  5. puts withdraw.uuid
  6. puts withdraw.status # accepted, :pending, :fail, :success
  7. puts withdraw.transaction_id
  8. else
  9. puts withdraw.response_text
  10. puts withdraw.status
  11. end

Query Transaction status

  1. # Checking transaction status
  2. # You always need the transaction UUID to get status response
  3. withdraw = Bygpay::Withdrawals.new
  4. result = withdraw.transaction_status('e81216aa-9ef7-4c5c-aed0-6e5ff1fe')
  5. if result
  6. puts withdraw.uuid
  7. puts withdraw.status # accepted, :pending, :fail, :success
  8. puts withdraw.transaction_id
  9. else
  10. puts withdraw.response_text
  11. puts withdraw.status
  12. end

Development

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 tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/nukturnal/bygpay_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.