pxpay 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +69 -0
- data/VERSION +1 -1
- data/lib/pxpay/base.rb +4 -2
- data/lib/pxpay/init.rb +1 -0
- data/lib/pxpay/install_generator.rb +1 -2
- data/lib/pxpay/notification.rb +14 -7
- data/lib/pxpay/railtie.rb +3 -0
- data/lib/pxpay/request.rb +9 -1
- data/lib/pxpay/response.rb +3 -1
- data/lib/pxpay/templates/pxpay.rb +0 -1
- data/pxpay.gemspec +85 -0
- metadata +8 -6
- data/README.rdoc +0 -44
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
PxPay
|
2
|
+
=======
|
3
|
+
A Rubygem to integrate DPS-hosted payments through the Payment Express PxPay system.
|
4
|
+
For self-hosted systems check out the amazing [ActiveMerchant](https://www.github.com/Shopify/active_merchant) gem
|
5
|
+
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
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
Install from Rubygems
|
10
|
+
gem install pxpay
|
11
|
+
Then run `rails g pxpay:install` to copy an initializer and a config yml file to your rails app.
|
12
|
+
Make sure you add your own development credentials to the `config/pxpay.yml` file and create success and failure URLs for Payment Express to redirect you back to
|
13
|
+
You can apply for a development account at https://www.paymentexpress.com/pxmi/apply
|
14
|
+
|
15
|
+
|
16
|
+
Usage
|
17
|
+
-----
|
18
|
+
>> require 'nokogiri'
|
19
|
+
>> require 'pxpay'
|
20
|
+
>> request = Pxpay::Request.new( 1, 12.00 )
|
21
|
+
=> #<Pxpay::Request:0x00000101c9a840 >
|
22
|
+
>> request.url
|
23
|
+
=> "https://sec2.paymentexpress.com/pxpay/pxpay.aspx?userid=Fake_Dev&request=xxxxxxxxxx"
|
24
|
+
|
25
|
+
|
26
|
+
To send your customer to Payment Express for payment make a call to Pxpay::Request to request a redirection URL
|
27
|
+
|
28
|
+
def create
|
29
|
+
request = Pxpay::Request.new( id , price, options )
|
30
|
+
redirect_to request.url
|
31
|
+
end
|
32
|
+
|
33
|
+
Once your customer has entered their details Payment Express will redirect the back to the success URL that you provided. Use Pxpay:Response to get the details back from Payment Express.
|
34
|
+
|
35
|
+
def success
|
36
|
+
response = Pxpay::Response.new(params).response
|
37
|
+
hash = response.to_hash
|
38
|
+
## Do something with the results hash
|
39
|
+
end
|
40
|
+
|
41
|
+
N.B. There is a minor caveat here: Payment Express has a system called fail-proof result notification where as soon as the customer has finished the transaction they will send a background request. This means your success/failure URL will be hit at least twice for
|
42
|
+
each transaction, so you must allow for this in your code. See <http://www.paymentexpress.com/technical_resources/ecommerce_hosted/pxpay.html#ResultNotification> for details.
|
43
|
+
|
44
|
+
|
45
|
+
TODO
|
46
|
+
Add tests
|
47
|
+
Add ability to set global configuration options
|
48
|
+
Token Billing
|
49
|
+
Remove rails dependencies
|
50
|
+
|
51
|
+
This gem is as of yet untested.
|
52
|
+
|
53
|
+
This gem is in no way endorsed or affiliated with Payment Express
|
54
|
+
|
55
|
+
== Contributing to PxPay
|
56
|
+
|
57
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
58
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
59
|
+
* Fork the project
|
60
|
+
* Start a feature/bugfix branch
|
61
|
+
* Commit and push until you are happy with your contribution
|
62
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
63
|
+
* 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.
|
64
|
+
|
65
|
+
== Copyright
|
66
|
+
|
67
|
+
Copyright (c) 2011 Bradley Priest. See LICENSE.txt for
|
68
|
+
further details.
|
69
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/pxpay/base.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
module Pxpay
|
2
2
|
class Base
|
3
|
-
#
|
3
|
+
# A list of the acceptable payment currencies
|
4
|
+
# See http://www.paymentexpress.com/technical_resources/ecommerce_hosted/pxpay.html#Properties
|
4
5
|
def self.currency_types
|
5
6
|
%w( CAD CHF EUR FRF GBP HKD JPY NZD SGD USD ZAR AUD WST VUV TOP SBD PNG MYR KWD FJD )
|
6
7
|
end
|
7
|
-
|
8
|
+
|
9
|
+
# The currently returned details from Payment Express. Access with Pxpay::Base.return_details
|
8
10
|
def self.return_details
|
9
11
|
[ :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
12
|
end
|
data/lib/pxpay/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
PXPAY_CONFIG = YAML.load_file("#{Rails.root}/config/pxpay.yml")[Rails.env]
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module Pxpay
|
2
2
|
class InstallGenerator < Rails::Generators::Base
|
3
|
-
desc "Copies pxpay.yml to config
|
3
|
+
desc "Copies pxpay.yml to config"
|
4
4
|
|
5
5
|
source_root File.expand_path('../templates', __FILE__)
|
6
6
|
|
7
7
|
def copy_files
|
8
|
-
template 'pxpay.rb' ,'config/initializers/pxpay.rb'
|
9
8
|
template 'pxpay.yml' ,'config/pxpay.yml'
|
10
9
|
end
|
11
10
|
|
data/lib/pxpay/notification.rb
CHANGED
@@ -1,20 +1,27 @@
|
|
1
1
|
module Pxpay
|
2
|
+
# The return notification from Payment Express
|
2
3
|
class Notification
|
3
4
|
mattr_accessor :order_details
|
4
|
-
attr_accessor :
|
5
|
+
attr_accessor :response
|
5
6
|
|
6
7
|
def initialize(response)
|
7
|
-
@
|
8
|
-
@xml = response
|
8
|
+
@response = response
|
9
9
|
end
|
10
|
-
|
11
|
-
|
10
|
+
|
11
|
+
# Return the xml response
|
12
|
+
def to_xml
|
13
|
+
response
|
14
|
+
end
|
15
|
+
|
16
|
+
# Return the response as a hash
|
17
|
+
def to_hash
|
12
18
|
require 'nokogiri'
|
13
|
-
doc = Nokogiri::XML(response)
|
19
|
+
doc = Nokogiri::XML(self.response)
|
14
20
|
hash = {}
|
15
21
|
doc.at_css("Response").element_children.each do |attribute|
|
16
|
-
hash[attribute.name.underscore.to_sym] = attribute.inner_text
|
22
|
+
hash[attribute.name.underscore.to_sym] = attribute.inner_text
|
17
23
|
end
|
24
|
+
hash[:valid] = doc.at_css("Response")['valid']
|
18
25
|
hash
|
19
26
|
end
|
20
27
|
end
|
data/lib/pxpay/railtie.rb
CHANGED
data/lib/pxpay/request.rb
CHANGED
@@ -3,10 +3,18 @@ module Pxpay
|
|
3
3
|
|
4
4
|
attr_accessor :post
|
5
5
|
|
6
|
+
# Create a new instance of Pxpay::Request
|
7
|
+
# Pxpay::Request.new( id, amount, options = {} )
|
8
|
+
# Current available options are:
|
9
|
+
# :currency, currency for transaction, default is NZD, can be any of Pxpay::Base.currency_types
|
10
|
+
# :reference, a reference field, default is the id
|
11
|
+
# :email, email address of user, default is nil
|
12
|
+
|
6
13
|
def initialize( id , price, options = {} )
|
7
14
|
@post = build_xml( id, price, options )
|
8
15
|
end
|
9
16
|
|
17
|
+
# Get the redirect URL from Payment Express
|
10
18
|
def url
|
11
19
|
require 'rest_client'
|
12
20
|
response = ::RestClient.post("https://sec2.paymentexpress.com/pxpay/pxaccess.aspx", post )
|
@@ -15,7 +23,7 @@ module Pxpay
|
|
15
23
|
end
|
16
24
|
|
17
25
|
private
|
18
|
-
|
26
|
+
# Internal method to build the xml to send to Payment Express
|
19
27
|
def build_xml( id, price, options )
|
20
28
|
xml = Builder::XmlMarkup.new
|
21
29
|
xml.GenerateRequest do
|
data/lib/pxpay/response.rb
CHANGED
@@ -5,7 +5,8 @@ module Pxpay
|
|
5
5
|
@result = params[:result]
|
6
6
|
@user_id = params[:userid]
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
|
+
# Retrieving the transaction details from Payment Express as an instance of Pxpay::Notification
|
9
10
|
def response
|
10
11
|
require 'rest_client'
|
11
12
|
response = ::RestClient.post( 'https://www.paymentexpress.com/pxpay/pxaccess.aspx', build_xml( result ) )
|
@@ -13,6 +14,7 @@ module Pxpay
|
|
13
14
|
end
|
14
15
|
|
15
16
|
private
|
17
|
+
# Internal method to build the xml to send to Payment Express
|
16
18
|
def build_xml( result )
|
17
19
|
xml = Builder::XmlMarkup.new
|
18
20
|
|
@@ -1 +0,0 @@
|
|
1
|
-
PXPAY_CONFIG = YAML.load_file("#{Rails.root}/config/pxpay.yml")[Rails.env]
|
data/pxpay.gemspec
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{pxpay}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Bradley Priest"]
|
12
|
+
s.date = %q{2011-03-13}
|
13
|
+
s.description = %q{A Ruby wrapper around the DPS-hosted PxPay service}
|
14
|
+
s.email = %q{bradleypriest@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/pxpay.rb",
|
28
|
+
"lib/pxpay/base.rb",
|
29
|
+
"lib/pxpay/init.rb",
|
30
|
+
"lib/pxpay/install_generator.rb",
|
31
|
+
"lib/pxpay/notification.rb",
|
32
|
+
"lib/pxpay/railtie.rb",
|
33
|
+
"lib/pxpay/request.rb",
|
34
|
+
"lib/pxpay/response.rb",
|
35
|
+
"lib/pxpay/templates/pxpay.rb",
|
36
|
+
"lib/pxpay/templates/pxpay.yml",
|
37
|
+
"pxpay.gemspec",
|
38
|
+
"test/helper.rb",
|
39
|
+
"test/test_pxpay.rb"
|
40
|
+
]
|
41
|
+
s.homepage = %q{http://github.com/bradleypriest/pxpay}
|
42
|
+
s.licenses = ["MIT"]
|
43
|
+
s.require_paths = ["lib"]
|
44
|
+
s.rubygems_version = %q{1.3.7}
|
45
|
+
s.summary = %q{Ruby wrapper for the Payment Express' PxPay API}
|
46
|
+
s.test_files = [
|
47
|
+
"test/helper.rb",
|
48
|
+
"test/test_pxpay.rb"
|
49
|
+
]
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
53
|
+
s.specification_version = 3
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
57
|
+
s.add_runtime_dependency(%q<rest-client>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
59
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
61
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
62
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
63
|
+
s.add_runtime_dependency(%q<rest-client>, [">= 0"])
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
66
|
+
s.add_dependency(%q<rest-client>, [">= 0"])
|
67
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
68
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
69
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
70
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
71
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
72
|
+
s.add_dependency(%q<rest-client>, [">= 0"])
|
73
|
+
end
|
74
|
+
else
|
75
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
76
|
+
s.add_dependency(%q<rest-client>, [">= 0"])
|
77
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
78
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
79
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
80
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
81
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
82
|
+
s.add_dependency(%q<rest-client>, [">= 0"])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Bradley Priest
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-03-
|
17
|
+
date: 2011-03-13 00:00:00 +13:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -133,17 +133,18 @@ extensions: []
|
|
133
133
|
|
134
134
|
extra_rdoc_files:
|
135
135
|
- LICENSE.txt
|
136
|
-
- README.
|
136
|
+
- README.md
|
137
137
|
files:
|
138
138
|
- .document
|
139
139
|
- Gemfile
|
140
140
|
- Gemfile.lock
|
141
141
|
- LICENSE.txt
|
142
|
-
- README.
|
142
|
+
- README.md
|
143
143
|
- Rakefile
|
144
144
|
- VERSION
|
145
145
|
- lib/pxpay.rb
|
146
146
|
- lib/pxpay/base.rb
|
147
|
+
- lib/pxpay/init.rb
|
147
148
|
- lib/pxpay/install_generator.rb
|
148
149
|
- lib/pxpay/notification.rb
|
149
150
|
- lib/pxpay/railtie.rb
|
@@ -151,6 +152,7 @@ files:
|
|
151
152
|
- lib/pxpay/response.rb
|
152
153
|
- lib/pxpay/templates/pxpay.rb
|
153
154
|
- lib/pxpay/templates/pxpay.yml
|
155
|
+
- pxpay.gemspec
|
154
156
|
- test/helper.rb
|
155
157
|
- test/test_pxpay.rb
|
156
158
|
has_rdoc: true
|
@@ -167,7 +169,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
167
169
|
requirements:
|
168
170
|
- - ">="
|
169
171
|
- !ruby/object:Gem::Version
|
170
|
-
hash:
|
172
|
+
hash: 3313518574838189803
|
171
173
|
segments:
|
172
174
|
- 0
|
173
175
|
version: "0"
|
data/README.rdoc
DELETED
@@ -1,44 +0,0 @@
|
|
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
|
-
|