-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from ostdotcom/webhooks
Merge wekhooks to develop
- Loading branch information
Showing
10 changed files
with
291 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.1.0 | ||
2.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
module OSTSdk | ||
|
||
module Saas | ||
|
||
class Webhooks < OSTSdk::Saas::Base | ||
|
||
# Initialize | ||
# | ||
# Arguments: | ||
# api_base_url: (String) | ||
# api_key: (String) | ||
# api_secret: (String) | ||
# api_spec: (Boolean) | ||
# config: (Hash) | ||
# | ||
def initialize(params) | ||
super | ||
@url_prefix = '/webhooks' | ||
end | ||
|
||
# Create a Webhook | ||
# | ||
# Returns: | ||
# response: (Hash) | ||
# | ||
def create(params = {}) | ||
http_helper.send_post_request("#{@url_prefix}/", params) | ||
end | ||
|
||
# Update a Webhook | ||
# | ||
# Returns: | ||
# response: (Hash) | ||
# | ||
def update(params = {}) | ||
http_helper.send_post_request("#{@url_prefix}/#{get_webhook_id!(params)}", params) | ||
end | ||
|
||
# Get webhook details | ||
# | ||
# Returns: | ||
# response: (Hash) | ||
# | ||
def get(params = {}) | ||
http_helper.send_get_request("#{@url_prefix}/#{get_webhook_id!(params)}", params) | ||
end | ||
|
||
# List Webhooks | ||
# | ||
# Returns: | ||
# response: (Hash) | ||
# | ||
def get_list(params = {}) | ||
http_helper.send_get_request("#{@url_prefix}/", params) | ||
end | ||
|
||
# Delete a Webhook | ||
# | ||
# Returns: | ||
# response: (Hash) | ||
# | ||
def delete(params = {}) | ||
http_helper.send_delete_request("#{@url_prefix}/#{get_webhook_id!(params)}", params) | ||
end | ||
|
||
# Verify webhook request signature | ||
# | ||
# Returns: | ||
# response: (Boolean) | ||
# | ||
def verify_signature(params = {}) | ||
version = params[:version] | ||
webhook_secret = params[:webhook_secret] | ||
stringified_data = params[:stringified_data] | ||
request_timestamp = params[:request_timestamp] | ||
signature = params[:signature] | ||
|
||
signature_params = "#{request_timestamp}.#{version}.#{stringified_data}" | ||
digest = OpenSSL::Digest.new('sha256') | ||
signature_to_be_verified = OpenSSL::HMAC.hexdigest(digest, webhook_secret, signature_params) | ||
|
||
signature == signature_to_be_verified | ||
|
||
end | ||
|
||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require_relative "../../../lib/ost-sdk-ruby/util" | ||
require_relative "../../../lib/ost-sdk-ruby/saas" | ||
require "test/unit" | ||
require_relative "../../../lib/config" | ||
|
||
class UsersTest < Test::Unit::TestCase | ||
|
||
def webhooks_service | ||
@webhooks_service ||= Config::OST_SDK.services.webhooks | ||
end | ||
|
||
def test_webhooks_create | ||
result = webhooks_service.create({ | ||
topics: ['transactions/initiate', 'transactions/success'], | ||
url: 'https://testingWebhooks.com' | ||
}) | ||
puts "result=>#{result}" unless result["success"] | ||
webhook_id = result["data"]["webhook"]["id"] | ||
webhooks_get(webhook_id) | ||
webhooks_get_all | ||
webhooks_update(webhook_id) | ||
webhooks_delete(webhook_id) | ||
assert_equal(result["success"], true) | ||
end | ||
|
||
def webhooks_get(webhook_id) | ||
result = webhooks_service.get({ | ||
webhook_id: webhook_id | ||
}) | ||
puts "result=>#{result}" unless result["success"] | ||
assert_equal(result["success"], true) | ||
end | ||
|
||
def webhooks_get_all | ||
result = webhooks_service.get_list() | ||
puts "result=>#{result}" unless result["success"] | ||
assert_equal(result["success"], true) | ||
end | ||
|
||
def webhooks_update(webhook_id) | ||
result = webhooks_service.update({ | ||
webhook_id: webhook_id, | ||
topics: ['transactions/initiate', 'transactions/success', 'transactions/failure'], | ||
status: 'inactive' | ||
}) | ||
puts "result=>#{result}" unless result["success"] | ||
assert_equal(result["success"], true) | ||
end | ||
|
||
def webhooks_delete(webhook_id) | ||
result = webhooks_service.delete({ | ||
webhook_id: webhook_id, | ||
}) | ||
puts "result=>#{result}" unless result["success"] | ||
assert_equal(result["success"], true) | ||
end | ||
|
||
def test_webhooks_verify_signature | ||
data = {} | ||
data[:hello] = 'hello' | ||
result = webhooks_service.verify_signature({ | ||
version: "2", | ||
webhook_secret: "mySecret", | ||
request_timestamp: "1559902637", | ||
signature: "2c56c143550c603a6ff47054803f03ee4755c9c707986ae27f7ca1dd1c92a824", | ||
stringified_data: data.to_json | ||
}) | ||
puts "result=>#{result}" unless result | ||
assert_equal(result, true) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module OSTSdk | ||
|
||
VERSION = "2.1.0" | ||
VERSION = "2.2.0" | ||
|
||
end |