Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/undr/cloud_payments
CloudPayments ruby client
https://github.com/undr/cloud_payments
Last synced: about 1 month ago
JSON representation
CloudPayments ruby client
- Host: GitHub
- URL: https://github.com/undr/cloud_payments
- Owner: undr
- License: mit
- Created: 2014-12-25T13:27:23.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2023-09-19T08:37:32.000Z (over 1 year ago)
- Last Synced: 2024-10-31T13:15:04.032Z (about 2 months ago)
- Language: Ruby
- Homepage: http://cloudpayments.eu/Docs/Integration
- Size: 70.3 KB
- Stars: 19
- Watchers: 3
- Forks: 24
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Attention!!!
This repository is outdated. The main repository is https://github.com/platmart/cloud_payments.
# CloudPayments
CloudPayments ruby client (http://cloudpayments.eu/Docs/Integration)
[![Build Status](https://travis-ci.org/undr/cloud_payments.svg)](https://travis-ci.org/undr/cloud_payments)
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'cloud_payments'
```And then execute:
```
$ bundle
```Or install it yourself as:
```
$ gem install cloud_payments
```## Usage
### Configuration
```ruby
CloudPayments.configure do |c|
c.host = 'http://localhost:3000' # By default, it is https://api.cloudpayments.ru
c.public_key = ''
c.secret_key = ''
c.log = false # By default. it is true
c.logger = Logger.new('/dev/null') # By default, it writes logs to stdout
c.raise_banking_errors = true # By default, it is not raising banking errors
end
```### Test method
```ruby
CloudPayments.client.ping
# => true
```### Cryptogram-based payments
```ruby
transaction = CloudPayments.client.payments.cards.charge(
amount: 120,
currency: 'RUB',
ip_address: request.remote_ip,
name: params[:name],
card_cryptogram_packet: params[:card_cryptogram_packet]
)
# => {:metadata=>nil,
# :id=>12345,
# :amount=>120,
# :currency=>"RUB",
# :currency_code=>0,
# :invoice_id=>"1234567",
# :account_id=>"user_x",
# :email=>nil,
# :description=>"Payment for goods on example.com",
# :created_at=>#,
# :authorized_at=>#,
# :confirmed_at=>#,
# :auth_code=>"123456",
# :test_mode=>true,
# :ip_address=>"195.91.194.13",
# :ip_country=>"RU",
# :ip_city=>"Ufa",
# :ip_region=>"Bashkortostan Republic",
# :ip_district=>"Volga Federal District",
# :ip_lat=>54.7355,
# :ip_lng=>55.991982,
# :card_first_six=>"411111",
# :card_last_four=>"1111",
# :card_type=>"Visa",
# :card_type_code=>0,
# :issuer=>"Sberbank of Russia",
# :issuer_bank_country=>"RU",
# :status=>"Completed",
# :status_code=>3,
# :reason=>"Approved",
# :reason_code=>0,
# :card_holder_message=>"Payment successful",
# :name=>"CARDHOLDER NAME",
# :token=>"a4e67841-abb0-42de-a364-d1d8f9f4b3c0"}
transaction.class
# => CloudPayments::Transaction
transaction.token
# => "a4e67841-abb0-42de-a364-d1d8f9f4b3c0"
```## Webhooks
```ruby
if CloudPayments.webhooks.data_valid?(payload, hmac_token)
event = CloudPayments.webhooks.on_recurrent(payload)
# or
event = CloudPayments.webhooks.on_pay(payload)
# or
event = CloudPayments.webhooks.on_fail(payload)
end
```with capturing of an exception
```ruby
rescue_from CloudPayments::Webhooks::HMACError, :handle_hmac_errorbefore_action -> { CloudPayments.webhooks.validate_data!(payload, hmac_token) }
def pay
event = CloudPayments.webhooks.on_pay(payload)
# ...
enddef fail
event = CloudPayments.webhooks.on_fail(payload)
# ...
enddef recurrent
event = CloudPayments.webhooks.on_recurrent(payload)
# ...
end
```## Contributing
1. Fork it ( https://github.com/undr/cloud_payments/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request