Class: Io::Flow::V0::Clients::Payments

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Payments

Returns a new instance of Payments.



3056
3057
3058
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3056

def initialize(client)
  @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client)
end

Instance Method Details

#delete_by_id(organization, id) ⇒ Object

Deletes the specified payment



3107
3108
3109
3110
3111
3112
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3107

def delete_by_id(organization, id)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/#{CGI.escape(organization)}/payments/#{CGI.escape(id)}").delete
  nil
end

#get(organization, incoming = {}) ⇒ Object



3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3060

def get(organization, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
    :payment_method => (x = opts.delete(:payment_method); x.nil? ? nil : HttpClient::Preconditions.assert_class('payment_method', x, String)),
    :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
    :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
    :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "-created_at" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/payments").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::Payment.from_json(x) }
end

#get_by_id(organization, id) ⇒ Object

Returns information about a specific payment.



3099
3100
3101
3102
3103
3104
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3099

def get_by_id(organization, id)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/#{CGI.escape(organization)}/payments/#{CGI.escape(id)}").get
  ::Io::Flow::V0::Models::Payment.from_json(r)
end

#get_versions(organization, incoming = {}) ⇒ Object

Provides visibility into recent changes of each object, including deletion



3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3084

def get_versions(organization, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, Integer) }),
    :payment_id => (x = opts.delete(:payment_id); x.nil? ? nil : HttpClient::Preconditions.assert_class('payment_id', x, Array).map { |v| HttpClient::Preconditions.assert_class('payment_id', v, String) }),
    :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
    :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
    :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "journal_timestamp" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/payments/versions").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::PaymentVersion.new(x) }
end

#post(organization, payment_form) ⇒ Object

Create a new payment. Note that when using JSONP to submit a payment, you do not need to authenticate.



3076
3077
3078
3079
3080
3081
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 3076

def post(organization, payment_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  (x = payment_form; x.is_a?(::Io::Flow::V0::Models::PaymentForm) ? x : ::Io::Flow::V0::Models::PaymentForm.from_json(x))
  r = @client.request("/#{CGI.escape(organization)}/payments").with_json(payment_form.to_json).post
  ::Io::Flow::V0::Models::Payment.from_json(r)
end