slimpay_client 0.1.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/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +232 -0
- data/Rakefile +12 -0
- data/lib/slimpay_client/app.rb +84 -0
- data/lib/slimpay_client/base.rb +183 -0
- data/lib/slimpay_client/card.rb +18 -0
- data/lib/slimpay_client/card_alias.rb +18 -0
- data/lib/slimpay_client/configuration.rb +27 -0
- data/lib/slimpay_client/creditor.rb +18 -0
- data/lib/slimpay_client/direct_debit.rb +38 -0
- data/lib/slimpay_client/error.rb +80 -0
- data/lib/slimpay_client/mandate.rb +18 -0
- data/lib/slimpay_client/order.rb +108 -0
- data/lib/slimpay_client/payment.rb +39 -0
- data/lib/slimpay_client/recurrent_card_transaction.rb +25 -0
- data/lib/slimpay_client/recurrent_direct_debit.rb +25 -0
- data/lib/slimpay_client/resource.rb +29 -0
- data/lib/slimpay_client/version.rb +5 -0
- data/lib/slimpay_client.rb +70 -0
- data/sig/slimpay_client.rbs +4 -0
- metadata +227 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c877f64434afcfc536f35f655513016378812511148e1acfd06253773556acca
|
4
|
+
data.tar.gz: 64a0b5b31b3adb349ac525144e6fd6ebc4cdddb79d6f49c714105f069ec8ab22
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eb2567473d6f701279d72de25806e207e84b024a868c79bae29ba6faec952f32beae25a7cc184b9215865c16b6587c21d971562e1f10e93006fb426bfbe40022
|
7
|
+
data.tar.gz: ea6e26aa6877b4a156d0c381f781931a5a233f73316e7073eccfc32352922a67481cb73e2996733b2b88cc7d7f92bb58ad5e85b108fffa5e7b9b3990f3233b93
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at idrissa.bara@widegroup.eu. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Idrissa Bara
|
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
ADDED
@@ -0,0 +1,232 @@
|
|
1
|
+
# SlimpayClient
|
2
|
+
|
3
|
+
Welcome to your new gem!
|
4
|
+
|
5
|
+
SlimpayClient is a Ruby gem designed to provide a comprehensive and up-to-date interface for interacting with the Slimpay API. This gem extends the original \`slimpay\` gem created by gdurelle, addressing the need for maintenance and updates to ensure compatibility with the latest Slimpay API features and best practices.
|
6
|
+
|
7
|
+
## Features
|
8
|
+
|
9
|
+
- Seamless integration with the Slimpay API
|
10
|
+
- Support for the latest API endpoints and features
|
11
|
+
- Improved error handling and logging
|
12
|
+
- Easy configuration and setup
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'slimpay_client'
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
$ bundle
|
26
|
+
```
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
$ gem install slimpay_client
|
32
|
+
```
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
**API Docs: [https://dev.slimpay.com/](https://dev.slimpay.com/)**
|
37
|
+
|
38
|
+
### Configuration
|
39
|
+
|
40
|
+
If you use _Rails_ place this code in _config/initializers/slimpay_client.rb_:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
SlimpayClient.configure do |config|
|
44
|
+
config.client_id = "your_client_id"
|
45
|
+
config.client_secret = "your_client_secret"
|
46
|
+
config.creditor_reference = "your_creditor_reference"
|
47
|
+
config.sandbox = true
|
48
|
+
config.notify_url = 'you_notifications_url'
|
49
|
+
config.success_url = 'your_success_url'
|
50
|
+
config.failure_url = 'your_failure_url'
|
51
|
+
config.cancel_url = 'your_cancel_url'
|
52
|
+
# or
|
53
|
+
config.return_url = 'your_return_url'
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
### Notification and return URLs
|
58
|
+
|
59
|
+
The notification URL is the point of your application where Slimpay will send a POST request with the result of the current order.
|
60
|
+
The state of the order will be either **close.completed** or **closed.aborted.aborted_byclient** if everything worked normally, or one of those quoted in the ([API Order documentation](https://dev.slimpay.com/hapi/reference/orders)).
|
61
|
+
|
62
|
+
The return URL is the point of your application where your user/customer will be redirected to when he will have finish signing its mandate with Slimpay.
|
63
|
+
|
64
|
+
### The root endpoint:
|
65
|
+
|
66
|
+
The Slimpay API uses self-discovery. It means that each time you will perform a request, the answer will be a Hash of links to follow in order to perform more requestq.
|
67
|
+
|
68
|
+
The more you do requests, the more methods will appear.
|
69
|
+
|
70
|
+
When you emplement any class, it will inherits from the root-endpoint and thus already have available methods.
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
slimpay = Slimpay::Base.new(client_id = '1234', client_secret = '987654321', creditor_reference = 'azerty')
|
74
|
+
slimpay.api_methods
|
75
|
+
```
|
76
|
+
|
77
|
+
⚠️ If you call ``Slimpay::Base.new`` without arguments, the _Sandbox_ credentials will be used.
|
78
|
+
|
79
|
+
Result will be a Hash:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
{"self"=>"https://api.preprod.slimpay.com/",
|
83
|
+
"profile"=>"https://api.preprod.slimpay.com/alps/v1",
|
84
|
+
"post_token"=>"https://api.preprod.slimpay.com/oauth/token",
|
85
|
+
"create_orders"=>"https://api.preprod.slimpay.com/orders",
|
86
|
+
"get_orders"=>"https://api.preprod.slimpay.com/orders{?creditorReference,reference}",
|
87
|
+
"search_order_by_id"=>"https://api.preprod.slimpay.com/orders/{id}",
|
88
|
+
"search_orders"=>"https://api.preprod.slimpay.com/orders{?id,creditorReference,entityReference,subscriberReference,reference,state,type,dateCreatedBefore,dateCreatedAfter,embed,withPageMetadata,page,size}",
|
89
|
+
"get_creditors"=>"https://api.preprod.slimpay.com/creditors{?reference}",
|
90
|
+
"create_mandates"=>"https://api.preprod.slimpay.com/mandates",
|
91
|
+
"get_mandates"=>"https://api.preprod.slimpay.com/mandates{?creditorReference,reference,rum,id,paymentScheme}",
|
92
|
+
"search_mandates"=>"https://api.preprod.slimpay.com/mandates{?creditorReference,entityReference,subscriberReference,mandateReference,paymentScheme,creationChannel,dateSignedBefore,dateSignedAfter,state,iban,signatoryLastName,signatoryEmail,companyName,embed,withPageMetadata,page,size}",
|
93
|
+
"create_documents"=>"https://api.preprod.slimpay.com/documents",
|
94
|
+
"get_documents"=>"https://api.preprod.slimpay.com/documents{?creditorReference,entityReference,reference}",
|
95
|
+
"search_document_by_id"=>"https://api.preprod.slimpay.com/documents/{id}",
|
96
|
+
"search_documents"=>"https://api.preprod.slimpay.com/documents/search{?creditorReference,status,creationDateBefore,creationDateAfter,documentReference,publicReference,subscriberReference,signatoryLastName,signatoryEmail,withPageMetadata,page,size}",
|
97
|
+
"create_payins"=>"https://api.preprod.slimpay.com/payments/in",
|
98
|
+
"create_payouts"=>"https://api.preprod.slimpay.com/payments/out",
|
99
|
+
"search_payments"=>"https://api.preprod.slimpay.com/payments{?creditorReference,entityReference,subscriberReference,mandateReference,cardAliasReference,scheme,direction,reference,category,currency,state,executionStatus,processor,executionDateBefore,executionDateAfter,embed,withPageMetadata,page,size}",
|
100
|
+
"search_payment_by_id"=>"https://api.preprod.slimpay.com/payments/{id}",
|
101
|
+
"search_payment_issues"=>"https://api.preprod.slimpay.com/payment-issues{?creditorReference,entityReference,subscriberReference,scheme,currency,executionStatus,dateCreatedBefore,dateCreatedAfter,withPageMetadata,page,size}",
|
102
|
+
"search_payment_issue_by_id"=>"https://api.preprod.slimpay.com/payment-issues/{id}",
|
103
|
+
"create_direct_debits"=>"https://api.preprod.slimpay.com/direct-debits",
|
104
|
+
"get_direct_debits"=>"https://api.preprod.slimpay.com/direct-debits{?id}",
|
105
|
+
"search_direct_debits"=>"https://api.preprod.slimpay.com/direct-debits{?creditorReference,entityReference,subscriberReference,mandateReference,paymentReference,currency,executionDateBefore,executionDateAfter,withPageMetadata,page,size}",
|
106
|
+
"search_direct_debit_issues"=>"https://api.preprod.slimpay.com/direct-debit-issues{?creditorReference,entityReference,subscriberReference,currency,executionStatus,dateCreatedBefore,dateCreatedAfter,withPageMetadata,page,size}",
|
107
|
+
"get_direct_debit_issues"=>"https://api.preprod.slimpay.com/direct-debit-issues{?id}",
|
108
|
+
"create_recurrent_direct_debits"=>"https://api.preprod.slimpay.com/recurrent-direct-debits",
|
109
|
+
"get_recurrent_direct_debits"=>"https://api.preprod.slimpay.com/recurrent-direct-debits{?id}",
|
110
|
+
"search_recurrent_direct_debits"=>"https://api.preprod.slimpay.com/recurrent-direct-debits{?creditorReference,entityReference,subscriberReference,reference,currency,activated,frequency,dateFromBefore,dateFromAfter,withPageMetadata,page,size}",
|
111
|
+
"create_credit_transfers"=>"https://api.preprod.slimpay.com/credit-transfers",
|
112
|
+
"get_credit_transfers"=>"https://api.preprod.slimpay.com/credit-transfers{?id}",
|
113
|
+
"search_credit_transfers"=>"https://api.preprod.slimpay.com/credit-transfers{?creditorReference,entityReference,subscriberReference,mandateReference,paymentReference,currency,executionDateBefore,executionDateAfter,page,size}",
|
114
|
+
"get_card_aliases"=>"https://api.preprod.slimpay.com/card-aliases{?id}",
|
115
|
+
"search_card_aliases"=>"https://api.preprod.slimpay.com/card-aliases{?creditorReference,entityReference,subscriberReference,reference,status,withPageMetadata,page,size}",
|
116
|
+
"search_card_by_id"=>"https://api.preprod.slimpay.com/cards/{id}",
|
117
|
+
"get_recurrent_card_transactions"=>"https://api.preprod.slimpay.com/recurrent-card-transactions{?id}",
|
118
|
+
"search_recurrent_card_transactions"=>"https://api.preprod.slimpay.com/recurrent-card-transactions{?creditorReference,entityReference,subscriberReference,reference,currency,activated,frequency,dateFromBefore,dateFromAfter,page,size}",
|
119
|
+
"create_recurrent_card_transactions"=>"https://api.preprod.slimpay.com/recurrent-card-transactions",
|
120
|
+
"get_card_transaction_issues"=>"https://api.preprod.slimpay.com/card-transaction-issues{?id}",
|
121
|
+
"search_bank_account_by_id"=>"https://api.preprod.slimpay.com/bank-accounts{?id}",
|
122
|
+
"search_balances"=>"https://api.preprod.slimpay.com/balances{?creditorReference,entityReference,currency,lastCalculated,page,size}",
|
123
|
+
"search_order_item_by_id"=>"https://api.preprod.slimpay.com/order-items/{id}",
|
124
|
+
"search_subscribers"=>"https://api.preprod.slimpay.com/subscribers{?creditorReference,entityReference,reference,withPageMetadata,page,size}",
|
125
|
+
"search_report"=>"https://api.preprod.slimpay.com/reports{?creditorReference,entityReference,dateFrom,dateTo}",
|
126
|
+
"search_document_templates"=>"https://api.preprod.slimpay.com/document-templates{?creditorReference,page,size}",
|
127
|
+
"create_document_template"=>"https://api.preprod.slimpay.com/document-templates",
|
128
|
+
"search_document_template_by_id"=>"https://api.preprod.slimpay.com/document-templates/{id}",
|
129
|
+
"search_mandate_templates"=>"https://api.preprod.slimpay.com/mandate-templates{?creditorReference,page,size}",
|
130
|
+
"create_mandate_template"=>"https://api.preprod.slimpay.com/mandate-templates",
|
131
|
+
"search_mandate_template_by_id"=>"https://api.preprod.slimpay.com/mandate-templates/{id}",
|
132
|
+
"search_files"=>"https://api.preprod.slimpay.com/files{?creditorReference,name,creationDateBefore,creationDateAfter,flow,category,status,state,withPageMetadata,page,size}",
|
133
|
+
"search_file_by_id"=>"https://api.preprod.slimpay.com/files/{id}",
|
134
|
+
"create_file"=>"https://api.preprod.slimpay.com/files{?creditorReference}",
|
135
|
+
"create_webhook"=>"https://api.preprod.slimpay.com/v1/webhook-configurations",
|
136
|
+
"get_webhook"=>"https://api.preprod.slimpay.com/v1/webhook-configurations/{id}",
|
137
|
+
"get_webhooks"=>"https://api.preprod.slimpay.com/v1/webhook-configurations{?creditorReference}"}
|
138
|
+
```
|
139
|
+
|
140
|
+
The keys of this Hash are the methods name you can call on the class instance (here Slimpay::Base).
|
141
|
+
The value is the URL that will be used, with its arguments.
|
142
|
+
|
143
|
+
**Example:**
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
"get_orders"=>"https://api.preprod.slimpay.com/orders{?creditorReference,reference}",
|
147
|
+
```
|
148
|
+
|
149
|
+
The arguments will be _creditorReference_ and _reference_. You can give them as a Hash.
|
150
|
+
See below for an example.
|
151
|
+
|
152
|
+
Some methods as been added to this gem as shortcuts to these root methods.
|
153
|
+
|
154
|
+
### Available resources :
|
155
|
+
|
156
|
+
**Order**, **Mandate**, **App**
|
157
|
+
|
158
|
+
Each resource inherit from _Resource_ wich itself inherits from _Base_.
|
159
|
+
_Base_ defines root methods according to the Slimpay API.
|
160
|
+
|
161
|
+
**Example:**
|
162
|
+
|
163
|
+
The official API method:
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
orders = Slimpay::Order.new(client_id = '1234', client_secret = '987654321', creditor_reference = 'azerty')
|
167
|
+
orders.get_orders({creditorReference: 'mysellername', reference: 1234})
|
168
|
+
```
|
169
|
+
|
170
|
+
The shortcut:
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
orders = Slimpay::Order.new(client_id = '1234', client_secret = '987654321', creditor_reference = 'azerty')
|
174
|
+
orders.get_one(1234)
|
175
|
+
```
|
176
|
+
|
177
|
+
Result will be a Hash:
|
178
|
+
|
179
|
+
```json
|
180
|
+
{"_links"=>
|
181
|
+
{"self"=>{"href"=>"https://api.preprod.slimpay.com/creditors/democreditor/orders/1"},
|
182
|
+
"https://api.slimpay.net/alps#get-creditor"=>{"href"=>"https://api.preprod.slimpay.com/creditors/democreditor"},
|
183
|
+
"https://api.slimpay.net/alps#get-subscriber"=>{"href"=>"https://api.preprod.slimpay.com/creditors/democreditor/orders/1/subscribers/subscriber01"},
|
184
|
+
"https://api.slimpay.net/alps#user-approval"=>{"href"=>"https://slimpay.net/slimpaytpe16/userApproval?accessCode=spK534N0cuZztBGwj2FjC6eKzcsKFRzXbfy8buloUHiZV6p9PhIfcPgV7c507R"},
|
185
|
+
"https://api.slimpay.net/alps#get-order-items"=>{"href"=>"https://api.preprod.slimpay.com/creditors/democreditor/orders/1/items"},
|
186
|
+
"https://api.slimpay.net/alps#get-mandate"=>{"href"=>"https://api.preprod.slimpay.com/creditors/democreditor/mandates/1"}},
|
187
|
+
"reference"=>"1",
|
188
|
+
"state"=>"closed.completed",
|
189
|
+
"started"=>true,
|
190
|
+
"dateCreated"=>"2014-12-12T09:35:39.000+0000",
|
191
|
+
"mandateReused"=>false}
|
192
|
+
```
|
193
|
+
|
194
|
+
Now you can call new methods : get_creditor, get_subscriber, user_approval, get_order_items, get_mandate
|
195
|
+
|
196
|
+
**NB:** Note that the methods in the resulting Hash are dashed-named, but the generated methods are camelcased.
|
197
|
+
|
198
|
+
## Credentials
|
199
|
+
|
200
|
+
The sanbox let you test credentials connection and few methods.
|
201
|
+
|
202
|
+
You will need a test environment setted up by Slimpay to go further.
|
203
|
+
|
204
|
+
### SANDBOX
|
205
|
+
|
206
|
+
* client_id = 'democreditor01'
|
207
|
+
* client_secret = 'demosecret01'
|
208
|
+
* creditor_reference : democreditor
|
209
|
+
|
210
|
+
### Test
|
211
|
+
|
212
|
+
* IBAN : FR1420041010050500013M02606
|
213
|
+
* BIC : PSSTFRPP
|
214
|
+
* Code for phone verification : 0000
|
215
|
+
|
216
|
+
## Development
|
217
|
+
|
218
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
219
|
+
|
220
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
221
|
+
|
222
|
+
## Contributing
|
223
|
+
|
224
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/slimpay_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/slimpay_client/blob/master/CODE_OF_CONDUCT.md).
|
225
|
+
|
226
|
+
## License
|
227
|
+
|
228
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
229
|
+
|
230
|
+
## Code of Conduct
|
231
|
+
|
232
|
+
Everyone interacting in the SlimpayClient project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/slimpay_client/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
module SlimpayClient
|
2
|
+
# Used only to get and set callback URLs.
|
3
|
+
class App < Resource
|
4
|
+
# Prepare an admin token for app requests.
|
5
|
+
#
|
6
|
+
# Arguments:
|
7
|
+
# username: Your SlimpayClient admin username
|
8
|
+
# password: Your SlimpayClient admin password
|
9
|
+
def initialize(username = nil, password = nil)
|
10
|
+
init_config
|
11
|
+
@username = username || SlimpayClient.configuration.username
|
12
|
+
@password = password || SlimpayClient.configuration.password
|
13
|
+
@basic_auth = {username: "#{@creditor_reference}##{@username}", password: @password}
|
14
|
+
response = HTTParty.post(@token_endpoint, basic_auth: @basic_auth, body: app_options)
|
15
|
+
@token = response['access_token']
|
16
|
+
end
|
17
|
+
|
18
|
+
# Change the successUrl
|
19
|
+
# ===== Example:
|
20
|
+
# app = SlimpayClient::App.new
|
21
|
+
# app.success_url = "mywebsite.com/client/123/"
|
22
|
+
def success_url(url)
|
23
|
+
response = HTTParty.patch("#{@endpoint}/creditors/#{@creditor_reference}/apps/#{@client_id}", body: {successUrl: url}.to_json, headers: options)
|
24
|
+
SlimpayClient.answer(response)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Change the failureUrl
|
28
|
+
# ===== Example:
|
29
|
+
# app = SlimpayClient::App.new
|
30
|
+
# app.failure_url = "mywebsite.com/client/123/"
|
31
|
+
def failure_url(url)
|
32
|
+
response = HTTParty.patch("#{@endpoint}/creditors/#{@creditor_reference}/apps/#{@client_id}", body: {failureUrl: url}.to_json, headers: options)
|
33
|
+
SlimpayClient.answer(response)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Change the cancelUrl
|
37
|
+
# ===== Example:
|
38
|
+
# app = SlimpayClient::App.new
|
39
|
+
# app.cancel_url = "mywebsite.com/client/123/"
|
40
|
+
def cancel_url(url)
|
41
|
+
response = HTTParty.patch("#{@endpoint}/creditors/#{@creditor_reference}/apps/#{@client_id}", body: {cancelUrl: url}.to_json, headers: options)
|
42
|
+
SlimpayClient.answer(response)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Change the returnUrl
|
46
|
+
# ===== Example:
|
47
|
+
# app = SlimpayClient::App.new
|
48
|
+
# app.return_url = "mywebsite.com/client/123/"
|
49
|
+
def return_url(url)
|
50
|
+
response = HTTParty.patch("#{@endpoint}/creditors/#{@creditor_reference}/apps/#{@client_id}", body: {returnUrl: url}.to_json, headers: options)
|
51
|
+
SlimpayClient.answer(response)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Change the notifyUrl
|
55
|
+
def notify_url(url)
|
56
|
+
response = HTTParty.patch("#{@endpoint}/creditors/#{@creditor_reference}/apps/#{@client_id}", body: {notifyUrl: url}.to_json, headers: options)
|
57
|
+
SlimpayClient.answer(response)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Change the notification and return URLs.
|
61
|
+
#
|
62
|
+
# ===== Arguments:
|
63
|
+
# successUrl: (String) URL to your app the customer is gonna be redirected to when leaving SlimpayClient platform (success).
|
64
|
+
# failureUrl: (String) URL to your app the customer is gonna be redirected to when leaving SlimpayClient platform (failure).
|
65
|
+
# cancelUrl: (String) URL to your app the customer is gonna be redirected to when leaving SlimpayClient platform (cancel).
|
66
|
+
# returnUrl: (String) URL to your app the customer is gonna be redirected to when leaving SlimpayClient platform.
|
67
|
+
# notifyUrl: (String) URL to your app SlimpayClient is gonna send a notification to, to confirm a Signature, a payment, etc.
|
68
|
+
def change_urls(urls_params)
|
69
|
+
response = HTTParty.patch("#{@endpoint}/creditors/#{@creditor_reference}/apps/#{@client_id}", body: urls_params.to_json, headers: options)
|
70
|
+
SlimpayClient.answer(response)
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def app_options
|
76
|
+
{
|
77
|
+
'Accept' => API_HEADER,
|
78
|
+
'Content-type' => 'application/hal+json',
|
79
|
+
'grant_type' => 'client_credentials',
|
80
|
+
'scope' => 'api_admin'
|
81
|
+
}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
module SlimpayClient
|
2
|
+
# Defines constants, main variables, requests options.
|
3
|
+
#
|
4
|
+
# Connect to the API through OAuth2 and generates API's first resources GET methods.
|
5
|
+
# ===== Usage:
|
6
|
+
# slimpay = SlimpayClient::Base.new(client_id = '1234', client_secret = '987654321', creditor_reference = 'azerty')
|
7
|
+
# slimpay.api_methods
|
8
|
+
# =>
|
9
|
+
# { "post_token"=>"https://api-sandbox.slimpay.net/oauth/token",
|
10
|
+
# "create_orders"=>"https://api-sandbox.slimpay.net/orders",
|
11
|
+
# "get_creditors"=>"https://api-sandbox.slimpay.net/creditors{?reference}",
|
12
|
+
# "get_orders"=>"https://api-sandbox.slimpay.net/orders{?creditorReference,reference}",
|
13
|
+
# "get_mandates"=>"https://api-sandbox.slimpay.net/mandates{?creditorReference,rum}",
|
14
|
+
# "create_documents"=>"https://api-sandbox.slimpay.net/documents",
|
15
|
+
# "get_documents"=>"https://api-sandbox.slimpay.net/documents{?creditorReference,entityReference,reference}",
|
16
|
+
# "create_direct_debits"=>"https://api-sandbox.slimpay.net/direct-debits",
|
17
|
+
# "get_direct_debits"=>"https://api-sandbox.slimpay.net/direct-debits{?id}",
|
18
|
+
# "create_recurrent_direct_debits"=>"https://api-sandbox.slimpay.net/recurrent-direct-debits",
|
19
|
+
# "get_recurrent_direct_debits"=>"https://api-sandbox.slimpay.net/recurrent-direct-debits{?id}",
|
20
|
+
# "get_card_transactions"=>"https://api-sandbox.slimpay.net/card-transactions{?id}",
|
21
|
+
# "get_card_transaction_issues"=>"https://api-sandbox.slimpay.net/card-transaction-issues{?id}",
|
22
|
+
# "profile"=>"https://api-sandbox.slimpay.net/alps/v1"}
|
23
|
+
#
|
24
|
+
# ===== Arguments
|
25
|
+
# client_id: (String)
|
26
|
+
# client_secret: (String)
|
27
|
+
# creditor_reference: (String)
|
28
|
+
class Base
|
29
|
+
def initialize
|
30
|
+
init_config
|
31
|
+
connect_api_with_oauth
|
32
|
+
api_response = JSON.parse(request_to_api)
|
33
|
+
generate_api_methods(api_response)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Root endpoint provides GET links to resources.
|
37
|
+
# This methods create a method for each resources.
|
38
|
+
# It will also create new methods from future answers.
|
39
|
+
def generate_api_methods(response)
|
40
|
+
methods = {}
|
41
|
+
links = response['_links']
|
42
|
+
links = links.merge(response['_embedded']['items'].first['_links']) if response['_embedded'] && response['_embedded']['items']
|
43
|
+
return if links.nil?
|
44
|
+
|
45
|
+
links.each do |k, v|
|
46
|
+
name = k.gsub('https://api.slimpay.net/alps#', '').underscore
|
47
|
+
next if @methods && @methods.keys.include?(name) && !k.eql?('self')
|
48
|
+
|
49
|
+
url = v['href']
|
50
|
+
api_args = url.scan(/{\?(.*),?}/).flatten.first
|
51
|
+
|
52
|
+
methods[name] = generate_method(name, url, api_args)
|
53
|
+
end
|
54
|
+
list_api_methods(methods)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def init_config
|
60
|
+
SlimpayClient.configuration ||= SlimpayClient::Configuration.new
|
61
|
+
@client_id = SlimpayClient.configuration.client_id
|
62
|
+
@client_secret = SlimpayClient.configuration.client_secret
|
63
|
+
@creditor_reference = SlimpayClient.configuration.creditor_reference
|
64
|
+
@sandbox = SlimpayClient.configuration.sandbox
|
65
|
+
@success_url = SlimpayClient.configuration.success_url
|
66
|
+
@failure_url = SlimpayClient.configuration.failure_url
|
67
|
+
@cancel_url = SlimpayClient.configuration.cancel_url
|
68
|
+
@return_url = SlimpayClient.configuration.return_url
|
69
|
+
@notify_url = SlimpayClient.configuration.notify_url
|
70
|
+
@endpoint = sandbox? ? SANDBOX_ENDPOINT : PRODUCTION_ENDPOINT
|
71
|
+
@token_endpoint = @endpoint# + '/oauth/token'
|
72
|
+
end
|
73
|
+
|
74
|
+
# A request call to the endpoint.
|
75
|
+
# An empty call will return list of available methods in the API.
|
76
|
+
def request_to_api(url = '')
|
77
|
+
response = HTTParty.get("#{@endpoint}/#{url}", headers: options)
|
78
|
+
SlimpayClient.answer response
|
79
|
+
end
|
80
|
+
|
81
|
+
# OAuth2 call to retrieve the token
|
82
|
+
def connect_api_with_oauth
|
83
|
+
client = OAuth2::Client.new(@client_id, @client_secret, site: @token_endpoint, headers: oauth_options, auth_scheme: :basic_auth)
|
84
|
+
response = client.client_credentials.get_token
|
85
|
+
@token = response.token
|
86
|
+
end
|
87
|
+
|
88
|
+
# === Arguments:
|
89
|
+
# name: (String) The method name
|
90
|
+
# url: (String) URL called in the method block
|
91
|
+
# api_args: (String) API arguments for this URL.
|
92
|
+
def generate_method(name, url, api_args)
|
93
|
+
if name.start_with?('create', 'post', 'cancel')
|
94
|
+
generate_post_method(name, url)
|
95
|
+
elsif name.start_with?('patch')
|
96
|
+
generate_patch_method(name, url)
|
97
|
+
else
|
98
|
+
generate_get_method(name, url, api_args)
|
99
|
+
end
|
100
|
+
url
|
101
|
+
end
|
102
|
+
|
103
|
+
def generate_get_method(name, url, api_args)
|
104
|
+
self.class.send(:define_method, name) do |method_arguments = nil|
|
105
|
+
if api_args.nil?
|
106
|
+
response = HTTParty.get(url, headers: options)
|
107
|
+
else
|
108
|
+
clean_url = url.gsub(/{\?.*/, '')
|
109
|
+
url_args = format_html_arguments(api_args, method_arguments)
|
110
|
+
response = HTTParty.get("#{clean_url}?#{url_args}", headers: options)
|
111
|
+
end
|
112
|
+
follow_up_api(response)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def generate_post_method(name, url)
|
117
|
+
self.class.send(:define_method, name) do |method_arguments = nil|
|
118
|
+
response = HTTParty.post(url, body: method_arguments.to_json, headers: options)
|
119
|
+
follow_up_api(response)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def generate_patch_method(name, url)
|
124
|
+
self.class.send(:define_method, name) do |method_arguments = nil|
|
125
|
+
response = HTTParty.patch(url, body: method_arguments.to_json, headers: options)
|
126
|
+
follow_up_api(response)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Change APIs documented URL's arguments into real HTTP arguments through given method arguments
|
131
|
+
# ===== Arguments
|
132
|
+
# api_args: (String) SlimpayClient given argument within URLs. Formated like: ?{arg1, arg2}
|
133
|
+
# method_arguments: (String) Arguments called on the currently defined method.
|
134
|
+
def format_html_arguments(api_args, method_arguments)
|
135
|
+
url_args = ''
|
136
|
+
api_args.split(',').each_with_index do |arg, index|
|
137
|
+
if method_arguments[arg.to_sym].to_s.present?
|
138
|
+
url_args += "#{arg}=#{method_arguments[arg.to_sym]}"
|
139
|
+
url_args += '&' if (index + 1) < api_args.size
|
140
|
+
end
|
141
|
+
end
|
142
|
+
url_args
|
143
|
+
end
|
144
|
+
|
145
|
+
# Create the 'api_methods' instance method to retrieve an array of API methods previously created.
|
146
|
+
#
|
147
|
+
# ===== Usage:
|
148
|
+
# slim = SlimpayClient::Base.new
|
149
|
+
# slim.api_methods
|
150
|
+
# => [apps, creditors, direct_debits, mandates, orders, recurrent_direct_debits, subscribers, ...]
|
151
|
+
def list_api_methods(methods)
|
152
|
+
@methods ||= methods
|
153
|
+
self.class.send(:define_method, 'api_methods') do
|
154
|
+
@methods = @methods.merge(methods) if @methods != methods
|
155
|
+
@methods
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# Catch up potential errors and generate new methods if needed.
|
160
|
+
def follow_up_api(response)
|
161
|
+
answer = SlimpayClient.answer(response)
|
162
|
+
generate_api_methods(response)
|
163
|
+
answer
|
164
|
+
end
|
165
|
+
|
166
|
+
def oauth_options
|
167
|
+
{
|
168
|
+
'Accept' => 'application/json',
|
169
|
+
'Content-type' => 'application/x-www-form-urlencoded',
|
170
|
+
'grant_type' => 'client_credentials',
|
171
|
+
'scope' => 'api'
|
172
|
+
}
|
173
|
+
end
|
174
|
+
|
175
|
+
def options
|
176
|
+
{'Authorization' => "Bearer #{@token}", 'Content-type' => 'application/json'}
|
177
|
+
end
|
178
|
+
|
179
|
+
def sandbox?
|
180
|
+
@sandbox || @client_id.eql?('democreditor01') ? true : false
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|