Class: Amiando::PaymentType

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

Instance Attribute Summary

Attributes inherited from Resource

#attributes, #request, #response, #success

Class Method Summary (collapse)

Methods inherited from Resource

#==, #[], #extract_attributes_from, #id, #initialize, map, map_params, mapping, #method_missing, method_missing, #populate_create, reverse_map_params, typecasting

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::Resource

Class Method Details

+ (Object) create(event_id, type)

Create a payment type for an event

Parameters:

  • event

    id

  • string

    or symbol of the following:

    • PAYMENT_TYPE_ELV

    • PAYMENT_TYPE_CC

    • PAYMENT_TYPE_INVOICE

    • PAYMENT_TYPE_PREPAYMENT

    • PAYMENT_TYPE_PP

    • PAYMENT_TYPE_ONLOCATION

    CC = CreditCard, PP = PayPal

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



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

def self.create(event_id, type)
  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

+ (PaymentType) find(payment_type_id)

The payment type with that id

Parameters:

  • payment

    type id

Returns:



60
61
62
63
64
65
66
# File 'lib/amiando/payment_type.rb', line 60

def self.find(payment_type_id)
  object = new

  get object, "api/paymentType/#{payment_type_id}"

  object
end

+ (Result) find_all_by_event_id(event_id)

With the list of payment types for that event.

Parameters:

  • event

    id

Returns:

  • (Result)

    with the list of payment types for that event.



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

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