Class: Caboose::PaymentProcessors::Payscape

Inherits:
Base
  • Object
show all
Defined in:
app/models/caboose/payment_processors/payscape.rb

Class Method Summary collapse

Class Method Details

.api(root, body, test = false) ⇒ Object



4
5
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
32
# File 'app/models/caboose/payment_processors/payscape.rb', line 4

def self.api(root, body, test=false)
  
  # Determine if transaction should be a test
  body['api-key'] = if test or Rails.env == 'development'
    '2F822Rw39fx762MaV7Yy86jXGTC7sCDy'
  else
    Caboose::api_key
  end
  
  ap "API key used: #{body['api-key']}"
  # ap "AUTH USERNAME: #{Caboose::payscape_username}"
  # ap "AUTH PASSWORD: #{Caboose::payscape_password}"
  
  uri                  = URI.parse('https://secure.payscapegateway.com/api/v2/three-step')
  http                 = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl         = true
  request              = Net::HTTP::Post.new(uri.path)
  request.content_type = 'text/xml'
  request.body         = body.to_xml({:root => root})
  xml_response         = http.request(request)
  document             = REXML::Document.new(xml_response.body.to_s)
  response             = Hash.new
  
  document.root.elements.each { |element| response[element.name] = element.text }
  
  ap response
  
  return response
end

.authorize(order, params) ⇒ Object



70
71
72
73
74
# File 'app/models/caboose/payment_processors/payscape.rb', line 70

def self.authorize(order, params)
  response = self.api 'complete-action', { 'token-id' => params['token-id'] }, order.test?
  order.update_attribute(:transaction_id, params['transaction-id']) if params['transaction-id']
  return response['result-code'].to_i == 100
end

.authorized?(order) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/caboose/payment_processors/payscape.rb', line 56

def self.authorized?(order)
  uri              = URI.parse("https://secure.payscapegateway.com/api/query.php?username=#{Caboose::payscape_username}&password=#{Caboose::payscape_password}&transaction_id=#{order.transaction_id}")
  http             = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl     = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  request          = Net::HTTP::Get.new(uri.request_uri)
  response         = http.request(request)
  document         = Nokogiri::XML response.body
  actions          = Hash.new
  
  document.xpath('//action').each { |action| actions[action.xpath('action_type').text] = action.xpath('success').text == '1' }
  return actions['auth']
end

.capture(order) ⇒ Object



81
82
83
84
# File 'app/models/caboose/payment_processors/payscape.rb', line 81

def self.capture(order)
  response = self.api 'capture', { 'transaction-id' => order.transaction_id }, order.test?
  return response['result-code'].to_i == 100
end

.form_url(order) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/caboose/payment_processors/payscape.rb', line 34

def self.form_url(order)
  response = self.api 'auth', {
    'redirect-url' => "#{Caboose::store_url}/checkout/relay/#{order.id}",
    'amount'       => order.total.to_s,
    'billing'      => {
      'first-name' => order.billing_address.first_name,
      'last-name'  => order.billing_address.last_name,
      'address1'   => order.billing_address.address1,
      'address2'   => order.billing_address.address2,
      'city'       => order.billing_address.city,
      'state'      => order.billing_address.state,
      'postal'     => order.billing_address.zip
    }
  }, order.test?
  
  order.transaction_id = response['transaction-id']
  order.transaction_service = 'payscape'
  order.save
  
  return response['form-url']
end

.refund(order) ⇒ Object



86
87
88
89
90
91
92
93
# File 'app/models/caboose/payment_processors/payscape.rb', line 86

def self.refund(order)
  response = self.api 'refund', {
    'transaction-id' => order.transaction_id,
    'amount'         => order.total.to_s
  }, order.test?
  
  return response['result-code'].to_i == 100
end

.void(order) ⇒ Object



76
77
78
79
# File 'app/models/caboose/payment_processors/payscape.rb', line 76

def self.void(order)
  response = self.api 'void', { 'transaction-id' => order.transaction_id }, order.test?
  return response['result-code'].to_i == 100
end