paysafe 0.9.4 → 0.14.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 +4 -4
- data/.env.sample +9 -2
- data/.github/workflows/ci.yml +34 -0
- data/.gitignore +0 -1
- data/CHANGELOG.md +36 -0
- data/Gemfile.lock +69 -0
- data/README.md +21 -22
- data/bin/console +24 -12
- data/bin/setup +9 -0
- data/lib/paysafe.rb +14 -0
- data/lib/paysafe/address.rb +1 -1
- data/lib/paysafe/api/base_api.rb +70 -0
- data/lib/paysafe/api/card_payments_api.rb +23 -0
- data/lib/paysafe/api/customer_vault_api.rb +74 -0
- data/lib/paysafe/api/payments_api.rb +39 -0
- data/lib/paysafe/birth_date.rb +4 -0
- data/lib/paysafe/configuration.rb +20 -0
- data/lib/paysafe/customer.rb +11 -0
- data/lib/paysafe/error.rb +54 -16
- data/lib/paysafe/gateway_response.rb +12 -0
- data/lib/paysafe/payment.rb +27 -0
- data/lib/paysafe/payment_method.rb +7 -0
- data/lib/paysafe/payment_methods.rb +7 -0
- data/lib/paysafe/payment_processor.rb +7 -0
- data/lib/paysafe/rest/client.rb +10 -203
- data/lib/paysafe/single_use_token.rb +2 -1
- data/lib/paysafe/standalone_credit.rb +23 -0
- data/lib/paysafe/verification.rb +2 -2
- data/lib/paysafe/version.rb +1 -1
- data/paysafe.gemspec +5 -5
- metadata +36 -9
- data/.travis.yml +0 -18
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aacbcf63a5572fd1a11b9c453cad38fdd3e4b59ac2ecc9108ea658ba0900cc88
|
|
4
|
+
data.tar.gz: bd24d67aa5287677b587dc542e05be536699c81331a3b9ba454cfe8b47723657
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9b01adaf15f3be353afd3b56146c17649f9e696057f328530c585e3ee98e897722708e7082668127979d5a47e1ac28a039c519b22b6d39a52790cb8c947a7b4f
|
|
7
|
+
data.tar.gz: 88ee0cbc687f66dd4eb109febf8c881c775c11e174c3440a076cf137ef27ff5d0c7ae2880f7e3e11b6cefe86311edbceca08eacda9a9b0f9179c66d94ac4a685
|
data/.env.sample
CHANGED
|
@@ -4,5 +4,12 @@ PAYSAFE_API_SECRET="YOUR_API_SECRET"
|
|
|
4
4
|
|
|
5
5
|
# This is only needed if you want to generate your own Single
|
|
6
6
|
# Use Tokens which utilize a different API key and secret.
|
|
7
|
-
PAYSAFE_SUT_API_KEY="
|
|
8
|
-
PAYSAFE_SUT_API_SECRET="
|
|
7
|
+
PAYSAFE_SUT_API_KEY="YOUR_SUT_API_KEY"
|
|
8
|
+
PAYSAFE_SUT_API_SECRET="YOUR_SUT_API_SECRET"
|
|
9
|
+
|
|
10
|
+
# These are for the Paysafe Payments API which are part of
|
|
11
|
+
# what Paysafe refers to as the Unity platform.
|
|
12
|
+
PAYSAFE_UNITY_API_KEY="YOUR_UNITY_API_KEY"
|
|
13
|
+
PAYSAFE_UNITY_API_SECRET="YOUR_UNITY_API_SECRET"
|
|
14
|
+
PAYSAFE_UNITY_SUT_API_KEY="YOUR_UNITY_SUT_API_KEY"
|
|
15
|
+
PAYSAFE_UNITY_SUT_API_SECRET="YOUR_UNITY_SUT_API_SECRET"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ master ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ master ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
ruby: [ '2.5', '2.6', '2.7', '3.0' ]
|
|
15
|
+
name: Ruby ${{ matrix.ruby }}
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v2
|
|
18
|
+
- uses: ruby/setup-ruby@v1
|
|
19
|
+
with:
|
|
20
|
+
ruby-version: ${{ matrix.ruby }}
|
|
21
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
22
|
+
- name: Run Tests
|
|
23
|
+
env:
|
|
24
|
+
PAYSAFE_ACCOUNT_NUMBER: test
|
|
25
|
+
PAYSAFE_API_KEY: test
|
|
26
|
+
PAYSAFE_API_SECRET: test
|
|
27
|
+
PAYSAFE_SUT_API_KEY: test
|
|
28
|
+
PAYSAFE_SUT_API_SECRET: test
|
|
29
|
+
PAYSAFE_UNITY_API_KEY: test
|
|
30
|
+
PAYSAFE_UNITY_API_SECRET: test
|
|
31
|
+
PAYSAFE_UNITY_SUT_API_KEY: test
|
|
32
|
+
PAYSAFE_UNITY_SUT_API_SECRET: test
|
|
33
|
+
run: |
|
|
34
|
+
bundle exec rake
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,42 @@
|
|
|
1
1
|
Changelog
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
+
## 0.14.0 (2021-01-19)
|
|
5
|
+
|
|
6
|
+
* No code changes - moved repository to Jackpocket organization and updated URLs
|
|
7
|
+
|
|
8
|
+
## 0.13.0 (2021-01-14)
|
|
9
|
+
|
|
10
|
+
* Renamed client `timeouts` option to `timeout`.
|
|
11
|
+
* Requires Ruby 2.5 and up.
|
|
12
|
+
* Added Ruby 3.0 build to CI.
|
|
13
|
+
|
|
14
|
+
## 0.12.0 (2020-05-14)
|
|
15
|
+
|
|
16
|
+
* Added customers and single use tokens support for Payments API:
|
|
17
|
+
* `client.payments.create_single_use_customer_token`
|
|
18
|
+
* `client.payments.create_customer`
|
|
19
|
+
* `client.payments.get_customer`
|
|
20
|
+
* Removed deprecated methods on `Client` object. Please use API scoped methods defined on `payments`, `customer_vault`, or `card_payments`.
|
|
21
|
+
|
|
22
|
+
## 0.11.0 (2020-04-08)
|
|
23
|
+
|
|
24
|
+
* Added standalone credits support for Payments API:
|
|
25
|
+
* `client.payments.create_standalone_credit`
|
|
26
|
+
* `client.payments.get_standalone_credit`
|
|
27
|
+
|
|
28
|
+
## 0.10.0 (2020-02-24)
|
|
29
|
+
|
|
30
|
+
* Removed client configuration using a block.
|
|
31
|
+
* Deprecated `Client` object API methods.
|
|
32
|
+
* All API methods are now grouped by API objects, for example:
|
|
33
|
+
* Customer Vault API: `client.create_profile` is now `client.customer_vault.create_profile`
|
|
34
|
+
* Card Payments API: `client.create_verification` is now `client.card_payments.create_verification`
|
|
35
|
+
* Includes some methods for new Payments API through `client.payments` (aka Paysafe Unity Platform)
|
|
36
|
+
* Requires http gem v4.
|
|
37
|
+
* Requires Ruby 2.4 and up.
|
|
38
|
+
* Added Ruby 2.7 build to CI.
|
|
39
|
+
|
|
4
40
|
## 0.9.4 (2019-09-24)
|
|
5
41
|
|
|
6
42
|
* Relax http gem dependency to allow v2 through v4.
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
paysafe (0.14.0)
|
|
5
|
+
http (>= 4, < 5)
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
addressable (2.7.0)
|
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
|
12
|
+
ansi (1.5.0)
|
|
13
|
+
builder (3.2.4)
|
|
14
|
+
crack (0.4.5)
|
|
15
|
+
rexml
|
|
16
|
+
domain_name (0.5.20190701)
|
|
17
|
+
unf (>= 0.0.5, < 1.0.0)
|
|
18
|
+
dotenv (2.7.6)
|
|
19
|
+
ffi (1.14.2)
|
|
20
|
+
ffi-compiler (1.0.1)
|
|
21
|
+
ffi (>= 1.0.0)
|
|
22
|
+
rake
|
|
23
|
+
hashdiff (1.0.1)
|
|
24
|
+
http (4.4.1)
|
|
25
|
+
addressable (~> 2.3)
|
|
26
|
+
http-cookie (~> 1.0)
|
|
27
|
+
http-form_data (~> 2.2)
|
|
28
|
+
http-parser (~> 1.2.0)
|
|
29
|
+
http-cookie (1.0.3)
|
|
30
|
+
domain_name (~> 0.5)
|
|
31
|
+
http-form_data (2.3.0)
|
|
32
|
+
http-parser (1.2.3)
|
|
33
|
+
ffi-compiler (>= 1.0, < 2.0)
|
|
34
|
+
minitest (5.14.3)
|
|
35
|
+
minitest-mock_expectations (1.1.3)
|
|
36
|
+
minitest-reporters (1.4.2)
|
|
37
|
+
ansi
|
|
38
|
+
builder
|
|
39
|
+
minitest (>= 5.0)
|
|
40
|
+
ruby-progressbar
|
|
41
|
+
public_suffix (4.0.6)
|
|
42
|
+
rake (13.0.3)
|
|
43
|
+
rexml (3.2.4)
|
|
44
|
+
ruby-progressbar (1.11.0)
|
|
45
|
+
unf (0.1.4)
|
|
46
|
+
unf_ext
|
|
47
|
+
unf_ext (0.0.7.7)
|
|
48
|
+
vcr (6.0.0)
|
|
49
|
+
webmock (3.11.1)
|
|
50
|
+
addressable (>= 2.3.6)
|
|
51
|
+
crack (>= 0.3.2)
|
|
52
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
53
|
+
|
|
54
|
+
PLATFORMS
|
|
55
|
+
ruby
|
|
56
|
+
|
|
57
|
+
DEPENDENCIES
|
|
58
|
+
bundler (~> 2.0)
|
|
59
|
+
dotenv
|
|
60
|
+
minitest
|
|
61
|
+
minitest-mock_expectations
|
|
62
|
+
minitest-reporters
|
|
63
|
+
paysafe!
|
|
64
|
+
rake
|
|
65
|
+
vcr
|
|
66
|
+
webmock
|
|
67
|
+
|
|
68
|
+
BUNDLED WITH
|
|
69
|
+
2.1.4
|
data/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# The Paysafe Ruby Gem
|
|
2
2
|
|
|
3
|
-
[]
|
|
4
|
-
|
|
3
|
+
[](https://badge.fury.io/rb/paysafe)
|
|
4
|
+

|
|
5
5
|
|
|
6
|
-
A well tested Ruby interface to the [Paysafe REST API](paysafe_api_reference) (formerly Optimal Payments). Requires Ruby 2.
|
|
6
|
+
A well tested Ruby interface to the [Paysafe REST API](paysafe_api_reference) (formerly Optimal Payments). Requires Ruby 2.5 and up. Not all API actions are supported yet. Since the Paysafe API uses camelCase, this gem will handle converting to and from snake_case for you.
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
@@ -24,23 +24,26 @@ To try out the gem, just follow the Development section instructions as the buil
|
|
|
24
24
|
Create and configure a client with your API authentication.
|
|
25
25
|
|
|
26
26
|
```ruby
|
|
27
|
-
client = Paysafe::REST::Client.new
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
|
|
27
|
+
client = Paysafe::REST::Client.new(
|
|
28
|
+
api_key: 'your_api_key',
|
|
29
|
+
api_secret: 'your_api_secret',
|
|
30
|
+
test_mode: false, # to enable Production requests, default is `true`
|
|
31
|
+
account_number: '1234', # used for the Card Payments API
|
|
32
|
+
# Provide optional timeouts in seconds
|
|
33
|
+
# timeout: { connect: 2, read: 5, write: 10 }
|
|
34
|
+
# Or as a global timeout in seconds
|
|
35
|
+
# timeout: 20
|
|
36
|
+
)
|
|
36
37
|
```
|
|
37
38
|
|
|
39
|
+
At a minimum the following options: `api_key`, `api_secret`, and `test_mode` should be specified. The `account_number` is only necessary for certain API's such as the Card Payments API.
|
|
40
|
+
|
|
38
41
|
### Making Requests
|
|
39
42
|
|
|
40
43
|
Make an API request with a payload in the structure documented by the [Paysafe REST API](paysafe_api_reference) but using snake_case. The request payload will be converted to camelCase for you.
|
|
41
44
|
|
|
42
45
|
```ruby
|
|
43
|
-
profile = client.create_profile(
|
|
46
|
+
profile = client.customer_vault.create_profile(
|
|
44
47
|
merchant_customer_id: '123',
|
|
45
48
|
locale: 'en_US',
|
|
46
49
|
card: {
|
|
@@ -66,16 +69,14 @@ profile.cards.first.card_expiry.year
|
|
|
66
69
|
# => 2020
|
|
67
70
|
```
|
|
68
71
|
|
|
69
|
-
Further API methods are provided in the `Paysafe::REST::Client` object.
|
|
70
|
-
|
|
71
72
|
## Development
|
|
72
73
|
|
|
73
|
-
1. `git clone https://github.com/
|
|
74
|
-
2. Run `./bin/setup` to install dependencies and fill out API key info
|
|
74
|
+
1. `git clone https://github.com/jackpocket/paysafe.git`
|
|
75
|
+
2. Run `./bin/setup` to install dependencies and fill out API key/secret info
|
|
75
76
|
3. Run `./bin/console` for an interactive prompt with an authenticated client for you to experiment:
|
|
76
77
|
|
|
77
78
|
```ruby
|
|
78
|
-
profile = client.create_profile(merchant_customer_id:
|
|
79
|
+
profile = client.customer_vault.create_profile(merchant_customer_id: SecureRandom.uuid, locale: 'en_US')
|
|
79
80
|
puts profile.id
|
|
80
81
|
# => b088ac37...
|
|
81
82
|
```
|
|
@@ -84,7 +85,7 @@ All code is written in snake_case since requests and responses are converted to
|
|
|
84
85
|
|
|
85
86
|
### Tests
|
|
86
87
|
|
|
87
|
-
|
|
88
|
+
If the API key/secret info is different from what was used to record the cassettes, you'll need to run `bundle exec rake test RECORD_MODE=all` otherwise run `bundle exec rake test`.
|
|
88
89
|
|
|
89
90
|
### Releasing
|
|
90
91
|
|
|
@@ -92,12 +93,10 @@ To release a new version, update the version number in `version.rb`, and then ru
|
|
|
92
93
|
|
|
93
94
|
## Contributing
|
|
94
95
|
|
|
95
|
-
Bug reports and pull requests for missing API support are welcome on GitHub at https://github.com/
|
|
96
|
+
Bug reports and pull requests for missing API support are welcome on GitHub at https://github.com/jackpocket/paysafe. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
|
96
97
|
|
|
97
98
|
## License
|
|
98
99
|
|
|
99
100
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
100
101
|
|
|
101
|
-
[gem]: https://rubygems.org/gems/paysafe
|
|
102
|
-
[travis]: https://travis-ci.org/javierjulio/paysafe
|
|
103
102
|
[paysafe_api_reference]: https://developer.paysafe.com/en/api-reference/
|
data/bin/console
CHANGED
|
@@ -1,25 +1,37 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
3
|
require "bundler/setup"
|
|
4
|
+
require "dotenv/load"
|
|
4
5
|
require "paysafe"
|
|
5
6
|
|
|
6
7
|
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
8
|
# with your gem easier. You can also use a different console, if you like.
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
def client
|
|
11
|
+
Paysafe::REST::Client.new(
|
|
12
|
+
account_number: ENV['PAYSAFE_ACCOUNT_NUMBER'],
|
|
13
|
+
api_key: ENV['PAYSAFE_API_KEY'],
|
|
14
|
+
api_secret: ENV['PAYSAFE_API_SECRET']
|
|
15
|
+
)
|
|
16
|
+
end
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
def sut_client
|
|
19
|
+
Paysafe::REST::Client.new(
|
|
20
|
+
api_key: ENV['PAYSAFE_SUT_API_KEY'],
|
|
21
|
+
api_secret: ENV['PAYSAFE_SUT_API_SECRET']
|
|
22
|
+
)
|
|
23
|
+
end
|
|
15
24
|
|
|
16
|
-
def
|
|
17
|
-
Paysafe::REST::Client.new
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
end
|
|
25
|
+
def unity_client
|
|
26
|
+
Paysafe::REST::Client.new(
|
|
27
|
+
api_key: ENV['PAYSAFE_UNITY_API_KEY'],
|
|
28
|
+
api_secret: ENV['PAYSAFE_UNITY_API_SECRET']
|
|
29
|
+
)
|
|
22
30
|
end
|
|
23
31
|
|
|
32
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
33
|
+
# require "pry"
|
|
34
|
+
# Pry.start
|
|
35
|
+
|
|
24
36
|
require "irb"
|
|
25
|
-
IRB.start
|
|
37
|
+
IRB.start(__FILE__)
|
data/bin/setup
CHANGED
|
@@ -23,10 +23,19 @@ echo "Enter your account credentials below."
|
|
|
23
23
|
read -p 'Account Number: ' account_number
|
|
24
24
|
read -p 'API Key: ' api_key
|
|
25
25
|
read -p 'API Secret: ' api_secret
|
|
26
|
+
read -p 'Single Use Token API Key: ' sut_api_key
|
|
27
|
+
read -p 'Single Use Token API Secret: ' sut_api_secret
|
|
28
|
+
read -p 'Unity API Key: ' unity_api_key
|
|
29
|
+
read -p 'Unity API Secret: ' unity_api_secret
|
|
26
30
|
|
|
27
31
|
cp .env.sample .env
|
|
32
|
+
|
|
28
33
|
sed -i '' -e "s/YOUR_ACCOUNT_NUMBER/$account_number/g" .env
|
|
29
34
|
sed -i '' -e "s/YOUR_API_KEY/$api_key/g" .env
|
|
30
35
|
sed -i '' -e "s/YOUR_API_SECRET/$api_secret/g" .env
|
|
36
|
+
sed -i '' -e "s/YOUR_SUT_API_KEY/$sut_api_key/g" .env
|
|
37
|
+
sed -i '' -e "s/YOUR_SUT_API_SECRET/$sut_api_secret/g" .env
|
|
38
|
+
sed -i '' -e "s/YOUR_UNITY_API_KEY/$unity_api_key/g" .env
|
|
39
|
+
sed -i '' -e "s/YOUR_UNITY_API_SECRET/$unity_api_secret/g" .env
|
|
31
40
|
|
|
32
41
|
echo "Done."
|
data/lib/paysafe.rb
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
require "http"
|
|
2
|
+
require "json"
|
|
1
3
|
require "paysafe/version"
|
|
2
4
|
require "paysafe/error"
|
|
3
5
|
require "paysafe/single_use_token"
|
|
4
6
|
require "paysafe/profile"
|
|
7
|
+
require "paysafe/customer"
|
|
8
|
+
require "paysafe/payment"
|
|
9
|
+
require "paysafe/gateway_response"
|
|
10
|
+
require "paysafe/payment_processor"
|
|
11
|
+
require "paysafe/payment_methods"
|
|
12
|
+
require "paysafe/payment_method"
|
|
13
|
+
require "paysafe/standalone_credit"
|
|
5
14
|
require "paysafe/birth_date"
|
|
6
15
|
require "paysafe/address"
|
|
7
16
|
require "paysafe/card"
|
|
@@ -10,4 +19,9 @@ require "paysafe/verification"
|
|
|
10
19
|
require "paysafe/authorization"
|
|
11
20
|
require "paysafe/refinements/camel_case"
|
|
12
21
|
require "paysafe/refinements/snake_case"
|
|
22
|
+
require "paysafe/configuration"
|
|
13
23
|
require "paysafe/rest/client"
|
|
24
|
+
require "paysafe/api/base_api"
|
|
25
|
+
require "paysafe/api/card_payments_api"
|
|
26
|
+
require "paysafe/api/customer_vault_api"
|
|
27
|
+
require "paysafe/api/payments_api"
|
data/lib/paysafe/address.rb
CHANGED
|
@@ -2,7 +2,7 @@ require 'paysafe/result'
|
|
|
2
2
|
|
|
3
3
|
module Paysafe
|
|
4
4
|
class Address < Result
|
|
5
|
-
attributes :id, :nick_name, :street, :street2, :city,
|
|
5
|
+
attributes :id, :nick_name, :street, :street1, :street2, :city,
|
|
6
6
|
:country, :state, :zip, :recipient_name, :phone, :status,
|
|
7
7
|
:default_shipping_address_indicator
|
|
8
8
|
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
module Paysafe
|
|
2
|
+
module Api
|
|
3
|
+
class BaseApi
|
|
4
|
+
HEADERS = {
|
|
5
|
+
'Content-Type' => 'application/json',
|
|
6
|
+
'User-Agent' => "PaysafeRubyGem/#{Paysafe::VERSION}",
|
|
7
|
+
'X-Ruby-Version' => RUBY_VERSION,
|
|
8
|
+
'X-Ruby-Platform' => RUBY_PLATFORM
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
using Refinements::CamelCase
|
|
12
|
+
using Refinements::SnakeCase
|
|
13
|
+
|
|
14
|
+
def initialize(config)
|
|
15
|
+
@config = config
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
protected
|
|
19
|
+
|
|
20
|
+
# Needed for some API URLs
|
|
21
|
+
def account_number
|
|
22
|
+
@config.account_number
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def http_client
|
|
26
|
+
HTTP
|
|
27
|
+
.headers(HEADERS)
|
|
28
|
+
.timeout(@config.timeout || :null)
|
|
29
|
+
.basic_auth(user: @config.api_key, pass: @config.api_secret)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def perform_post_with_object(path, data, klass)
|
|
33
|
+
response = http_client.post("#{@config.api_base}#{path}", json: data.to_camel_case)
|
|
34
|
+
process_response(response, klass)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def perform_get_with_object(path, klass)
|
|
38
|
+
response = http_client.get("#{@config.api_base}#{path}")
|
|
39
|
+
process_response(response, klass)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def perform_delete(path)
|
|
43
|
+
response = http_client.delete("#{@config.api_base}#{path}")
|
|
44
|
+
process_response(response)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def perform_put_with_object(path, data, klass)
|
|
48
|
+
response = http_client.put("#{@config.api_base}#{path}", json: data.to_camel_case)
|
|
49
|
+
process_response(response, klass)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def process_response(response, klass=nil)
|
|
53
|
+
data = parse_response_body(response.to_s)
|
|
54
|
+
|
|
55
|
+
if response.status.success?
|
|
56
|
+
klass&.new(data)
|
|
57
|
+
else
|
|
58
|
+
fail Error.from_response(data, response.code)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def parse_response_body(body)
|
|
63
|
+
return nil if body.strip.empty?
|
|
64
|
+
JSON.parse(body, symbolize_names: true)&.to_snake_case
|
|
65
|
+
rescue JSON::ParserError
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Paysafe
|
|
2
|
+
module Api
|
|
3
|
+
class CardPaymentsApi < BaseApi
|
|
4
|
+
|
|
5
|
+
def create_authorization(**data)
|
|
6
|
+
perform_post_with_object("/cardpayments/v1/accounts/#{account_number}/auths", data, Authorization)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def create_verification(**data)
|
|
10
|
+
perform_post_with_object("/cardpayments/v1/accounts/#{account_number}/verifications", data, Verification)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def get_authorization(id:)
|
|
14
|
+
perform_get_with_object("/cardpayments/v1/accounts/#{account_number}/auths/#{id}", Authorization)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def get_verification(id:)
|
|
18
|
+
perform_get_with_object("/cardpayments/v1/accounts/#{account_number}/verifications/#{id}", Verification)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module Paysafe
|
|
2
|
+
module Api
|
|
3
|
+
class CustomerVaultApi < BaseApi
|
|
4
|
+
|
|
5
|
+
def create_address(profile_id:, country:, zip:, **args)
|
|
6
|
+
data = args.merge({ country: country, zip: zip })
|
|
7
|
+
perform_post_with_object("/customervault/v1/profiles/#{profile_id}/addresses", data, Address)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def create_card(profile_id:, **data)
|
|
11
|
+
perform_post_with_object("/customervault/v1/profiles/#{profile_id}/cards", data, Card)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create_profile(merchant_customer_id:, locale:, **args)
|
|
15
|
+
data = args.merge({
|
|
16
|
+
merchant_customer_id: merchant_customer_id,
|
|
17
|
+
locale: locale
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
perform_post_with_object("/customervault/v1/profiles", data, Profile)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def create_single_use_token(**data)
|
|
24
|
+
perform_post_with_object("/customervault/v1/singleusetokens", data, SingleUseToken)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def delete_address(profile_id:, id:)
|
|
28
|
+
perform_delete("/customervault/v1/profiles/#{profile_id}/addresses/#{id}")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def delete_card(profile_id:, id:)
|
|
32
|
+
perform_delete("/customervault/v1/profiles/#{profile_id}/cards/#{id}")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def delete_profile(id:)
|
|
36
|
+
perform_delete("/customervault/v1/profiles/#{id}")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def get_address(profile_id:, id:)
|
|
40
|
+
perform_get_with_object("/customervault/v1/profiles/#{profile_id}/addresses/#{id}", Address)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def get_card(profile_id:, id:)
|
|
44
|
+
perform_get_with_object("/customervault/v1/profiles/#{profile_id}/cards/#{id}", Card)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def get_profile(id:, fields: [])
|
|
48
|
+
path = "/customervault/v1/profiles/#{id}"
|
|
49
|
+
path += "?fields=#{fields.join(',')}" if !fields.empty?
|
|
50
|
+
|
|
51
|
+
perform_get_with_object(path, Profile)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def update_address(profile_id:, id:, country:, zip:, **args)
|
|
55
|
+
data = args.merge({ country: country, zip: zip })
|
|
56
|
+
perform_put_with_object("/customervault/v1/profiles/#{profile_id}/addresses/#{id}", data, Address)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def update_card(profile_id:, id:, **data)
|
|
60
|
+
perform_put_with_object("/customervault/v1/profiles/#{profile_id}/cards/#{id}", data, Card)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def update_profile(id:, merchant_customer_id:, locale:, **args)
|
|
64
|
+
data = args.merge({
|
|
65
|
+
merchant_customer_id: merchant_customer_id,
|
|
66
|
+
locale: locale
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
perform_put_with_object("/customervault/v1/profiles/#{id}", data, Profile)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module Paysafe
|
|
2
|
+
module Api
|
|
3
|
+
class PaymentsApi < BaseApi
|
|
4
|
+
|
|
5
|
+
def get_payment_methods(currency_code:)
|
|
6
|
+
perform_get_with_object("/paymenthub/v1/paymentmethods?currencyCode=#{currency_code}", PaymentMethods)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def create_customer(**data)
|
|
10
|
+
perform_post_with_object("/paymenthub/v1/customers", data, Customer)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def create_single_use_customer_token(id:)
|
|
14
|
+
perform_post_with_object("/paymenthub/v1/customers/#{id}/singleusecustomertokens", {}, SingleUseToken)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def create_payment(**data)
|
|
18
|
+
perform_post_with_object("/paymenthub/v1/payments", data, Payment)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def create_standalone_credit(**data)
|
|
22
|
+
perform_post_with_object("/paymenthub/v1/standalonecredits", data, StandaloneCredit)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def get_customer(id:)
|
|
26
|
+
perform_get_with_object("/paymenthub/v1/customers/#{id}", Customer)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def get_payment(id:)
|
|
30
|
+
perform_get_with_object("/paymenthub/v1/payments/#{id}", Payment)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def get_standalone_credit(id:)
|
|
34
|
+
perform_get_with_object("/paymenthub/v1/standalonecredits/#{id}", StandaloneCredit)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
data/lib/paysafe/birth_date.rb
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Paysafe
|
|
2
|
+
class Configuration
|
|
3
|
+
|
|
4
|
+
API_TEST = 'https://api.test.paysafe.com'
|
|
5
|
+
API_LIVE = 'https://api.paysafe.com'
|
|
6
|
+
|
|
7
|
+
attr_reader :account_number, :api_base, :api_key, :api_secret, :test_mode, :timeout
|
|
8
|
+
|
|
9
|
+
def initialize(**options)
|
|
10
|
+
@test_mode = true
|
|
11
|
+
|
|
12
|
+
options.each do |key, value|
|
|
13
|
+
instance_variable_set("@#{key}", value)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
@api_base = test_mode ? API_TEST : API_LIVE
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'paysafe/result'
|
|
2
|
+
|
|
3
|
+
module Paysafe
|
|
4
|
+
class Customer < Result
|
|
5
|
+
attributes :id, :status, :merchant_customer_id, :locale,
|
|
6
|
+
:ip, :first_name, :middle_name, :last_name, :gender,
|
|
7
|
+
:nationality, :email, :phone, :cell_phone, :payment_token
|
|
8
|
+
|
|
9
|
+
object_attribute :BirthDate, :date_of_birth
|
|
10
|
+
end
|
|
11
|
+
end
|
data/lib/paysafe/error.rb
CHANGED
|
@@ -48,7 +48,7 @@ module Paysafe
|
|
|
48
48
|
# Raised on the HTTP status code 504
|
|
49
49
|
GatewayTimeout = Class.new(ServerError)
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
ERRORS_BY_STATUS = {
|
|
52
52
|
400 => Paysafe::Error::BadRequest,
|
|
53
53
|
401 => Paysafe::Error::Unauthorized,
|
|
54
54
|
402 => Paysafe::Error::RequestDeclined,
|
|
@@ -65,24 +65,14 @@ module Paysafe
|
|
|
65
65
|
504 => Paysafe::Error::GatewayTimeout,
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
# The Paysafe API Error Code
|
|
69
|
-
#
|
|
70
|
-
# @return [Integer]
|
|
71
|
-
attr_reader :code
|
|
72
|
-
|
|
73
|
-
# The JSON HTTP response in Hash form
|
|
74
|
-
#
|
|
75
|
-
# @return [Hash]
|
|
76
|
-
attr_reader :response
|
|
77
|
-
|
|
78
68
|
class << self
|
|
79
69
|
# Create a new error from an HTTP response
|
|
80
70
|
#
|
|
81
71
|
# @param body [String]
|
|
82
|
-
# @param
|
|
72
|
+
# @param status [Integer]
|
|
83
73
|
# @return [Paysafe::Error]
|
|
84
|
-
def from_response(body,
|
|
85
|
-
klass =
|
|
74
|
+
def from_response(body, status)
|
|
75
|
+
klass = ERRORS_BY_STATUS[status] || Paysafe::Error
|
|
86
76
|
message, error_code = parse_error(body)
|
|
87
77
|
klass.new(message: message, code: error_code, response: body)
|
|
88
78
|
end
|
|
@@ -98,16 +88,64 @@ module Paysafe
|
|
|
98
88
|
end
|
|
99
89
|
end
|
|
100
90
|
|
|
91
|
+
# The Paysafe API Error Code
|
|
92
|
+
#
|
|
93
|
+
# @return [String]
|
|
94
|
+
attr_reader :code
|
|
95
|
+
|
|
96
|
+
# The JSON HTTP response in Hash form
|
|
97
|
+
#
|
|
98
|
+
# @return [Hash]
|
|
99
|
+
attr_reader :response
|
|
100
|
+
|
|
101
101
|
# Initializes a new Error object
|
|
102
102
|
#
|
|
103
103
|
# @param message [Exception, String]
|
|
104
|
-
# @param code [
|
|
104
|
+
# @param code [String]
|
|
105
105
|
# @param response [Hash]
|
|
106
106
|
# @return [Paysafe::Error]
|
|
107
107
|
def initialize(message: '', code: nil, response: {})
|
|
108
|
-
super(message)
|
|
109
108
|
@code = code
|
|
110
109
|
@response = response
|
|
110
|
+
super(message)
|
|
111
111
|
end
|
|
112
|
+
|
|
113
|
+
def to_s
|
|
114
|
+
[ super, code_text, field_error_text, detail_text ].compact.join(' ')
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def id
|
|
118
|
+
response.dig(:id) if response.is_a?(Hash)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def merchant_ref_num
|
|
122
|
+
response.dig(:merchant_ref_num) if response.is_a?(Hash)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
private
|
|
126
|
+
|
|
127
|
+
def code_text
|
|
128
|
+
"(Code #{code})" if code
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def field_error_text
|
|
132
|
+
if field_errors
|
|
133
|
+
msgs = field_errors.map { |f| "The \`#{f[:field]}\` #{f[:error]}." }.join(' ')
|
|
134
|
+
"Field Errors: #{msgs}".strip
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def field_errors
|
|
139
|
+
response.dig(:error, :field_errors) if response.is_a?(Hash)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def detail_text
|
|
143
|
+
"Details: #{details.join('. ')}".strip if details
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def details
|
|
147
|
+
response.dig(:error, :details) if response.is_a?(Hash)
|
|
148
|
+
end
|
|
149
|
+
|
|
112
150
|
end
|
|
113
151
|
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'paysafe/result'
|
|
2
|
+
|
|
3
|
+
module Paysafe
|
|
4
|
+
class Payment < Result
|
|
5
|
+
attributes :id,
|
|
6
|
+
:payment_type,
|
|
7
|
+
:payment_handle_token,
|
|
8
|
+
:merchant_ref_num,
|
|
9
|
+
:currency_code,
|
|
10
|
+
:settle_with_auth,
|
|
11
|
+
:txn_time,
|
|
12
|
+
:status,
|
|
13
|
+
:gateway_reconciliation_id,
|
|
14
|
+
:amount,
|
|
15
|
+
:available_to_settle,
|
|
16
|
+
:available_to_refund,
|
|
17
|
+
:consumer_ip,
|
|
18
|
+
:live_mode,
|
|
19
|
+
:updated_time,
|
|
20
|
+
:status_time
|
|
21
|
+
|
|
22
|
+
object_attribute :Address, :billing_details
|
|
23
|
+
object_attribute :Customer, :profile
|
|
24
|
+
object_attribute :GatewayResponse, :gateway_response
|
|
25
|
+
object_attribute :PaymentProcessor, :sightline
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/paysafe/rest/client.rb
CHANGED
|
@@ -1,40 +1,16 @@
|
|
|
1
|
-
require 'http'
|
|
2
|
-
require 'json'
|
|
3
|
-
|
|
4
1
|
module Paysafe
|
|
5
2
|
module REST
|
|
6
3
|
class Client
|
|
4
|
+
extend Forwardable
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
API_LIVE = 'https://api.paysafe.com'
|
|
10
|
-
|
|
11
|
-
HEADERS = {
|
|
12
|
-
'Content-Type' => 'application/json',
|
|
13
|
-
'User-Agent' => "PaysafeRubyGem/#{Paysafe::VERSION}",
|
|
14
|
-
'X-Ruby-Version' => RUBY_VERSION,
|
|
15
|
-
'X-Ruby-Platform' => RUBY_PLATFORM
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
using Refinements::CamelCase
|
|
19
|
-
using Refinements::SnakeCase
|
|
20
|
-
|
|
21
|
-
attr_accessor :account_number, :api_key, :api_secret, :test_mode, :timeouts
|
|
22
|
-
attr_reader :api_base
|
|
6
|
+
delegate [:account_number, :api_base, :api_key, :api_secret, :test_mode, :timeout] => :@config
|
|
23
7
|
|
|
24
8
|
# Initializes a new Client object
|
|
25
9
|
#
|
|
26
10
|
# @param options [Hash]
|
|
27
11
|
# @return [Paysafe::REST::Client]
|
|
28
|
-
def initialize(options
|
|
29
|
-
@
|
|
30
|
-
|
|
31
|
-
options.each do |key, value|
|
|
32
|
-
instance_variable_set("@#{key}", value)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
yield(self) if block_given?
|
|
36
|
-
|
|
37
|
-
@api_base = test_mode ? API_TEST : API_LIVE
|
|
12
|
+
def initialize(**options)
|
|
13
|
+
@config = Configuration.new(**options)
|
|
38
14
|
end
|
|
39
15
|
|
|
40
16
|
# @return [Hash]
|
|
@@ -47,186 +23,17 @@ module Paysafe
|
|
|
47
23
|
credentials.values.all?
|
|
48
24
|
end
|
|
49
25
|
|
|
50
|
-
def
|
|
51
|
-
|
|
52
|
-
process_response(response, SingleUseToken)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def create_profile_from_token(data)
|
|
56
|
-
response = post(path: "/customervault/v1/profiles", data: data.to_camel_case)
|
|
57
|
-
process_response(response, Profile)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def create_profile(merchant_customer_id:, locale:, **args)
|
|
61
|
-
data = args.merge({
|
|
62
|
-
merchant_customer_id: merchant_customer_id,
|
|
63
|
-
locale: locale
|
|
64
|
-
}).to_camel_case
|
|
65
|
-
|
|
66
|
-
response = post(path: "/customervault/v1/profiles", data: data)
|
|
67
|
-
process_response(response, Profile)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def delete_profile(id:)
|
|
71
|
-
response = delete(path: "/customervault/v1/profiles/#{id}")
|
|
72
|
-
process_response(response)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def get_profile(id:, fields: [])
|
|
76
|
-
path = "/customervault/v1/profiles/#{id}"
|
|
77
|
-
path += "?fields=#{fields.join(',')}" if !fields.empty?
|
|
78
|
-
|
|
79
|
-
response = get(path: path)
|
|
80
|
-
process_response(response, Profile)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def update_profile(id:, merchant_customer_id:, locale:, **args)
|
|
84
|
-
data = args.merge({
|
|
85
|
-
merchant_customer_id: merchant_customer_id,
|
|
86
|
-
locale: locale
|
|
87
|
-
}).to_camel_case
|
|
88
|
-
|
|
89
|
-
response = put(path: "/customervault/v1/profiles/#{id}", data: data)
|
|
90
|
-
process_response(response, Profile)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def create_address(profile_id:, country:, zip:, **args)
|
|
94
|
-
data = args.merge({ country: country, zip: zip }).to_camel_case
|
|
95
|
-
response = post(path: "/customervault/v1/profiles/#{profile_id}/addresses", data: data)
|
|
96
|
-
process_response(response, Address)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
def get_address(profile_id:, id:)
|
|
100
|
-
response = get(path: "/customervault/v1/profiles/#{profile_id}/addresses/#{id}")
|
|
101
|
-
process_response(response, Address)
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def create_card_from_token(profile_id:, token:)
|
|
105
|
-
data = { single_use_token: token }.to_camel_case
|
|
106
|
-
response = post(path: "/customervault/v1/profiles/#{profile_id}/cards", data: data)
|
|
107
|
-
process_response(response, Card)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def create_card(profile_id:, number:, month:, year:, **args)
|
|
111
|
-
data = args.merge({
|
|
112
|
-
card_num: number,
|
|
113
|
-
card_expiry: {
|
|
114
|
-
month: month,
|
|
115
|
-
year: year
|
|
116
|
-
}
|
|
117
|
-
}).reject { |key, value| value.nil? }.to_camel_case
|
|
118
|
-
|
|
119
|
-
response = post(path: "/customervault/v1/profiles/#{profile_id}/cards", data: data)
|
|
120
|
-
process_response(response, Card)
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
def delete_card(profile_id:, id:)
|
|
124
|
-
response = delete(path: "/customervault/v1/profiles/#{profile_id}/cards/#{id}")
|
|
125
|
-
process_response(response)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def get_card(profile_id:, id:)
|
|
129
|
-
response = get(path: "/customervault/v1/profiles/#{profile_id}/cards/#{id}")
|
|
130
|
-
process_response(response, Card)
|
|
26
|
+
def customer_vault
|
|
27
|
+
@customer_vault ||= Api::CustomerVaultApi.new(@config)
|
|
131
28
|
end
|
|
132
29
|
|
|
133
|
-
def
|
|
134
|
-
|
|
135
|
-
card_expiry: {
|
|
136
|
-
month: month,
|
|
137
|
-
year: year
|
|
138
|
-
}
|
|
139
|
-
}).reject { |key, value| value.nil? }.to_camel_case
|
|
140
|
-
|
|
141
|
-
response = put(path: "/customervault/v1/profiles/#{profile_id}/cards/#{id}", data: data)
|
|
142
|
-
process_response(response, Card)
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def purchase(amount:, token:, merchant_ref_num:, **args)
|
|
146
|
-
data = args.merge({
|
|
147
|
-
amount: amount,
|
|
148
|
-
merchant_ref_num: merchant_ref_num,
|
|
149
|
-
settle_with_auth: true,
|
|
150
|
-
card: {
|
|
151
|
-
payment_token: token
|
|
152
|
-
}
|
|
153
|
-
}).to_camel_case
|
|
154
|
-
|
|
155
|
-
response = post(path: "/cardpayments/v1/accounts/#{account_number}/auths", data: data)
|
|
156
|
-
process_response(response, Authorization)
|
|
30
|
+
def card_payments
|
|
31
|
+
@card_payments ||= Api::CardPaymentsApi.new(@config)
|
|
157
32
|
end
|
|
158
33
|
|
|
159
|
-
def
|
|
160
|
-
|
|
161
|
-
merchant_ref_num: merchant_ref_num,
|
|
162
|
-
card: {
|
|
163
|
-
payment_token: token
|
|
164
|
-
}
|
|
165
|
-
}).to_camel_case
|
|
166
|
-
|
|
167
|
-
response = post(path: "/cardpayments/v1/accounts/#{account_number}/verifications", data: data)
|
|
168
|
-
process_response(response, Verification)
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
def verify_card(merchant_ref_num:, number:, month:, year:, cvv:, address:, **args)
|
|
172
|
-
data = args.merge({
|
|
173
|
-
merchant_ref_num: merchant_ref_num,
|
|
174
|
-
billing_details: address,
|
|
175
|
-
card: {
|
|
176
|
-
card_num: number,
|
|
177
|
-
cvv: cvv,
|
|
178
|
-
card_expiry: {
|
|
179
|
-
month: month,
|
|
180
|
-
year: year
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}).to_camel_case
|
|
184
|
-
|
|
185
|
-
response = post(path: "/cardpayments/v1/accounts/#{account_number}/verifications", data: data)
|
|
186
|
-
process_response(response, Verification)
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
private
|
|
190
|
-
|
|
191
|
-
def http_client
|
|
192
|
-
HTTP
|
|
193
|
-
.headers(HEADERS)
|
|
194
|
-
.timeout(timeouts ? timeouts : :null)
|
|
195
|
-
.basic_auth(user: api_key, pass: api_secret)
|
|
34
|
+
def payments
|
|
35
|
+
@payments ||= Api::PaymentsApi.new(@config)
|
|
196
36
|
end
|
|
197
|
-
|
|
198
|
-
def post(path:, data:)
|
|
199
|
-
http_client.post("#{api_base}#{path}", json: data)
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
def get(path:)
|
|
203
|
-
http_client.get("#{api_base}#{path}")
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
def delete(path:)
|
|
207
|
-
http_client.delete("#{api_base}#{path}")
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
def put(path:, data:)
|
|
211
|
-
http_client.put("#{api_base}#{path}", json: data)
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
def process_response(response, klass=nil)
|
|
215
|
-
data = parse_response_body(response.to_s)
|
|
216
|
-
|
|
217
|
-
if response.status.success?
|
|
218
|
-
klass&.new(data)
|
|
219
|
-
else
|
|
220
|
-
fail Error.from_response(data, response.code)
|
|
221
|
-
end
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
def parse_response_body(body)
|
|
225
|
-
return nil if body.strip.empty?
|
|
226
|
-
JSON.parse(body, symbolize_names: true)&.to_snake_case
|
|
227
|
-
rescue JSON::ParserError
|
|
228
|
-
end
|
|
229
|
-
|
|
230
37
|
end
|
|
231
38
|
end
|
|
232
39
|
end
|
|
@@ -2,7 +2,8 @@ require 'paysafe/result'
|
|
|
2
2
|
|
|
3
3
|
module Paysafe
|
|
4
4
|
class SingleUseToken < Result
|
|
5
|
-
attributes :id, :payment_token, :time_to_live_seconds
|
|
5
|
+
attributes :id, :payment_token, :time_to_live_seconds, :customer_id,
|
|
6
|
+
:status, :single_use_customer_token, :locale
|
|
6
7
|
|
|
7
8
|
object_attribute :Card, :card
|
|
8
9
|
object_attribute :Address, :billing_address
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'paysafe/result'
|
|
2
|
+
|
|
3
|
+
module Paysafe
|
|
4
|
+
class StandaloneCredit < Result
|
|
5
|
+
attributes :id,
|
|
6
|
+
:payment_type,
|
|
7
|
+
:payment_handle_token,
|
|
8
|
+
:merchant_ref_num,
|
|
9
|
+
:currency_code,
|
|
10
|
+
:txn_time,
|
|
11
|
+
:status,
|
|
12
|
+
:gateway_reconciliation_id,
|
|
13
|
+
:amount,
|
|
14
|
+
:live_mode,
|
|
15
|
+
:updated_time,
|
|
16
|
+
:status_time
|
|
17
|
+
|
|
18
|
+
object_attribute :Address, :billing_details
|
|
19
|
+
object_attribute :Customer, :profile
|
|
20
|
+
object_attribute :GatewayResponse, :gateway_response
|
|
21
|
+
object_attribute :PaymentProcessor, :sightline
|
|
22
|
+
end
|
|
23
|
+
end
|
data/lib/paysafe/verification.rb
CHANGED
|
@@ -12,13 +12,13 @@ module Paysafe
|
|
|
12
12
|
|
|
13
13
|
[:unknown, :not_processed, :no_match, :match, :match_address_only, :match_zip_only].each do |key|
|
|
14
14
|
define_method("avs_#{key}?") do
|
|
15
|
-
avs_response == key.to_s.upcase
|
|
15
|
+
avs_response.to_s.upcase == key.to_s.upcase
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
[:unknown, :match, :no_match, :not_processed].each do |key|
|
|
20
20
|
define_method("cvv_#{key}?") do
|
|
21
|
-
cvv_verification == key.to_s.upcase
|
|
21
|
+
cvv_verification.to_s.upcase == key.to_s.upcase
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
end
|
data/lib/paysafe/version.rb
CHANGED
data/paysafe.gemspec
CHANGED
|
@@ -7,11 +7,11 @@ Gem::Specification.new do |spec|
|
|
|
7
7
|
spec.name = "paysafe"
|
|
8
8
|
spec.version = Paysafe::VERSION
|
|
9
9
|
spec.authors = ["Javier Julio"]
|
|
10
|
-
spec.email = ["
|
|
10
|
+
spec.email = ["javier@jackpocket.com"]
|
|
11
11
|
|
|
12
12
|
spec.summary = "A Ruby interface to the Paysafe REST API."
|
|
13
13
|
spec.description = "A Ruby interface to the Paysafe REST API."
|
|
14
|
-
spec.homepage = "https://github.com/
|
|
14
|
+
spec.homepage = "https://github.com/jackpocket/paysafe"
|
|
15
15
|
spec.license = "MIT"
|
|
16
16
|
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
@@ -19,16 +19,16 @@ Gem::Specification.new do |spec|
|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
20
|
spec.require_paths = ["lib"]
|
|
21
21
|
|
|
22
|
-
spec.required_ruby_version = '>= 2.
|
|
22
|
+
spec.required_ruby_version = '>= 2.5'
|
|
23
23
|
|
|
24
|
-
spec.add_dependency "http", '>=
|
|
24
|
+
spec.add_dependency "http", '>= 4', '< 5'
|
|
25
25
|
|
|
26
26
|
spec.add_development_dependency "rake"
|
|
27
27
|
spec.add_development_dependency "bundler", "~> 2.0"
|
|
28
28
|
spec.add_development_dependency "dotenv"
|
|
29
29
|
spec.add_development_dependency "minitest"
|
|
30
30
|
spec.add_development_dependency "minitest-reporters"
|
|
31
|
+
spec.add_development_dependency "minitest-mock_expectations"
|
|
31
32
|
spec.add_development_dependency "vcr"
|
|
32
33
|
spec.add_development_dependency "webmock"
|
|
33
|
-
|
|
34
34
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: paysafe
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.14.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Javier Julio
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-01-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: http
|
|
@@ -16,7 +16,7 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
19
|
+
version: '4'
|
|
20
20
|
- - "<"
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
22
|
version: '5'
|
|
@@ -26,7 +26,7 @@ dependencies:
|
|
|
26
26
|
requirements:
|
|
27
27
|
- - ">="
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version:
|
|
29
|
+
version: '4'
|
|
30
30
|
- - "<"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
32
|
version: '5'
|
|
@@ -100,6 +100,20 @@ dependencies:
|
|
|
100
100
|
- - ">="
|
|
101
101
|
- !ruby/object:Gem::Version
|
|
102
102
|
version: '0'
|
|
103
|
+
- !ruby/object:Gem::Dependency
|
|
104
|
+
name: minitest-mock_expectations
|
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
type: :development
|
|
111
|
+
prerelease: false
|
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - ">="
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '0'
|
|
103
117
|
- !ruby/object:Gem::Dependency
|
|
104
118
|
name: vcr
|
|
105
119
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -130,17 +144,18 @@ dependencies:
|
|
|
130
144
|
version: '0'
|
|
131
145
|
description: A Ruby interface to the Paysafe REST API.
|
|
132
146
|
email:
|
|
133
|
-
-
|
|
147
|
+
- javier@jackpocket.com
|
|
134
148
|
executables: []
|
|
135
149
|
extensions: []
|
|
136
150
|
extra_rdoc_files: []
|
|
137
151
|
files:
|
|
138
152
|
- ".env.sample"
|
|
153
|
+
- ".github/workflows/ci.yml"
|
|
139
154
|
- ".gitignore"
|
|
140
|
-
- ".travis.yml"
|
|
141
155
|
- CHANGELOG.md
|
|
142
156
|
- CODE_OF_CONDUCT.md
|
|
143
157
|
- Gemfile
|
|
158
|
+
- Gemfile.lock
|
|
144
159
|
- LICENSE.txt
|
|
145
160
|
- README.md
|
|
146
161
|
- Rakefile
|
|
@@ -148,21 +163,33 @@ files:
|
|
|
148
163
|
- bin/setup
|
|
149
164
|
- lib/paysafe.rb
|
|
150
165
|
- lib/paysafe/address.rb
|
|
166
|
+
- lib/paysafe/api/base_api.rb
|
|
167
|
+
- lib/paysafe/api/card_payments_api.rb
|
|
168
|
+
- lib/paysafe/api/customer_vault_api.rb
|
|
169
|
+
- lib/paysafe/api/payments_api.rb
|
|
151
170
|
- lib/paysafe/authorization.rb
|
|
152
171
|
- lib/paysafe/birth_date.rb
|
|
153
172
|
- lib/paysafe/card.rb
|
|
154
173
|
- lib/paysafe/card_expiry.rb
|
|
174
|
+
- lib/paysafe/configuration.rb
|
|
175
|
+
- lib/paysafe/customer.rb
|
|
155
176
|
- lib/paysafe/error.rb
|
|
177
|
+
- lib/paysafe/gateway_response.rb
|
|
178
|
+
- lib/paysafe/payment.rb
|
|
179
|
+
- lib/paysafe/payment_method.rb
|
|
180
|
+
- lib/paysafe/payment_methods.rb
|
|
181
|
+
- lib/paysafe/payment_processor.rb
|
|
156
182
|
- lib/paysafe/profile.rb
|
|
157
183
|
- lib/paysafe/refinements/camel_case.rb
|
|
158
184
|
- lib/paysafe/refinements/snake_case.rb
|
|
159
185
|
- lib/paysafe/rest/client.rb
|
|
160
186
|
- lib/paysafe/result.rb
|
|
161
187
|
- lib/paysafe/single_use_token.rb
|
|
188
|
+
- lib/paysafe/standalone_credit.rb
|
|
162
189
|
- lib/paysafe/verification.rb
|
|
163
190
|
- lib/paysafe/version.rb
|
|
164
191
|
- paysafe.gemspec
|
|
165
|
-
homepage: https://github.com/
|
|
192
|
+
homepage: https://github.com/jackpocket/paysafe
|
|
166
193
|
licenses:
|
|
167
194
|
- MIT
|
|
168
195
|
metadata: {}
|
|
@@ -174,14 +201,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
174
201
|
requirements:
|
|
175
202
|
- - ">="
|
|
176
203
|
- !ruby/object:Gem::Version
|
|
177
|
-
version: 2.
|
|
204
|
+
version: '2.5'
|
|
178
205
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
206
|
requirements:
|
|
180
207
|
- - ">="
|
|
181
208
|
- !ruby/object:Gem::Version
|
|
182
209
|
version: '0'
|
|
183
210
|
requirements: []
|
|
184
|
-
rubygems_version: 3.
|
|
211
|
+
rubygems_version: 3.1.4
|
|
185
212
|
signing_key:
|
|
186
213
|
specification_version: 4
|
|
187
214
|
summary: A Ruby interface to the Paysafe REST API.
|
data/.travis.yml
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
language: ruby
|
|
2
|
-
rvm:
|
|
3
|
-
- 2.3.4
|
|
4
|
-
- 2.4.7
|
|
5
|
-
- 2.5.6
|
|
6
|
-
- 2.6.4
|
|
7
|
-
before_install:
|
|
8
|
-
- gem update --system
|
|
9
|
-
- gem install bundler
|
|
10
|
-
cache: bundler
|
|
11
|
-
sudo: false
|
|
12
|
-
fast_finish: true
|
|
13
|
-
env:
|
|
14
|
-
- SKIP_INTEGRATION=true
|
|
15
|
-
notifications:
|
|
16
|
-
email:
|
|
17
|
-
on_success: always
|
|
18
|
-
on_failure: always
|