Module: Versapay
- Defined in:
- lib/versapay.rb,
lib/versapay/version.rb,
lib/versapay/fund_sources.rb,
lib/versapay/transactions.rb,
lib/versapay/rails_helpers.rb,
lib/versapay/debit_agreement.rb,
lib/versapay/webhooks.rb
Defined Under Namespace
Modules: Helpers Classes: DebitAgreement, DuplicateTransaction, FundSources, InvalidInput, InvalidWebhookSignature, NotFound, Transactions, Unprocessable, VersapayError, WebhookSignature
Constant Summary collapse
- VERSION =
"0.1.5"
- @@token =
"PleaseOverrideYourToken"
- @@key =
"PleaseOverriedYourKey"
Class Attribute Summary collapse
-
.key ⇒ Object
Returns the value of attribute key.
-
.token ⇒ Object
Returns the value of attribute token.
Class Method Summary collapse
Class Attribute Details
.key ⇒ Object
Returns the value of attribute key.
21 22 23 |
# File 'lib/versapay.rb', line 21 def key @key end |
.token ⇒ Object
Returns the value of attribute token.
21 22 23 |
# File 'lib/versapay.rb', line 21 def token @token end |
Class Method Details
.make_request(method, url, args = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/versapay.rb', line 32 def self.make_request(method, url, args = {}) if method == :get then RestClient.get("https://#{Versapay.token}:#{Versapay.key}@" + Versapay::site + url, {:params => args}) do |response, request, result, &block| case response.code when 200 return JSON.parse(response) when 422 raise Versapay::Unprocessable, response when 500 raise Versapay::NotFound, response end end end if method == :post then RestClient.post("https://#{Versapay.token}:#{Versapay.key}@" + Versapay::site + url, args.to_json, :content_type => :json, :accept => :json) do |response, request, result, &block| case response.code when 200,201 return JSON.parse(response) when 412 result = JSON.parse(response) if result.key? "unique_reference" raise Versapay::DuplicateTransaction, response else raise Versapay::InvalidInput, response end when 422 raise Versapay::Unprocessable, response when 500 raise Versapay::NotFound, response end end end end |
.site ⇒ Object
27 28 29 |
# File 'lib/versapay.rb', line 27 def self.site Rails.env.production? ? "secure.versapay.com" : "demo.versapay.com" end |