paysimple-ruby 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +12 -11
- data/.rspec +2 -2
- data/.travis.yml +3 -3
- data/Gemfile +2 -2
- data/LICENSE.txt +21 -21
- data/README.md +106 -0
- data/Rakefile +2 -2
- data/bin/console +14 -14
- data/bin/setup +7 -7
- data/lib/paysimple.rb +161 -151
- data/lib/paysimple/enumerations/execution_frequency_type.rb +16 -0
- data/lib/paysimple/enumerations/issuer.rb +10 -0
- data/lib/paysimple/enumerations/payment_status.rb +18 -0
- data/lib/paysimple/enumerations/payment_sub_type.rb +15 -0
- data/lib/paysimple/enumerations/payment_type.rb +8 -0
- data/lib/paysimple/enumerations/schedule_status.rb +10 -0
- data/lib/paysimple/errors/invalid_request_error.rb +0 -6
- data/lib/paysimple/resources/credit_card.rb +22 -22
- data/lib/paysimple/resources/customer.rb +38 -22
- data/lib/paysimple/resources/payment.rb +8 -0
- data/lib/paysimple/resources/payment_plan.rb +39 -0
- data/lib/paysimple/resources/recurring_payment.rb +39 -0
- data/lib/paysimple/util.rb +77 -84
- data/lib/paysimple/version.rb +3 -3
- data/paysimple.gemspec +27 -27
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb3367f2302103d5d06aa6c4c11359d45042a677
|
4
|
+
data.tar.gz: 8be13c5c7af22787762cfc642c7d4ebdd1dad67a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/.travis.yml
CHANGED
@@ -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
|
data/LICENSE.txt
CHANGED
@@ -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
|
+
|
data/bin/console
CHANGED
@@ -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
|
data/lib/paysimple.rb
CHANGED
@@ -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
|
-
#
|
14
|
-
require 'paysimple/
|
15
|
-
require 'paysimple/
|
16
|
-
require 'paysimple/
|
17
|
-
require 'paysimple/
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
require 'paysimple/
|
23
|
-
require 'paysimple/
|
24
|
-
require 'paysimple/
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
"
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
end
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
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,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
|
@@ -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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
data/lib/paysimple/util.rb
CHANGED
@@ -1,85 +1,78 @@
|
|
1
|
-
module Paysimple
|
2
|
-
module Util
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
object
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
data/lib/paysimple/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Paysimple
|
2
|
-
VERSION = '0.
|
3
|
-
end
|
1
|
+
module Paysimple
|
2
|
+
VERSION = '0.2.0'
|
3
|
+
end
|
data/paysimple.gemspec
CHANGED
@@ -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.
|
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-
|
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
|