aurfy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.rspec +2 -0
- data/Gemfile +5 -0
- data/README.md +55 -0
- data/aurfy.gemspec +20 -0
- data/lib/aurfy.rb +7 -0
- data/lib/aurfy/client.rb +26 -0
- data/lib/aurfy/configure.rb +51 -0
- data/lib/aurfy/parser.rb +15 -0
- data/lib/aurfy/response.rb +31 -0
- data/lib/aurfy/version.rb +6 -0
- data/spec/aurfy/client_spec.rb +16 -0
- data/spec/aurfy/configure_spec.rb +54 -0
- data/spec/aurfy/parser_spec.rb +18 -0
- data/spec/aurfy/response_spec.rb +49 -0
- data/spec/spec_helper.rb +8 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fa8f0d82429b69e14cc73d05ca8304d710de54e2
|
4
|
+
data.tar.gz: 07ac03c1b0622e5bfe4354a4b7a4924d7378c3ff
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c7b9ef62157d025a13ddbcba071af0df6358b4bfc535a445c4c20efebbabb486dfbbc522731b085441956adb9b7176580d94d5f2b5472527918825a132caaec7
|
7
|
+
data.tar.gz: 8f04055a20aaaf89b31349a596225ba513bbaba3cf274f3ab13874551a530bbe351ea80e4adf67571456a6c928b5ca99faf5ddc18ba22349a9a74646816b2941
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# aurfy
|
2
|
+
|
3
|
+
Ruby client for [Aurfy](http://www.aurfy.com/)
|
4
|
+
|
5
|
+
Instration
|
6
|
+
----------
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'aurfy'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install aurfy
|
19
|
+
|
20
|
+
Usage
|
21
|
+
-----
|
22
|
+
|
23
|
+
```rb
|
24
|
+
merchantid = "M000000000"
|
25
|
+
trade_certificate = "D0123456789012345678901234567789"
|
26
|
+
cardnumber = "0123456789012345"
|
27
|
+
expirydate = "1701"
|
28
|
+
cv2 = "123"
|
29
|
+
cardtype = "UP"
|
30
|
+
orderamount = "100.00"
|
31
|
+
clientip = "192.168.0.1"
|
32
|
+
|
33
|
+
client = Aurfy::Client.new(
|
34
|
+
test: true,
|
35
|
+
merchantid: merchantid,
|
36
|
+
trade_certificate: trade_certificate
|
37
|
+
)
|
38
|
+
|
39
|
+
client.request(
|
40
|
+
ordercurrency: ordercurrency,
|
41
|
+
cardnumber: cardnumber,
|
42
|
+
expirydate: expirydate,
|
43
|
+
cv2: cv2,
|
44
|
+
cardtype: cardtype,
|
45
|
+
orderamount: orderamount,
|
46
|
+
clientip: clientip
|
47
|
+
)
|
48
|
+
```
|
49
|
+
|
50
|
+
Test
|
51
|
+
----
|
52
|
+
|
53
|
+
```
|
54
|
+
bundle exec rspec
|
55
|
+
```
|
data/aurfy.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'aurfy/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'aurfy'
|
6
|
+
s.version = Aurfy::VERSION
|
7
|
+
s.authors = ['Masahiro Saito']
|
8
|
+
s.email = ['camelmasa@gmail.com']
|
9
|
+
s.summary = 'Ruby client for Aurfy'
|
10
|
+
s.description = 'Ruby client for Aurfy'
|
11
|
+
s.homepage = 'https://github.com/camelmasa/aurfy'
|
12
|
+
s.license = 'MIT'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split($/)
|
15
|
+
s.require_paths = ['lib']
|
16
|
+
|
17
|
+
s.add_runtime_dependency 'faraday', '~> 0.9.0'
|
18
|
+
s.add_development_dependency "pry", "~> 0.10.0"
|
19
|
+
s.add_development_dependency 'rspec', '~> 3.0', '>= 3.0.0'
|
20
|
+
end
|
data/lib/aurfy.rb
ADDED
data/lib/aurfy/client.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Aurfy
|
2
|
+
API_URL = "https://pgw.aurfy.com/v2/api/purchase/express"
|
3
|
+
TEST_API_URL = "http://test-pgw.comconnpay.com/v2/api/purchase/express"
|
4
|
+
|
5
|
+
attr_reader :api_url
|
6
|
+
|
7
|
+
class Client
|
8
|
+
def initialize(options = {})
|
9
|
+
@api_url = (options.delete :test) ? TEST_API_URL : API_URL
|
10
|
+
configure.options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def request(options = {})
|
14
|
+
configure.options = options
|
15
|
+
|
16
|
+
result = Faraday.post @api_url, configure.params
|
17
|
+
Response.new(result)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def configure
|
23
|
+
@configure ||= Configure.new
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Aurfy
|
2
|
+
class Configure
|
3
|
+
def self.keys
|
4
|
+
[:merchantid, :orderid, :ordertime, :ordercurrency, :orderamount, :orderdescription, :txnremark1, :txnremark2,
|
5
|
+
:charset, :clientip, :version, :transtype, :website, :cardtype, :cardnumber, :cv2, :expirydate, :signmethod,
|
6
|
+
:trade_certificate]
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@charset = "UTF-8"
|
11
|
+
@ordertime = DateTime.now.strftime("%Y%m%d%H%M%S")
|
12
|
+
@orderid = DateTime.now.strftime("%Y%m%d%H%M%S%N")
|
13
|
+
@ordercurrency = "USD"
|
14
|
+
@orderdescription = ""
|
15
|
+
@signmethod = "MD5"
|
16
|
+
@transtype = "PURCHASE"
|
17
|
+
@txnremark1 = ""
|
18
|
+
@txnremark2 = ""
|
19
|
+
@version = "1.0"
|
20
|
+
@website = ""
|
21
|
+
end
|
22
|
+
|
23
|
+
def params
|
24
|
+
sorted_variables.merge({ signature: signature })
|
25
|
+
end
|
26
|
+
|
27
|
+
def options=(options = {})
|
28
|
+
options.each_pair do |key, value|
|
29
|
+
next unless Configure.keys.include? key
|
30
|
+
instance_variable_set(:"@#{key}", value)
|
31
|
+
end
|
32
|
+
options
|
33
|
+
end
|
34
|
+
|
35
|
+
def sorted_variables
|
36
|
+
instance_variables.map { |v| [v.to_s.sub("@", "").to_sym, instance_variable_get(v)] }.delete_if do
|
37
|
+
|k, _| k == :trade_certificate
|
38
|
+
end.sort.to_h
|
39
|
+
end
|
40
|
+
|
41
|
+
def signature_key
|
42
|
+
sorted_variables.delete_if { |k, _| k == :signmethod }.map {|p| "#{p.first}=#{p.last}" }.join("&") + "&#{@trade_certificate}"
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def signature
|
48
|
+
Digest::MD5.hexdigest(signature_key)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/aurfy/parser.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Aurfy
|
2
|
+
class Parser
|
3
|
+
attr_reader :body
|
4
|
+
|
5
|
+
def initialize(body)
|
6
|
+
@body = body
|
7
|
+
end
|
8
|
+
|
9
|
+
def parse
|
10
|
+
params = body.split("&").map { |p| p.split("=") }
|
11
|
+
params = params.map { |p| p.length >= 2 ? p : p.push("") }
|
12
|
+
params.to_h.each_with_object({}) { |(k, v), a| a[k.to_s.to_sym] = v }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Aurfy
|
2
|
+
class Response
|
3
|
+
attr_reader :result, :merchantid, :orderamount, :ordercurrency, :orderid, :ordertime, :respcode, :respmsg, :signature, :signmethod,
|
4
|
+
:txnid, :txnremark1, :txnremark2, :txnstatus, :txntime
|
5
|
+
|
6
|
+
def self.keys
|
7
|
+
[:merchantid, :orderamount, :ordercurrency, :orderid, :ordertime, :respcode, :respmsg, :signature, :signmethod,
|
8
|
+
:txnid, :txnremark1, :txnremark2, :txnstatus, :txntime]
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(result)
|
12
|
+
@result = result
|
13
|
+
|
14
|
+
parsed_params = Parser.new(result.body).parse
|
15
|
+
assign_variables(parsed_params)
|
16
|
+
end
|
17
|
+
|
18
|
+
def success?
|
19
|
+
respcode == "00"
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def assign_variables(params)
|
25
|
+
params.each_pair do |key, value|
|
26
|
+
next unless Response.keys.include? key
|
27
|
+
instance_variable_set(:"@#{key}", value)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Aurfy::Client do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe "#request" do
|
7
|
+
context "with valid credit card" do
|
8
|
+
it "returns successful Aurfy::Response instance" do
|
9
|
+
response = double(Faraday::Response, body: "merchantid=M000000000&orderamount=600.00&ordercurrency=USD&orderid=20150429115552415102000&ordertime=20150429115552&respcode=00&respmsg=The payment is successful.&signature=d2c4c43a7b2447d512ee3ef3c33754f4&signmethod=MD5&txnid=21150428000000006409&txnremark1=&txnremark2=&txnstatus=0&txntime=")
|
10
|
+
allow_any_instance_of(Faraday).to receive(:post) { response }
|
11
|
+
|
12
|
+
expect(subject.request).to be_a Aurfy::Response
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Aurfy::Configure do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe ".keys" do
|
7
|
+
it "returns configure keys" do
|
8
|
+
keys = [:merchantid, :orderid, :ordertime, :ordercurrency, :orderamount, :orderdescription, :txnremark1,
|
9
|
+
:txnremark2, :charset, :clientip, :version, :transtype, :website, :cardtype, :cardnumber, :cv2,
|
10
|
+
:expirydate, :signmethod, :trade_certificate]
|
11
|
+
|
12
|
+
expect(described_class.keys).to eq keys
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#params" do
|
17
|
+
it "returns configure params" do
|
18
|
+
allow(subject).to receive(:sorted_variables) { {} }
|
19
|
+
allow(subject).to receive(:signature) { "signature" }
|
20
|
+
|
21
|
+
expect(subject.params).to eq({ signature: "signature" })
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#options=" do
|
26
|
+
it "assigns variable for option" do
|
27
|
+
expect do
|
28
|
+
subject.options = { merchantid: "merchantid" }
|
29
|
+
end.to change { subject.instance_variable_get(:"@merchantid") } .from(nil).to("merchantid")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#sorted_variables" do
|
34
|
+
it "returns sorted instance variables" do
|
35
|
+
subject.options = { trade_certificate: "test", cardnumber: "0123456789012345", orderid: "orderid",
|
36
|
+
ordertime: "20150429124533" }
|
37
|
+
sorted_variables = { cardnumber: "0123456789012345", charset: "UTF-8", ordercurrency: "USD", orderdescription: "",
|
38
|
+
orderid: "orderid", ordertime: "20150429124533", signmethod: "MD5",
|
39
|
+
transtype: "PURCHASE", txnremark1: "", txnremark2: "", version: "1.0", website: "" }
|
40
|
+
|
41
|
+
expect(subject.sorted_variables).to eq(sorted_variables)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#signature_key" do
|
46
|
+
it "returns sorted instance variables" do
|
47
|
+
subject.options = { signmethod: "MD5", trade_certificate: "trade_certificate", orderid: "orderid",
|
48
|
+
ordertime: "20150429124533" }
|
49
|
+
signature_key = "charset=UTF-8&ordercurrency=USD&orderdescription=&orderid=orderid&ordertime=20150429124533&transtype=PURCHASE&txnremark1=&txnremark2=&version=1.0&website=&trade_certificate"
|
50
|
+
|
51
|
+
expect(subject.signature_key).to eq(signature_key)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Aurfy::Parser do
|
4
|
+
subject { described_class.new(body) }
|
5
|
+
let(:body) { "merchantid=M000000000&orderamount=600.00&ordercurrency=USD&orderid=20150429115552415102000&ordertime=20150429115552&respcode=00&respmsg=The payment is successful.&signature=d2c4c43a7b2447d512ee3ef3c33754f4&signmethod=MD5&txnid=21150428000000006409&txnremark1=&txnremark2=&txnstatus=0&txntime=" }
|
6
|
+
|
7
|
+
describe "#parse" do
|
8
|
+
it "returns parsed params" do
|
9
|
+
parsed_params = { merchantid: "M000000000", orderamount: "600.00", ordercurrency: "USD",
|
10
|
+
orderid: "20150429115552415102000", ordertime: "20150429115552", respcode: "00",
|
11
|
+
respmsg: "The payment is successful.", signature: "d2c4c43a7b2447d512ee3ef3c33754f4",
|
12
|
+
signmethod: "MD5", txnid: "21150428000000006409", txnremark1: "", txnremark2: "",
|
13
|
+
txnstatus: "0", txntime: "" }
|
14
|
+
|
15
|
+
expect(subject.parse).to eq parsed_params
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Aurfy::Response do
|
4
|
+
subject { described_class.new(result) }
|
5
|
+
|
6
|
+
let(:result) { double(Faraday::Response, body: "merchantid=M000000000&orderamount=600.00&ordercurrency=USD&orderid=20150429115552415102000&ordertime=20150429115552&respcode=00&respmsg=The payment is successful.&signature=d2c4c43a7b2447d512ee3ef3c33754f4&signmethod=MD5&txnid=21150428000000006409&txnremark1=&txnremark2=&txnstatus=0&txntime=") }
|
7
|
+
|
8
|
+
it "assigns params" do
|
9
|
+
expect(subject.merchantid).to eq "M000000000"
|
10
|
+
expect(subject.orderamount).to eq "600.00"
|
11
|
+
expect(subject.ordercurrency).to eq "USD"
|
12
|
+
expect(subject.orderid).to eq "20150429115552415102000"
|
13
|
+
expect(subject.ordertime).to eq "20150429115552"
|
14
|
+
expect(subject.respcode).to eq "00"
|
15
|
+
expect(subject.respmsg).to eq "The payment is successful."
|
16
|
+
expect(subject.signature).to eq "d2c4c43a7b2447d512ee3ef3c33754f4"
|
17
|
+
expect(subject.signmethod).to eq "MD5"
|
18
|
+
expect(subject.txnid).to eq "21150428000000006409"
|
19
|
+
expect(subject.txnremark1).to eq ""
|
20
|
+
expect(subject.txnremark2).to eq ""
|
21
|
+
expect(subject.txnstatus).to eq "0"
|
22
|
+
expect(subject.txntime).to eq ""
|
23
|
+
end
|
24
|
+
|
25
|
+
describe ".keys" do
|
26
|
+
it "returns response keys" do
|
27
|
+
keys = [:merchantid, :orderamount, :ordercurrency, :orderid, :ordertime, :respcode, :respmsg, :signature,
|
28
|
+
:signmethod, :txnid, :txnremark1, :txnremark2, :txnstatus, :txntime]
|
29
|
+
|
30
|
+
expect(described_class.keys).to eq keys
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#success?" do
|
35
|
+
context "with successful result" do
|
36
|
+
it "returns true" do
|
37
|
+
expect(subject.success?).to be_truthy
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "with failure result" do
|
42
|
+
let(:result) { double(Faraday::Response, body: "merchantid=M000000000&orderamount=600.00&ordercurrency=USD&orderid=20150429115552415102000&ordertime=20150429115552&respcode=97&respmsg=Internal error.&signature=d2c4c43a7b2447d512ee3ef3c33754f4&signmethod=MD5&txnid=21150428000000006409&txnremark1=&txnremark2=&txnstatus=0&txntime=") }
|
43
|
+
|
44
|
+
it "returns false" do
|
45
|
+
expect(subject.success?).to be_falsey
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aurfy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Masahiro Saito
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.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: 0.10.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 3.0.0
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '3.0'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 3.0.0
|
61
|
+
description: Ruby client for Aurfy
|
62
|
+
email:
|
63
|
+
- camelmasa@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- ".gitignore"
|
69
|
+
- ".rspec"
|
70
|
+
- Gemfile
|
71
|
+
- README.md
|
72
|
+
- aurfy.gemspec
|
73
|
+
- lib/aurfy.rb
|
74
|
+
- lib/aurfy/client.rb
|
75
|
+
- lib/aurfy/configure.rb
|
76
|
+
- lib/aurfy/parser.rb
|
77
|
+
- lib/aurfy/response.rb
|
78
|
+
- lib/aurfy/version.rb
|
79
|
+
- spec/aurfy/client_spec.rb
|
80
|
+
- spec/aurfy/configure_spec.rb
|
81
|
+
- spec/aurfy/parser_spec.rb
|
82
|
+
- spec/aurfy/response_spec.rb
|
83
|
+
- spec/spec_helper.rb
|
84
|
+
homepage: https://github.com/camelmasa/aurfy
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.4.5
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Ruby client for Aurfy
|
108
|
+
test_files: []
|