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,52 +0,0 @@
1
- require 'cgi'
2
-
3
- module PaysonAPI
4
- class Receiver
5
- FORMAT_STRING = "receiverList.receiver(%d).%s"
6
- attr_accessor :email, :amount, :first_name, :last_name, :primary
7
-
8
- def initialize(email, amount, first_name = nil, last_name = nil, primary = true)
9
- @email = email
10
- @amount = amount
11
- @first_name = first_name
12
- @last_name = last_name
13
- @primary = primary
14
- end
15
-
16
- def self.to_hash(receivers)
17
- {}.tap do |hash|
18
- receivers.each_with_index do |receiver, index|
19
- raise "Invalid receiver" unless receiver.instance_of?(self)
20
- hash.merge!({
21
- FORMAT_STRING % [index, 'email'] => receiver.email,
22
- FORMAT_STRING % [index, 'amount'] => receiver.amount,
23
- FORMAT_STRING % [index, 'firstName'] => receiver.first_name,
24
- FORMAT_STRING % [index, 'lastName'] => receiver.last_name,
25
- FORMAT_STRING % [index, 'primary'] => receiver.primary
26
- })
27
- if receiver.first_name
28
- hash[FORMAT_STRING % [index, 'firstName']] = receiver.first_name
29
- end
30
- if receiver.last_name
31
- hash[FORMAT_STRING % [index, 'lastName']] = receiver.last_name
32
- end
33
- end
34
- end
35
- end
36
-
37
- def self.parse(data)
38
- [].tap do |receivers|
39
- i = 0
40
- while data[FORMAT_STRING % [i, 'email']]
41
- email = CGI.unescape(data[FORMAT_STRING % [i, 'email']].to_s)
42
- amount = data[FORMAT_STRING % [i, 'amount']]
43
- first_name = CGI.unescape(data[FORMAT_STRING % [i, 'firstName']].to_s)
44
- last_name = CGI.unescape(data[FORMAT_STRING % [i, 'lastName']].to_s)
45
- primary = data[FORMAT_STRING % [i, 'primary']]
46
- receivers << self.new(email, amount, first_name, last_name, primary)
47
- i += 1
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,31 +0,0 @@
1
- require 'cgi'
2
-
3
- module PaysonAPI
4
- class RemoteError
5
- attr_accessor :id, :message, :parameter
6
- FORMAT_STRING = "errorList.error(%d).%s"
7
-
8
- def initialize(id, message, parameter)
9
- @id = id
10
- @message = message
11
- @parameter = parameter
12
- end
13
-
14
- def self.parse(data)
15
- [].tap do |errors|
16
- i = 0
17
- while data[FORMAT_STRING % [i, 'errorId']]
18
- id = data[FORMAT_STRING % [i, 'errorId']]
19
- message = CGI.unescape(data[FORMAT_STRING % [i, 'message']])
20
- parameter = CGI.unescape(data[FORMAT_STRING % [i, 'parameter']])
21
- errors << self.new(id, message, parameter)
22
- i += 1
23
- end
24
- end
25
- end
26
-
27
- def to_s
28
- "ID: #{@id}, Message: #{@message}, Parameter: #{@parameter}"
29
- end
30
- end
31
- end
@@ -1,15 +0,0 @@
1
- module PaysonAPI
2
- module Request
3
- class IPN
4
- attr_accessor :data
5
-
6
- def initialize(data)
7
- @data = data
8
- end
9
-
10
- def to_s
11
- @data
12
- end
13
- end
14
- end
15
- end
@@ -1,66 +0,0 @@
1
- module PaysonAPI
2
- module Request
3
- class Payment
4
- attr_accessor :return_url, :cancel_url, :ipn_url, :memo, :sender, :receivers,
5
- :locale, :currency, :tracking_id, :invoice_fee, :order_items, :fundings,
6
- :fees_payer, :guarantee_offered
7
-
8
- def initialize(return_url, cancel_url, ipn_url, memo, sender, receivers)
9
- @return_url = return_url
10
- @cancel_url = cancel_url
11
- @ipn_url = ipn_url
12
- @memo = memo
13
- @sender = sender
14
- @receivers = receivers
15
- end
16
-
17
- def to_hash
18
- {}.tap do |hash|
19
- # Append mandatory params
20
- hash['returnUrl'] = @return_url
21
- hash['cancelUrl'] = @cancel_url
22
- hash['memo'] = @memo
23
- hash.merge!(@sender.to_hash)
24
- hash.merge!(Receiver.to_hash(@receivers))
25
-
26
- # Append optional params
27
- append_locale(hash, @locale) if @locale
28
- append_currency(hash, @currency) if @currency
29
- append_fees_payer(hash, @fees_payer) if @fees_payer
30
- append_guarantee(hash, @guarantee_offered) if @guarantee_offered
31
- hash.merge!(OrderItem.to_hash(@order_items)) if @order_items
32
- hash.merge!(Funding.to_hash(@fundings)) if @fundings
33
- hash['ipnNotificationUrl'] = @ipn_url if @ipn_url
34
- hash['invoiceFee'] = @invoice_fee if @invoice_fee
35
- hash['trackingId'] = @tracking_id if @tracking_id
36
- end
37
- end
38
-
39
- private
40
-
41
- def append_locale(hash, locale)
42
- raise "Unknown locale: #{locale}" if !LOCALES.include?(locale)
43
- hash['localeCode'] = locale
44
- end
45
-
46
- def append_currency(hash, currency)
47
- raise "Unknown currency: #{currency}" if !CURRENCIES.include?(currency)
48
- hash['currencyCode'] = currency
49
- end
50
-
51
- def append_guarantee(hash, guarantee_offered)
52
- if !GUARANTEE_OFFERINGS.include?(guarantee_offered)
53
- raise "Unknown guarantee offering: #{guarantee_offered}"
54
- end
55
- hash['guaranteeOffered'] = guarantee_offered
56
- end
57
-
58
- def append_fees_payer(hash, fees_payer)
59
- if !FEES_PAYERS.include?(fees_payer)
60
- raise "Unknown fees payer: #{fees_payer}"
61
- end
62
- hash['feesPayer'] = fees_payer
63
- end
64
- end
65
- end
66
- end
@@ -1,15 +0,0 @@
1
- module PaysonAPI
2
- module Request
3
- class PaymentDetails
4
- attr_accessor :token
5
-
6
- def initialize(token)
7
- @token = token
8
- end
9
-
10
- def to_hash
11
- { 'token' => @token }
12
- end
13
- end
14
- end
15
- end
@@ -1,22 +0,0 @@
1
- module PaysonAPI
2
- module Request
3
- class PaymentUpdate
4
- attr_accessor :token, :action
5
-
6
- def initialize(token, action)
7
- @token = token
8
- if !PAYMENT_ACTIONS.include?(action)
9
- raise "Unknown payment update action: #{action}"
10
- end
11
- @action = action
12
- end
13
-
14
- def to_hash
15
- {}.tap do |hash|
16
- hash['token'] = @token
17
- hash['action'] = @action
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,36 +0,0 @@
1
- module PaysonAPI
2
- module Response
3
- class IPN
4
- attr_accessor :purchase_id, :sender_email, :status,
5
- :payment_type, :guarantee_status, :guarantee_deadline_at,
6
- :invoice_status, :custom, :tracking_id, :receivers, :currency,
7
- :order_items, :fundings, :token, :shipping_address, :raw, :hash
8
-
9
- def initialize(raw_data)
10
- @raw = raw_data
11
- data_hash = PaysonAPI::Client.params_to_hash(raw_data)
12
- @purchase_id = data_hash['purchaseId']
13
- @payment_type = data_hash['type']
14
- @comment = data_hash['custom']
15
- @tracking_id = data_hash['trackingId']
16
- @currency = data_hash['currencyCode']
17
- @sender_email = data_hash['senderEmail']
18
- @status = data_hash['status']
19
- @token = data_hash['token']
20
- @fundings = Funding.parse(data_hash)
21
- @receivers = Receiver.parse(data_hash)
22
- @order_items = OrderItem.parse(data_hash)
23
- @hash = data_hash['HASH']
24
-
25
- case @payment_type
26
- when 'GUARANTEE'
27
- @guarantee_status = data_hash['guaranteeStatus']
28
- @guarantee_deadline_at = Time.parse(data_hash['guaranteeDeadlineTimestamp'])
29
- when 'INVOICE'
30
- @invoice_status = data_hash['invoiceStatus']
31
- @shipping_address = ShippingAddress.parse(data_hash)
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,22 +0,0 @@
1
- module PaysonAPI
2
- module Response
3
- class Payment
4
- attr_accessor :envelope, :token, :errors
5
-
6
- def initialize(data)
7
- @envelope = Envelope.parse(data)
8
- @token = data['TOKEN']
9
- @errors = RemoteError.parse(data)
10
- end
11
-
12
- def success?
13
- @envelope.ack == 'SUCCESS'
14
- end
15
-
16
- def forward_url
17
- PAYSON_WWW_HOST % (PaysonAPI.test? ? 'test-www' : 'www') +
18
- PAYSON_WWW_PAY_FORWARD_URL % @token
19
- end
20
- end
21
- end
22
- end
@@ -1,43 +0,0 @@
1
- require 'cgi'
2
-
3
- module PaysonAPI
4
- module Response
5
- class PaymentDetails
6
- attr_accessor :envelope, :purchase_id, :sender_email, :status,
7
- :payment_type, :guarantee_status, :guarantee_deadline_at,
8
- :invoice_status, :custom, :tracking_id, :receivers, :currency,
9
- :order_items, :errors, :fundings, :token, :shipping_address
10
-
11
- def initialize(data)
12
- @envelope = Envelope.parse(data)
13
- @purchase_id = data['purchaseId']
14
- @payment_type = data['type']
15
- @comment = data['custom']
16
- @tracking_id = data['trackingId']
17
- @currency = data['currencyCode']
18
- @sender_email = data['senderEmail']
19
- @status = data['status']
20
- @token = data['token']
21
- @fundings = Funding.parse(data)
22
- @receivers = Receiver.parse(data)
23
- @order_items = OrderItem.parse(data)
24
- @errors = RemoteError.parse(data)
25
-
26
- case @payment_type
27
- when 'GUARANTEE'
28
- @guarantee_status = data['guaranteeStatus']
29
- @guarantee_deadline_at = Time.parse(CGI.unescape(data['guaranteeDeadlineTimestamp']))
30
- when 'INVOICE'
31
- @invoice_status = data['invoiceStatus']
32
- if %w[ORDERCREATED SHIPPED DONE CREDITED].include?(@invoice_status)
33
- @shipping_address = ShippingAddress.parse(data)
34
- end
35
- end
36
- end
37
-
38
- def success?
39
- @envelope.ack == 'SUCCESS'
40
- end
41
- end
42
- end
43
- end
@@ -1,16 +0,0 @@
1
- module PaysonAPI
2
- module Response
3
- class PaymentUpdate
4
- attr_accessor :envelope, :errors
5
-
6
- def initialize(data)
7
- @envelope = Envelope.parse(data)
8
- @errors = RemoteError.parse(data)
9
- end
10
-
11
- def success?
12
- @envelope.ack == 'SUCCESS'
13
- end
14
- end
15
- end
16
- end
@@ -1,15 +0,0 @@
1
- module PaysonAPI
2
- module Response
3
- class Validate
4
- attr_accessor :data
5
-
6
- def initialize(data)
7
- @data = data
8
- end
9
-
10
- def verified?
11
- @data == 'VERIFIED'
12
- end
13
- end
14
- end
15
- end
@@ -1,29 +0,0 @@
1
- require 'cgi'
2
-
3
- module PaysonAPI
4
- class Sender
5
- FORMAT_STRING = "sender%s"
6
- attr_accessor :email, :first_name, :last_name
7
-
8
- def initialize(email, first_name, last_name)
9
- @email = email
10
- @first_name = first_name
11
- @last_name = last_name
12
- end
13
-
14
- def to_hash
15
- {}.tap do |hash|
16
- hash[FORMAT_STRING % 'Email'] = @email
17
- hash[FORMAT_STRING % 'FirstName'] = @first_name
18
- hash[FORMAT_STRING % 'LastName'] = @last_name
19
- end
20
- end
21
-
22
- def self.parse(data)
23
- email = data[FORMAT_STRING % 'email']
24
- first_name = CGI.unescape(data[FORMAT_STRING % 'FirstName'].to_s)
25
- last_name = CGI.unescape(data[FORMAT_STRING % 'LastName'].to_s)
26
- self.new(email, first_name, last_name)
27
- end
28
- end
29
- end
@@ -1,36 +0,0 @@
1
- require 'cgi'
2
-
3
- module PaysonAPI
4
- class ShippingAddress
5
- FORMAT_STRING = "shippingAddress.%s"
6
- attr_accessor :name, :street_address, :postal_code, :city, :country
7
-
8
- def initialize(name, street_address, postal_code, city, country)
9
- @name = name
10
- @street_address = street_address
11
- @postal_code = postal_code
12
- @city = city
13
- @country = country
14
- end
15
-
16
- def to_hash
17
- {}.tap do |hash|
18
- hash[FORMAT_STRING % 'name'] = @name
19
- hash[FORMAT_STRING % 'streetAddress'] = @street_address
20
- hash[FORMAT_STRING % 'postalCode'] = @postal_code
21
- hash[FORMAT_STRING % 'city'] = @city
22
- hash[FORMAT_STRING % 'country'] = @country
23
- end
24
- end
25
-
26
- def self.parse(data)
27
- return unless data[FORMAT_STRING % 'name']
28
- name = CGI.unescape(data[FORMAT_STRING % 'name'].to_s)
29
- street_address = CGI.unescape(data[FORMAT_STRING % 'streetAddress'].to_s)
30
- postal_code = CGI.unescape(data[FORMAT_STRING % 'postalCode'].to_s)
31
- city = CGI.unescape(data[FORMAT_STRING % 'city'].to_s)
32
- country = CGI.unescape(data[FORMAT_STRING % 'country'].to_s)
33
- self.new(name, street_address, postal_code, city, country)
34
- end
35
- end
36
- end
data/payson_api.gemspec DELETED
@@ -1,23 +0,0 @@
1
- # encoding: utf-8
2
-
3
- $:.push File.expand_path("../lib", __FILE__)
4
- require "payson_api/version"
5
-
6
- Gem::Specification.new do |s|
7
- s.name = "payson_api"
8
- s.version = PaysonAPI::VERSION
9
- s.authors = ["Christopher Svensson"]
10
- s.email = ["stoffus@stoffus.com"]
11
- s.homepage = "https://github.com/stoffus/payson_api"
12
- s.summary = %q{Client for Payson API}
13
- s.description = %q{Client that enables access to the Payson payment gateway API.}
14
- s.license = 'MIT'
15
-
16
- s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
20
-
21
- s.add_development_dependency 'rake'
22
- s.add_development_dependency 'guard-test'
23
- end