paysimple-ruby 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a26074b9683b716e2a6db729e0859d11d32179f8
4
- data.tar.gz: e94335c05375789b558572bbeba8570fccc2effc
3
+ metadata.gz: fb3367f2302103d5d06aa6c4c11359d45042a677
4
+ data.tar.gz: 8be13c5c7af22787762cfc642c7d4ebdd1dad67a
5
5
  SHA512:
6
- metadata.gz: 0ce84fc7b7c3124b35b2d83f7608f6ebec246cf54401b9cf4878f3f46b1f21ea4d1a7a3ef955471e07715e6bbd1777c16f3687c09ca5e09c4b3533bb6f1e0256
7
- data.tar.gz: 6495fbca110a86add9be0c8bfcd0294391459afd15d966d80c6b55169f6609524c72633e963c47718b3c7ed4816aae96f53b540d3993706f8f87815a4e4883f8
6
+ metadata.gz: 938547ea35e75a7616adaddb6ed9bc0d51c65d0c526eb3fb172a3fdddacd05dd3cdeffd1a944f865ada7bf7333d4f4aef4ee5f2888c387b2cf96b614880d9249
7
+ data.tar.gz: b427840135611f8bd9f1cf61d97d2f17a1767e641e074de2774dc8bf5720fdcfd2a235b94a29948d1f2ff926c3cd36964be660dbb3f420d175cf177bff77b521
data/.gitignore CHANGED
@@ -1,11 +1,12 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- .idea/
11
- .env
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea/
11
+ .env
12
+ *.gem
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --format documentation
2
- --color
1
+ --format documentation
2
+ --color
@@ -1,3 +1,3 @@
1
- language: ruby
2
- rvm:
3
- - 2.0.0
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source 'https://rubygems.org'
2
- gemspec
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015 Konstantin Lebedev
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Konstantin Lebedev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -0,0 +1,106 @@
1
+ # Ruby client library for Paysimple API v4.0
2
+
3
+ Ruby client to interact with [PaySimple] API. Detailed API documentation can be found here: [documentation]
4
+
5
+ ## Installation
6
+
7
+ Execute this command:
8
+
9
+ ```ruby
10
+ gem install 'paysimple-ruby'
11
+ ```
12
+
13
+ If you're using Rails, simply add this to your `Gemfile` :
14
+
15
+ ```ruby
16
+ gem 'paysimple-ruby'
17
+ ```
18
+
19
+ ## Configuration
20
+
21
+ Initialize Paysimple client with user id and access token:
22
+
23
+ ```ruby
24
+ require 'paysimple'
25
+ Paysimple.api_user = '<your api username>'
26
+ Paysimple.api_key = '<your api key>
27
+ ```
28
+
29
+ By default the library will try to connect to the production endpoint. You can customize this behavior by specifying API endpoint explicitly:
30
+
31
+ ```ruby
32
+ Paysimple.api_endpoint = Paysimple::Endpoint::PRODUCTION
33
+ ```
34
+
35
+ or
36
+
37
+ ```ruby
38
+ Paysimple.api_endpoint = Paysimple::Endpoint::SANDBOX
39
+ ```
40
+
41
+ ## Usage examples
42
+
43
+ ###Customer
44
+
45
+ ```ruby
46
+ # create new customer
47
+ customer = Paysimple::Customer.create({ first_name: 'John', last_name: 'Doe' })
48
+
49
+ # update customer
50
+ updated_customer = Paysimple::Customer.update({ id: customer[:id], first_name: 'John', last_name: 'Smith' })
51
+
52
+ # get customer by ID
53
+ customer = Paysimple::Customer.get(customer[:id])
54
+
55
+ # find customers
56
+ customers = Paysimple::Customer.find({ page: 1, page_size: 10, company: 'ABC company' })
57
+
58
+ # get customer's payments and payment schedules
59
+ payments = Paysimple::Customer.payments(customer[:id], { page_size: 5 })
60
+ payment_schedules = Paysimple::Customer.payment_schedules(customer[:id], { page_size: 5 })
61
+
62
+ # delete customer
63
+ Paysimple::Customer.delete(customer[:id])
64
+ ```
65
+
66
+ ### CreditCard
67
+
68
+ ```ruby
69
+ # create credit card
70
+ credit_card = Paysimple::CreditCard.create({
71
+ customer_id: customer[:id],
72
+ credit_card_number: '4111111111111111',
73
+ expiration_date: '12/2021',
74
+ billing_zip_code: '80202',
75
+ issuer: Issuer::VISA,
76
+ is_default: true
77
+ })
78
+
79
+ # update credit card
80
+ updated_credit_card = Paysimple::CreditCard.update({ id: credit_card[:id], ... })
81
+
82
+ # delete credit card
83
+ Paysimple::CreditCard.delete(credit_card[:id])
84
+ ```
85
+
86
+ ###Payment
87
+
88
+ ```ruby
89
+ # create payment
90
+ payment = Paysimple::Payment.create({ amount: 100, account_id: credit_card[:id] })
91
+
92
+ # get payment
93
+ payment = Paysimple::Payment.get(payment[:id])
94
+
95
+ # void payment
96
+ Paysimple::Payment.void(payment[:id])
97
+
98
+ # refund payment
99
+ Paysimple::Payment.refund(payment[:id])
100
+
101
+ # find payments
102
+ payments = Paysimple::Payment.find({ status: 'authorized', page_size: 10 })
103
+ ```
104
+
105
+ [PaySimple]:http://www.paysimple.com
106
+ [documentation]:http://developer.paysimple.com/documentation/
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
- require "bundler/gem_tasks"
2
-
1
+ require "bundler/gem_tasks"
2
+
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "paysimple"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "paysimple"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup CHANGED
@@ -1,7 +1,7 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -1,152 +1,162 @@
1
- require 'time'
2
- require 'digest'
3
- require 'base64'
4
-
5
- require 'rest-client'
6
- require 'json'
7
-
8
- # Common
9
- require 'paysimple/version'
10
- require 'paysimple/endpoint'
11
- require 'paysimple/util'
12
-
13
- # Resources
14
- require 'paysimple/resources/customer'
15
- require 'paysimple/resources/credit_card'
16
- require 'paysimple/resources/ach'
17
- require 'paysimple/resources/payment'
18
-
19
- # Errors
20
- require 'paysimple/errors/paysimple_error'
21
- require 'paysimple/errors/api_connection_error'
22
- require 'paysimple/errors/api_error'
23
- require 'paysimple/errors/invalid_request_error'
24
- require 'paysimple/errors/authentication_error'
25
-
26
- module Paysimple
27
-
28
- @api_endpoint = Endpoint::PRODUCTION
29
-
30
- class << self
31
- attr_accessor :api_key, :api_user, :api_endpoint
32
- end
33
-
34
- def self.request(method, url, params={})
35
-
36
- raise AuthenticationError.new('API key is not provided.') unless @api_key
37
- raise AuthenticationError.new('API user is not provided.') unless @api_user
38
-
39
- url = api_url(url)
40
- case method
41
- when :get, :head
42
- url += "#{URI.parse(url).query ? '&' : '?'}#{uri_encode(params)}" if params && params.any?
43
- payload = nil
44
- when :delete
45
- payload = nil
46
- else
47
- payload = Util.camelize_and_symbolize_keys(params).to_json
48
- end
49
-
50
- request_opts = { headers: request_headers, method: method, open_timeout: 30,
51
- payload: payload, url: url, timeout: 80 }
52
-
53
- begin
54
- response = execute_request(request_opts)
55
- rescue SocketError => e
56
- handle_restclient_error(e)
57
- rescue RestClient::ExceptionWithResponse => e
58
- if rcode = e.http_code and rbody = e.http_body
59
- handle_api_error(rcode, rbody)
60
- else
61
- handle_restclient_error(e)
62
- end
63
- rescue RestClient::Exception, Errno::ECONNREFUSED => e
64
- handle_restclient_error(e)
65
- end
66
-
67
- parse(response)
68
- end
69
-
70
- def self.api_url(url='')
71
- @api_endpoint + '/v4' + url
72
- end
73
-
74
- def self.execute_request(opts)
75
- RestClient::Request.execute(opts)
76
- end
77
-
78
- def self.request_headers
79
- {
80
- authorization: authorization_header,
81
- content_type: :json,
82
- accept: :json
83
- }
84
- end
85
-
86
- def self.uri_encode(params)
87
- Util.flatten_params(params).map { |k,v| "#{k}=#{Util.url_encode(v)}" }.join('&')
88
- end
89
-
90
- def self.parse(response)
91
- if response.body.empty?
92
- {}
93
- else
94
- response = JSON.parse(response.body)
95
- Util.underscore_and_symbolize_names(response)[:response]
96
- end
97
- rescue JSON::ParserError
98
- raise general_api_error(response.code, response.body)
99
- end
100
-
101
- def self.general_api_error(rcode, rbody)
102
- APIError.new("Invalid response object from API: #{rbody.inspect} " +
103
- "(HTTP response code was #{rcode})", rcode, rbody)
104
- end
105
-
106
- def self.authorization_header
107
- utc_timestamp = Time.now.getutc.iso8601.encode(Encoding::UTF_8)
108
- secret_key = @api_key.encode(Encoding::UTF_8)
109
- hash = OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'), secret_key, utc_timestamp)
110
- signature = Base64.encode64(hash)
111
-
112
- "PSSERVER accessid=#{@api_user}; timestamp=#{utc_timestamp}; signature=#{signature}"
113
- end
114
-
115
- def self.handle_api_error(rcode, rbody)
116
- begin
117
- error_obj = rbody.empty? ? {} : Util.underscore_and_symbolize_names(JSON.parse(rbody))
118
- rescue JSON::ParserError
119
- raise general_api_error(rcode, rbody)
120
- end
121
-
122
- case rcode
123
- when 400, 404
124
- error = error_obj[:meta][:errors][:error_messages].collect { |e| e[:message]}
125
- raise InvalidRequestError.new(error, nil, rcode, rbody, error_obj)
126
- when 401
127
- raise AuthenticationError.new(error, rcode, rbody, error_obj)
128
- else
129
- raise APIError.new(error, rcode, rbody, error_obj)
130
- end
131
- end
132
-
133
- def self.handle_restclient_error(e, api_base_url=nil)
134
- connection_message = 'Please check your internet connection and try again.'
135
-
136
- case e
137
- when RestClient::RequestTimeout
138
- message = "Could not connect to Paysimple (#{@api_endpoint}). #{connection_message}"
139
- when RestClient::ServerBrokeConnection
140
- message = "The connection to the server (#{@api_endpoint}) broke before the " \
141
- "request completed. #{connection_message}"
142
- when SocketError
143
- message = 'Unexpected error communicating when trying to connect to Paysimple. ' \
144
- 'You may be seeing this message because your DNS is not working. '
145
- else
146
- message = 'Unexpected error communicating with Paysimple. '
147
- end
148
-
149
- raise APIConnectionError.new(message + "\n\n(Network error: #{e.message})")
150
- end
151
-
1
+ require 'time'
2
+ require 'digest'
3
+ require 'base64'
4
+
5
+ require 'rest-client'
6
+ require 'json'
7
+
8
+ # Common
9
+ require 'paysimple/version'
10
+ require 'paysimple/endpoint'
11
+ require 'paysimple/util'
12
+
13
+ # Enumerations
14
+ require 'paysimple/enumerations/issuer'
15
+ require 'paysimple/enumerations/payment_type'
16
+ require 'paysimple/enumerations/payment_sub_type'
17
+ require 'paysimple/enumerations/schedule_status'
18
+ require 'paysimple/enumerations/payment_status'
19
+ require 'paysimple/enumerations/execution_frequency_type'
20
+
21
+ # Resources
22
+ require 'paysimple/resources/customer'
23
+ require 'paysimple/resources/credit_card'
24
+ require 'paysimple/resources/ach'
25
+ require 'paysimple/resources/payment'
26
+ require 'paysimple/resources/recurring_payment'
27
+ require 'paysimple/resources/payment_plan'
28
+
29
+ # Errors
30
+ require 'paysimple/errors/paysimple_error'
31
+ require 'paysimple/errors/api_connection_error'
32
+ require 'paysimple/errors/api_error'
33
+ require 'paysimple/errors/invalid_request_error'
34
+ require 'paysimple/errors/authentication_error'
35
+
36
+ module Paysimple
37
+
38
+ @api_endpoint = Endpoint::PRODUCTION
39
+
40
+ class << self
41
+ attr_accessor :api_key, :api_user, :api_endpoint
42
+ end
43
+
44
+ def self.request(method, url, params={})
45
+
46
+ raise AuthenticationError.new('API key is not provided.') unless @api_key
47
+ raise AuthenticationError.new('API user is not provided.') unless @api_user
48
+
49
+ url = api_url(url)
50
+ case method
51
+ when :get, :head
52
+ url += "#{URI.parse(url).query ? '&' : '?'}#{uri_encode(params)}" if params && params.any?
53
+ payload = nil
54
+ when :delete
55
+ payload = nil
56
+ else
57
+ payload = Util.camelize_and_symbolize_keys(params).to_json
58
+ end
59
+
60
+ request_opts = { headers: request_headers, method: method, open_timeout: 30,
61
+ payload: payload, url: url, timeout: 80 }
62
+
63
+ begin
64
+ response = execute_request(request_opts)
65
+ rescue SocketError => e
66
+ handle_restclient_error(e)
67
+ rescue RestClient::ExceptionWithResponse => e
68
+ if rcode = e.http_code and rbody = e.http_body
69
+ handle_api_error(rcode, rbody)
70
+ else
71
+ handle_restclient_error(e)
72
+ end
73
+ rescue RestClient::Exception, Errno::ECONNREFUSED => e
74
+ handle_restclient_error(e)
75
+ end
76
+
77
+ parse(response)
78
+ end
79
+
80
+ def self.api_url(url='')
81
+ @api_endpoint + '/v4' + url
82
+ end
83
+
84
+ def self.execute_request(opts)
85
+ RestClient::Request.execute(opts)
86
+ end
87
+
88
+ def self.request_headers
89
+ {
90
+ authorization: authorization_header,
91
+ content_type: :json,
92
+ accept: :json
93
+ }
94
+ end
95
+
96
+ def self.uri_encode(params)
97
+ Util.flatten_params(params).map { |k,v| "#{k}=#{Util.url_encode(v)}" }.join('&')
98
+ end
99
+
100
+ def self.parse(response)
101
+ if response.body.empty?
102
+ {}
103
+ else
104
+ response = JSON.parse(response.body)
105
+ Util.underscore_and_symbolize_names(response)[:response]
106
+ end
107
+ rescue JSON::ParserError
108
+ raise general_api_error(response.code, response.body)
109
+ end
110
+
111
+ def self.general_api_error(rcode, rbody)
112
+ APIError.new("Invalid response object from API: #{rbody.inspect} " +
113
+ "(HTTP response code was #{rcode})", rcode, rbody)
114
+ end
115
+
116
+ def self.authorization_header
117
+ utc_timestamp = Time.now.getutc.iso8601.encode(Encoding::UTF_8)
118
+ secret_key = @api_key.encode(Encoding::UTF_8)
119
+ hash = OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha256'), secret_key, utc_timestamp)
120
+ signature = Base64.encode64(hash)
121
+
122
+ "PSSERVER accessid=#{@api_user}; timestamp=#{utc_timestamp}; signature=#{signature}"
123
+ end
124
+
125
+ def self.handle_api_error(rcode, rbody)
126
+ begin
127
+ error_obj = rbody.empty? ? {} : Util.underscore_and_symbolize_names(JSON.parse(rbody))
128
+ rescue JSON::ParserError
129
+ raise general_api_error(rcode, rbody)
130
+ end
131
+
132
+ case rcode
133
+ when 400, 404
134
+ errors = error_obj[:meta][:errors][:error_messages].collect { |e| e[:message]}
135
+ raise InvalidRequestError.new(errors, rcode, rbody, error_obj)
136
+ when 401
137
+ raise AuthenticationError.new(error, rcode, rbody, error_obj)
138
+ else
139
+ raise APIError.new(error, rcode, rbody, error_obj)
140
+ end
141
+ end
142
+
143
+ def self.handle_restclient_error(e, api_base_url=nil)
144
+ connection_message = 'Please check your internet connection and try again.'
145
+
146
+ case e
147
+ when RestClient::RequestTimeout
148
+ message = "Could not connect to Paysimple (#{@api_endpoint}). #{connection_message}"
149
+ when RestClient::ServerBrokeConnection
150
+ message = "The connection to the server (#{@api_endpoint}) broke before the " \
151
+ "request completed. #{connection_message}"
152
+ when SocketError
153
+ message = 'Unexpected error communicating when trying to connect to Paysimple. ' \
154
+ 'You may be seeing this message because your DNS is not working. '
155
+ else
156
+ message = 'Unexpected error communicating with Paysimple. '
157
+ end
158
+
159
+ raise APIConnectionError.new(message + "\n\n(Network error: #{e.message})")
160
+ end
161
+
152
162
  end
@@ -0,0 +1,16 @@
1
+ module Paysimple
2
+ class ExecutionFrequencyType
3
+
4
+ DAILY = 1
5
+ WEEKLY = 2
6
+ BIWEEKLY = 3
7
+ FIRST_OF_MONTH = 4
8
+ SPECIFIC_DAY_OF_MONTH = 5
9
+ LAST_OF_MONTH = 6
10
+ QUARTERLY = 7
11
+ SEMI_ANNUALLY = 8
12
+ ANNUALLY = 9
13
+
14
+ end
15
+ end
16
+
@@ -0,0 +1,10 @@
1
+ module Paysimple
2
+ class Issuer
3
+
4
+ VISA = 12
5
+ MASTER_CARD = 13
6
+ AMERICAN_EXPRESS = 14
7
+ DISCOVER = 15
8
+
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ module Paysimple
2
+ class PaymentStatus
3
+
4
+ PENDING = 0
5
+ POSTED = 1
6
+ SETTLED = 2
7
+ FAILED = 3
8
+ VOIDED = 5
9
+ REVERSED = 6
10
+ REVERSE_POSTED = 9
11
+ CHARGEBACK = 10
12
+ AUTHORIZED = 12
13
+ RETURNED = 13
14
+ REVERSE_NSF = 15
15
+ REFUND_SETTLED = 17
16
+
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module Paysimple
2
+ class PaymentSubType
3
+
4
+ # ACH
5
+ WEB = 4
6
+ TEL = 5
7
+ PPD = 6
8
+ CCD = 7
9
+
10
+ # CC
11
+ SWIPE = 10
12
+ MOTO = 11
13
+
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ module Paysimple
2
+ class PaymentType
3
+
4
+ CREDIT_CARD = 1
5
+ ACH = 2
6
+
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ module Paysimple
2
+ class ScheduleStatus
3
+
4
+ ACTIVE = 1
5
+ PAUSE_UNTIL = 2
6
+ EXPIRED = 3
7
+ SUSPENDED = 4
8
+
9
+ end
10
+ end
@@ -1,12 +1,6 @@
1
1
  module Paysimple
2
2
 
3
3
  class InvalidRequestError < PaysimpleError
4
- attr_accessor :param
5
-
6
- def initialize(message, param, http_status=nil, http_body=nil, json_body=nil)
7
- super(message, http_status, http_body, json_body)
8
- @param = param
9
- end
10
4
  end
11
5
 
12
6
  end
@@ -1,23 +1,23 @@
1
- module Paysimple
2
- class CreditCard
3
-
4
- def self.create(opts)
5
- Paysimple.request(:post, url, opts)
6
- end
7
-
8
- def self.update(opts)
9
- Paysimple.request(:put, url, opts)
10
- end
11
-
12
- def self.delete(id)
13
- Paysimple.request(:delete, "#{url}/#{id}")
14
- end
15
-
16
- protected
17
-
18
- def self.url
19
- '/account/creditcard'
20
- end
21
-
22
- end
1
+ module Paysimple
2
+ class CreditCard
3
+
4
+ def self.create(opts)
5
+ Paysimple.request(:post, url, opts)
6
+ end
7
+
8
+ def self.update(opts)
9
+ Paysimple.request(:put, url, opts)
10
+ end
11
+
12
+ def self.delete(id)
13
+ Paysimple.request(:delete, "#{url}/#{id}")
14
+ end
15
+
16
+ protected
17
+
18
+ def self.url
19
+ '/account/creditcard'
20
+ end
21
+
22
+ end
23
23
  end
@@ -1,23 +1,39 @@
1
- module Paysimple
2
- class Customer
3
-
4
- def self.create(opts)
5
- Paysimple.request(:post, url, opts)
6
- end
7
-
8
- def self.update(opts)
9
- Paysimple.request(:put, url, opts)
10
- end
11
-
12
- def self.delete(id)
13
- Paysimple.request(:delete, "#{url}/#{id}")
14
- end
15
-
16
- protected
17
-
18
- def self.url
19
- '/customer'
20
- end
21
-
22
- end
1
+ module Paysimple
2
+ class Customer
3
+
4
+ def self.create(opts)
5
+ Paysimple.request(:post, url, opts)
6
+ end
7
+
8
+ def self.update(opts)
9
+ Paysimple.request(:put, url, opts)
10
+ end
11
+
12
+ def self.delete(id)
13
+ Paysimple.request(:delete, "#{url}/#{id}")
14
+ end
15
+
16
+ def self.get(id)
17
+ Paysimple.request(:get, "#{url}/#{id}")
18
+ end
19
+
20
+ def self.find(opts)
21
+ Paysimple.request(:get, url, opts)
22
+ end
23
+
24
+ def self.payments(id, opts)
25
+ Paysimple.request(:get, "#{url}/#{id}/payments", opts)
26
+ end
27
+
28
+ def self.payment_schedules(id, opts)
29
+ Paysimple.request(:get, "#{url}/#{id}/paymentschedules", opts)
30
+ end
31
+
32
+ protected
33
+
34
+ def self.url
35
+ '/customer'
36
+ end
37
+
38
+ end
23
39
  end
@@ -13,6 +13,14 @@ module Paysimple
13
13
  Paysimple.request(:get, "#{url}/#{id}")
14
14
  end
15
15
 
16
+ def self.find(opts)
17
+ Paysimple.request(:get, url, opts)
18
+ end
19
+
20
+ def self.refund(id)
21
+ Paysimple.request(:put, "#{url}/#{id}/reverse")
22
+ end
23
+
16
24
  protected
17
25
 
18
26
  def self.url
@@ -0,0 +1,39 @@
1
+ module Paysimple
2
+ class PaymentPlan
3
+
4
+ def self.create(opts)
5
+ Paysimple.request(:post, url, opts)
6
+ end
7
+
8
+ def self.get(id)
9
+ Paysimple.request(:get, "#{url}/#{id}")
10
+ end
11
+
12
+ def self.suspend(id)
13
+ Paysimple.request(:put, "#{url}/#{id}/suspend")
14
+ end
15
+
16
+ def self.resume(id)
17
+ Paysimple.request(:put, "#{url}/#{id}/resume")
18
+ end
19
+
20
+ def self.delete(id)
21
+ Paysimple.request(:delete, "#{url}/#{id}")
22
+ end
23
+
24
+ def self.payments(id)
25
+ Paysimple.request(:get, "#{url}/#{id}/payments")
26
+ end
27
+
28
+ def self.find(opts)
29
+ Paysimple.request(:get, url, opts)
30
+ end
31
+
32
+ protected
33
+
34
+ def self.url
35
+ '/paymentplan'
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ module Paysimple
2
+ class RecurringPayment
3
+
4
+ def self.create(opts)
5
+ Paysimple.request(:post, url, opts)
6
+ end
7
+
8
+ def self.get(id)
9
+ Paysimple.request(:get, "#{url}/#{id}")
10
+ end
11
+
12
+ def self.suspend(id)
13
+ Paysimple.request(:put, "#{url}/#{id}/suspend")
14
+ end
15
+
16
+ def self.resume(id)
17
+ Paysimple.request(:put, "#{url}/#{id}/resume")
18
+ end
19
+
20
+ def self.delete(id)
21
+ Paysimple.request(:delete, "#{url}/#{id}")
22
+ end
23
+
24
+ def self.payments(id)
25
+ Paysimple.request(:get, "#{url}/#{id}/payments")
26
+ end
27
+
28
+ def self.find(opts)
29
+ Paysimple.request(:get, url, opts)
30
+ end
31
+
32
+ protected
33
+
34
+ def self.url
35
+ '/recurringpayment'
36
+ end
37
+
38
+ end
39
+ end
@@ -1,85 +1,78 @@
1
- module Paysimple
2
- module Util
3
-
4
- # class ::Hash
5
- # def method_missing(name)
6
- # return self[name] if key? name
7
- # self.each { |k,v| return v if k.to_s.to_sym == name }
8
- # super.method_missing name
9
- # end
10
- # end
11
-
12
- def self.underscore(str)
13
- str.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
14
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
15
- tr('-', '_').
16
- downcase
17
- end
18
-
19
- def self.camelize(str)
20
- str.split('_').collect(&:capitalize).join
21
- end
22
-
23
- def self.camelize_and_symbolize_keys(object)
24
- transform_names object do |key|
25
- camelize(key.to_s).to_sym
26
- end
27
- end
28
-
29
- def self.underscore_and_symbolize_names(object)
30
- transform_names object do |key|
31
- underscore(key).to_sym
32
- end
33
- end
34
-
35
- def self.transform_names(object, &block)
36
- case object
37
- when Hash
38
- new_hash = {}
39
- object.each do |key, value|
40
- key = block.call(key) || key
41
- new_hash[key] = transform_names(value, &block)
42
- end
43
- new_hash
44
- when Array
45
- object.map { |value| transform_names(value, &block) }
46
- else
47
- object
48
- end
49
- end
50
-
51
- def self.flatten_params(params, parent_key=nil)
52
- result = []
53
- params.each do |key, value|
54
- calculated_key = parent_key ? "#{parent_key}[#{url_encode(key)}]" : url_encode(key)
55
- if value.is_a?(Hash)
56
- result += flatten_params(value, calculated_key)
57
- elsif value.is_a?(Array)
58
- result += flatten_params_array(value, calculated_key)
59
- else
60
- result << [calculated_key, value]
61
- end
62
- end
63
- result
64
- end
65
-
66
- def self.url_encode(key)
67
- URI.escape(key.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
68
- end
69
-
70
- def self.flatten_params_array(value, calculated_key)
71
- result = []
72
- value.each do |elem|
73
- if elem.is_a?(Hash)
74
- result += flatten_params(elem, calculated_key)
75
- elsif elem.is_a?(Array)
76
- result += flatten_params_array(elem, calculated_key)
77
- else
78
- result << ["#{calculated_key}[]", elem]
79
- end
80
- end
81
- result
82
- end
83
-
84
- end
1
+ module Paysimple
2
+ module Util
3
+
4
+ def self.underscore(str)
5
+ str.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
6
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
7
+ tr('-', '_').
8
+ downcase
9
+ end
10
+
11
+ def self.camelize(str)
12
+ str.split('_').collect(&:capitalize).join
13
+ end
14
+
15
+ def self.camelize_and_symbolize_keys(object)
16
+ transform_names object do |key|
17
+ camelize(key.to_s).to_sym
18
+ end
19
+ end
20
+
21
+ def self.underscore_and_symbolize_names(object)
22
+ transform_names object do |key|
23
+ underscore(key).to_sym
24
+ end
25
+ end
26
+
27
+ def self.transform_names(object, &block)
28
+ case object
29
+ when Hash
30
+ new_hash = {}
31
+ object.each do |key, value|
32
+ key = block.call(key) || key
33
+ new_hash[key] = transform_names(value, &block)
34
+ end
35
+ new_hash
36
+ when Array
37
+ object.map { |value| transform_names(value, &block) }
38
+ else
39
+ object
40
+ end
41
+ end
42
+
43
+ def self.flatten_params(params, parent_key=nil)
44
+ result = []
45
+ params.each do |key, value|
46
+ calculated_key = parent_key ? "#{parent_key}[#{url_encode(key)}]" : url_encode(key)
47
+ calculated_key = camelize(calculated_key)
48
+ if value.is_a?(Hash)
49
+ result += flatten_params(value, calculated_key)
50
+ elsif value.is_a?(Array)
51
+ result += flatten_params_array(value, calculated_key)
52
+ else
53
+ result << [calculated_key, value]
54
+ end
55
+ end
56
+ result
57
+ end
58
+
59
+ def self.url_encode(key)
60
+ URI.escape(key.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
61
+ end
62
+
63
+ def self.flatten_params_array(value, calculated_key)
64
+ result = []
65
+ value.each do |elem|
66
+ if elem.is_a?(Hash)
67
+ result += flatten_params(elem, calculated_key)
68
+ elsif elem.is_a?(Array)
69
+ result += flatten_params_array(elem, calculated_key)
70
+ else
71
+ result << ["#{calculated_key}[]", elem]
72
+ end
73
+ end
74
+ result
75
+ end
76
+
77
+ end
85
78
  end
@@ -1,3 +1,3 @@
1
- module Paysimple
2
- VERSION = '0.1.0'
3
- end
1
+ module Paysimple
2
+ VERSION = '0.2.0'
3
+ end
@@ -1,27 +1,27 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'paysimple/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'paysimple-ruby'
7
- spec.version = Paysimple::VERSION
8
- spec.authors = ['Konstantin Lebedev']
9
- spec.email = ['koss.lebedev@gmail.com']
10
-
11
- spec.summary = 'Ruby bindings for Paysimple API'
12
- spec.description = ''
13
- spec.homepage = 'http://developer.paysimple.com'
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
- spec.bindir = 'exe'
18
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
- spec.require_paths = ['lib']
20
-
21
- spec.add_development_dependency 'bundler', '~> 1.8'
22
- spec.add_development_dependency 'rake', '~> 10.0'
23
- spec.add_development_dependency 'rspec'
24
-
25
- spec.add_dependency('rest-client', '~> 1.4')
26
- spec.add_dependency('json', '~> 1.8.1')
27
- end
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'paysimple/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'paysimple-ruby'
7
+ spec.version = Paysimple::VERSION
8
+ spec.authors = ['Konstantin Lebedev']
9
+ spec.email = ['koss.lebedev@gmail.com']
10
+
11
+ spec.summary = 'Ruby bindings for Paysimple API'
12
+ spec.description = ''
13
+ spec.homepage = 'http://developer.paysimple.com'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.8'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec'
24
+
25
+ spec.add_dependency('rest-client', '~> 1.4')
26
+ spec.add_dependency('json', '~> 1.8.1')
27
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paysimple-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Lebedev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-31 00:00:00.000000000 Z
11
+ date: 2015-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -98,6 +98,12 @@ files:
98
98
  - bin/setup
99
99
  - lib/paysimple.rb
100
100
  - lib/paysimple/endpoint.rb
101
+ - lib/paysimple/enumerations/execution_frequency_type.rb
102
+ - lib/paysimple/enumerations/issuer.rb
103
+ - lib/paysimple/enumerations/payment_status.rb
104
+ - lib/paysimple/enumerations/payment_sub_type.rb
105
+ - lib/paysimple/enumerations/payment_type.rb
106
+ - lib/paysimple/enumerations/schedule_status.rb
101
107
  - lib/paysimple/errors/api_connection_error.rb
102
108
  - lib/paysimple/errors/api_error.rb
103
109
  - lib/paysimple/errors/authentication_error.rb
@@ -107,6 +113,8 @@ files:
107
113
  - lib/paysimple/resources/credit_card.rb
108
114
  - lib/paysimple/resources/customer.rb
109
115
  - lib/paysimple/resources/payment.rb
116
+ - lib/paysimple/resources/payment_plan.rb
117
+ - lib/paysimple/resources/recurring_payment.rb
110
118
  - lib/paysimple/util.rb
111
119
  - lib/paysimple/version.rb
112
120
  - paysimple.gemspec