Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,46 @@ dda = client.direct_debit_authorities.find('8f233e04-ffaa-4c9d-adf9-244853848e21
dda.delete
```

##Callbacks
[Callback API doc](https://reference.prelive.promisepay.com/#callbacks)
#####Create a callback
```ruby
callback = client.callbacks.create(
url: 'https://httpbin.org/post',
description: 'User Callback',
object_type: 'users',
enabled: 'true'
)
```
#####Update a callback
```ruby
callback = client.callbacks.update(
id: '123456',
url: 'https://httpbin.org/post',
description: 'User Callback',
object_type: 'users',
enabled: 'true'
)
```
or
```ruby
callback = client.callbacks.find('123456')
callback.update(enabled: false)
```
#####Get a callback
```ruby
callback = client.callbacks.find('1')
```
#####Get a list of callbacks
```ruby
callbacks = client.callbacks.find_all
```
#####Delete a callback
```ruby
callback = client.callbacks.find('1')
callback.delete
```

##Tools
#####Health check
```ruby
Expand Down
3 changes: 3 additions & 0 deletions lib/promisepay/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require_relative 'models/account'
require_relative 'models/bank_account'
require_relative 'models/batch_transaction'
require_relative 'models/callback'
require_relative 'models/card_account'
require_relative 'models/charge'
require_relative 'models/company'
Expand All @@ -18,6 +19,7 @@
require_relative 'resources/account_resource'
require_relative 'resources/bank_account_resource'
require_relative 'resources/batch_transaction_resource'
require_relative 'resources/callback_resource'
require_relative 'resources/card_account_resource'
require_relative 'resources/charge_resource'
require_relative 'resources/company_resource'
Expand Down Expand Up @@ -131,6 +133,7 @@ def self.resources
{
bank_accounts: BankAccountResource,
batch_transactions: BatchTransactionResource,
callbacks: CallbackResource,
card_accounts: CardAccountResource,
charges: ChargeResource,
companies: CompanyResource,
Expand Down
30 changes: 30 additions & 0 deletions lib/promisepay/models/callback.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

module Promisepay
# Manage Callback
class Callback < BaseModel
# Update the attributes of a callback.
#
# @see https://reference.promisepay.com/#update-callback
#
# @param attributes [Hash] Callback's attributes to be updated.
#
# @return [self]
def update(attributes)
response = JSON.parse(@client.patch("callbacks/#{send(:id)}", attributes).body)
@attributes = response['callbacks']
self
end

# Deletes a callback on a marketplace.
#
# @see https://reference.promisepay.com/#delete-callback
#
#
# @return [Boolean]
def delete
response = JSON.parse(@client.delete("callbacks/#{id}").body)
return (response['callbacks'] && response['callbacks'] == 'Successfully redacted')
end

end
end
59 changes: 59 additions & 0 deletions lib/promisepay/resources/callback_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module Promisepay
# Resource for the Users API
class CallbackResource < BaseResource
def model
Promisepay::Callback
end

# List all callbacks for a marketplace
#
# @see https://reference.promisepay.com/#list-callbacks
#
# @param options [Hash] Optional options.
# @option options [Integer] :limit Can ask for up to 200 callbacks. default: 10
# @option options [Integer] :offset Pagination help. default: 0
#
# @return [Array<Promisepay::Callback>] List all callbacks for a marketplace.
def find_all(options = {})
response = JSON.parse(@client.get('callbacks', options).body)
callbacks = response.key?('callbacks') ? response['callbacks'] : []
callbacks.map { |attributes| Promisepay::Callback.new(@client, attributes) }
end

# Get a callback
#
# @see https://reference.promisepay.com/#show-callback
#
# @param id [String] Marketplace callback ID.
#
# @return [Promisepay::Callback]
def find(id)
response = JSON.parse(@client.get("callbacks/#{id}").body)
Promisepay::Callback.new(@client, response['callbacks'])
end

# Create a new callback for a marketplace
#
# @see https://reference.promisepay.com/#create-callback
#
# @param attributes [Hash] Callback's attributes.
#
# @return [Promisepay::Callback]
def create(attributes)
response = JSON.parse(@client.post('callbacks', attributes).body)
Promisepay::Callback.new(@client, response['callbacks'])
end

# Update a user for a marketplace
#
# @see https://reference.promisepay.com/#update-callback
#
# @param attributes [Hash] Callback's attributes.
#
# @return [Promisepay::Callback]
def update(attributes)
response = JSON.parse(@client.patch("callbacks/#{attributes[:id]}", attributes).body)
Promisepay::Callback.new(@client, response['callbacks'])
end
end
end
69 changes: 69 additions & 0 deletions spec/fixtures/callback_created.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions spec/fixtures/callback_created_error.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions spec/fixtures/callback_deleted.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading