payson_api 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - 1.8.7
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ guard 'test' do
2
+ watch(%r{^lib/(.+)\.rb$}) { "test" }
3
+ watch(%r{^lib/payson_api/(.+)\.rb$}) { "test" }
4
+
5
+ watch(%r{^test/unit/.+_test\.rb$}) { "test" }
6
+ watch(%r{^test/fixtures/(.+)\.yml$}) { "test" }
7
+ watch(%r{^test/integration/.+_test\.rb$}) { "test" }
8
+ watch('test/.+.rb') { "test" }
9
+ end
data/README.rdoc CHANGED
@@ -1,11 +1,11 @@
1
1
  = Payson API
2
2
 
3
- A simple utility to handle requests against the Payson payment gateway.
3
+ A simple utility to handle requests against the Payson payment gateway API.
4
4
 
5
5
 
6
6
  == Supported versions
7
7
 
8
- * Ruby 1.9.3
8
+ * Ruby 1.8.7, 1.9.2, 1.9.3
9
9
 
10
10
 
11
11
  == Install
@@ -21,11 +21,11 @@ Then bundle:
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 can configure the following default values by overriding these values using the <tt>PaysonAPI.configure</tt> method:
25
25
 
26
26
  PaysonAPI.configure do |config|
27
- config.api_user = 'XXXX'
28
- config.api_key = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
27
+ config.api_user_id = 'XXXX'
28
+ config.api_password = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
29
29
  end
30
30
 
31
31
  === Initiating a payment
@@ -74,6 +74,20 @@ You can configure the following default values by overriding these values using
74
74
  puts response.errors
75
75
  end
76
76
 
77
+
78
+ == Todo
79
+
80
+ Implement the following requests:
81
+
82
+ * PaymentDetails - Get details on a payment.
83
+ * PaymentUpdate - Update a payment.
84
+ * Validate - Validate an IPN (Instant Payment Notification).
85
+
86
+
87
+
88
+ == Build Status {<img src="https://secure.travis-ci.org/stoffus/payson_api.png"/>}[http://travis-ci.org/stoffus/payson_api]
89
+
90
+
77
91
  == Questions, Feedback
78
92
 
79
93
  Feel free to message me on Github (stoffus).
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ task :default => ["test"]
4
+
5
+ task :test do
6
+ Rake::Task['test:unit'].execute
7
+ Rake::Task['test:integration'].execute
8
+ end
9
+
10
+ namespace :test do
11
+ desc "Run unit tests"
12
+ task :unit do
13
+ Dir["test/unit/*_test.rb"].each do |path|
14
+ system "ruby -Ilib -Itest #{path}"
15
+ end
16
+ end
17
+
18
+ desc "Run integration tests"
19
+ task :integration do
20
+ Dir["test/integration/*_test.rb"].each do |path|
21
+ system "ruby -Ilib -Itest #{path}"
22
+ end
23
+ end
24
+ end
@@ -8,6 +8,12 @@ module PaysonAPI
8
8
  Response.new(response.body)
9
9
  end
10
10
 
11
+ def self.payment_details(token)
12
+ action = '/%s/%s/' % [PAYSON_API_VERSION, PAYSON_API_PAYMENT_DETAILS_ACTION]
13
+ response = post(PAYSON_API_ENDPOINT + action, { :token => token })
14
+ Response.new(response.body)
15
+ end
16
+
11
17
  private
12
18
 
13
19
  def self.post(url, data)
@@ -16,7 +16,9 @@ class PayData
16
16
  {}.tap do |hash|
17
17
  hash['returnUrl'] = @return_url
18
18
  hash['cancelUrl'] = @cancel_url
19
- hash['ipnNotificationUrl'] = @ipn_url unless @ipn_url.empty?
19
+ if @ipn_url && !@ipn_url.empty?
20
+ hash['ipnNotificationUrl'] = @ipn_url
21
+ end
20
22
  hash['memo'] = @memo
21
23
  hash['localeCode'] = LOCALES[@locale] if @locale
22
24
  hash['currencyCode'] = CURRENCIES[@currency] if @currency
@@ -1,3 +1,3 @@
1
1
  module PaysonAPI
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/payson_api.gemspec CHANGED
@@ -18,8 +18,4 @@ Gem::Specification.new do |s|
18
18
  s.require_paths = ["lib"]
19
19
 
20
20
  s.add_dependency 'httpclient'
21
-
22
- # specify any dependencies here; for example:
23
- # s.add_development_dependency "rspec"
24
- # s.add_runtime_dependency "httpclient"
25
21
  end
@@ -0,0 +1,2 @@
1
+ :api_user_id: XXXX
2
+ :api_password: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
@@ -0,0 +1,28 @@
1
+ :return_url: http://localhost/return
2
+ :cancel_url: http://localhost/cancel
3
+ :ipn_url:
4
+ :memo: Test
5
+ :receivers:
6
+ -
7
+ :email: mytest@domain.com
8
+ :amount: 123
9
+ -
10
+ :email: mytest2@domain2.com
11
+ :amount: 234
12
+ :sender:
13
+ :email: test_person@anotherdomain.com
14
+ :first_name: Test
15
+ :last_name: Person
16
+ :order_items:
17
+ -
18
+ :description: 'My order item description'
19
+ :unit_price: 1103
20
+ :quantity: 3
21
+ :tax: 0
22
+ :sku: 'MY-ITEM-1'
23
+ -
24
+ :description: 'Another order item description'
25
+ :unit_price: 242
26
+ :quantity: 2
27
+ :tax: 10
28
+ :sku: 'MY-ITEM-2'
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/unit'
4
+ require 'test_helper'
5
+ require 'payson_api'
6
+
7
+ class ConfigTest < Test::Unit::TestCase
8
+ include TestHelper
9
+
10
+ def test_ensure_expected_config
11
+ assert_equal CONFIG[:api_user_id], PaysonAPI.config.api_user_id
12
+ assert_equal CONFIG[:api_password], PaysonAPI.config.api_password
13
+ end
14
+ end
@@ -0,0 +1,80 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test/unit'
4
+ require 'test_helper'
5
+ require 'payson_api'
6
+
7
+ class PayDataTest < Test::Unit::TestCase
8
+ include TestHelper
9
+ ORDER = YAML.load_file('test/fixtures/order.yml')
10
+
11
+ def test_generated_hash_from_pay_data
12
+ sender = PaysonAPI::Sender.new(
13
+ ORDER[:sender][:email],
14
+ ORDER[:sender][:first_name],
15
+ ORDER[:sender][:last_name]
16
+ )
17
+
18
+ receivers = []
19
+ ORDER[:receivers].each do |receiver|
20
+ receivers << PaysonAPI::Receiver.new(
21
+ receiver[:email],
22
+ receiver[:amount]
23
+ )
24
+ end
25
+
26
+ pay_data = PaysonAPI::PayData.new(
27
+ ORDER[:return_url],
28
+ ORDER[:cancel_url],
29
+ ORDER[:ipn_url],
30
+ ORDER[:memo],
31
+ sender,
32
+ receivers
33
+ )
34
+
35
+ order_items = []
36
+ ORDER[:order_items].each do |order_item|
37
+ order_items << PaysonAPI::OrderItem.new(
38
+ order_item[:description],
39
+ order_item[:unit_price],
40
+ order_item[:quantity],
41
+ order_item[:tax],
42
+ order_item[:sku]
43
+ )
44
+ end
45
+
46
+ pay_data.order_items = order_items
47
+ pay_data_hash = pay_data.to_hash
48
+
49
+ assert_equal ORDER[:return_url], pay_data_hash['returnUrl']
50
+ assert_equal ORDER[:cancel_url], pay_data_hash['cancelUrl']
51
+ assert_equal ORDER[:ipn_url], pay_data_hash['ipnNotificationUrl']
52
+ assert_equal ORDER[:memo], pay_data_hash['memo']
53
+
54
+ # Ensure expected format of receiver list
55
+ receiver_format = PaysonAPI::Receiver::FORMAT_STRING
56
+ receivers.each_with_index do |receiver, index|
57
+ email = pay_data_hash[receiver_format % [index, 'email']]
58
+ amount = pay_data_hash[receiver_format % [index, 'amount']]
59
+
60
+ assert_equal receiver.email, email
61
+ assert_equal receiver.amount, amount
62
+ end
63
+
64
+ # Do same test for order items
65
+ order_item_format = PaysonAPI::OrderItem::FORMAT_STRING
66
+ order_items.each_with_index do |order_item, index|
67
+ description = pay_data_hash[order_item_format % [index, 'description']]
68
+ unit_price = pay_data_hash[order_item_format % [index, 'unitPrice']]
69
+ quantity = pay_data_hash[order_item_format % [index, 'quantity']]
70
+ tax = pay_data_hash[order_item_format % [index, 'taxPercentage']]
71
+ sku = pay_data_hash[order_item_format % [index, 'sku']]
72
+
73
+ assert_equal order_item.description, description
74
+ assert_equal order_item.unit_price, unit_price
75
+ assert_equal order_item.quantity, quantity
76
+ assert_equal order_item.tax, tax
77
+ assert_equal order_item.sku, sku
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,15 @@
1
+ require 'yaml'
2
+
3
+ module TestHelper
4
+ CONFIG = YAML.load_file('test/fixtures/config.yml')
5
+
6
+ def setup
7
+ PaysonAPI.configure do |config|
8
+ config.api_user_id = CONFIG[:api_user_id]
9
+ config.api_password = CONFIG[:api_password]
10
+ end
11
+ end
12
+
13
+ def teardown
14
+ end
15
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: payson_api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christopher Svensson
@@ -42,8 +42,11 @@ extra_rdoc_files: []
42
42
 
43
43
  files:
44
44
  - .gitignore
45
+ - .travis.yml
45
46
  - Gemfile
47
+ - Guardfile
46
48
  - README.rdoc
49
+ - Rakefile
47
50
  - lib/payson_api.rb
48
51
  - lib/payson_api/client.rb
49
52
  - lib/payson_api/config.rb
@@ -56,6 +59,11 @@ files:
56
59
  - lib/payson_api/sender.rb
57
60
  - lib/payson_api/version.rb
58
61
  - payson_api.gemspec
62
+ - test/fixtures/config.yml
63
+ - test/fixtures/order.yml
64
+ - test/integration/config_test.rb
65
+ - test/integration/pay_data_test.rb
66
+ - test/test_helper.rb
59
67
  homepage: https://github.com/stoffus/payson_api
60
68
  licenses: []
61
69
 
@@ -89,5 +97,9 @@ rubygems_version: 1.8.15
89
97
  signing_key:
90
98
  specification_version: 3
91
99
  summary: Client for Payson API
92
- test_files: []
93
-
100
+ test_files:
101
+ - test/fixtures/config.yml
102
+ - test/fixtures/order.yml
103
+ - test/integration/config_test.rb
104
+ - test/integration/pay_data_test.rb
105
+ - test/test_helper.rb