payplug_rails 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6c115f749c21bc68e6a7ba9fb06d3b835710de67
4
+ data.tar.gz: 4852f3e5d4e04088911a8e9cee531c29df65689f
5
+ SHA512:
6
+ metadata.gz: 71a498ad10b57472eaea170d8f8bec0caa80de24380cdefa85529a2ab48a377b12ae9f7f2dfd6b4ed4e0c687f76e882150a8e9f68fe1f829788b638e5f386403
7
+ data.tar.gz: 0969c30559caa1688a8d74ad451a3ce6921c22f66bc4f1bbfbd8eff79ccd2166dd875011c6f19dd3f229b83682552a0635b4409861163a7343ff5a423a7be969
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in payplug_rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 calve
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # PayplugRails
2
+
3
+ A Rails plugin to create payments using Payplug's solution
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'payplug_rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install payplug_rails
18
+
19
+ ## Usage
20
+
21
+ Get your [Payplug autoconfig](https://www.payplug.fr/portal/ecommerce/autoconfig) and set the following values in ``initializer/payplugrails.rb``
22
+
23
+ def ipn_callback(params)
24
+ # Define what to do when an valid IPN is received
25
+ #
26
+ # params contains a json objet of the POST request sent by Payplug
27
+ Order.find_by_id(params['order'])
28
+ Order.status = 'paid'
29
+ Order.save
30
+ end
31
+
32
+ # Mind the colomn to pass a function pointer
33
+ PayplugRails.ipn_callback = :ipn_callback
34
+
35
+ # The following parameters comes from your autoconfig
36
+ PayplugRails.url = "https://www.payplug.fr/p/<you-url>"
37
+ PayplugRails.payplug_public_key = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtN4dpK368PEEYKeee7S5\n1m2a8GUFLDAZ/HgRI1H6diYt87gzDPftn1UyW96YuIBed0T0dtl0tuABaIgGeddR\nuo3zfMpkyYWM2D5UHUEMKzEY5WIyaaWoVYJaZU5DWzCiroKcnUJgKm41RL32/CHU\nSFoymxjOOzpvkazbaY+Ql2GYev2QwKAf7lkH91Wp3frjQYXEFIwYnt6ZET8wPUwX\nMdF0hRaZYlaDQrCB2S/+k4Djb8mXqVkJ0qqgItycL05zyysJw/IGMr2zZ5hQSnfN\nCJ+i33ywnoT/qctGgLW4bGuGdTdcbA7VzdxhXtHaAQjuJvrf+twNCQSLCMbZ6pnK\nzQIDAQAB\n-----END PUBLIC KEY-----\n"
38
+ PayplugRails.private_key = "-----BEGIN RSA PRIVATE KEY-----\nrawprivatekey\n-----END RSA PRIVATE KEY-----""
39
+
40
+ Add the following to ``config/routes.rb``
41
+
42
+ mount PayplugRails::Engine, at: "/ipn"
43
+
44
+ Then, in a controller, to get a payment url and redirect your user, require the module with
45
+
46
+ require 'payplug_rails'
47
+
48
+ Then
49
+
50
+ ipn_url = request.base_url + payplug_rails_engine_path # Create an ipn url relatives to the url used
51
+ redirect_to PayplugRails::Payplug.create_payment(1200, ipn_url) # Create a payment for 12€00
52
+
53
+ You can also pass extra parameters :
54
+
55
+ redirect_to PayplugRails::Payplug.create_payment(1200, ipn_url, {first_name: customer.first_name, last_name: customer.last_name, email: customer.email, order: order.id})
56
+
57
+
58
+ ## Get IPN in development
59
+
60
+ Payplug expect your ipn_url to be reachable from the internet, which is typically not the case in a developement setup. However, you can set a [localtunnel](https://www.localtunnel.me) and access your application with the url provided.
61
+
62
+
63
+ ## Disclosure
64
+
65
+ This plugin is not supported nor maintened by Payplug SAS.
66
+
67
+
68
+ ## Contributing
69
+
70
+ 1. Fork it ( https://github.com/calve/payplug_rails/fork )
71
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
72
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
73
+ 4. Push to the branch (`git push origin my-new-feature`)
74
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,4 @@
1
+ module PayplugRails
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,19 @@
1
+ require 'payplug_rails'
2
+
3
+ class PayplugIpnsController < ApplicationController
4
+ protect_from_forgery :except => :ipn
5
+
6
+ def ipn
7
+ puts "IPN : " + request.raw_post
8
+ valid = PayplugRails::Payplug.verify(request)
9
+ render :text => request.method+ " : " + request.raw_post + "///" + payplug_ipn_params.to_s
10
+ if valid
11
+ send(PayplugRails.ipn_callback, JSON.parse(request.raw_post))
12
+ end
13
+ end
14
+
15
+ private
16
+ def payplug_ipn_params
17
+ params.permit(:id_transaction, :is_test, :custom_datas, :origin, :last_name, :amount, :order, :state, :email, :first_name, :status, :customer)
18
+ end
19
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ PayplugRails::Engine.routes.draw do
2
+ get '/' => 'payplug_ipns#ipn'
3
+ post '/' => 'payplug_ipns#ipn'
4
+ end
@@ -0,0 +1,4 @@
1
+ module PayplugRails
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module PayplugRails
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,45 @@
1
+ require "payplug_rails/version"
2
+ require "payplug_rails/engine"
3
+ require 'openssl'
4
+ require 'base64'
5
+ require 'json'
6
+ require 'cgi'
7
+
8
+ module PayplugRails
9
+
10
+ mattr_accessor :url
11
+ mattr_accessor :private_key
12
+ mattr_accessor :payplug_public_key
13
+ mattr_accessor :ipn_callback
14
+
15
+ class Payplug
16
+
17
+ def self.create_payment(amount, ipn_url, customer_hash={})
18
+ data = {
19
+ currency: 'EUR',
20
+ amount: amount,
21
+ ipn_url: ipn_url,
22
+ origin: "PayplugRails-"+PayplugRails::VERSION,
23
+ }.merge(customer_hash).to_query
24
+
25
+ key = OpenSSL::PKey::RSA.new PayplugRails.private_key
26
+ raw_sign = key.sign(OpenSSL::Digest::SHA1.new, data)
27
+ http_sign = CGI.escape(Base64.encode64(raw_sign))
28
+ http_data = CGI.escape(Base64.encode64(data))
29
+
30
+ return PayplugRails.url+"?data="+http_data+"&sign="+http_sign
31
+ end
32
+
33
+ def self.verify(request)
34
+ # Verify the IPN contained in the http request
35
+ if request.raw_post.blank?
36
+ return false
37
+ end
38
+ signature = Base64.decode64(request.headers['HTTP_PAYPLUG_SIGNATURE'])
39
+ body = request.raw_post
40
+ key = OpenSSL::PKey::RSA.new PayplugRails.payplug_public_key
41
+ status = key.verify(OpenSSL::Digest::SHA1.new, signature, body)
42
+ return status
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'payplug_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "payplug_rails"
8
+ spec.version = PayplugRails::VERSION
9
+ spec.authors = ["calve"]
10
+ spec.email = ["calvinh34@gmail.com"]
11
+ spec.summary = "A Rails module to use Payplug"
12
+ spec.description = "Generate payment easily"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib", "config", "app"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: payplug_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - calve
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Generate payment easily
42
+ email:
43
+ - calvinh34@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - app/controllers/application_controller.rb
54
+ - app/controllers/payplug_ipns_controller.rb
55
+ - config/routes.rb
56
+ - lib/payplug_rails.rb
57
+ - lib/payplug_rails/engine.rb
58
+ - lib/payplug_rails/version.rb
59
+ - payplug_rails.gemspec
60
+ homepage: ''
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ - config
69
+ - app
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.4.5
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: A Rails module to use Payplug
86
+ test_files: []