payson_api 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Guardfile +1 -1
- data/README.rdoc +2 -2
- data/lib/payson_api/client.rb +4 -7
- data/lib/payson_api/config.rb +7 -2
- data/lib/payson_api/response/payment.rb +2 -1
- data/lib/payson_api/version.rb +1 -1
- data/test/fixtures/config.yml +2 -5
- data/test/fixtures/payment_data.yml +9 -14
- data/test/integration/config_test.rb +1 -0
- data/test/integration/payment_details_test.rb +7 -10
- data/test/integration/payment_test.rb +8 -10
- data/test/test_helper.rb +3 -8
- metadata +2 -2
data/Guardfile
CHANGED
data/README.rdoc
CHANGED
@@ -14,14 +14,14 @@ Put this line in your Gemfile:
|
|
14
14
|
gem 'payson_api'
|
15
15
|
|
16
16
|
Then bundle:
|
17
|
-
|
17
|
+
$ bundle
|
18
18
|
|
19
19
|
|
20
20
|
== Usage
|
21
21
|
|
22
22
|
=== General configuration options
|
23
23
|
|
24
|
-
You
|
24
|
+
You need to configure the gem with your own Payson credentials through the <tt>PaysonAPI.configure</tt> method:
|
25
25
|
|
26
26
|
PaysonAPI.configure do |config|
|
27
27
|
config.api_user_id = 'XXXX'
|
data/lib/payson_api/client.rb
CHANGED
@@ -38,16 +38,13 @@ class Client
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def self.hash_to_params(hash)
|
41
|
-
|
42
|
-
hash.each { |k, v| out << "#{k}=#{v}&" }
|
43
|
-
out.chop
|
41
|
+
hash.map { |k, v| "#{k}=#{v}" }.join('&')
|
44
42
|
end
|
45
43
|
|
46
44
|
def self.params_to_hash(params)
|
47
45
|
{}.tap do |hash|
|
48
|
-
|
49
|
-
|
50
|
-
key, val = part.split(/=/)
|
46
|
+
params.split('&').each do |param|
|
47
|
+
key, val = param.split('=')
|
51
48
|
hash[key] = val
|
52
49
|
end
|
53
50
|
end
|
@@ -57,7 +54,7 @@ private
|
|
57
54
|
|
58
55
|
def self.payson_request(action, data)
|
59
56
|
action = '/%s/%s/' % [PAYSON_API_VERSION, action]
|
60
|
-
url = PAYSON_API_ENDPOINT + action
|
57
|
+
url = PAYSON_API_ENDPOINT % (PaysonAPI.test? ? 'test-api' : 'api') + action
|
61
58
|
headers = {
|
62
59
|
'PAYSON-SECURITY-USERID' => PaysonAPI.config.api_user_id,
|
63
60
|
'PAYSON-SECURITY-PASSWORD' => PaysonAPI.config.api_password,
|
data/lib/payson_api/config.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module PaysonAPI
|
2
2
|
extend self
|
3
3
|
|
4
|
-
PAYSON_WWW_HOST = "https
|
4
|
+
PAYSON_WWW_HOST = "https://%s.payson.se"
|
5
5
|
PAYSON_WWW_PAY_FORWARD_URL = "/paysecure/?token=%s"
|
6
6
|
|
7
|
-
PAYSON_API_ENDPOINT = "https
|
7
|
+
PAYSON_API_ENDPOINT = "https://%s.payson.se"
|
8
8
|
PAYSON_API_VERSION = "1.0"
|
9
9
|
PAYSON_API_PAY_ACTION = "Pay"
|
10
10
|
PAYSON_API_PAYMENT_DETAILS_ACTION = "PaymentDetails"
|
@@ -42,4 +42,9 @@ module PaysonAPI
|
|
42
42
|
config.api_user_id = 'XXXX'
|
43
43
|
config.api_password = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
|
44
44
|
end
|
45
|
+
|
46
|
+
def test?
|
47
|
+
@config.api_user_id == '1'
|
48
|
+
end
|
49
|
+
|
45
50
|
end
|
data/lib/payson_api/version.rb
CHANGED
data/test/fixtures/config.yml
CHANGED
@@ -4,33 +4,27 @@
|
|
4
4
|
:memo: Test
|
5
5
|
:receivers:
|
6
6
|
-
|
7
|
-
:email:
|
7
|
+
:email: test-shopper@payson.se
|
8
8
|
:amount: 123
|
9
9
|
:first_name: Test
|
10
|
-
:last_name:
|
10
|
+
:last_name: Shopper
|
11
11
|
:primary: true
|
12
|
-
-
|
13
|
-
:email: mytest2@domain2.com
|
14
|
-
:amount: 234
|
15
|
-
:first_name: Test
|
16
|
-
:last_name: Person 2
|
17
|
-
:primary: false
|
18
12
|
:sender:
|
19
|
-
:email:
|
13
|
+
:email: test-sender@payson.se
|
20
14
|
:first_name: Test
|
21
|
-
:last_name:
|
15
|
+
:last_name: Sender
|
22
16
|
:order_items:
|
23
17
|
-
|
24
18
|
:description: 'My order item description'
|
25
|
-
:unit_price:
|
19
|
+
:unit_price: 1000 * 0.8
|
26
20
|
:quantity: 3
|
27
|
-
:tax: 0
|
21
|
+
:tax: 0.25
|
28
22
|
:sku: 'MY-ITEM-1'
|
29
23
|
-
|
30
24
|
:description: 'Another order item description'
|
31
|
-
:unit_price:
|
25
|
+
:unit_price: 1500 * 0.8
|
32
26
|
:quantity: 2
|
33
|
-
:tax:
|
27
|
+
:tax: 0.25
|
34
28
|
:sku: 'MY-ITEM-2'
|
35
29
|
:fundings:
|
36
30
|
-
|
@@ -40,3 +34,4 @@
|
|
40
34
|
:fees_payer: EACHRECEIVER
|
41
35
|
:guarantee_offered: NO
|
42
36
|
:locale: SV
|
37
|
+
:currency: SEK
|
@@ -7,18 +7,15 @@ require 'payson_api'
|
|
7
7
|
class PaymentDetailsTest < Test::Unit::TestCase
|
8
8
|
include TestHelper
|
9
9
|
|
10
|
-
def
|
11
|
-
|
12
|
-
#token = 'b28c31bb-1499-4988-9fc6-fa915c287e90'
|
13
|
-
token = '4d7328b0-9883-44e3-a19d-b25cef65a3b8'
|
14
|
-
|
15
|
-
if !token
|
16
|
-
puts "Token was not received, please look into your test config"
|
17
|
-
return
|
18
|
-
end
|
10
|
+
def test_payment_details_request
|
11
|
+
token = initiate_payment.token
|
19
12
|
|
20
13
|
payment_details = PaysonAPI::Request::PaymentDetails.new(token)
|
21
14
|
response = PaysonAPI::Client.get_payment_details(payment_details)
|
22
|
-
|
15
|
+
|
16
|
+
assert response.success?
|
17
|
+
assert_equal token, response.token
|
18
|
+
assert_equal PAYMENT_DATA[:sender][:email], URI.unescape(response.sender_email)
|
19
|
+
assert_equal PAYMENT_DATA[:currency], response.currency
|
23
20
|
end
|
24
21
|
end
|
@@ -7,6 +7,13 @@ require 'payson_api'
|
|
7
7
|
class PaymentTest < Test::Unit::TestCase
|
8
8
|
include TestHelper
|
9
9
|
|
10
|
+
def test_payment_initiation
|
11
|
+
response = initiate_payment
|
12
|
+
|
13
|
+
assert response.success?
|
14
|
+
assert response.forward_url =~ /test-www/
|
15
|
+
end
|
16
|
+
|
10
17
|
def test_generated_hash_from_payment_data
|
11
18
|
setup_payment_hash(include_order_items = true)
|
12
19
|
|
@@ -14,7 +21,7 @@ class PaymentTest < Test::Unit::TestCase
|
|
14
21
|
assert_equal PAYMENT_DATA[:cancel_url], @payment_hash['cancelUrl']
|
15
22
|
assert_equal PAYMENT_DATA[:ipn_url], @payment_hash['ipnNotificationUrl']
|
16
23
|
assert_equal PAYMENT_DATA[:memo], @payment_hash['memo']
|
17
|
-
|
24
|
+
assert_equal PAYMENT_DATA[:locale], @payment_hash['localeCode']
|
18
25
|
|
19
26
|
# Ensure expected format of receiver list
|
20
27
|
receiver_format = PaysonAPI::Receiver::FORMAT_STRING
|
@@ -55,13 +62,4 @@ class PaymentTest < Test::Unit::TestCase
|
|
55
62
|
assert_equal funding.constraint, constraint
|
56
63
|
end
|
57
64
|
end
|
58
|
-
|
59
|
-
def test_payment_initiation_request
|
60
|
-
token = acquire_token
|
61
|
-
|
62
|
-
if !token
|
63
|
-
puts "Token was not received, please look into your test config"
|
64
|
-
return
|
65
|
-
end
|
66
|
-
end
|
67
65
|
end
|
data/test/test_helper.rb
CHANGED
@@ -61,19 +61,14 @@ module TestHelper
|
|
61
61
|
@payment.fees_payer = PAYMENT_DATA[:fees_payer]
|
62
62
|
@payment.locale = PAYMENT_DATA[:locale]
|
63
63
|
@payment.guarantee_offered = PAYMENT_DATA[:guarantee_offered]
|
64
|
+
@payment.currency = PAYMENT_DATA[:currency]
|
64
65
|
|
65
66
|
@payment_hash = @payment.to_hash
|
66
67
|
end
|
67
68
|
|
68
|
-
|
69
|
-
# with your personal details:
|
70
|
-
# * The api_user_id/api_password must be valid (in config.yml)
|
71
|
-
# * The receiver email must be valid for the supplied credentials
|
72
|
-
# (in payment_data.yml)
|
73
|
-
def acquire_token
|
69
|
+
def initiate_payment
|
74
70
|
setup_payment_hash
|
75
|
-
|
76
|
-
response.token
|
71
|
+
PaysonAPI::Client.initiate_payment(@payment_hash)
|
77
72
|
end
|
78
73
|
|
79
74
|
def teardown
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: payson_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|