Class: Easypay::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/easypay/client.rb

Constant Summary collapse

EASYPAY_SERVICE_URL =
Rails.env.production? ? "www.easypay.pt" : "test.easypay.pt"

Instance Method Summary collapse

Constructor Details

#initialize(*params) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/easypay/client.rb', line 6

def initialize *params
  if params.first.is_a?(Hash)
    hash_options = params.first
    @easypay_cin = hash_options[:easypay_cin] || Easypay::Engine.config.cin
    @easypay_user = hash_options[:easypay_user] || Easypay::Engine.config.user
    @easypay_entity = hash_options[:easypay_entity] || Easypay::Engine.config.entity
    @easypay_code = hash_options[:easypay_code] || Easypay::Engine.config.code
    @easypay_ref_type = hash_options[:easypay_ref_type] || "auto"
    @easypay_country = hash_options[:easypay_country] || "PT"
  elsif params.first
    puts "* warning: the method Easypay::Client.new(ep_cin, ep_user, ep_entity) is deprecated, use Easypay::Client.new(:easypay_cin => 'cin', :easypay_user => 'user', :easypay_entity => 'entity')"
    @easypay_cin = params.shift || Easypay::Engine.config.cin
    @easypay_user = params.shift || Easypay::Engine.config.user
    @easypay_entity = params.shift || Easypay::Engine.config.entity
    @easypay_code = params.shift || Easypay::Engine.config.code
    @easypay_ref_type = params.shift || "auto"
    @easypay_country = params.shift || "PT"
  else
    @easypay_cin = Easypay::Engine.config.cin
    @easypay_user = Easypay::Engine.config.user
    @easypay_entity = Easypay::Engine.config.entity
    @easypay_code = Easypay::Engine.config.code
    @easypay_ref_type = "auto"
    @easypay_country = "PT"
  end
end

Instance Method Details

#create_reference(object) ⇒ Object

API methods



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/easypay/client.rb', line 35

def create_reference(object)
  get "01BG",
    :t_key => object.ep_key, 
    :t_value => object.ep_value,
    :ep_language => object.ep_language.upcase,
    :o_name =>  object.o_name.nil? ? "" : URI.escape(object.o_name),
    :o_description => object.o_description.nil? ? "" : URI.escape(object.o_description),
    :o_obs => object.o_obs.nil? ? "" : URI.escape(object.o_obs),
    :o_mobile => object.o_mobile.nil? ? "" : URI.escape(object.o_mobile),
    :o_email => object.o_email.nil? ? "" : URI.escape(object.o_email)
    # :ep_rec => "yes", # Reccurrence stuff
    # :ep_rec_freq => recurrence,
    # :ep_rec_url => url_notification_cc
end

#get_payment_detail(ep_key, ep_doc) ⇒ Object



50
51
52
53
54
# File 'lib/easypay/client.rb', line 50

def get_payment_detail(ep_key, ep_doc)
  get "03AG",
    :ep_key => ep_key, 
    :ep_doc => ep_doc
end

#get_payment_list(type = "last", detail = 10, format = "xml") ⇒ Object



56
57
58
59
60
61
# File 'lib/easypay/client.rb', line 56

def get_payment_list(type="last", detail=10, format="xml")
  get "040BG1",
      :o_list_type => type,
      :o_ini => detail,
      :type => format
end

#request_payment(entity, reference, value, identifier) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/easypay/client.rb', line 63

def request_payment(entity, reference, value, identifier)
  get "05AG",
      :e => entity,
      :r => reference,
      :v => value,
      :k => identifier
      # :ep_k1 => identifier,
      # :rec => "yes",
      # :ep_key_rec => uid
end