Class: Versapay::Client
- Inherits:
-
Object
- Object
- Versapay::Client
- Defined in:
- lib/versapay/client.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(user, password, environment = 'secure') ⇒ Client
constructor
A new instance of Client.
- #send(amount, email, message = nil) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(user, password, environment = 'secure') ⇒ Client
Returns a new instance of Client.
6 7 8 9 10 |
# File 'lib/versapay/client.rb', line 6 def initialize(user, password, environment='secure') @user = user @password = password @environment = environment end |
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
12 13 14 |
# File 'lib/versapay/client.rb', line 12 def environment @environment end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
12 13 14 |
# File 'lib/versapay/client.rb', line 12 def password @password end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
12 13 14 |
# File 'lib/versapay/client.rb', line 12 def user @user end |
Instance Method Details
#send(amount, email, message = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/versapay/client.rb', line 18 def send(amount, email, =nil) amount_in_cents = (amount.to_f * 100).to_i payload = { transaction_type: 'send', email: email, amount_in_cents: amount_in_cents, message: }.to_json response_hash = nil RestClient.post(url, payload, content_type: :json, accept: :json) do |response, request, result, &block| unless response.code == 201 raise "Error: #{JSON.parse(response.body).inspect}" end response_hash = JSON.parse(response.body) end response_hash end |
#url ⇒ Object
14 15 16 |
# File 'lib/versapay/client.rb', line 14 def url "https://#{user}:#{password}@#{environment}.versapay.com/api/transactions.json" end |