Class: FraudlabsproRuby::Api::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/fraudlabspro_ruby/api/order.rb

Constant Summary collapse

APPROVE =

Order statuses.

'APPROVE'
REJECT =
'REJECT'
REJECT_BLACKLIST =
'REJECT_BLACKLIST'
CREDIT_CARD =

Payment methods.

'CREDITCARD'
PAYPAL =
'PAYPAL'
CASH_ON_DELIVERY =
'COD'
BANK_DEPOSIT =
'BANKDEPOSIT'
GIFT_CARD =
'GIFTCARD'
CRYPTO =
'CRYPTO'
WIRE_TRANSFER =
'WIRED'
OTHERS =
'OTHERS'
FLP_ID =

ID types.

'fraudlabspro_id'
ORDER_ID =
'user_order_id'

Class Method Summary collapse

Class Method Details

.do_hash(value) ⇒ Object

Hashes a string to protect its real value.



153
154
155
156
157
158
159
# File 'lib/fraudlabspro_ruby/api/order.rb', line 153

def self.do_hash(value)
  hash = 'fraudlabspro_' + value.to_s
  for i in 0..65536
    hash = Digest::SHA1.hexdigest('fraudlabspro_' + hash)
  end
  return hash
end

.feedback(params = {}) ⇒ Object

Sends feedback back to FraudLabs Pro.



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/fraudlabspro_ruby/api/order.rb', line 110

def self.feedback(params = {})
  uri = URI.parse("https://api.fraudlabspro.com/v2/order/feedback")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  request = Net::HTTP::Post.new(uri.request_uri)
  request.set_form_data({
    'key' => FraudlabsproRuby::Configuration.api_key,
    'format' => 'json',
    'id' => params[:transaction_id],
    'action' => params[:status] || '',
    'note' => params[:note] || ''
  })

  response = http.request(request)

  if response == nil
    return false
  else
    return response
  end
end

.getTransaction(params = {}) ⇒ Object

Gets transaction result.



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/fraudlabspro_ruby/api/order.rb', line 133

def self.getTransaction(params = {})
  if params[:id_type] == nil
    params[:id_type] = ''
  end

  uri = URI.parse("https://api.fraudlabspro.com/v2/order/result?key=" + FraudlabsproRuby::Configuration.api_key + "&format=json&id=" + params[:transaction_id] + "&id_type=" + params[:id_type])
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  request = Net::HTTP::Get.new(uri.request_uri)

  response = http.request(request)

  if response == nil
    return false
  else
    return response
  end
end

.validate(params = {}) ⇒ Object

Validate order for possible fraud.



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
58
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/fraudlabspro_ruby/api/order.rb', line 32

def self.validate(params = {})
  if params[:email] != nil
    email_domain = params[:email][(params[:email].index('@') + 1)..-1]
  end

  if params[:phone] != nil
    params[:phone] = params[:phone].scan(/\d/).join('')
  end

  if params[:amount] != nil
    params[:amount] = '%.2f' % params[:amount]
  end

  if params[:card_number] != nil
    params[:card_number] = params[:card_number][0..5]
  end

  uri = URI.parse("https://api.fraudlabspro.com/v2/order/screen")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  request = Net::HTTP::Post.new(uri.request_uri)
  request.set_form_data({
    'key' => FraudlabsproRuby::Configuration.api_key,
    'format' => 'json',
    'source' => 'sdk-ruby',
    'source_version' => FraudlabsproRuby::VERSION,
    'flp_checksum' => params[:flp_checksum] || '',

    # Billing information.
    'ip' => params[:ip],
    'first_name' => params[:first_name] || '',
    'last_name' => params[:last_name] || '',
    'username_hash' => do_hash(params[:username]) || '',
    'email' => params[:email] || '',
    'email_domain' => email_domain || '',
    'user_phone' => params[:phone] || '',
    'bill_addr' => params[:bill_addr] || '',
    'bill_city' => params[:bill_city] || '',
    'bill_state' => params[:bill_state] || '',
    'bill_zip_code' => params[:bill_zip_code] || '',
    'bill_country' => params[:bill_country] || '',

    # Order information.
    'user_order_id' => params[:user_order_id] || '',
    'user_order_memo' => params[:user_order_memo] || '',
    'amount' => params[:amount] || 0,
    'quantity' => params[:quantity] || 1,
    'currency' => params[:currency] || 'USD',
    'department' => params[:department] || '',
    'payment_gateway' => params[:payment_gateway] || '',
    'payment_mode' => params[:payment_mode] || '',

    # Credit card information.
    'bin_no' => params[:card_number] || '',
    'card_hash' => do_hash(params[:card_number]) || '',
    'avs_result' => params[:card_avs] || '',
    'cvv_result' => params[:card_cvv] || '',

    # Shipping information.
    'ship_first_name' => params[:ship_first_name] || '',
    'ship_last_name' => params[:ship_last_name] || '',
    'ship_addr' => params[:ship_addr] || '',
    'ship_city' => params[:ship_city] || '',
    'ship_state' => params[:ship_state] || '',
    'ship_zip_code' => params[:ship_zip_code] || '',
    'ship_country' => params[:ship_country] || ''
  })

  response = http.request(request)

  if response == nil
    return false
  else
    return response
  end
end