teligem 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.markdown +45 -46
- data/lib/teligem.rb +30 -0
- data/spec/lib/teligem_spec.rb +27 -0
- data/teligem.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43ff7f46e4ecf7ef3f9105b97ae66151be6e8bb8
|
4
|
+
data.tar.gz: 8822daa689f8f22805b62633244c6dc228161687
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8697ce223379ac15366d18b35c86f953068269995db7310361833e752080b7db72b83c68bfa29229541c5f41ec77d7ec9319e04b12f94074eb374defa4884641
|
7
|
+
data.tar.gz: acec9bcafd7d3ad0d564bc3ba75c98a52bd080c2af9708b2299be255b490667bd5ab07c5d3af205b23fcf21ad93ac206d59aaabb9bbb1f1a60d54e1b663798f8
|
data/Gemfile.lock
CHANGED
data/README.markdown
CHANGED
@@ -19,38 +19,9 @@ Then run 'bundle install'
|
|
19
19
|
When a payment has been made, Telipass sends to the notification url those parameters.
|
20
20
|
Pick the ones you are interested in and put it in your payment model.
|
21
21
|
|
22
|
-
You must at least have those attributes: security_code:string, enduser_ip:string and ntu:string,
|
22
|
+
You must at least have those attributes in your payment model: security_code:string, enduser_ip:string and ntu:string,
|
23
23
|
as they are used to check if the payment really comes from the Telipass plateform.
|
24
24
|
|
25
|
-
```ruby
|
26
|
-
# Security
|
27
|
-
t.string :security_code # SecurityCode
|
28
|
-
# User Infos
|
29
|
-
t.string :enduser_ip # UserIP
|
30
|
-
t.string :enduser_host # Userhost
|
31
|
-
t.string :enduser_useragent # UserAgent
|
32
|
-
t.string :enduser_userlanguage # Webbrowser language
|
33
|
-
t.string :enduser_plateform # Exploitation system
|
34
|
-
# Transaction
|
35
|
-
t.string :ntu, null: false # Unique transaction number (NTU)
|
36
|
-
t.string :module_name # Name of the payment module
|
37
|
-
t.string :module_id # Module ID
|
38
|
-
t.string :site_name # Website name
|
39
|
-
t.string :solution_name # Payment solution name
|
40
|
-
t.string :payment_method # Payment used name
|
41
|
-
t.string :point_name # Point name
|
42
|
-
t.string :country_code # Country code name
|
43
|
-
t.string :country_name # Country name
|
44
|
-
t.integer :credits # Credits (only for virtual money)
|
45
|
-
t.decimal :amount # Commission
|
46
|
-
t.integer :status # Transaction status
|
47
|
-
# 1 = Valid, 2 = Rejected, 3 = Differed, 4 = Test
|
48
|
-
t.string :status_text # Transaction status in text
|
49
|
-
t.date :transaction_date # Transaction date
|
50
|
-
t.string :transaction_id # Transaction ID
|
51
|
-
t.string :custom # Custom parameters
|
52
|
-
```
|
53
|
-
|
54
25
|
### RAILS SECRETS
|
55
26
|
|
56
27
|
Add to your config/secrets.yml (don't forget to add it to .gitignore)
|
@@ -60,29 +31,57 @@ Add to your config/secrets.yml (don't forget to add it to .gitignore)
|
|
60
31
|
```
|
61
32
|
|
62
33
|
## USAGE
|
34
|
+
### security_check
|
35
|
+
To check if the payment really comes from the Telipass website, set your params and call the security check method.
|
63
36
|
|
64
|
-
|
37
|
+
```ruby
|
38
|
+
# in payment_controller.rb
|
39
|
+
|
40
|
+
def create
|
41
|
+
params = {
|
42
|
+
security_code: params[:security_code],
|
43
|
+
enduser_ip: params[:enduser_ip],
|
44
|
+
ntu: params[:ntu]
|
45
|
+
}
|
46
|
+
|
47
|
+
if Telipass.new.security_check(params) do
|
48
|
+
# ex: Create payment, give some user coins
|
49
|
+
else
|
50
|
+
# ex: Create payment, send a security alert
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
```
|
55
|
+
The security check method will return true if the payment really comes from Telipass, otherwise it will return false.
|
56
|
+
|
57
|
+
### check_status
|
58
|
+
Before giving coins to your user, you may want to check if the status of the transaction is valid, differed, rejected or is test.
|
59
|
+
Call the check_status function.
|
65
60
|
|
66
61
|
```ruby
|
67
|
-
params
|
68
|
-
|
69
|
-
enduser_ip: params[:enduser_ip],
|
70
|
-
ntu: params[:ntu]
|
71
|
-
}
|
72
|
-
|
73
|
-
if Telipass.new.security_check(params) do
|
74
|
-
# ex: Give some user coins
|
62
|
+
if Telipass.new.check_status(params[:status])
|
63
|
+
# Give coins to user
|
75
64
|
else
|
76
|
-
#
|
65
|
+
# Don't give user some coins
|
77
66
|
end
|
78
|
-
|
79
67
|
```
|
80
|
-
It will return true if
|
68
|
+
It will return true if status is valid, and return false if status is test or rejected or differed.
|
69
|
+
|
70
|
+
### get_earning
|
71
|
+
First, set earnings per point_name:
|
72
|
+
```
|
73
|
+
Teligem::EARNING = {
|
74
|
+
"FRSMS10" => 10,
|
75
|
+
"FRSMS20" => 20
|
76
|
+
}
|
77
|
+
```
|
78
|
+
Then call the get_earning method to the get the earning.
|
79
|
+
```
|
80
|
+
Teligem.new.get_earning(params[:point_name])
|
81
|
+
# It will return 10 if point_name is FRSMS10.
|
82
|
+
```
|
83
|
+
When the point_name is unknown, it will return 0.
|
81
84
|
|
82
|
-
## TODO
|
83
|
-
* Check if telikey is here otherwise show logger error info
|
84
|
-
* Get payment detailed info in order to set easier the earning
|
85
|
-
(most important infos are: module_name, payment_method, point_name, amount, credit)
|
86
85
|
|
87
86
|
|
88
87
|
## How to contribute?
|
data/lib/teligem.rb
CHANGED
@@ -30,6 +30,36 @@ class Teligem
|
|
30
30
|
return response
|
31
31
|
end
|
32
32
|
|
33
|
+
# === check_status(status)
|
34
|
+
# Return true if status is 1 (valid)
|
35
|
+
# Otherwise return false
|
36
|
+
def check_status(status)
|
37
|
+
case status
|
38
|
+
when 1 # Valid
|
39
|
+
true
|
40
|
+
when 2 # Rejected
|
41
|
+
false
|
42
|
+
when 3 # Differed
|
43
|
+
false
|
44
|
+
when 4 # Test
|
45
|
+
false
|
46
|
+
else
|
47
|
+
false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# === get_earning(point_name)
|
52
|
+
# Get earning from the hash Teligem::EARNING
|
53
|
+
# Hash exemple:
|
54
|
+
# Teligem::EARNING =
|
55
|
+
# { "FRSMS10" => 10,
|
56
|
+
# "FRSMS20" => 20
|
57
|
+
# }
|
58
|
+
# Return 0 if key unknown
|
59
|
+
def get_earning(point_name)
|
60
|
+
return Teligem::EARNING[point_name].to_i
|
61
|
+
end
|
62
|
+
|
33
63
|
private
|
34
64
|
def get_security_code(enduser_ip, ntu)
|
35
65
|
code = enduser_ip.to_s + ntu.to_s + @configs['telikey'].to_s
|
data/spec/lib/teligem_spec.rb
CHANGED
@@ -41,4 +41,31 @@ RSpec.describe Teligem do
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
describe '#check_status' do
|
45
|
+
it 'should return true if status valid' do
|
46
|
+
expect(Teligem.new.check_status(1)).to eq true
|
47
|
+
end
|
48
|
+
it 'should return false if status rejected' do
|
49
|
+
expect(Teligem.new.check_status(2)).to eq false
|
50
|
+
end
|
51
|
+
it 'should return false if status differed' do
|
52
|
+
expect(Teligem.new.check_status(3)).to eq false
|
53
|
+
end
|
54
|
+
it 'should return true if status test' do
|
55
|
+
expect(Teligem.new.check_status(4)).to eq false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#get_earning' do
|
60
|
+
it 'should return correct earning' do
|
61
|
+
Teligem::EARNING = {
|
62
|
+
"FRSMS10" => 10,
|
63
|
+
"FRSMS20" => 20
|
64
|
+
}
|
65
|
+
|
66
|
+
expect(Teligem.new.get_earning("FRSMS10")).to eq 10
|
67
|
+
expect(Teligem.new.get_earning("FRSMS20")).to eq 20
|
68
|
+
expect(Teligem.new.get_earning("UNKNOWN")).to eq 0
|
69
|
+
end
|
70
|
+
end
|
44
71
|
end
|
data/teligem.gemspec
CHANGED