paypoint-blue 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +8 -0
- data/bin/console +10 -9
- data/lib/paypoint/blue/api.rb +63 -5
- data/lib/paypoint/blue/base.rb +0 -1
- data/lib/paypoint/blue/hosted.rb +27 -2
- data/lib/paypoint/blue/payload_builder.rb +14 -1
- data/lib/paypoint/blue/version.rb +1 -1
- data/lib/paypoint/blue.rb +10 -0
- data/paypoint-blue.gemspec +4 -0
- metadata +59 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 617bb51fe80f9911886c294298720bb7c150286d
|
4
|
+
data.tar.gz: 9fb48b6b0bba74eaa3e17d136c1f6e3d0f9f54df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5d26c4e5cc872308c605aa8352fc112a5d20ac5fc105f49fe3f87a0c5ab75ac372f7116a4fee7df941ea4e800e87de6922822f1ef4e86615aaa9480a6f6e2ff
|
7
|
+
data.tar.gz: f4ee41a5cb74df53e8d83e64fb69aee524ae700ccaa2c6a986891574358f9b1c5da86d5e80a8b4fab9624c68d464be261244eee60018a0596104aabe5e7cad1c
|
data/Guardfile
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
guard :minitest, all_after_pass: true do
|
2
|
+
watch(%r{^test/test_(.*)\.rb$})
|
3
|
+
watch(%r{^lib/((?:.*/)?[^/]+)\.rb$}) do |m|
|
4
|
+
test_file = "test/test_#{m[1].tr('/', '_')}.rb"
|
5
|
+
File.exists?(test_file) ? test_file : 'test'
|
6
|
+
end
|
7
|
+
watch(%r{^test/minitest_helper\.rb$}) { 'test' }
|
8
|
+
end
|
data/bin/console
CHANGED
@@ -36,7 +36,7 @@ client helpers:
|
|
36
36
|
This is most useful when using the Runscope integration. The available ids are:
|
37
37
|
|
38
38
|
:preauth_proceed, :preauth_cancel, :preauth_suspend, :preauth_suspend_replay,
|
39
|
-
:postauth_proceed, :postauth_cancel, :empty
|
39
|
+
:postauth_proceed, :postauth_cancel, :transaction, :expiry, :empty
|
40
40
|
|
41
41
|
These will return mocky.io urls which return the proper response. Using the
|
42
42
|
Runscope integration you will see the requests PayPoint makes to these endpoints
|
@@ -60,19 +60,18 @@ end
|
|
60
60
|
alias :h :help
|
61
61
|
|
62
62
|
def blue_default_options
|
63
|
-
return_base = ENV['RUNSCOPE_BUCKET'] ? "https://#{RUNSCOPE_BUCKET}.runscope.net" : "http://bluedemo.dev"
|
63
|
+
return_base = ENV['RUNSCOPE_BUCKET'] ? "https://#{ENV['RUNSCOPE_BUCKET']}.runscope.net" : "http://bluedemo.dev"
|
64
64
|
{
|
65
65
|
runscope: ENV['RUNSCOPE_BUCKET'],
|
66
66
|
defaults: {
|
67
67
|
currency: 'GBP',
|
68
68
|
commerce_type: 'ECOM',
|
69
69
|
skin: ENV['BLUE_SKIN'],
|
70
|
-
return_url: "#{return_base}/callback/return",
|
71
|
-
restore_url: "#{return_base}/callback/restore",
|
70
|
+
return_url: "#{return_base}/callback/return/%merchant_ref%",
|
72
71
|
pre_auth_callback: cb(:preauth_proceed),
|
73
72
|
post_auth_callback: cb(:postauth_proceed),
|
74
|
-
transaction_notification: cb(:
|
75
|
-
expiry_notification: cb(:
|
73
|
+
transaction_notification: cb(:transaction),
|
74
|
+
expiry_notification: cb(:expiry)
|
76
75
|
}
|
77
76
|
}
|
78
77
|
end
|
@@ -95,8 +94,10 @@ def cb(id)
|
|
95
94
|
preauth_suspend_replay: "http://www.mocky.io/v2/550f110a364506690a2a4211",
|
96
95
|
postauth_proceed: "http://www.mocky.io/v2/550f1159364506650a2a4212",
|
97
96
|
postauth_cancel: "http://www.mocky.io/v2/550f11633645066c0a2a4213",
|
97
|
+
transaction: "http://www.mocky.io/v2/550f11723645066c0a2a4214",
|
98
|
+
expiry: "http://www.mocky.io/v2/550f11723645066c0a2a4214",
|
98
99
|
empty: "http://www.mocky.io/v2/550f11723645066c0a2a4214"
|
99
|
-
}[id]
|
100
|
+
}[id] + "/#{id.to_s.split('_').first}"
|
100
101
|
end
|
101
102
|
|
102
103
|
def callbacks
|
@@ -104,8 +105,8 @@ def callbacks
|
|
104
105
|
callbacks: {
|
105
106
|
preAuthCallback: { url: cb(:preauth_proceed), format: "REST_JSON" },
|
106
107
|
postAuthCallback: { url: cb(:postauth_proceed), format: "REST_JSON" },
|
107
|
-
transactionNotification: { url: cb(:
|
108
|
-
expiryNotification: { url: cb(:
|
108
|
+
transactionNotification: { url: cb(:transaction), format: "REST_JSON" },
|
109
|
+
expiryNotification: { url: cb(:expiry), format: "REST_JSON" }
|
109
110
|
}
|
110
111
|
}
|
111
112
|
end
|
data/lib/paypoint/blue/api.rb
CHANGED
@@ -12,6 +12,7 @@ class PayPoint::Blue::API < PayPoint::Blue::Base
|
|
12
12
|
shortcut :amount, 'transaction.amount'
|
13
13
|
shortcut :currency, 'transaction.currency'
|
14
14
|
shortcut :commerce_type, 'transaction.commerce_type'
|
15
|
+
shortcut :description, 'transaction.description'
|
15
16
|
shortcut :customer_ref, 'customer.merchant_ref'
|
16
17
|
shortcut :customer_name, 'customer.display_name'
|
17
18
|
|
@@ -74,7 +75,9 @@ class PayPoint::Blue::API < PayPoint::Blue::Base
|
|
74
75
|
#
|
75
76
|
# @api_url https://developer.paypoint.com/payments/docs/#payments/capture_an_authorisation
|
76
77
|
#
|
77
|
-
# @applies_defaults
|
78
|
+
# @applies_defaults
|
79
|
+
# +:commerce_type+, +:pre_auth_callback+, +:post_auth_callback+,
|
80
|
+
# +:transaction_notification+, +:expiry_notification+
|
78
81
|
#
|
79
82
|
# @param [String] transaction_id the id of the previous transaction
|
80
83
|
# @param [Hash] payload the payload is made up of the keyword
|
@@ -82,7 +85,12 @@ class PayPoint::Blue::API < PayPoint::Blue::Base
|
|
82
85
|
#
|
83
86
|
# @return the API response
|
84
87
|
def capture_authorisation(transaction_id, **payload)
|
85
|
-
payload = build_payload(payload,
|
88
|
+
payload = build_payload(payload,
|
89
|
+
defaults: %i[
|
90
|
+
commerce_type pre_auth_callback post_auth_callback
|
91
|
+
transaction_notification expiry_notification
|
92
|
+
]
|
93
|
+
)
|
86
94
|
client.post "transactions/#{inst_id}/#{transaction_id}/capture", payload
|
87
95
|
end
|
88
96
|
|
@@ -90,13 +98,20 @@ class PayPoint::Blue::API < PayPoint::Blue::Base
|
|
90
98
|
#
|
91
99
|
# @api_url https://developer.paypoint.com/payments/docs/#payments/cancel_an_authorisation
|
92
100
|
#
|
93
|
-
# @applies_defaults
|
101
|
+
# @applies_defaults
|
102
|
+
# +:commerce_type+, +:pre_auth_callback+, +:post_auth_callback+,
|
103
|
+
# +:transaction_notification+, +:expiry_notification+
|
94
104
|
#
|
95
105
|
# @param (see #capture_authorisation)
|
96
106
|
#
|
97
107
|
# @return the API response
|
98
108
|
def cancel_authorisation(transaction_id, **payload)
|
99
|
-
payload = build_payload(payload,
|
109
|
+
payload = build_payload(payload,
|
110
|
+
defaults: %i[
|
111
|
+
commerce_type pre_auth_callback post_auth_callback
|
112
|
+
transaction_notification expiry_notification
|
113
|
+
]
|
114
|
+
)
|
100
115
|
client.post "transactions/#{inst_id}/#{transaction_id}/cancel", payload
|
101
116
|
end
|
102
117
|
|
@@ -111,6 +126,17 @@ class PayPoint::Blue::API < PayPoint::Blue::Base
|
|
111
126
|
client.get "transactions/#{inst_id}/#{transaction_id}"
|
112
127
|
end
|
113
128
|
|
129
|
+
# Get transaction details by merchant reference
|
130
|
+
#
|
131
|
+
# @api_url https://developer.paypoint.com/payments/docs/#payments/request_a_previous_transaction
|
132
|
+
#
|
133
|
+
# @param [String] merchant_ref the merchant reference for the transactions
|
134
|
+
#
|
135
|
+
# @return the API response
|
136
|
+
def transactions_by_ref(merchant_ref)
|
137
|
+
client.get "transactions/#{inst_id}/byRef?merchantRef=#{merchant_ref}"
|
138
|
+
end
|
139
|
+
|
114
140
|
# Refund a payment
|
115
141
|
#
|
116
142
|
# @api_url https://developer.paypoint.com/payments/docs/#payments/refund_a_payment
|
@@ -122,13 +148,45 @@ class PayPoint::Blue::API < PayPoint::Blue::Base
|
|
122
148
|
# @example Partial refund
|
123
149
|
# blue.refund_payment(txn_id, amount: '3.49') # assumes currency set as default
|
124
150
|
#
|
151
|
+
# @applies_defaults
|
152
|
+
# only if amount is set: +:currency+, +:commerce_type+
|
153
|
+
# @applies_defaults
|
154
|
+
# +:pre_auth_callback+, +:post_auth_callback+,
|
155
|
+
# +:transaction_notification+, +:expiry_notification+
|
156
|
+
#
|
125
157
|
# @param (see #capture_authorisation)
|
126
158
|
#
|
127
159
|
# @return the API response
|
128
160
|
def refund_payment(transaction_id, **payload)
|
129
|
-
defaults =
|
161
|
+
defaults = %i[ pre_auth_callback post_auth_callback transaction_notification expiry_notification ]
|
162
|
+
if payload[:amount] || payload[:transaction] && payload[:transaction][:amount]
|
163
|
+
defaults += %i[currency commerce_type]
|
164
|
+
end
|
130
165
|
payload = build_payload(payload, defaults: defaults)
|
131
166
|
client.post "transactions/#{inst_id}/#{transaction_id}/refund", payload
|
132
167
|
end
|
133
168
|
|
169
|
+
# Submit a payout
|
170
|
+
#
|
171
|
+
# @api_url https://developer.paypoint.com/payments/docs/#payments/submit_a_payout
|
172
|
+
#
|
173
|
+
# @applies_defaults
|
174
|
+
# +:currency+, +:commerce_type+, +:pre_auth_callback+,
|
175
|
+
# +:post_auth_callback+, +:transaction_notification+,
|
176
|
+
# +:expiry_notification+
|
177
|
+
#
|
178
|
+
# @param [Hash] payload the payload is made up of the keyword
|
179
|
+
# arguments passed to the method
|
180
|
+
#
|
181
|
+
# @return the API response
|
182
|
+
def submit_payout(**payload)
|
183
|
+
payload = build_payload(payload,
|
184
|
+
defaults: %i[
|
185
|
+
currency commerce_type pre_auth_callback post_auth_callback
|
186
|
+
transaction_notification expiry_notification
|
187
|
+
]
|
188
|
+
)
|
189
|
+
client.post "transactions/#{inst_id}/payout", payload
|
190
|
+
end
|
191
|
+
|
134
192
|
end
|
data/lib/paypoint/blue/base.rb
CHANGED
data/lib/paypoint/blue/hosted.rb
CHANGED
@@ -13,6 +13,8 @@ class PayPoint::Blue::Hosted < PayPoint::Blue::Base
|
|
13
13
|
shortcut :merchant_ref, 'transaction.merchant_reference'
|
14
14
|
shortcut :amount, 'transaction.money.amount.fixed'
|
15
15
|
shortcut :currency, 'transaction.money.currency'
|
16
|
+
shortcut :commerce_type, 'transaction.commerce_type'
|
17
|
+
shortcut :description, 'transaction.description'
|
16
18
|
shortcut :customer_ref, 'customer.identity.merchant_customer_id'
|
17
19
|
shortcut :customer_name, 'customer.details.name'
|
18
20
|
shortcut :return_url, 'session.return_url.url'
|
@@ -29,6 +31,7 @@ class PayPoint::Blue::Hosted < PayPoint::Blue::Base
|
|
29
31
|
:capture_authorisation,
|
30
32
|
:cancel_authorisation,
|
31
33
|
:transaction,
|
34
|
+
:transactions_by_ref,
|
32
35
|
:refund_payment
|
33
36
|
|
34
37
|
# The Hosted product has only a few endpoints. However, users most
|
@@ -55,7 +58,7 @@ class PayPoint::Blue::Hosted < PayPoint::Blue::Base
|
|
55
58
|
# @api_url https://developer.paypoint.com/payments/docs/#payments/make_a_payment
|
56
59
|
#
|
57
60
|
# @applies_defaults
|
58
|
-
# +:currency+, +:return_url+, +:restore_url+, +:skin+,
|
61
|
+
# +:currency+, +:commerce_type+, +:return_url+, +:restore_url+, +:skin+,
|
59
62
|
# +:pre_auth_callback+, +:post_auth_callback+, +:transaction_notification+
|
60
63
|
#
|
61
64
|
# @param [Hash] payload the payload is made up of the keyword
|
@@ -65,7 +68,7 @@ class PayPoint::Blue::Hosted < PayPoint::Blue::Base
|
|
65
68
|
def make_payment(**payload)
|
66
69
|
payload = build_payload(payload,
|
67
70
|
defaults: %i[
|
68
|
-
currency return_url restore_url skin
|
71
|
+
currency commerce_type return_url restore_url skin
|
69
72
|
pre_auth_callback post_auth_callback transaction_notification
|
70
73
|
]
|
71
74
|
)
|
@@ -89,4 +92,26 @@ class PayPoint::Blue::Hosted < PayPoint::Blue::Base
|
|
89
92
|
make_payment(**payload)
|
90
93
|
end
|
91
94
|
|
95
|
+
# Submit a payout
|
96
|
+
#
|
97
|
+
# @api_url https://developer.paypoint.com/payments/docs/#payments/submit_a_payout
|
98
|
+
#
|
99
|
+
# @applies_defaults
|
100
|
+
# +:currency+, +:commerce_type+, +:return_url+, +:restore_url+, +:skin+,
|
101
|
+
# +:pre_auth_callback+, +:post_auth_callback+, +:transaction_notification+
|
102
|
+
#
|
103
|
+
# @param [Hash] payload the payload is made up of the keyword
|
104
|
+
# arguments passed to the method
|
105
|
+
#
|
106
|
+
# @return the API response
|
107
|
+
def submit_payout(**payload)
|
108
|
+
payload = build_payload(payload,
|
109
|
+
defaults: %i[
|
110
|
+
currency commerce_type return_url restore_url skin
|
111
|
+
pre_auth_callback post_auth_callback transaction_notification
|
112
|
+
]
|
113
|
+
)
|
114
|
+
client.post "sessions/#{inst_id}/payouts", build_payload(payload)
|
115
|
+
end
|
116
|
+
|
92
117
|
end
|
@@ -42,6 +42,11 @@ module PayPoint
|
|
42
42
|
# Builds the payload by applying default values and replacing
|
43
43
|
# shortcuts
|
44
44
|
#
|
45
|
+
# @note When using the callback and notification shortcuts, the
|
46
|
+
# builder will also default their +format+ to +'REST_JSON'+,
|
47
|
+
# because the PayPoint API requires it in _some_ cases. If your
|
48
|
+
# endpoints expect XML, you won't be able to use these shortcuts.
|
49
|
+
#
|
45
50
|
# @param [Hash] payload the original payload using shortcuts
|
46
51
|
# @param [Array<Symbol>] defaults an array of symbols for defaults
|
47
52
|
# that should be applied to this payload
|
@@ -54,6 +59,10 @@ module PayPoint
|
|
54
59
|
leaf = segments.pop
|
55
60
|
leaf_parent = segments.reduce(payload) {|h,k| h[k] ||= {}}
|
56
61
|
leaf_parent[leaf] ||= value
|
62
|
+
|
63
|
+
if key =~ /_(?:callback|notification)\Z/
|
64
|
+
leaf_parent[:format] ||= "REST_JSON"
|
65
|
+
end
|
57
66
|
end
|
58
67
|
end
|
59
68
|
payload
|
@@ -66,11 +75,15 @@ module PayPoint
|
|
66
75
|
|
67
76
|
defaults.each do |key, value|
|
68
77
|
if applicable_defaults.include?(key) && !payload.has_key?(key)
|
69
|
-
payload[key] = value
|
78
|
+
payload[key] = interpolate_values(value, payload)
|
70
79
|
end
|
71
80
|
end
|
72
81
|
end
|
73
82
|
|
83
|
+
def interpolate_values(value, payload)
|
84
|
+
value.gsub(/%(\w+)%/) {|m| payload[$1.to_sym] || m}
|
85
|
+
end
|
86
|
+
|
74
87
|
end
|
75
88
|
|
76
89
|
end
|
data/lib/paypoint/blue.rb
CHANGED
@@ -20,5 +20,15 @@ module PayPoint
|
|
20
20
|
PayPoint::Blue::Hosted.new(**options)
|
21
21
|
end
|
22
22
|
|
23
|
+
# Parse a raw JSON PayPoint callback payload similarly to the
|
24
|
+
# Faraday response middlewares set up in {PayPoint::Blue::Base}.
|
25
|
+
#
|
26
|
+
# @return [Hashie::Mash] the parsed, snake_cased response
|
27
|
+
def self.parse_payload(json)
|
28
|
+
payload = JSON.parse(json.is_a?(IO) ? json.read : json.to_s)
|
29
|
+
payload = Utils.snakecase_and_symbolize_keys(payload)
|
30
|
+
Hashie::Mash.new(payload)
|
31
|
+
end
|
32
|
+
|
23
33
|
end
|
24
34
|
end
|
data/paypoint-blue.gemspec
CHANGED
@@ -26,4 +26,8 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.8"
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
28
|
spec.add_development_dependency "webmock"
|
29
|
+
spec.add_development_dependency "guard"
|
30
|
+
spec.add_development_dependency "guard-minitest"
|
31
|
+
spec.add_development_dependency "terminal-notifier-guard"
|
32
|
+
spec.add_development_dependency "terminal-notifier"
|
29
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paypoint-blue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Laszlo Bacsi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -94,6 +94,62 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard-minitest
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: terminal-notifier-guard
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: terminal-notifier
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
97
153
|
description: API client for PayPoint's 3rd generation PSP product a.k.a PayPoint Blue
|
98
154
|
email:
|
99
155
|
- lackac@lackac.hu
|
@@ -105,6 +161,7 @@ files:
|
|
105
161
|
- ".travis.yml"
|
106
162
|
- ".yardopts"
|
107
163
|
- Gemfile
|
164
|
+
- Guardfile
|
108
165
|
- LICENSE
|
109
166
|
- README.md
|
110
167
|
- Rakefile
|