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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/lib/paymentsjs-rails.rb +59 -54
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7379b35394ec7edc937364d75be0d9c14a293212
4
- data.tar.gz: 4314bb9e290915ef16fa1dc5c47fe5ed8892df06
3
+ metadata.gz: d7dc7d8bdd59d7e2262dd6192f84121f3a58550b
4
+ data.tar.gz: cbecceaddeb1ea164f8abf4ce77b0a9c3a495858
5
5
  SHA512:
6
- metadata.gz: ee09f5a5aca1d6d44983a7d0f53eb265fdddf8ee9246ee857949bc8755b5835c132b10aba24fb0a246d68664b1d88774ae8b8606c05a2c16b51183af60c1d2aa
7
- data.tar.gz: e5b0c733d6a4c8ee4129441b71477dca2dd3d4abaf5cc8f19b1c2db5041eacb88de48d57da4a6a8bb759a6c0253109b2ea10f163b7cca330657ea29a6014fb82
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: "<%= PaymentJs.api_key %>", // your developer ID
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.
@@ -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
- cipher = OpenSSL::Cipher::AES.new(256, :CBC)
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
- req_id = "invoice" + rand(10...42).to_s
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
- define_setting :mid, "999999999997"
22
- define_setting :mkey, "K3QD6YWyhfD"
23
- define_setting :api_key, "7SMmEF02WyC7H5TSdG1KssOQlwOOCagb"
24
- define_setting :api_secret, "wtC5Ns0jbtiNA8sP"
25
- define_setting :req_id, req_id
26
- define_setting :request_type, "payment"
27
- define_setting :postback_url, "https://www.example.com"
28
- define_setting :amount, "1.00"
29
- define_setting :pre_auth, false
30
- define_setting :environment, "cert"
31
-
32
- mid = PaymentsJs.mid
33
- mkey = PaymentsJs.mkey
34
- api_key = PaymentsJs.api_key
35
- api_secret = PaymentsJs.api_secret
36
- req_id = PaymentsJs.req_id
37
- request_type = PaymentsJs.request_type
38
- postback_url = PaymentsJs.postback_url
39
- amount = PaymentsJs.amount
40
- pre_auth = PaymentsJs.pre_auth
41
- environment = PaymentsJs.environment
42
-
43
- req = {
44
- "apiKey" => api_key,
45
- "merchantId" => mid,
46
- "merchantKey" => mkey,
47
- "requestType" => request_type,
48
- "requestId" => req_id,
49
- "postbackUrl" => postback_url,
50
- "amount" => amount,
51
- "nonce" => salt,
52
- "preAuth" => false,
53
- "environment" => environment
54
- }
55
-
56
- data = JSON.generate(req)
57
- key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(api_secret, salt, 1500, 32)
58
- cipher.key = key
59
- cipher.iv = iv
60
- authKey = cipher.update(data) + cipher.final()
61
- authKey = Base64.strict_encode64(authKey)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paymentsjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Bartlett