payson_api 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Guardfile CHANGED
@@ -5,5 +5,5 @@ guard 'test' do
5
5
  watch(%r{^test/unit/.+_test\.rb$}) { "test" }
6
6
  watch(%r{^test/fixtures/(.+)\.yml$}) { "test" }
7
7
  watch(%r{^test/integration/.+_test\.rb$}) { "test" }
8
- watch('test/.+\.rb') { "test" }
8
+ watch(%r{^test/.+_helper\.rb$}) { "test" }
9
9
  end
@@ -14,14 +14,14 @@ Put this line in your Gemfile:
14
14
  gem 'payson_api'
15
15
 
16
16
  Then bundle:
17
- % bundle
17
+ $ bundle
18
18
 
19
19
 
20
20
  == Usage
21
21
 
22
22
  === General configuration options
23
23
 
24
- You can configure the following default values by overriding these values using the <tt>PaysonAPI.configure</tt> method:
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'
@@ -38,16 +38,13 @@ class Client
38
38
  end
39
39
 
40
40
  def self.hash_to_params(hash)
41
- out = ""
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
- parts = params.split(/&/)
49
- parts.each do |part|
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,
@@ -1,10 +1,10 @@
1
1
  module PaysonAPI
2
2
  extend self
3
3
 
4
- PAYSON_WWW_HOST = "https://www.payson.se"
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://api.payson.se"
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
@@ -14,7 +14,8 @@ class Payment
14
14
  end
15
15
 
16
16
  def forward_url
17
- PAYSON_WWW_HOST + PAYSON_WWW_PAY_FORWARD_URL % @token
17
+ PAYSON_WWW_HOST % (PaysonAPI.test? ? 'test-www' : 'www') +
18
+ PAYSON_WWW_PAY_FORWARD_URL % @token
18
19
  end
19
20
  end
20
21
  end
@@ -1,3 +1,3 @@
1
1
  module PaysonAPI
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,5 +1,2 @@
1
- #:api_user_id: XXXX
2
- #:api_password: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
3
-
4
- :api_user_id: 13671
5
- :api_password: 305390e8-f866-41e5-a543-dc8747f545f8
1
+ :api_user_id: '1'
2
+ :api_password: 'fddb19ac-7470-42b6-a91d-072cb1495f0a'
@@ -4,33 +4,27 @@
4
4
  :memo: Test
5
5
  :receivers:
6
6
  -
7
- :email: mytest@domain.com
7
+ :email: test-shopper@payson.se
8
8
  :amount: 123
9
9
  :first_name: Test
10
- :last_name: Person 1
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: test_person@anotherdomain.com
13
+ :email: test-sender@payson.se
20
14
  :first_name: Test
21
- :last_name: Receiver
15
+ :last_name: Sender
22
16
  :order_items:
23
17
  -
24
18
  :description: 'My order item description'
25
- :unit_price: 1103
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: 242
25
+ :unit_price: 1500 * 0.8
32
26
  :quantity: 2
33
- :tax: 10
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
@@ -10,5 +10,6 @@ class ConfigTest < Test::Unit::TestCase
10
10
  def test_ensure_expected_config
11
11
  assert_equal CONFIG[:api_user_id], PaysonAPI.config.api_user_id
12
12
  assert_equal CONFIG[:api_password], PaysonAPI.config.api_password
13
+ assert PaysonAPI.test?
13
14
  end
14
15
  end
@@ -7,18 +7,15 @@ require 'payson_api'
7
7
  class PaymentDetailsTest < Test::Unit::TestCase
8
8
  include TestHelper
9
9
 
10
- def test_generated_hash_from_payment_details
11
- #token = acquire_token
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
- #p response
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
- #assert_equal PAYMENT_DATA[:locale], @payment_hash['localeCode']
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
@@ -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
- # Note that for this method to succeed you must configure the tests
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
- response = PaysonAPI::Client.initiate_payment(@payment_hash)
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.2.2
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-08-23 00:00:00.000000000 Z
12
+ date: 2012-12-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake