pxpay 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ end
14
+
15
+ gem 'nokogiri'
16
+ gem "rest-client"
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ mime-types (1.16)
10
+ nokogiri (1.4.4)
11
+ rake (0.8.7)
12
+ rcov (0.9.9)
13
+ rest-client (1.6.1)
14
+ mime-types (>= 1.16)
15
+ shoulda (2.11.3)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ bundler (~> 1.0.0)
22
+ jeweler (~> 1.5.2)
23
+ nokogiri
24
+ rcov
25
+ rest-client
26
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Bradley Priest
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,44 @@
1
+ = PxPay
2
+ A gem to integrate DPS-hosted payments through Payment Express' PxPay system.
3
+ See http://www.paymentexpress.com/technical_resources/ecommerce_hosted/pxpay.html or http://www.paymentexpress.com/downloads/DPSECOM_PXPay.pdf for more details of PxPay
4
+
5
+ gem install pxpay
6
+
7
+ rails g pxpay:install to copy an initializer and a config yml file.
8
+ Make sure you add your own development credentials to the pxpay.yml file. Apply for a development account at https://www.paymentexpress.com/pxmi/apply
9
+
10
+ To send your customer to Payment Express for payment make a call to PaymentExpress::Request to request a redirection URL
11
+
12
+ def create
13
+ request = PaymentExpress::Request.new( id , price, options )
14
+ redirect_to request.url
15
+ end
16
+
17
+ Payment Express will redirect you back to the success URL that you provided. Use PaymentExpress:Response to get the details back from Payment Express
18
+
19
+ def success
20
+ response = PaymentExpress::Response.new(params).response
21
+ hash = response.hash
22
+ end
23
+
24
+ TODO
25
+ Add code comments
26
+ Add tests
27
+ Add ability to set global configuration options
28
+ Add ability to use recurring billing
29
+
30
+ == Contributing to PxPay
31
+
32
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
33
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
34
+ * Fork the project
35
+ * Start a feature/bugfix branch
36
+ * Commit and push until you are happy with your contribution
37
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
38
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
39
+
40
+ == Copyright
41
+
42
+ Copyright (c) 2011 Bradley Priest. See LICENSE.txt for
43
+ further details.
44
+
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "pxpay"
16
+ gem.homepage = "http://github.com/bradleypriest/pxpay"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Ruby wrapper for the Payment Express' PxPay API}
19
+ gem.description = %Q{A Ruby wrapper around the DPS-hosted PxPay service}
20
+ gem.email = "bradleypriest@gmail.com"
21
+ gem.authors = ["Bradley Priest"]
22
+ gem.add_dependency 'nokogiri'
23
+ gem.add_dependency 'rest-client'
24
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
25
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
26
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
27
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ require 'rake/testtask'
32
+ Rake::TestTask.new(:test) do |test|
33
+ test.libs << 'lib' << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+
38
+ require 'rcov/rcovtask'
39
+ Rcov::RcovTask.new do |test|
40
+ test.libs << 'test'
41
+ test.pattern = 'test/**/test_*.rb'
42
+ test.verbose = true
43
+ end
44
+
45
+ task :default => :test
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "pxpay #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/pxpay.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Pxpay
2
+ require "pxpay/railtie" if defined?(Rails)
3
+ require "pxpay/base"
4
+ require "pxpay/request"
5
+ require "pxpay/response"
6
+ require "pxpay/notification"
7
+ end
data/lib/pxpay/base.rb ADDED
@@ -0,0 +1,12 @@
1
+ module Pxpay
2
+ class Base
3
+ # Acceptable payment currencies
4
+ def self.currency_types
5
+ %w( CAD CHF EUR FRF GBP HKD JPY NZD SGD USD ZAR AUD WST VUV TOP SBD PNG MYR KWD FJD )
6
+ end
7
+
8
+ def self.return_details
9
+ [ :dps_billing_id, :txn_data1, :success, :card_number2, :email_address, :card_number, :amount_settlement, :txn_data2, :client_info, :date_expiry, :currency_settlement, :txn_data3, :txn_id, :txn_type, :date_settlement, :auth_code, :dps_txn_ref, :currency_input, :txn_mac, :card_name, :billing_id, :merchant_reference, :response_text, :card_holder_name ]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ module Pxpay
2
+ class InstallGenerator < Rails::Generators::Base
3
+ desc "Copies pxpay.yml to config and a config initializer to config/initializers/pxpay_config.rb"
4
+
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def copy_files
8
+ template 'pxpay.rb' ,'config/initializers/pxpay.rb'
9
+ template 'pxpay.yml' ,'config/pxpay.yml'
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ module Pxpay
2
+ class Notification
3
+ mattr_accessor :order_details
4
+ attr_accessor :hash, :xml
5
+
6
+ def initialize(response)
7
+ @hash = parse(response)
8
+ @xml = response
9
+ end
10
+
11
+ def parse(response)
12
+ require 'nokogiri'
13
+ doc = Nokogiri::XML(response)
14
+ hash = {}
15
+ doc.at_css("Response").element_children.each do |attribute|
16
+ hash[attribute.name.underscore.to_sym] = attribute.inner_text# if ::Pxpay::Base.return_details.include?(attribute.name)
17
+ end
18
+ hash
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ require 'pxpay'
2
+ require 'rails'
3
+ module Pxpay
4
+ class Railtie < ::Rails::Railtie
5
+ generators do
6
+ require 'pxpay/install_generator'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,35 @@
1
+ module Pxpay
2
+ class Request
3
+
4
+ attr_accessor :post
5
+
6
+ def initialize( id , price, options = {} )
7
+ @post = build_xml( id, price, options )
8
+ end
9
+
10
+ def url
11
+ require 'rest_client'
12
+ response = ::RestClient.post("https://sec2.paymentexpress.com/pxpay/pxaccess.aspx", post )
13
+ url = Hash.from_xml(response)['Request']['URI']
14
+ return URI::extract(url).first.gsub("&amp;", "&")
15
+ end
16
+
17
+ private
18
+
19
+ def build_xml( id, price, options )
20
+ xml = Builder::XmlMarkup.new
21
+ xml.GenerateRequest do
22
+ xml.PxPayUserId PXPAY_CONFIG[:pxpay][:pxpay_user_id]
23
+ xml.PxPayKey PXPAY_CONFIG[:pxpay][:pxpay_key]
24
+ xml.AmountInput sprintf("%.2f", price)
25
+ xml.CurrencyInput options[:currency] || "NZD"
26
+ xml.MerchantReference options[:reference] || id.to_s
27
+ xml.EmailAddress options[:email]
28
+ xml.TxnType "Purchase"
29
+ xml.TxnId id
30
+ xml.UrlSuccess PXPAY_CONFIG[:pxpay][:success_url]
31
+ xml.UrlFail PXPAY_CONFIG[:pxpay][:failure_url]
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,26 @@
1
+ module Pxpay
2
+ class Response
3
+ attr_accessor :result
4
+ def initialize(params)
5
+ @result = params[:result]
6
+ @user_id = params[:userid]
7
+ end
8
+
9
+ def response
10
+ require 'rest_client'
11
+ response = ::RestClient.post( 'https://www.paymentexpress.com/pxpay/pxaccess.aspx', build_xml( result ) )
12
+ return ::Pxpay::Notification.new( response )
13
+ end
14
+
15
+ private
16
+ def build_xml( result )
17
+ xml = Builder::XmlMarkup.new
18
+
19
+ xml.ProcessResponse do
20
+ xml.PxPayUserId PXPAY_CONFIG[:pxpay][:pxpay_user_id]
21
+ xml.PxPayKey PXPAY_CONFIG[:pxpay][:pxpay_key]
22
+ xml.Response result
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1 @@
1
+ PXPAY_CONFIG = YAML.load_file("#{Rails.root}/config/pxpay.yml")[Rails.env]
@@ -0,0 +1,6 @@
1
+ development:
2
+ :pxpay:
3
+ :pxpay_user_id: Demo
4
+ :pxpay_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
5
+ :success_url: http://localhost:3000/success
6
+ :failure_url: http://localhost:3000/failure
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'pxpay'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestPxpay < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pxpay
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Bradley Priest
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-03-12 00:00:00 +13:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: nokogiri
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ prerelease: false
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: rest-client
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ version: "0"
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: shoulda
48
+ requirement: &id003 !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *id003
59
+ - !ruby/object:Gem::Dependency
60
+ name: bundler
61
+ requirement: &id004 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 1
68
+ - 0
69
+ - 0
70
+ version: 1.0.0
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: *id004
74
+ - !ruby/object:Gem::Dependency
75
+ name: jeweler
76
+ requirement: &id005 !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 1
83
+ - 5
84
+ - 2
85
+ version: 1.5.2
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: *id005
89
+ - !ruby/object:Gem::Dependency
90
+ name: rcov
91
+ requirement: &id006 !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *id006
102
+ - !ruby/object:Gem::Dependency
103
+ name: nokogiri
104
+ requirement: &id007 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ type: :runtime
113
+ prerelease: false
114
+ version_requirements: *id007
115
+ - !ruby/object:Gem::Dependency
116
+ name: rest-client
117
+ requirement: &id008 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ type: :runtime
126
+ prerelease: false
127
+ version_requirements: *id008
128
+ description: A Ruby wrapper around the DPS-hosted PxPay service
129
+ email: bradleypriest@gmail.com
130
+ executables: []
131
+
132
+ extensions: []
133
+
134
+ extra_rdoc_files:
135
+ - LICENSE.txt
136
+ - README.rdoc
137
+ files:
138
+ - .document
139
+ - Gemfile
140
+ - Gemfile.lock
141
+ - LICENSE.txt
142
+ - README.rdoc
143
+ - Rakefile
144
+ - VERSION
145
+ - lib/pxpay.rb
146
+ - lib/pxpay/base.rb
147
+ - lib/pxpay/install_generator.rb
148
+ - lib/pxpay/notification.rb
149
+ - lib/pxpay/railtie.rb
150
+ - lib/pxpay/request.rb
151
+ - lib/pxpay/response.rb
152
+ - lib/pxpay/templates/pxpay.rb
153
+ - lib/pxpay/templates/pxpay.yml
154
+ - test/helper.rb
155
+ - test/test_pxpay.rb
156
+ has_rdoc: true
157
+ homepage: http://github.com/bradleypriest/pxpay
158
+ licenses:
159
+ - MIT
160
+ post_install_message:
161
+ rdoc_options: []
162
+
163
+ require_paths:
164
+ - lib
165
+ required_ruby_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ hash: -2524755229026388599
171
+ segments:
172
+ - 0
173
+ version: "0"
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ none: false
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ segments:
180
+ - 0
181
+ version: "0"
182
+ requirements: []
183
+
184
+ rubyforge_project:
185
+ rubygems_version: 1.3.7
186
+ signing_key:
187
+ specification_version: 3
188
+ summary: Ruby wrapper for the Payment Express' PxPay API
189
+ test_files:
190
+ - test/helper.rb
191
+ - test/test_pxpay.rb