paymentsjs-rails 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/paymentsjs-rails.rb +59 -54
- 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: d7dc7d8bdd59d7e2262dd6192f84121f3a58550b
|
4
|
+
data.tar.gz: cbecceaddeb1ea164f8abf4ce77b0a9c3a495858
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd6cf5e96f5d3bd4c9a314854b17c81a577bf943b9d7784ea3d9026ccd07da86b7e404baa258befd9c3fd0b22afbf7d7846dfc414e84e6db9c02841b17b605a2
|
7
|
+
data.tar.gz: e3cee6db2aaec9d57b182f9a2f177f442e310f6ec7869e4e83a3a316a77cfd72a3cd3ea64eeb9c047ad40c1d4691abfdb2c5ef8774775edaae50dd1e32b4a228
|
data/README.md
CHANGED
@@ -40,7 +40,7 @@ PaymentsJS requires several variables to be added to the `$UI.Initialize()` func
|
|
40
40
|
PayJS(['PayJS/UI'], // the name of the module we want to use
|
41
41
|
function($UI) { // assigning the module to a variable
|
42
42
|
$UI.Initialize({ // configuring the UI
|
43
|
-
apiKey: "<%=
|
43
|
+
apiKey: "<%= PaymentsJs.api_key %>", // your developer ID
|
44
44
|
merchantId: "<%= PaymentsJs.mid %>", // your 12-digit account identifier
|
45
45
|
authKey: "<%= PaymentsJs.encrypt %>", // covered in the next section!
|
46
46
|
requestType: "<%= PaymentsJs.request_type %>", // use can use "vault" to tokenize a card without charging it
|
@@ -94,4 +94,4 @@ PaymentsJs.request_type = "ORDER REQUEST TYPE"
|
|
94
94
|
PaymentsJs.pre_auth = boolean
|
95
95
|
PaymentsJs.environment = "ORDER ENVIRONMENT"
|
96
96
|
```
|
97
|
-
The other variables are generated by encryption.
|
97
|
+
The other variables are generated by encryption.
|
data/lib/paymentsjs-rails.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class PaymentsJs
|
2
|
-
require 'helpers/configuration'
|
2
|
+
require './paymentsjs-rails/lib/helpers/configuration'
|
3
3
|
require 'openssl'
|
4
4
|
require 'base64'
|
5
5
|
require 'json'
|
@@ -7,60 +7,65 @@ class PaymentsJs
|
|
7
7
|
|
8
8
|
extend Configuration
|
9
9
|
|
10
|
-
|
11
|
-
cipher.encrypt
|
12
|
-
|
13
|
-
iv = OpenSSL::Random.pseudo_bytes(16)
|
14
|
-
salt = iv.unpack('H*').first
|
15
|
-
salt = salt.bytes.to_a
|
16
|
-
salt = salt.pack('U*')
|
17
|
-
salt = Base64.strict_encode64(salt)
|
10
|
+
attr_reader :address, :city, :state, :zip, :amount, :req_id, :name, :request_type, :pre_auth, :environment, :api_key, :salt, :mid, :postback_url, :auth_key
|
18
11
|
|
19
|
-
|
12
|
+
def initialize(order)
|
13
|
+
@order = order
|
14
|
+
@address = @order[:address]
|
15
|
+
@city = @order[:city]
|
16
|
+
@state = @order[:state]
|
17
|
+
@zip = @order[:zip]
|
18
|
+
@amount = @order[:total]
|
19
|
+
@req_id = @order[:req_id]
|
20
|
+
@name = @order[:name]
|
21
|
+
@request_type = @order[:request_type]
|
22
|
+
@pre_auth = @order[:pre_auth]
|
23
|
+
@environment = @order[:environment]
|
24
|
+
|
25
|
+
cipher = OpenSSL::Cipher::AES.new(256, :CBC)
|
26
|
+
cipher.encrypt
|
20
27
|
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
define_setting :authKey, authKey
|
64
|
-
define_setting :salt, salt
|
28
|
+
iv = OpenSSL::Random.pseudo_bytes(16)
|
29
|
+
salt = iv.unpack('H*').first
|
30
|
+
salt = salt.bytes.to_a
|
31
|
+
salt = salt.pack('U*')
|
32
|
+
@salt = Base64.strict_encode64(salt)
|
33
|
+
|
34
|
+
req_id = "invoice" + rand(10...42).to_s
|
35
|
+
|
36
|
+
define_setting :mid, "999999999997"
|
37
|
+
define_setting :mkey, "K3QD6YWyhfD"
|
38
|
+
define_setting :api_key, "7SMmEF02WyC7H5TSdG1KssOQlwOOCagb"
|
39
|
+
define_setting :api_secret, "wtC5Ns0jbtiNA8sP"
|
40
|
+
define_setting :postback_url, "https://www.example.com"
|
41
|
+
|
42
|
+
@mid = PaymentsJs.mid
|
43
|
+
mkey = PaymentsJs.mkey
|
44
|
+
@api_key = PaymentsJs.api_key
|
45
|
+
api_secret = PaymentsJs.api_secret
|
46
|
+
@postback_url = PaymentsJs.postback_url
|
47
|
+
|
48
|
+
|
49
|
+
req = {
|
50
|
+
"apiKey" => @api_key,
|
51
|
+
"merchantId" => @mid,
|
52
|
+
"merchantKey" => mkey,
|
53
|
+
"requestType" => @request_type,
|
54
|
+
"requestId" => @req_id,
|
55
|
+
"postbackUrl" => @postback_url,
|
56
|
+
"amount" => @amount,
|
57
|
+
"nonce" => salt,
|
58
|
+
"preAuth" => @pre_auth,
|
59
|
+
"environment" => @environment
|
60
|
+
}
|
61
|
+
|
62
|
+
data = JSON.generate(req)
|
63
|
+
key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(api_secret, salt, 1500, 32)
|
64
|
+
cipher.key = key
|
65
|
+
cipher.iv = iv
|
66
|
+
authKey = cipher.update(data) + cipher.final()
|
67
|
+
@auth_key = Base64.strict_encode64(authKey)
|
68
|
+
|
69
|
+
end
|
65
70
|
|
66
71
|
end
|