paymentsjs-rails 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3889dd1072cc5e7b629af8e043c51033e23d281f
4
- data.tar.gz: bbc3ed2a5792caee64575a8fceb6d7c6b2ecabbd
3
+ metadata.gz: 796d4c3a2a054b2f93c1bf04e985c67b84220706
4
+ data.tar.gz: 1bffe60b7cd17a2a4c025d2b99ac5521a4008c7d
5
5
  SHA512:
6
- metadata.gz: c410e6b1b3bc4cc506cbbed6e0c6ca13dabe3643a8db44458c849c64aebc8fe23c4d4b117cfc15c0759693dff7ccefdfa84bc68ef149f016e3dc577137f1ca33
7
- data.tar.gz: b73988b407681c24889b9a9f13884bccd976cf04913271625f12470ca590ca4d39cd7ca1eec4c1bc80d7ca9ed5673e96d775dd07639353119882a68f2be6dc41
6
+ metadata.gz: 565459b4b11c908244ce7f46d5aeaf690483a0c59b5b78eebe1e53bc16f5eef20e197181b298779d1a310adb93a92dfb48b615c033695cceb278c8076a2b2667
7
+ data.tar.gz: cb4e010bc3023dcf6d1f1d791b7ab810c7bdce7e8f6a4776c5727053132ce1211cca541491e82b5f8fd6c17039295a526e9bc330ebc7acd7838217b2b8e86663
data/README.md CHANGED
@@ -1 +1,89 @@
1
- Coming soon
1
+ # Sage PaymentsJS-Rails Gem
2
+
3
+ The PaymentsJS-Rails gem simplifies the integration of Sage's PaymentsJS SDK by adding the PaymentsJs model and making configuring environmental variables easy.
4
+
5
+ ##Installation
6
+ Add it to your Gemfile:
7
+ ```bash
8
+ gem 'paymentsjs-rails'
9
+ ```
10
+
11
+ Use Bundler to install:
12
+ ```bash
13
+ bundle install
14
+ ```
15
+
16
+ And add the following file:
17
+ ```ruby
18
+ config/initializers/paymentsjs-rails.rb
19
+ ```
20
+ Then, in your `app/assets/javascripts/application.js` file, add:
21
+ ```javascript
22
+ //= require pay //this adds the pay.min.js file provided via Sage CDN
23
+ ```
24
+
25
+ Currently this gem is only intended for those using the PayJS(['PayJS/UI']) module. With time it will be extended to other modules.
26
+
27
+ ##Quick Start
28
+
29
+ Follow the [PaymentsJS GitHub Quick Start guide](https://github.com/SagePayments/PaymentsJS "PaymentsJS"), minus the
30
+ ```html
31
+ <script type="text/javascript" src="https://www.sagepayments.net/pay/1.0.0/js/pay.min.js"></script>
32
+ ```
33
+ part.
34
+
35
+ PaymentsJS requires several variables to be added to the `$UI.Initialize()` function in order to work. The Quick Start comes with several variables preloaded. We'll replace these with embedded ruby and the smae preloaded variables:
36
+
37
+ ```javascript
38
+ PayJS(['PayJS/UI'], // the name of the module we want to use
39
+ function($UI) { // assigning the module to a variable
40
+ $UI.Initialize({ // configuring the UI
41
+ apiKey: "<%= PaymentJs.api_key %>", // your developer ID
42
+ merchantId: "<%= PaymentJs.mid %>", // your 12-digit account identifier
43
+ authKey: "<%= PaymentJs.encrypt %>", // covered in the next section!
44
+ requestType: "<%= PaymentJs.request_type %>", // use can use "vault" to tokenize a card without charging it
45
+ requestId: "<%= PaymentJs.req_id %>", // an order number, customer or account identifier, etc.
46
+ amount: "<%= PaymentJs.amount %>", // the amount to charge the card. in test mode, different amounts produce different results.
47
+ elementId: "paymentButton", // the page element that will trigger the UI
48
+ nonce: "<%= PaymentJs.salt %>", // a unique identifier, used as salt
49
+ debug: true, // enables verbose console logging
50
+ preAuth: <%= PaymentJs.pre_auth %>, // run a Sale, rather than a PreAuth
51
+ environment: "<%= PaymentJs.environment %>" // hit the certification environment
52
+ });
53
+ $UI.setCallback(function(result) { // custom code that will execute when the UI receives a response
54
+ console.log(result.getResponse()); // log the result to the console
55
+ var wasApproved = result.getTransactionSuccess();
56
+ alert(wasApproved ? "ka-ching!" : "bummer");
57
+ });
58
+ });
59
+ ```
60
+
61
+ Reload the page and the payment system should work.
62
+
63
+ ##Configuring
64
+
65
+ In your `config/initializers/paymentsjs-rails.rb` file, add this:
66
+ ```ruby
67
+ PaymentsJs.configuration do |config|
68
+ config.mid = "YOUR MERCHANT ID"
69
+ config.mkey = "YOUR MERCHANT KEY"
70
+ config.api_key = "YOUR API KEY"
71
+ config.api_secret = "YOUR SECRET KEY"
72
+ config.postback_url = "YOUR POSTBACK URL"
73
+ end
74
+ ```
75
+ This will override the default variables.
76
+
77
+ ##Integration
78
+
79
+ Integrating is easy and very variable. There are several values that will need to be dynamically set, and in a semi-order. Before you can call `PaymentsJs.encrypt` the following variables need to be set:
80
+ ```ruby
81
+ PaymentsJs.amount = "ORDER PRICE" #note, this needs to be a string, not a float/integer
82
+ PaymentsJs.req_id = "ORDER NUMBER" #if blank, "invoice(xx)" with xx being a random integer between 10 and 42 will be generated
83
+ PaymentsJs.request_type = "ORDER REQUEST TYPE"
84
+ PaymentsJs.pre_auth = boolean
85
+ PaymentsJs.environment = "ORDER ENVIRONMENT"
86
+ ```
87
+ The other variables are generated by encryption.
88
+
89
+ ####NOTE: This gem is not yet finished and has not been extensively tested, be very careful using this gem until v.1.0 is released.
@@ -4,6 +4,10 @@ class PaymentsJs
4
4
  require 'base64'
5
5
  require 'json'
6
6
 
7
+ module PaymentsJs
8
+ require 'paymentsjs-rails/rails/engine'
9
+ end
10
+
7
11
  extend Configuration
8
12
 
9
13
  def self.generate_req_id
@@ -26,7 +30,6 @@ class PaymentsJs
26
30
  define_setting :amount, "1.00"
27
31
  define_setting :pre_auth, false
28
32
  define_setting :environment, "cert"
29
- define_setting :secret, "wtC5Ns0jbtiNA8sP"
30
33
  define_setting :iv, PaymentsJs.iv
31
34
 
32
35
  def self.salt
@@ -50,7 +53,7 @@ class PaymentsJs
50
53
  environment = PaymentsJs.environment
51
54
  secret = PaymentsJs.secret
52
55
 
53
- req = {mid: mid, mkey: mkey, api_key: api_key, api_secret: api_secret, req_id: req_id, request_type: request_type, postback_url: postback_url, amount: amount, pre_auth: pre_auth, environment: environment, secret: secret }
56
+ req = {mid: mid, mkey: mkey, api_key: api_key, api_secret: api_secret, req_id: req_id, request_type: request_type, postback_url: postback_url, amount: amount, pre_auth: pre_auth, environment: environment }
54
57
 
55
58
  req
56
59
  end
@@ -59,7 +62,7 @@ class PaymentsJs
59
62
  cipher = OpenSSL::Cipher::AES.new(256, :CBC)
60
63
  cipher.encrypt
61
64
  req = PaymentsJs.req
62
- secret = PaymentsJs.secret
65
+ secret = PaymentsJs.api_secret
63
66
  data = JSON.generate(req)
64
67
  salt = PaymentsJs.salt
65
68
  key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(secret, salt, 1500, 32)
@@ -0,0 +1,7 @@
1
+ module PaymentsJs
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+
5
+ end
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paymentsjs-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Bartlett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-19 00:00:00.000000000 Z
11
+ date: 2016-09-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A gem to simplify the encryption of data for the Sage PaymentsJS SDK
14
14
  for usage in Rails apps.
@@ -18,9 +18,10 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - README.md
21
+ - lib/assets/javascripts/pay.js
21
22
  - lib/helpers/configuration.rb
22
23
  - lib/paymentsjs-rails.rb
23
- - vendor/assets/javascripts/pay.js
24
+ - lib/paymentsjs-rails/rails/engine.rb
24
25
  homepage: http://rubygems.org/gems/paymentjs-rails
25
26
  licenses:
26
27
  - MIT