Class: Vivapayments::Order
- Inherits:
-
Object
- Object
- Vivapayments::Order
- Defined in:
- lib/vivapayments/order.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#id ⇒ Object
Returns the value of attribute id.
-
#params ⇒ Object
Returns the value of attribute params.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
-
#initialize(params = {}) ⇒ Order
constructor
A new instance of Order.
- #redirect_url ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Order
Returns a new instance of Order.
6 7 8 9 10 11 |
# File 'lib/vivapayments/order.rb', line 6 def initialize(params={}) @params = params @connection = Faraday.new(:url => Vivapayments.configuration.api_url) connection.basic_auth(Vivapayments.configuration.merchant_id, Vivapayments.configuration.api_key) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
3 4 5 |
# File 'lib/vivapayments/order.rb', line 3 def connection @connection end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/vivapayments/order.rb', line 3 def id @id end |
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/vivapayments/order.rb', line 4 def params @params end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/vivapayments/order.rb', line 3 def url @url end |
Instance Method Details
#create ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vivapayments/order.rb', line 17 def create raise ArgumentError, "`Amount` param is required." unless params.keys.map(&:to_sym).include?(:Amount) valid_params? content = connection.post("orders", params) if content.status == 200 && JSON.parse(content.body)["ErrorCode"] == 0 && JSON.parse(content.body)["OrderCode"] @id = JSON.parse(content.body)["OrderCode"] else raise "Status: #{content.status} - Message: #{content.body}" end end |
#delete ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vivapayments/order.rb', line 30 def delete id_set? content = connection.delete("orders/#{self.id}") if content.status == 200 @id = nil return content else raise "#{content.status} : #{JSON.parse(content.body)["Message"]}" end end |
#redirect_url ⇒ Object
42 43 44 45 |
# File 'lib/vivapayments/order.rb', line 42 def redirect_url id_set? [Vivapayments.configuration.redirect_url, "?ref=#{self.id}"].join end |