Module: Culqi::Post

Included in:
Card, Charge, Customer, Order, Plan, Refund, Subscription, Token, Yape
Defined in:
lib/operation/post.rb

Instance Method Summary collapse

Instance Method Details

#create(params = {}, rsa_key = '', rsa_id = '') ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/operation/post.rb', line 18

def create(params={}, rsa_key='', rsa_id='')
  key = ''
  puts params
  error = verifyClassValidation(@url, params)
  if error
    return error
  end

  if @url.include? 'token'
    if(rsa_key != '')
      params = Encrypt.encrypt_with_aes_rsa(params, rsa_key, true)
    end
    key = Culqi.public_key 
    response, statuscode = Culqi.connect(@url, key, params, 'post', Culqi::READ_TIMEOUT, true, rsa_id)
    return response, statuscode
  else
    key = Culqi.secret_key
    response, statuscode = Culqi.connect(@url, key, params, 'post', Culqi::READ_TIMEOUT, false, '')
    return response, statuscode
  end
  
end

#initializeObject



14
15
16
# File 'lib/operation/post.rb', line 14

def initialize
  @url = ''
end

#verifyClassValidation(url = '', params) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/operation/post.rb', line 41

def verifyClassValidation(url='', params)
  begin
    if @url.include? 'token'
      TokenValidation.create(params)
    end

    if @url.include? 'charge'
      ChargeValidation.create(params)
    end
    
    if @url.include? 'card'
      CardValidation.create(params)
    end
    
    if @url.include? 'customer'
      CustomerValidation.create(params)
    end
    
    if @url.include? 'refund'
      RefundValidation.create(params)
    end
    
    if @url.include? 'plan'
      PlanValidation.create(params)
    end
    
    if @url.include? 'subscription'
      SubscriptionValidation.create(params)
    end
    
    if @url.include? 'order'
      OrderValidation.create(params)
    end
  rescue CustomException => e
    return e.message
  end
end