payson_api 0.3.3 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +5 -13
  2. data/MIT-LICENSE +16 -17
  3. data/README.md +230 -0
  4. data/lib/payson_api.rb +55 -22
  5. data/lib/payson_api/v1/client.rb +80 -0
  6. data/lib/payson_api/v1/config.rb +63 -0
  7. data/lib/payson_api/v1/envelope.rb +27 -0
  8. data/lib/payson_api/v1/errors/unknown_currency_error.rb +13 -0
  9. data/lib/payson_api/v1/errors/unknown_fees_payer_error.rb +13 -0
  10. data/lib/payson_api/v1/errors/unknown_funding_constraint_error.rb +13 -0
  11. data/lib/payson_api/v1/errors/unknown_guarantee_offering_error.rb +13 -0
  12. data/lib/payson_api/v1/errors/unknown_locale_error.rb +13 -0
  13. data/lib/payson_api/v1/errors/unknown_payment_action_error.rb +13 -0
  14. data/lib/payson_api/v1/funding.rb +38 -0
  15. data/lib/payson_api/v1/order_item.rb +43 -0
  16. data/lib/payson_api/v1/receiver.rb +46 -0
  17. data/lib/payson_api/v1/remote_error.rb +36 -0
  18. data/lib/payson_api/v1/requests/ipn.rb +19 -0
  19. data/lib/payson_api/v1/requests/payment.rb +68 -0
  20. data/lib/payson_api/v1/requests/payment_details.rb +19 -0
  21. data/lib/payson_api/v1/requests/payment_update.rb +27 -0
  22. data/lib/payson_api/v1/responses/ipn.rb +43 -0
  23. data/lib/payson_api/v1/responses/payment.rb +25 -0
  24. data/lib/payson_api/v1/responses/payment_details.rb +50 -0
  25. data/lib/payson_api/v1/responses/payment_update.rb +20 -0
  26. data/lib/payson_api/v1/responses/validate.rb +19 -0
  27. data/lib/payson_api/v1/sender.rb +28 -0
  28. data/lib/payson_api/v1/shipping_address.rb +34 -0
  29. data/lib/payson_api/v2/client.rb +69 -0
  30. data/lib/payson_api/v2/config.rb +51 -0
  31. data/lib/payson_api/v2/errors/unauthorized_error.rb +10 -0
  32. data/lib/payson_api/v2/errors/validation_error.rb +16 -0
  33. data/lib/payson_api/v2/models/account.rb +23 -0
  34. data/lib/payson_api/v2/models/checkout.rb +28 -0
  35. data/lib/payson_api/v2/models/customer.rb +27 -0
  36. data/lib/payson_api/v2/models/merchant.rb +24 -0
  37. data/lib/payson_api/v2/models/order.rb +32 -0
  38. data/lib/payson_api/v2/models/order_item.rb +33 -0
  39. data/lib/payson_api/v2/requests/create_checkout.rb +26 -0
  40. data/lib/payson_api/v2/requests/customer.rb +23 -0
  41. data/lib/payson_api/v2/requests/list_checkouts.rb +23 -0
  42. data/lib/payson_api/v2/requests/merchant.rb +25 -0
  43. data/lib/payson_api/v2/requests/order.rb +22 -0
  44. data/lib/payson_api/v2/requests/order_item.rb +27 -0
  45. data/lib/payson_api/v2/requests/update_checkout.rb +25 -0
  46. data/lib/payson_api/version.rb +3 -1
  47. metadata +76 -59
  48. data/.gitignore +0 -7
  49. data/.travis.yml +0 -6
  50. data/Gemfile +0 -11
  51. data/Guardfile +0 -9
  52. data/README.rdoc +0 -155
  53. data/Rakefile +0 -24
  54. data/lib/payson_api/client.rb +0 -79
  55. data/lib/payson_api/config.rb +0 -50
  56. data/lib/payson_api/envelope.rb +0 -21
  57. data/lib/payson_api/funding.rb +0 -34
  58. data/lib/payson_api/order_item.rb +0 -52
  59. data/lib/payson_api/receiver.rb +0 -52
  60. data/lib/payson_api/remote_error.rb +0 -31
  61. data/lib/payson_api/request/ipn.rb +0 -15
  62. data/lib/payson_api/request/payment.rb +0 -66
  63. data/lib/payson_api/request/payment_details.rb +0 -15
  64. data/lib/payson_api/request/payment_update.rb +0 -22
  65. data/lib/payson_api/response/ipn.rb +0 -36
  66. data/lib/payson_api/response/payment.rb +0 -22
  67. data/lib/payson_api/response/payment_details.rb +0 -43
  68. data/lib/payson_api/response/payment_update.rb +0 -16
  69. data/lib/payson_api/response/validate.rb +0 -15
  70. data/lib/payson_api/sender.rb +0 -29
  71. data/lib/payson_api/shipping_address.rb +0 -36
  72. data/payson_api.gemspec +0 -23
  73. data/test/fixtures/config.yml +0 -2
  74. data/test/fixtures/payment_data.yml +0 -37
  75. data/test/integration/config_test.rb +0 -15
  76. data/test/integration/payment_details_test.rb +0 -21
  77. data/test/integration/payment_test.rb +0 -65
  78. data/test/test_helper.rb +0 -76
@@ -1,2 +0,0 @@
1
- :api_user_id: '4'
2
- :api_password: '2acab30d-fe50-426f-90d7-8c60a7eb31d4'
@@ -1,37 +0,0 @@
1
- :return_url: http://localhost/return
2
- :cancel_url: http://localhost/cancel
3
- :ipn_url: http://localhost/ipn
4
- :memo: Test
5
- :receivers:
6
- -
7
- :email: test-shopper@payson.se
8
- :amount: 123
9
- :first_name: Test
10
- :last_name: Shopper
11
- :primary: true
12
- :sender:
13
- :email: test-sender@payson.se
14
- :first_name: Test
15
- :last_name: Sender
16
- :order_items:
17
- -
18
- :description: 'My order item description'
19
- :unit_price: 1000 * 0.8
20
- :quantity: 3
21
- :tax: 0.25
22
- :sku: 'MY-ITEM-1'
23
- -
24
- :description: 'Another order item description'
25
- :unit_price: 1500 * 0.8
26
- :quantity: 2
27
- :tax: 0.25
28
- :sku: 'MY-ITEM-2'
29
- :fundings:
30
- -
31
- :constraint: CREDITCARD
32
- -
33
- :constraint: BANK
34
- :fees_payer: EACHRECEIVER
35
- :guarantee_offered: NO
36
- :locale: SV
37
- :currency: SEK
@@ -1,15 +0,0 @@
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
- assert PaysonAPI.test?
14
- end
15
- end
@@ -1,21 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'test/unit'
4
- require 'test_helper'
5
- require 'payson_api'
6
-
7
- class PaymentDetailsTest < Test::Unit::TestCase
8
- include TestHelper
9
-
10
- def test_payment_details_request
11
- token = initiate_payment.token
12
-
13
- payment_details = PaysonAPI::Request::PaymentDetails.new(token)
14
- response = PaysonAPI::Client.get_payment_details(payment_details)
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
20
- end
21
- end
@@ -1,65 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'test/unit'
4
- require 'test_helper'
5
- require 'payson_api'
6
-
7
- class PaymentTest < Test::Unit::TestCase
8
- include TestHelper
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
-
17
- def test_generated_hash_from_payment_data
18
- setup_payment_hash(include_order_items = true)
19
-
20
- assert_equal PAYMENT_DATA[:return_url], @payment_hash['returnUrl']
21
- assert_equal PAYMENT_DATA[:cancel_url], @payment_hash['cancelUrl']
22
- assert_equal PAYMENT_DATA[:ipn_url], @payment_hash['ipnNotificationUrl']
23
- assert_equal PAYMENT_DATA[:memo], @payment_hash['memo']
24
- assert_equal PAYMENT_DATA[:locale], @payment_hash['localeCode']
25
-
26
- # Ensure expected format of receiver list
27
- receiver_format = PaysonAPI::Receiver::FORMAT_STRING
28
- @receivers.each_with_index do |receiver, index|
29
- email = @payment_hash[receiver_format % [index, 'email']]
30
- amount = @payment_hash[receiver_format % [index, 'amount']]
31
- first_name = @payment_hash[receiver_format % [index, 'firstName']]
32
- last_name = @payment_hash[receiver_format % [index, 'lastName']]
33
- primary = @payment_hash[receiver_format % [index, 'primary']]
34
-
35
- assert_equal receiver.email, email
36
- assert_equal receiver.amount, amount
37
- assert_equal receiver.first_name, first_name
38
- assert_equal receiver.last_name, last_name
39
- assert_equal receiver.primary, primary
40
- end
41
-
42
- # Do same test for order items
43
- order_item_format = PaysonAPI::OrderItem::FORMAT_STRING
44
- @order_items.each_with_index do |order_item, index|
45
- description = @payment_hash[order_item_format % [index, 'description']]
46
- unit_price = @payment_hash[order_item_format % [index, 'unitPrice']]
47
- quantity = @payment_hash[order_item_format % [index, 'quantity']]
48
- tax = @payment_hash[order_item_format % [index, 'taxPercentage']]
49
- sku = @payment_hash[order_item_format % [index, 'sku']]
50
-
51
- assert_equal order_item.description, description
52
- assert_equal order_item.unit_price, unit_price
53
- assert_equal order_item.quantity, quantity
54
- assert_equal order_item.tax, tax
55
- assert_equal order_item.sku, sku
56
- end
57
-
58
- # Ensure expected format of fundings list
59
- funding_format = PaysonAPI::Funding::FORMAT_STRING
60
- @fundings.each_with_index do |funding, index|
61
- constraint = @payment_hash[funding_format % [index, 'constraint']]
62
- assert_equal funding.constraint, constraint
63
- end
64
- end
65
- end
data/test/test_helper.rb DELETED
@@ -1,76 +0,0 @@
1
- require 'yaml'
2
-
3
- module TestHelper
4
- CONFIG = YAML.load_file('test/fixtures/config.yml')
5
- PAYMENT_DATA = YAML.load_file('test/fixtures/payment_data.yml')
6
-
7
- def setup
8
- PaysonAPI.configure do |config|
9
- config.api_user_id = CONFIG[:api_user_id]
10
- config.api_password = CONFIG[:api_password]
11
- end
12
- end
13
-
14
- def setup_payment_hash(include_order_items = false)
15
- @sender = PaysonAPI::Sender.new(
16
- PAYMENT_DATA[:sender][:email],
17
- PAYMENT_DATA[:sender][:first_name],
18
- PAYMENT_DATA[:sender][:last_name]
19
- )
20
-
21
- @receivers = []
22
- PAYMENT_DATA[:receivers].each do |receiver|
23
- @receivers << PaysonAPI::Receiver.new(
24
- receiver[:email],
25
- receiver[:amount],
26
- receiver[:first_name],
27
- receiver[:last_name],
28
- receiver[:primary]
29
- )
30
- end
31
-
32
- @payment = PaysonAPI::Request::Payment.new(
33
- PAYMENT_DATA[:return_url],
34
- PAYMENT_DATA[:cancel_url],
35
- PAYMENT_DATA[:ipn_url],
36
- PAYMENT_DATA[:memo],
37
- @sender,
38
- @receivers
39
- )
40
-
41
- @order_items = []
42
- PAYMENT_DATA[:order_items].each do |order_item|
43
- @order_items << PaysonAPI::OrderItem.new(
44
- order_item[:description],
45
- order_item[:unit_price],
46
- order_item[:quantity],
47
- order_item[:tax],
48
- order_item[:sku]
49
- )
50
- end
51
-
52
- @fundings = []
53
- PAYMENT_DATA[:fundings].each do |funding|
54
- @fundings << PaysonAPI::Funding.new(
55
- funding[:constraint]
56
- )
57
- end
58
-
59
- @payment.order_items = @order_items if include_order_items
60
- @payment.fundings = @fundings
61
- @payment.fees_payer = PAYMENT_DATA[:fees_payer]
62
- @payment.locale = PAYMENT_DATA[:locale]
63
- @payment.guarantee_offered = PAYMENT_DATA[:guarantee_offered]
64
- @payment.currency = PAYMENT_DATA[:currency]
65
-
66
- @payment_hash = @payment.to_hash
67
- end
68
-
69
- def initiate_payment
70
- setup_payment_hash
71
- PaysonAPI::Client.initiate_payment(@payment_hash)
72
- end
73
-
74
- def teardown
75
- end
76
- end