Class: Amiando::PaymentType

Inherits:
Resource show all
Defined in:
lib/amiando/payment_type.rb

Instance Attribute Summary

Attributes inherited from Resource

#request, #response, #success

Class Method Summary collapse

Methods inherited from Resource

#==, #extract_attributes_from, #initialize, method_missing, #populate_create

Methods included from Attributes

#[], #id, included, #method_missing, #respond_to?, #type

Methods included from Autorun

included

Constructor Details

This class inherits a constructor from Amiando::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Amiando::Attributes

Class Method Details

.create(event_id, type) ⇒ Object

Create a payment type for an event

Parameters:

  • event_id
  • type

    string or symbol of the following:

    • PAYMENT_TYPE_ELV (debit card)

    • PAYMENT_TYPE_CC (credit card)

    • PAYMENT_TYPE_INVOICE

    • PAYMENT_TYPE_PREPAYMENT

    • PAYMENT_TYPE_PP (PayPal)

    • PAYMENT_TYPE_ONLOCATION

    It will also accept :cc, :invoice, etc and convert them appropriately



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/amiando/payment_type.rb', line 18

def self.create(event_id, type)
  type = type[:type] if type.is_a?(Hash)

  unless type =~ /^payment_type_\w+/i
    type = "payment_type_#{type}"
  end

  object = Result.new do |response_body, result|
    result.errors = response_body['errors']
    response_body['id'] || false
  end

  post object, "api/event/#{event_id}/paymentType/create", :params => { :type => type.upcase }

  object
end

.find(payment_type_id) ⇒ PaymentType

Find a Payment Type

Parameters:

  • payment_type_id

Returns:



64
65
66
67
68
69
# File 'lib/amiando/payment_type.rb', line 64

def self.find(payment_type_id)
  object = new
  get object, "api/paymentType/#{payment_type_id}"

  object
end

.find_all_by_event_id(event_id) ⇒ Result

Find all Payment Types of an event

Parameters:

  • event_id

Returns:

  • (Result)

    with the list of payment types for that event.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/amiando/payment_type.rb', line 41

def self.find_all_by_event_id(event_id)
  object = Result.new do |response_body, result|
    if response_body['success']
      response_body['results']['paymentTypes'].map do |payment_type|
        new(payment_type)
      end
    else
      result.errors = response_body['errors']
      false
    end
  end

  get object, "api/event/#{event_id}/paymentTypes"

  object
end

.update(payment_type_id, attributes) ⇒ Boolean

Update a payment type

Parameters:

  • payment_type_id
  • attributes (Hash)

    attributes to be updated

Returns:

  • (Boolean)

    result of the operation



78
79
80
81
82
83
# File 'lib/amiando/payment_type.rb', line 78

def self.update(payment_type_id, attributes)
  object = Boolean.new('success')
  post object, "api/paymentType/#{payment_type_id}", :params => attributes

  object
end