mangopay4-ruby-sdk 3.44.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 +7 -0
- data/.github/workflows/ruby_cd.yml +34 -0
- data/.github/workflows/ruby_ci.yml +30 -0
- data/.gitignore +30 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +640 -0
- data/Gemfile +2 -0
- data/LICENSE +20 -0
- data/README.md +162 -0
- data/Rakefile +5 -0
- data/bin/mangopay +9 -0
- data/lib/generators/mangopay/install_generator.rb +60 -0
- data/lib/generators/templates/mangopay.rb.erb +5 -0
- data/lib/mangopay/acquiring.rb +56 -0
- data/lib/mangopay/authorization_token.rb +89 -0
- data/lib/mangopay/bank_account.rb +49 -0
- data/lib/mangopay/bankingaliases.rb +29 -0
- data/lib/mangopay/bankingaliases_iban.rb +16 -0
- data/lib/mangopay/card.rb +54 -0
- data/lib/mangopay/card_registration.rb +9 -0
- data/lib/mangopay/client.rb +94 -0
- data/lib/mangopay/conversion.rb +49 -0
- data/lib/mangopay/deposit.rb +36 -0
- data/lib/mangopay/dispute.rb +152 -0
- data/lib/mangopay/errors.rb +66 -0
- data/lib/mangopay/event.rb +18 -0
- data/lib/mangopay/filter_parameters.rb +56 -0
- data/lib/mangopay/hook.rb +9 -0
- data/lib/mangopay/http_calls.rb +88 -0
- data/lib/mangopay/identity_verification.rb +16 -0
- data/lib/mangopay/json.rb +14 -0
- data/lib/mangopay/kyc_document.rb +83 -0
- data/lib/mangopay/legal_user.rb +21 -0
- data/lib/mangopay/legal_user_sca.rb +25 -0
- data/lib/mangopay/mandate.rb +42 -0
- data/lib/mangopay/natural_user.rb +20 -0
- data/lib/mangopay/natural_user_sca.rb +25 -0
- data/lib/mangopay/pay_in.rb +415 -0
- data/lib/mangopay/pay_out.rb +41 -0
- data/lib/mangopay/payment_method_metadata.rb +13 -0
- data/lib/mangopay/pre_authorization.rb +17 -0
- data/lib/mangopay/recipient.rb +35 -0
- data/lib/mangopay/refund.rb +19 -0
- data/lib/mangopay/regulatory.rb +22 -0
- data/lib/mangopay/report.rb +24 -0
- data/lib/mangopay/report_v2.rb +21 -0
- data/lib/mangopay/resource.rb +21 -0
- data/lib/mangopay/settlement.rb +21 -0
- data/lib/mangopay/transaction.rb +24 -0
- data/lib/mangopay/transfer.rb +20 -0
- data/lib/mangopay/ubo.rb +26 -0
- data/lib/mangopay/ubo_declaration.rb +32 -0
- data/lib/mangopay/user.rb +100 -0
- data/lib/mangopay/version.rb +3 -0
- data/lib/mangopay/virtual_account.rb +44 -0
- data/lib/mangopay/wallet.rb +17 -0
- data/lib/mangopay.rb +456 -0
- data/mangopay.gemspec +30 -0
- data/spec/mangopay/acquiring_spec.rb +176 -0
- data/spec/mangopay/authorization_token_spec.rb +70 -0
- data/spec/mangopay/bank_account_spec.rb +105 -0
- data/spec/mangopay/bankingaliases_spec.rb +29 -0
- data/spec/mangopay/card_registration_spec.rb +123 -0
- data/spec/mangopay/client_spec.png +0 -0
- data/spec/mangopay/client_spec.rb +213 -0
- data/spec/mangopay/configuration_spec.rb +249 -0
- data/spec/mangopay/conversion_spec.rb +96 -0
- data/spec/mangopay/deposit_spec.rb +107 -0
- data/spec/mangopay/dispute_spec.png +0 -0
- data/spec/mangopay/dispute_spec.rb +294 -0
- data/spec/mangopay/event_spec.rb +33 -0
- data/spec/mangopay/fetch_filters_spec.rb +63 -0
- data/spec/mangopay/hook_spec.rb +37 -0
- data/spec/mangopay/idempotency_spec.rb +41 -0
- data/spec/mangopay/identity_verification_spec.rb +47 -0
- data/spec/mangopay/kyc_document_spec.png +0 -0
- data/spec/mangopay/kyc_document_spec.rb +118 -0
- data/spec/mangopay/log_requests_filter_spec.rb +26 -0
- data/spec/mangopay/mandate_spec.rb +99 -0
- data/spec/mangopay/payin_applepay_direct_spec.rb +21 -0
- data/spec/mangopay/payin_bancontact_web_spec.rb +30 -0
- data/spec/mangopay/payin_bankwire_direct_spec.rb +74 -0
- data/spec/mangopay/payin_bankwire_external_instruction_spec.rb +104 -0
- data/spec/mangopay/payin_bizum_web_spec.rb +54 -0
- data/spec/mangopay/payin_blik_web_spec.rb +41 -0
- data/spec/mangopay/payin_card_direct_spec.rb +69 -0
- data/spec/mangopay/payin_card_web_spec.rb +64 -0
- data/spec/mangopay/payin_directdebit_direct_spec.rb +37 -0
- data/spec/mangopay/payin_directdebit_web_spec.rb +38 -0
- data/spec/mangopay/payin_giropay_web_spec.rb +30 -0
- data/spec/mangopay/payin_googlepay_direct_spec.rb +21 -0
- data/spec/mangopay/payin_ideal_web_spec.rb +30 -0
- data/spec/mangopay/payin_intent_spec.rb +151 -0
- data/spec/mangopay/payin_klarna_web_spec.rb +32 -0
- data/spec/mangopay/payin_mbway_web_spec.rb +32 -0
- data/spec/mangopay/payin_multibanco_web_spec.rb +31 -0
- data/spec/mangopay/payin_paybybank_web_spec.rb +56 -0
- data/spec/mangopay/payin_payconiq_web_spec.rb +31 -0
- data/spec/mangopay/payin_paypal_web_spec.rb +113 -0
- data/spec/mangopay/payin_preauthorized_direct_spec.rb +118 -0
- data/spec/mangopay/payin_satispay_web_spec.rb +32 -0
- data/spec/mangopay/payin_swish_web_spec.rb +30 -0
- data/spec/mangopay/payin_twint_web_spec.rb +30 -0
- data/spec/mangopay/payment_method_metadata_spec.rb +15 -0
- data/spec/mangopay/payout_bankwire_spec.rb +93 -0
- data/spec/mangopay/preauthorization_spec.rb +51 -0
- data/spec/mangopay/recipient_spec.rb +134 -0
- data/spec/mangopay/recurring_payin_spec.rb +222 -0
- data/spec/mangopay/refund_spec.rb +34 -0
- data/spec/mangopay/regulatory_spec.rb +26 -0
- data/spec/mangopay/report_spec.rb +40 -0
- data/spec/mangopay/report_v2_spec.rb +117 -0
- data/spec/mangopay/report_wallets_spec.rb +40 -0
- data/spec/mangopay/settlement_sample.csv +8 -0
- data/spec/mangopay/settlement_spec.rb +38 -0
- data/spec/mangopay/shared_resources.rb +1380 -0
- data/spec/mangopay/transaction_spec.rb +59 -0
- data/spec/mangopay/transfer_spec.rb +77 -0
- data/spec/mangopay/ubo_declaration_spec.rb +44 -0
- data/spec/mangopay/ubo_spec.rb +39 -0
- data/spec/mangopay/user_spec.rb +444 -0
- data/spec/mangopay/virtual_account_spec.rb +52 -0
- data/spec/mangopay/wallet_spec.rb +100 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/tmp/.keep +0 -0
- metadata +280 -0
data/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Mangopay Ruby SDK
|
|
2
|
+
|
|
3
|
+
[](https://rubygems.org/gems/mangopay4-ruby-sdk)
|
|
4
|
+
|
|
5
|
+
Official [Mangopay Gem](https://rubygems.org/gems/mangopay4-ruby-sdk) to access the [Mangopay API](https://docs.mangopay.com/api-reference) from applications written in Ruby.
|
|
6
|
+
|
|
7
|
+
See the [Mangopay API documentation](https://docs.mangopay.com/) for Ruby samples and details on product features. See the [SDK tests](#tests) for further usage examples.
|
|
8
|
+
|
|
9
|
+
## Prerequisites
|
|
10
|
+
- * A `ClientId` and an API key – if you don't have these, <a href="https://mangopay.com/contact" target="_blank">contact Sales</a> to get access to the <a href="https://hub.mangopay.com/" target="_blank">Mangopay Dashboard</a>
|
|
11
|
+
- Ruby 1.9.2 or higher (tested from 1.9.2 up to 3.4.4)
|
|
12
|
+
|
|
13
|
+
Since SDK [v3.0.17](https://github.com/Mangopay/mangopay2-ruby-sdk/releases/tag/v3.0.17), the library uses v2.01 of the API. The older API version (v2) is no longer available.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
* Install the gem by either running ```gem install mangopay4-ruby-sdk```
|
|
18
|
+
or by adding it to your Gemfile ```gem 'mangopay4-ruby-sdk'```
|
|
19
|
+
|
|
20
|
+
* Call ```MangoPay.configure``` in your script as shown in the snippet below.
|
|
21
|
+
|
|
22
|
+
### Usage
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
require 'mangopay'
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# configuration
|
|
29
|
+
MangoPay.configure do |c|
|
|
30
|
+
c.preproduction = true
|
|
31
|
+
c.client_id = 'YOUR_CLIENT_ID'
|
|
32
|
+
c.client_apiKey = 'YOUR_CLIENT_API_KEY'
|
|
33
|
+
c.log_file = File.join('mypath', 'mangopay.log')
|
|
34
|
+
c.http_timeout = 10000
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# get some user by id
|
|
39
|
+
john = MangoPay::User.fetch(john_id) # => {FirstName"=>"John", "LastName"=>"Doe", ...}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
# update some of his data
|
|
43
|
+
MangoPay::NaturalUser.update(john_id, {'LastName' => 'CHANGED'}) # => {FirstName"=>"John", "LastName"=>"CHANGED", ...}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# get all users (with pagination)
|
|
47
|
+
pagination = {'page' => 1, 'per_page' => 8} # get 1st page, 8 items per page
|
|
48
|
+
users = MangoPay::User.fetch(pagination) # => [{...}, ...]: list of 8 users data hashes
|
|
49
|
+
pagination # => {"page"=>1, "per_page"=>8, "total_pages"=>748, "total_items"=>5978}
|
|
50
|
+
|
|
51
|
+
# pass custom filters (transactions reporting filters)
|
|
52
|
+
filters = {'MinFeesAmount' => 1, 'MinFeesCurrency' => 'EUR', 'MaxFeesAmount' => 1000, 'MaxFeesCurrency' => 'EUR'}
|
|
53
|
+
reports = MangoPay::Report.fetch(filters) # => [{...}, ...]: list of transaction reports between 1 and 1000 EUR
|
|
54
|
+
|
|
55
|
+
# get John's bank accounts
|
|
56
|
+
accounts = MangoPay::BankAccount.fetch(john_id) # => [{...}, ...]: list of accounts data hashes (10 per page by default)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# error handling
|
|
60
|
+
begin
|
|
61
|
+
MangoPay::NaturalUser.create({})
|
|
62
|
+
rescue MangoPay::ResponseError => ex
|
|
63
|
+
|
|
64
|
+
ex # => #<MangoPay::ResponseError: One or several required parameters are missing or incorrect. [...] FirstName: The FirstName field is required. LastName: The LastName field is required. Nationality: The Nationality field is required.>
|
|
65
|
+
|
|
66
|
+
ex.details # => {
|
|
67
|
+
# "Message"=>"One or several required parameters are missing or incorrect. [...]",
|
|
68
|
+
# "Type"=>"param_error",
|
|
69
|
+
# "Id"=>"5c080105-4da3-467d-820d-0906164e55fe",
|
|
70
|
+
# "Date"=>1409048671.0,
|
|
71
|
+
# "errors"=>{
|
|
72
|
+
# "FirstName"=>"The FirstName field is required.",
|
|
73
|
+
# "LastName"=>"The LastName field is required.", ...},
|
|
74
|
+
# "Code"=>"400",
|
|
75
|
+
# "Url"=>"/v2/.../users/natural"
|
|
76
|
+
# }
|
|
77
|
+
end
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Using multiple Client IDs
|
|
81
|
+
The Ruby SDK offers the option to create multiple configuration objects tailored to your specific needs:
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
config = MangoPay::Configuration.new
|
|
85
|
+
config.client_id = 'your-client-id'
|
|
86
|
+
config.client_apiKey = 'your-api-key'
|
|
87
|
+
config.preproduction = true
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Add them using:
|
|
91
|
+
|
|
92
|
+
`MangoPay.add_config('config1', config)`
|
|
93
|
+
|
|
94
|
+
And perform a call with them using:
|
|
95
|
+
|
|
96
|
+
`MangoPay.get_config('config1').apply_configuration`
|
|
97
|
+
|
|
98
|
+
The previous method `configure()` is still working.
|
|
99
|
+
|
|
100
|
+
### Accessing rate limiting headers
|
|
101
|
+
The API returns rate limiting headers which are automatically updated in the `MangoPay` object:
|
|
102
|
+
|
|
103
|
+
* X-RateLimit-Limit
|
|
104
|
+
* X-RateLimit-Remaining
|
|
105
|
+
* X-RateLimit-Reset
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
MangoPay.ratelimit
|
|
109
|
+
|
|
110
|
+
{
|
|
111
|
+
:limit=>["74", "74", "75", "908"],
|
|
112
|
+
:remaining=>["2226", "4426", "8725", "104692"],
|
|
113
|
+
:reset=>["1495615620", "1495616520", "1495618320", "1495701060"]
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
For more information, see the [rate limiting](https://docs.mangopay.com/api-reference/overview/rate-limiting) article on the Mangopay docs.
|
|
118
|
+
|
|
119
|
+
### Log requests and responses
|
|
120
|
+
You can enable logs by setting the ```log_file``` configuration option (see [usage](#usage) above). If you don't want logs, remove the ```log_file``` line.
|
|
121
|
+
|
|
122
|
+
Requests and responses are filtered, so confidential data is not saved in logs.
|
|
123
|
+
|
|
124
|
+
### Tests
|
|
125
|
+
Make sure that you have run:
|
|
126
|
+
```
|
|
127
|
+
bundle install
|
|
128
|
+
```
|
|
129
|
+
Then to run the test suite, run:
|
|
130
|
+
```
|
|
131
|
+
rspec
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Issues
|
|
135
|
+
|
|
136
|
+
Create a [GitHub issue](https://github.com/Mangopay/mangopay2-ruby-sdk/issues) to report any problems or request features.
|
|
137
|
+
|
|
138
|
+
We aim to reply to issues and contributions in a timely manner. For additional followup or anything that can't be shared over GitHub, please get in touch with our Support teams via the <a href="https://hub.mangopay.com/" target="_blank">Mangopay Dashboard</a>.
|
|
139
|
+
|
|
140
|
+
## Contributing
|
|
141
|
+
|
|
142
|
+
1. Fork the repo.
|
|
143
|
+
|
|
144
|
+
2. Run the tests. We only take pull requests with passing tests, and it's great
|
|
145
|
+
to know that you have a clean slate: `bundle && bundle exec rspec`
|
|
146
|
+
|
|
147
|
+
3. Add a test for your change. Only refactoring and documentation changes
|
|
148
|
+
require no new tests. If you are adding functionality or fixing a bug, we need
|
|
149
|
+
a test!
|
|
150
|
+
|
|
151
|
+
4. Make the test pass.
|
|
152
|
+
|
|
153
|
+
5. Push to your fork and submit a pull request.
|
|
154
|
+
|
|
155
|
+
Syntax:
|
|
156
|
+
|
|
157
|
+
* Two spaces, no tabs.
|
|
158
|
+
* No trailing whitespace. Blank lines should not have any space.
|
|
159
|
+
* Prefer &&/|| over and/or.
|
|
160
|
+
* MyClass.my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
|
|
161
|
+
* a = b and not a=b.
|
|
162
|
+
* Follow the conventions you see used in the source already.
|
data/Rakefile
ADDED
data/bin/mangopay
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'rails/generators/base'
|
|
2
|
+
require 'mangopay'
|
|
3
|
+
|
|
4
|
+
module Mangopay
|
|
5
|
+
module Generators
|
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
|
7
|
+
source_root File.expand_path('../../templates', __FILE__)
|
|
8
|
+
argument :client_id, type: :string,
|
|
9
|
+
desc: 'The id you want to use to query the MangoPay API (must match with the regex ^[a-z0-9_-]{4,20}$)'
|
|
10
|
+
argument :client_name, type: :string, desc: "Full name of you're organization"
|
|
11
|
+
argument :client_email, type: :string, desc: "An email for future contacts"
|
|
12
|
+
class_option :preproduction, type: :boolean, default: true, desc: 'Whether or not use the preproduction environment'
|
|
13
|
+
|
|
14
|
+
desc 'Installs all the basic configuration of the mangopay gem'
|
|
15
|
+
def setup
|
|
16
|
+
begin
|
|
17
|
+
client = client_id_valid?
|
|
18
|
+
remove_file 'config/initializers/mangopay.rb'
|
|
19
|
+
@client_id = client_id
|
|
20
|
+
@client_apiKey = client['APIKey']
|
|
21
|
+
template 'mangopay.rb.erb', 'config/initializers/mangopay.rb'
|
|
22
|
+
rescue => e
|
|
23
|
+
puts e.message
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
protected
|
|
28
|
+
|
|
29
|
+
def client_id_valid?
|
|
30
|
+
check_client_id_validity
|
|
31
|
+
check_client_id_availablility
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def check_client_id_validity
|
|
35
|
+
if (/^[a-z0-9_-]{4,20}$/ =~ client_id).nil?
|
|
36
|
+
raise "The client_id must match the regexp ^[a-z0-9_-]{4,20}$"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def check_client_id_availablility
|
|
41
|
+
client = create_client
|
|
42
|
+
if client['Type'] == 'ClientID_already_exist'
|
|
43
|
+
raise client['Message']
|
|
44
|
+
end
|
|
45
|
+
client
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def create_client
|
|
49
|
+
MangoPay.configure do |c|
|
|
50
|
+
c.preproduction = options[:preproduction]
|
|
51
|
+
end
|
|
52
|
+
MangoPay::Client.create({
|
|
53
|
+
ClientID: client_id,
|
|
54
|
+
Name: client_name,
|
|
55
|
+
Email: client_email
|
|
56
|
+
})
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module MangoPay
|
|
2
|
+
|
|
3
|
+
class Acquiring < Resource
|
|
4
|
+
module PayIn
|
|
5
|
+
module Card
|
|
6
|
+
class Direct < Resource
|
|
7
|
+
def self.create(params, idempotency_key = nil)
|
|
8
|
+
MangoPay.request(:post, "#{MangoPay.api_path}/acquiring/payins/card/direct", params, {}, idempotency_key)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module ApplePay
|
|
14
|
+
class Direct < Resource
|
|
15
|
+
def self.create(params, idempotency_key = nil)
|
|
16
|
+
MangoPay.request(:post, "#{MangoPay.api_path}/acquiring/payins/payment-methods/applepay", params, {}, idempotency_key)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
module GooglePay
|
|
22
|
+
class Direct < Resource
|
|
23
|
+
def self.create(params, idempotency_key = nil)
|
|
24
|
+
MangoPay.request(:post, "#{MangoPay.api_path}/acquiring/payins/payment-methods/googlepay", params, {}, idempotency_key)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
module Ideal
|
|
30
|
+
class Web < Resource
|
|
31
|
+
def self.create(params, idempotency_key = nil)
|
|
32
|
+
MangoPay.request(:post, "#{MangoPay.api_path}/acquiring/payins/payment-methods/ideal", params, {}, idempotency_key)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
module PayPal
|
|
38
|
+
class Web < Resource
|
|
39
|
+
def self.create(params, idempotency_key = nil)
|
|
40
|
+
MangoPay.request(:post, "#{MangoPay.api_path}/acquiring/payins/payment-methods/paypal", params, {}, idempotency_key)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.create_data_collection(params, idempotency_key = nil)
|
|
44
|
+
MangoPay.request(:post, "#{MangoPay.api_path}/acquiring/payins/payment-methods/paypal/data-collection", params, {}, idempotency_key)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
class Refund < Resource
|
|
51
|
+
def self.create(pay_in_id, params, idempotency_key = nil)
|
|
52
|
+
MangoPay.request(:post, "#{MangoPay.api_path}/acquiring/payins/#{pay_in_id}/refunds", params, {}, idempotency_key)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
module MangoPay
|
|
2
|
+
module AuthorizationToken
|
|
3
|
+
|
|
4
|
+
# See http://docs.mangopay.com/api-references/authenticating/
|
|
5
|
+
class Manager
|
|
6
|
+
|
|
7
|
+
class << self
|
|
8
|
+
def storage
|
|
9
|
+
@@storage ||= StaticStorage.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def storage= (storage)
|
|
13
|
+
@@storage = storage
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def get_token
|
|
17
|
+
token = storage.get
|
|
18
|
+
env_key = get_environment_key_for_token
|
|
19
|
+
if token.nil? || token['timestamp'].nil? || token['timestamp'] <= Time.now || token['environment_key'] != env_key
|
|
20
|
+
token = MangoPay.request(:post, "/#{MangoPay.version_code}/oauth/token", {}, {}, {}, Proc.new do |req|
|
|
21
|
+
cfg = MangoPay.configuration
|
|
22
|
+
req.basic_auth cfg.client_id, cfg.client_apiKey
|
|
23
|
+
req.body = 'grant_type=client_credentials'
|
|
24
|
+
req.add_field('Content-Type', 'application/x-www-form-urlencoded')
|
|
25
|
+
end)
|
|
26
|
+
token['timestamp'] = Time.now + (token['expires_in'].to_i - 30)
|
|
27
|
+
token['environment_key'] = env_key
|
|
28
|
+
storage.store token
|
|
29
|
+
end
|
|
30
|
+
token
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def get_environment_key_for_token
|
|
34
|
+
cfg = MangoPay.configuration
|
|
35
|
+
key = "#{cfg.root_url}|#{cfg.client_id}|#{cfg.client_apiKey}"
|
|
36
|
+
key = Digest::MD5.hexdigest(key)
|
|
37
|
+
key
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class StaticStorage
|
|
43
|
+
def get
|
|
44
|
+
@@token ||= nil
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def store(token)
|
|
48
|
+
@@token = token
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class FileStorage
|
|
53
|
+
require 'yaml'
|
|
54
|
+
@temp_dir
|
|
55
|
+
|
|
56
|
+
def initialize(temp_dir = nil)
|
|
57
|
+
@temp_dir = temp_dir || MangoPay.configuration.temp_dir
|
|
58
|
+
if !@temp_dir
|
|
59
|
+
raise "Path to temporary folder is not defined"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def get
|
|
64
|
+
begin
|
|
65
|
+
f = File.open(file_path, File::RDONLY)
|
|
66
|
+
f.flock(File::LOCK_SH)
|
|
67
|
+
txt = f.read
|
|
68
|
+
f.close
|
|
69
|
+
YAML.load(txt) || nil
|
|
70
|
+
rescue Errno::ENOENT
|
|
71
|
+
nil
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def store(token)
|
|
76
|
+
File.open(file_path, File::RDWR | File::CREAT, 0644) do |f|
|
|
77
|
+
f.flock(File::LOCK_EX)
|
|
78
|
+
f.truncate(0)
|
|
79
|
+
f.rewind
|
|
80
|
+
f.puts(YAML.dump(token))
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def file_path
|
|
85
|
+
File.join(@temp_dir, "MangoPay.AuthorizationToken.FileStore.tmp")
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
module MangoPay
|
|
2
|
+
|
|
3
|
+
# See http://docs.mangopay.com/api-references/bank-accounts/
|
|
4
|
+
class BankAccount < Resource
|
|
5
|
+
include HTTPCalls::Fetch
|
|
6
|
+
class << self
|
|
7
|
+
def create(user_id, params, idempotency_key = nil)
|
|
8
|
+
type = params.fetch(:Type) { |no_symbol_key| params.fetch('Type') }
|
|
9
|
+
MangoPay.request(:post, "#{url(user_id)}/#{type}", params, {}, idempotency_key)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Fetches:
|
|
13
|
+
# - list of bank accounts belonging to the given +user_id+
|
|
14
|
+
# - or single bank account belonging to the given +user_id+ with the given +bank_account_id+.
|
|
15
|
+
#
|
|
16
|
+
# In case of list query, optional +filters+ is a hash accepting pagination and sorting params
|
|
17
|
+
# (+page+, +per_page+, +sort+; see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
|
|
18
|
+
#
|
|
19
|
+
def fetch(user_id, bank_account_id_or_filters={})
|
|
20
|
+
bank_account_id, filters = HTTPCalls::Fetch.parse_id_or_filters(bank_account_id_or_filters)
|
|
21
|
+
MangoPay.request(:get, url(user_id, bank_account_id), {}, filters)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# see https://docs.mangopay.com/endpoints/v2.01/bank-accounts#e306_disactivate-a-bank-account
|
|
25
|
+
def update(user_id, bank_account_id, params = {})
|
|
26
|
+
MangoPay.request(:put, url(user_id, bank_account_id), params)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Fetches list of transactions belonging to given +bank_account_id+.
|
|
30
|
+
#
|
|
31
|
+
# Optional +filters+ is a hash accepting following keys:
|
|
32
|
+
# - +page+, +per_page+, +sort+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
|
|
33
|
+
# - +Status+: TransactionStatus {CREATED, SUCCEEDED, FAILED}
|
|
34
|
+
# - +ResultCode+: string representing the transaction result
|
|
35
|
+
def transactions(bank_account_id, filters = {})
|
|
36
|
+
url = "#{MangoPay.api_path}/bankaccounts/#{bank_account_id}/transactions"
|
|
37
|
+
MangoPay.request(:get, url, {}, filters)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def url(user_id, bank_account_id = nil)
|
|
41
|
+
if bank_account_id
|
|
42
|
+
"#{MangoPay.api_path}/users/#{CGI.escape(user_id.to_s)}/bankaccounts/#{CGI.escape(bank_account_id.to_s)}"
|
|
43
|
+
else
|
|
44
|
+
"#{MangoPay.api_path}/users/#{CGI.escape(user_id.to_s)}/bankaccounts"
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module MangoPay
|
|
2
|
+
|
|
3
|
+
# See children class:
|
|
4
|
+
# - MangoPay::BankingAliasesIBAN
|
|
5
|
+
class BankingAliases < Resource
|
|
6
|
+
include HTTPCalls::Create
|
|
7
|
+
include HTTPCalls::Update
|
|
8
|
+
include HTTPCalls::Fetch
|
|
9
|
+
|
|
10
|
+
class << self
|
|
11
|
+
def create
|
|
12
|
+
raise 'Cannot create a MangoPay::BankingAlias. See MangoPay::BankingAliasesIBAN'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def url(id = nil)
|
|
16
|
+
if id
|
|
17
|
+
"#{MangoPay.api_path}/bankingaliases/#{CGI.escape(id)}"
|
|
18
|
+
else
|
|
19
|
+
"#{MangoPay.api_path}/bankingaliases"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def fetch_for_wallet(wallet_id, filters = {})
|
|
24
|
+
url = "#{MangoPay.api_path}/wallets/#{wallet_id}/bankingaliases"
|
|
25
|
+
MangoPay.request(:get, url, {}, filters)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module MangoPay
|
|
2
|
+
|
|
3
|
+
# See parent class MangoPay::BankingAliases
|
|
4
|
+
class BankingAliasesIBAN < BankingAliases
|
|
5
|
+
|
|
6
|
+
def self.create(params, wallet_id, headers_or_idempotency_key = nil)
|
|
7
|
+
url = "#{MangoPay.api_path}/wallets/#{wallet_id}/bankingaliases/iban"
|
|
8
|
+
MangoPay.request(:post, url, params, {}, headers_or_idempotency_key)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.url(id = nil)
|
|
12
|
+
"#{super.url(id)}"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
module MangoPay
|
|
2
|
+
|
|
3
|
+
# See http://docs.mangopay.com/api-references/card/
|
|
4
|
+
class Card < Resource
|
|
5
|
+
include HTTPCalls::Fetch
|
|
6
|
+
include HTTPCalls::Update
|
|
7
|
+
class << self
|
|
8
|
+
|
|
9
|
+
# Retrieves a list of cards having the same fingerprint.
|
|
10
|
+
# The fingerprint is a hash code uniquely generated
|
|
11
|
+
# for each 16-digit card number.
|
|
12
|
+
#
|
|
13
|
+
# @param +fingerprint+ The fingerprint hash code
|
|
14
|
+
# @param +filters+ Optional - a hash accepting following keys:
|
|
15
|
+
# - +page+, +per_page+, +sort+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
|
|
16
|
+
def get_by_fingerprint(fingerprint, filters = {})
|
|
17
|
+
MangoPay.request(:get, fingerprint_url(fingerprint), {}, filters)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Retrieves a list of transactions belonging to given +card_id+.
|
|
21
|
+
#
|
|
22
|
+
# Optional +filters+ is a hash accepting following keys:
|
|
23
|
+
# - +page+, +per_page+, +sort+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
|
|
24
|
+
# - +Status+: TransactionStatus {CREATED, SUCCEEDED, FAILED}
|
|
25
|
+
# - +ResultCode+: string representing the transaction result
|
|
26
|
+
def transactions(card_id, filters = {})
|
|
27
|
+
url = url(card_id) + '/transactions'
|
|
28
|
+
MangoPay.request(:get, url, {}, filters)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def fingerprint_url(fingerprint)
|
|
32
|
+
"#{MangoPay.api_path}/cards/fingerprints/#{fingerprint}"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def get_pre_authorizations(card_id, filters = {})
|
|
36
|
+
MangoPay.request(:get, "#{MangoPay.api_path}/cards/#{card_id}/preauthorizations")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def validate(card_id, params)
|
|
40
|
+
url = "#{MangoPay.api_path}/cards/#{card_id}/validation"
|
|
41
|
+
MangoPay.request(:post, url, params)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def get_card_validation(card_id, validation_id)
|
|
45
|
+
url = "#{MangoPay.api_path}/cards/#{card_id}/validation/#{validation_id}"
|
|
46
|
+
MangoPay.request(:get, url)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def get_transactions_by_fingerprint(fingerprint, filters = {})
|
|
50
|
+
MangoPay.request(:get, "#{fingerprint_url(fingerprint)}/transactions", {}, filters)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
require 'base64'
|
|
2
|
+
|
|
3
|
+
module MangoPay
|
|
4
|
+
class Client < Resource
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
|
|
8
|
+
# see https://docs.mangopay.com/api-references/client-details/
|
|
9
|
+
def fetch()
|
|
10
|
+
MangoPay.request(:get, url())
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# see https://docs.mangopay.com/api-references/client-details/
|
|
14
|
+
def update(params)
|
|
15
|
+
MangoPay.request(:put, url(), params)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# see https://docs.mangopay.com/api-references/client-details/
|
|
19
|
+
def upload_logo(file_content_base64, file_path = nil)
|
|
20
|
+
if file_content_base64.nil? && !file_path.nil?
|
|
21
|
+
bts = File.open(file_path, 'rb') { |f| f.read }
|
|
22
|
+
file_content_base64 = Base64.encode64(bts)
|
|
23
|
+
end
|
|
24
|
+
# normally it returns 204 HTTP code on success
|
|
25
|
+
begin
|
|
26
|
+
MangoPay.request(:put, url() + '/logo', {'File' => file_content_base64})
|
|
27
|
+
rescue ResponseError => ex
|
|
28
|
+
raise ex unless ex.code == '204'
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Fetch all your client wallets;
|
|
33
|
+
# +funds_type+ may be:
|
|
34
|
+
# - nil: all wallets
|
|
35
|
+
# - 'fees': fees wallets
|
|
36
|
+
# - 'credit': credit wallets
|
|
37
|
+
# see https://docs.mangopay.com/api-references/client-wallets/
|
|
38
|
+
def fetch_wallets(funds_type = nil)
|
|
39
|
+
MangoPay.request(:get, url() + "/wallets/#{funds_type}")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Fetch one of your client wallets (fees or credit) with a particular currency;
|
|
43
|
+
# +funds_type+ may be:
|
|
44
|
+
# - nil: all wallets
|
|
45
|
+
# - 'fees': fees wallets
|
|
46
|
+
# - 'credit': credit wallets
|
|
47
|
+
# +currency_iso_code+ is currncy ISO code
|
|
48
|
+
# see https://docs.mangopay.com/api-references/client-wallets/
|
|
49
|
+
def fetch_wallet(funds_type, currency_iso_code)
|
|
50
|
+
method = :get
|
|
51
|
+
path = url() + "/wallets/#{funds_type}/#{currency_iso_code}"
|
|
52
|
+
yield method, path if block_given?
|
|
53
|
+
MangoPay.request(method, path)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Fetch transactions for all your client wallets.
|
|
57
|
+
# Optional +filters+ hash: see MangoPay::Transaction.fetch
|
|
58
|
+
# See https://docs.mangopay.com/api-references/client-wallets/
|
|
59
|
+
def fetch_wallets_transactions(filters = {})
|
|
60
|
+
MangoPay.request(:get, url() + "/transactions", {}, filters)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Fetch transactions for one of your client wallets (fees or credit) with a particular currency;
|
|
64
|
+
# +funds_type+ may be:
|
|
65
|
+
# - nil: all wallets
|
|
66
|
+
# - 'fees': fees wallets
|
|
67
|
+
# - 'credit': credit wallets
|
|
68
|
+
# +currency_iso_code+ is currncy ISO code
|
|
69
|
+
# Optional +filters+ hash: see MangoPay::Transaction.fetch
|
|
70
|
+
# See https://docs.mangopay.com/api-references/client-wallets/
|
|
71
|
+
def fetch_wallet_transactions(funds_type, currency_iso_code, filters = {})
|
|
72
|
+
MangoPay.request(:get, url() + "/wallets/#{funds_type}/#{currency_iso_code}/transactions", {}, filters)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def create_bank_account(params)
|
|
76
|
+
MangoPay.request(:post, url() + "/bankaccounts/iban", params)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def create_payout(params)
|
|
80
|
+
method = :post
|
|
81
|
+
path = url() + "/payouts"
|
|
82
|
+
yield method, path, params if block_given?
|
|
83
|
+
MangoPay.request(method, path, params)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Create a Bank Wire PayIn to the Repudiation Wallet
|
|
87
|
+
# see https://docs.mangopay.com/api-reference/dispute-settlement/create-bank-wire-payin-to-repudiation-wallet
|
|
88
|
+
def create_bank_wire_direct_pay_in(params, idempotency_key = nil)
|
|
89
|
+
MangoPay.request(:post, url() + "/payins/bankwire/direct", params, {}, idempotency_key)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|