revolut-connect 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +51 -1
- data/lib/revolut/resources/account.rb +4 -0
- data/lib/revolut/resources/resource.rb +7 -9
- data/lib/revolut/resources/simulation.rb +41 -0
- data/lib/revolut/resources/webhook_event.rb +2 -2
- data/lib/revolut/version.rb +1 -1
- data/lib/revolut.rb +2 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f6c231899d0e5bfd5e675e2b911ccead17aa1df7c8f8e7e7475ba07ebfd4800
|
4
|
+
data.tar.gz: b15045344651b7a013b15dba27ac2ad19b868029fb85f642129fde6be5c5dd1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c0de989febb683fff5dc5d823dd89285dac611192e4053222eccb304df0d8d9ae4b3fc0589a4e74bcf6c7e6180736f4712ac45e036a4f1262fead830c53fc07
|
7
|
+
data.tar.gz: 4d77b497a69a1936ffb28fe30b1f64534c8ea3b5cf94776f3b449d925d3b986b8c7c29ad8ebc9e30e964d64baa01456930a7dc274128a09c73709d0ae4e7ae47
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -23,6 +23,7 @@ _:warning: For now this connector only supports the [Business API](https://devel
|
|
23
23
|
- `Transaction`
|
24
24
|
- `TransferReason`
|
25
25
|
- `Webhook`
|
26
|
+
- `Simulation`
|
26
27
|
|
27
28
|
## :construction: Roadmap
|
28
29
|
|
@@ -32,7 +33,6 @@ _:warning: For now this connector only supports the [Business API](https://devel
|
|
32
33
|
- `ForeignExchange` resource
|
33
34
|
- `PaymentDraft` resource
|
34
35
|
- `PayoutLink` resource
|
35
|
-
- `Simulation` resource
|
36
36
|
- `TeamMember` resource
|
37
37
|
- `Transfer` resource
|
38
38
|
|
@@ -247,6 +247,56 @@ transaction = Revolut::Payment.retrieve(payment.id)
|
|
247
247
|
deleted = Revolut::Payment.delete(transaction.id)
|
248
248
|
```
|
249
249
|
|
250
|
+
#### Simulations
|
251
|
+
|
252
|
+
<https://developer.revolut.com/docs/business/simulations>
|
253
|
+
|
254
|
+
```rb
|
255
|
+
# Update a transaction
|
256
|
+
transaction = Revolut::Simulation.update_transaction("a6ea39d7-62c9-481c-8ba6-8a887a44c486", action: :complete)
|
257
|
+
|
258
|
+
# Top up an account
|
259
|
+
transaction = Revolut::Simulation.top_up_account("e042f1fe-f721-49cc-af82-db7a6c46944f",
|
260
|
+
amount: 100,
|
261
|
+
currency: "GBP",
|
262
|
+
reference: "Test Top-up",
|
263
|
+
state: "completed"
|
264
|
+
)
|
265
|
+
```
|
266
|
+
|
267
|
+
#### Webhooks
|
268
|
+
|
269
|
+
<https://developer.revolut.com/docs/business/webhooks-v-2>
|
270
|
+
|
271
|
+
```rb
|
272
|
+
# Create a webhook
|
273
|
+
webhook = Revolut::Webhook.create(
|
274
|
+
url: "https://www.example.com",
|
275
|
+
events: [
|
276
|
+
"TransactionCreated",
|
277
|
+
"PayoutLinkCreated"
|
278
|
+
]
|
279
|
+
)
|
280
|
+
|
281
|
+
# List webhooks
|
282
|
+
webhooks = Revolut::Webhook.list
|
283
|
+
|
284
|
+
# Retrieve a webhook
|
285
|
+
webhook = Revolut::Webhook.retrieve(webhook.id)
|
286
|
+
|
287
|
+
# Update a webhook
|
288
|
+
webhook = Revolut::Webhook.update(webhook.id, url: "https://www.example.com/")
|
289
|
+
|
290
|
+
# Delete a webhook
|
291
|
+
deleted = Revolut::Webhook.delete(webhook.id)
|
292
|
+
|
293
|
+
# Rotate webhook secret
|
294
|
+
rotated = Revolut::Webhook.rotate_signing_secret(webhook.id)
|
295
|
+
|
296
|
+
# Retrieve list of failing events
|
297
|
+
failed_events = Revolut::Webhook.failed_events(webhook.id)
|
298
|
+
```
|
299
|
+
|
250
300
|
## Development
|
251
301
|
|
252
302
|
You can use `bin/console` to access an interactive console. This will preload environment variables from a `.env` file.
|
@@ -7,6 +7,10 @@ module Revolut
|
|
7
7
|
"accounts"
|
8
8
|
end
|
9
9
|
|
10
|
+
# Retrieves the bank details for a specific account.
|
11
|
+
#
|
12
|
+
# @param id [String] The ID of the account.
|
13
|
+
# @return [Array<Revolut::BankAccount>] An array of bank account objects.
|
10
14
|
def self.bank_details(id)
|
11
15
|
response = http_client.get("/#{resources_name}/#{id}/bank-details")
|
12
16
|
|
@@ -57,12 +57,12 @@ module Revolut
|
|
57
57
|
@coerce_with ||= attrs
|
58
58
|
end
|
59
59
|
|
60
|
-
protected
|
61
|
-
|
62
60
|
def http_client
|
63
61
|
@http_client ||= Revolut::Client.instance
|
64
62
|
end
|
65
63
|
|
64
|
+
protected
|
65
|
+
|
66
66
|
def resource_name
|
67
67
|
resources_name
|
68
68
|
end
|
@@ -88,16 +88,10 @@ module Revolut
|
|
88
88
|
|
89
89
|
def check_not_allowed
|
90
90
|
method = caller(1..1).first.match(/`(\w+)'/)[1].to_sym
|
91
|
-
raise Revolut::
|
91
|
+
raise Revolut::UnsupportedOperationError, "`#{method}` operation is not allowed on this resource" if not_allowed_to.include?(method) || only.any? && !only.include?(method)
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
def to_json
|
96
|
-
@_raw.to_json
|
97
|
-
end
|
98
|
-
|
99
|
-
protected
|
100
|
-
|
101
95
|
def initialize(attrs = {})
|
102
96
|
@_raw = attrs
|
103
97
|
|
@@ -121,5 +115,9 @@ module Revolut
|
|
121
115
|
|
122
116
|
instance_variables.each { |iv| self.class.send(:attr_accessor, iv.to_s[1..].to_sym) }
|
123
117
|
end
|
118
|
+
|
119
|
+
def to_json
|
120
|
+
@_raw.to_json
|
121
|
+
end
|
124
122
|
end
|
125
123
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Revolut
|
2
|
+
# Reference: https://developer.revolut.com/docs/business/counterparties
|
3
|
+
class Simulation < Resource
|
4
|
+
shallow
|
5
|
+
|
6
|
+
def self.resources_name
|
7
|
+
"sandbox"
|
8
|
+
end
|
9
|
+
|
10
|
+
# Updates a transaction in the sandbox environment.
|
11
|
+
#
|
12
|
+
# @param id [String] The ID of the transaction to update.
|
13
|
+
# @param action [Symbol] The action to perform on the transaction.
|
14
|
+
# @return [Revolut::Transaction] The updated transaction object.
|
15
|
+
# @raise [Revolut::UnsupportedOperationError] If the method is called in a non-sandbox environment or if the action is not supported.
|
16
|
+
def self.update_transaction(id, action:)
|
17
|
+
raise Revolut::UnsupportedOperationError, "#update_transaction is meant to be run only in sandbox environments" unless Revolut.sandbox?
|
18
|
+
raise Revolut::UnsupportedOperationError, "The action `#{action}` is not supported" unless %i[complete revert declined fail].include?(action)
|
19
|
+
|
20
|
+
response = http_client.post("/#{resources_name}/transactions/#{id}/#{action}")
|
21
|
+
|
22
|
+
Revolut::Transaction.new(response.body)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Adds funds to the specified account in the sandbox environment.
|
26
|
+
#
|
27
|
+
# @param id [String] The ID of the account to top up.
|
28
|
+
# @param data [Hash] Additional data for the top-up request.
|
29
|
+
# @option data [Float] :amount The amount to top up the account by.
|
30
|
+
# @option data [String] :currency The currency of the top-up amount.
|
31
|
+
# @return [Revolut::Transaction] The transaction object representing the top-up.
|
32
|
+
# @raise [Revolut::UnsupportedOperationError] If the method is called outside of the sandbox environment.
|
33
|
+
def self.top_up_account(id, **data)
|
34
|
+
raise Revolut::UnsupportedOperationError, "#top_up_account is meant to be run only in sandbox environments" unless Revolut.sandbox?
|
35
|
+
|
36
|
+
response = http_client.post("/#{resources_name}/topup", data: data.merge(account_id: id))
|
37
|
+
|
38
|
+
Revolut::Transaction.new(response.body)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -14,12 +14,12 @@ module Revolut
|
|
14
14
|
def self.construct_from(request, signing_secret)
|
15
15
|
json = request.body.read
|
16
16
|
timestamp = request.headers["Revolut-Request-Timestamp"]
|
17
|
-
|
17
|
+
header_signatures = request.headers["Revolut-Signature"].split(",")
|
18
18
|
payload_to_sign = "v1.#{timestamp}.#{json}"
|
19
19
|
digest = OpenSSL::Digest.new("sha256")
|
20
20
|
signature_digest = "v1=" + OpenSSL::HMAC.hexdigest(digest, signing_secret, payload_to_sign)
|
21
21
|
|
22
|
-
if signature_digest
|
22
|
+
if header_signatures.include? signature_digest
|
23
23
|
new(JSON.parse(json))
|
24
24
|
else
|
25
25
|
raise Revolut::SignatureVerificationError, "Signature verification failed"
|
data/lib/revolut/version.rb
CHANGED
data/lib/revolut.rb
CHANGED
@@ -19,6 +19,8 @@ module Revolut
|
|
19
19
|
|
20
20
|
class SignatureVerificationError < Error; end
|
21
21
|
|
22
|
+
class UnsupportedOperationError < Error; end
|
23
|
+
|
22
24
|
class Configuration
|
23
25
|
attr_accessor :request_timeout, :global_headers, :environment, :token_duration, :scope, :auth_json, :api_version
|
24
26
|
attr_writer :client_id, :signing_key, :iss, :authorize_redirect_uri
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: revolut-connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Mochetti
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/revolut/resources/counterparty.rb
|
85
85
|
- lib/revolut/resources/payment.rb
|
86
86
|
- lib/revolut/resources/resource.rb
|
87
|
+
- lib/revolut/resources/simulation.rb
|
87
88
|
- lib/revolut/resources/transaction.rb
|
88
89
|
- lib/revolut/resources/transfer_reason.rb
|
89
90
|
- lib/revolut/resources/webhook.rb
|