Class: Pin::Charges

Inherits:
Base
  • Object
show all
Defined in:
lib/pin_up/charge.rb

Overview

This class models Pin’s Charges API

Instance Attribute Summary

Attributes inherited from Base

#key

Class Method Summary collapse

Methods inherited from Base

#base_uri, build_collection_response, build_response, #initialize, make_request

Constructor Details

This class inherits a constructor from Pin::Base

Class Method Details

.all(page = nil, pagination = false) ⇒ Object

Lists all of the charges for your account args: page (Fixnum), pagination (Boolean) returns: a collection of charge objects

if pagination is passed, access the response hash with [:response] and the pagination hash with [:pagination]

pinpayments.com/docs/api/charges#get-charges



14
15
16
# File 'lib/pin_up/charge.rb', line 14

def self.all(page = nil, pagination = false)
  build_collection_response(make_request(:get, { url: "charges?page=#{page}" }), pagination)
end

.capture(token) ⇒ Object

Captures a previously authorised charge and returns its details. args: charge-token (String) returns: charge object pinpayments.com/docs/api/charges#put-charges



58
59
60
# File 'lib/pin_up/charge.rb', line 58

def self.capture(token)
  build_response(make_request(:put, { url: "charges/#{token}/capture" } ))
end

.create(options = {}) ⇒ Object

Create a charge given charge details and a card, a card_token or a customer_token args: options (Hash) returns: a charge object pinpayments.com/docs/api/charges#post-charges



50
51
52
# File 'lib/pin_up/charge.rb', line 50

def self.create(options = {})
  build_response(make_request(:post, {url: 'charges', options: options} ))
end

.find(token) ⇒ Object

Find a charge for your account given a token args: token (String) returns: a charge object pinpayments.com/docs/api/charges#get-charge



23
24
25
# File 'lib/pin_up/charge.rb', line 23

def self.find(token)
  build_response(make_request(:get, {url: "charges/#{token}" } ))
end

.search(page = nil, pagination = false, **options) ⇒ Object

Find a charge(s) for your account given a search term or set of terms args: options (Hash) returns: a collection of charge objects

if pagination is passed, access the response hash with [:response] and the pagination hash with [:pagination]

pinpayments.com/docs/api/charges#search-charges



35
36
37
38
39
40
41
42
43
# File 'lib/pin_up/charge.rb', line 35

def self.search(page = nil, pagination = false, **options)
  term = ''
  options.merge! page: page if page

  options.each do |key, option|
    term += "#{key.to_s}=#{URI.encode(option.to_s)}&"
  end
  build_collection_response(make_request(:get, {url: "charges/search?#{term}" } ), pagination)
end