Class: Caboose::Authnet

Inherits:
Object
  • Object
show all
Defined in:
app/models/caboose/authnet.rb

Class Method Summary collapse

Class Method Details

.create_customer_profile(store_config, user) ⇒ Object

Repconnex api_login_id: 3a79FjaHV api_transaction_key: 3K4v7n423KvA5R9P



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/caboose/authnet.rb', line 21

def self.create_customer_profile(store_config, user)      
  params = {
    "createCustomerProfileRequest" => {
      "merchantAuthentication" => {
        "name"           => '9qR2qa4ZWn', #store_config.pp_username,
        "transactionKey" => '386TLme2j8yp4BQy', #store_config.pp_password
      },
      "profile" => {
        "merchantCustomerId" => user.id,
        "description"        => "#{user.first_name} #{user.last_name}",
        "email"              => user.email            
      }          
    }
  }            
  resp = nil      
  resp = HTTParty.post('https://apitest.authorize.net/xml/v1/request.api', 
    :headers => { 'Content-Type' => 'application/json' }, 
    :body => params.to_json,
    :debug_output => $stdout
  )
  resp = JSON.parse(resp.body.to_s[1..-1])
  Caboose.log(resp)
  # See if we have a duplicate
  if resp['messages'] && 
     resp['messages']['resultCode'] && 
     resp['messages']['resultCode'] == 'Error' && 
     resp['messages']['message'][0]['code'] == 'E00039'
    
    Caboose.log("Error: duplicate customer profile.")
    str = resp['messages']['message'][0]['text']
    str.gsub!('A duplicate record with ID ', '')
    str.gsub!(' already exists.', '')
    user.customer_profile_id = str
    user.save
  end      
  return user.customer_profile_id
end

.hosted_profile_page_token(store_config, user) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/models/caboose/authnet.rb', line 59

def self.hosted_profile_page_token(store_config, user)
  params = {
    "getHostedProfilePageRequest" => {
      "merchantAuthentication" => {
        "name"           => '9qR2qa4ZWn', #store_config.pp_username,
        "transactionKey" => '386TLme2j8yp4BQy', #store_config.pp_password
      },
      "customerProfileId" => user.customer_profile_id,
      "hostedProfileSettings" => {
        "setting" => [
          { "settingName" => "hostedProfileReturnUrl"         , "settingValue" => "https://google.com" },
          { "settingName" => "hostedProfileReturnUrlText"     , "settingValue" => "Continue to confirmation page." },
          { "settingName" => "hostedProfilePageBorderVisible" , "settingValue" => "true" }
        ]
      }
    }
  }
  resp = nil      
  resp = HTTParty.get('https://apitest.authorize.net/xml/v1/request.api', 
    :headers => { 'Content-Type' => 'application/json' }, 
    :body => params.to_json,
    :debug_output => $stdout
  )
  resp = JSON.parse(resp.body.to_s[1..-1])
  Caboose.log(resp)
  if resp['messages'] && resp['messages']['resultCode'] && resp['messages']['resultCode'] == 'Ok'
    return resp['token']
  end
  return nil         
end