-
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 #11 from dreyks/corp-api
Add corporate api
- Loading branch information
Showing
26 changed files
with
835 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Monobank | ||
module Auth | ||
class Corporate | ||
def initialize(private_key:, key_id: nil, request_id: nil) | ||
@private_key = init_key(private_key:) | ||
@key_id = key_id | ||
@request_id = request_id | ||
end | ||
|
||
def to_headers(pathname:) | ||
time = Time.now.to_i | ||
|
||
{ | ||
'X-Time' => time.to_s, | ||
'X-Sign' => Base64.strict_encode64(sign(pathname:, time:)) | ||
}.tap do |headers| | ||
headers['X-Key-Id'] = key_id unless key_id.nil? | ||
headers['X-Request-Id'] = request_id unless request_id.nil? | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_accessor :private_key, :key_id, :request_id | ||
|
||
def init_key(private_key:) | ||
OpenSSL::PKey::EC.new(private_key) | ||
end | ||
|
||
def sign(pathname:, time:) | ||
private_key.sign(OpenSSL::Digest::SHA256.new, "#{time}#{request_id}#{pathname}") | ||
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,17 @@ | ||
module Monobank | ||
module Auth | ||
class Private | ||
def initialize(token:) | ||
@token = token | ||
end | ||
|
||
def to_headers(*) | ||
{ 'X-Token' => token } | ||
end | ||
|
||
private | ||
|
||
attr_reader :token | ||
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
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,21 @@ | ||
require 'forwardable' | ||
require 'monobank/corporate/client' | ||
|
||
module Monobank | ||
module Corporate | ||
extend SingleForwardable | ||
def_delegators \ | ||
:client, :registration, :registration_status, :set_webhook, :settings, | ||
:auth_request, :auth_check, :client_info, :statement | ||
|
||
def self.configure(private_key:, key_id: nil) | ||
@private_key = private_key | ||
@key_id = key_id | ||
@client = nil | ||
end | ||
|
||
def self.client | ||
@client ||= Client.new(private_key: @private_key, key_id: @key_id) | ||
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,60 @@ | ||
require 'monobank/auth/corporate' | ||
require 'monobank/personal/registration' | ||
require 'monobank/personal/registration_status' | ||
require 'monobank/personal/corporate_webhook' | ||
require 'monobank/personal/settings' | ||
require 'monobank/personal/auth_request' | ||
require 'monobank/personal/auth_check' | ||
require 'monobank/personal/client_info' | ||
require 'monobank/personal/statement' | ||
|
||
module Monobank | ||
module Corporate | ||
class Client | ||
def initialize(private_key:, key_id:) | ||
@private_key = private_key | ||
@key_id = key_id | ||
end | ||
|
||
def registration(public_key:, name:, description:, contact_person:, phone:, email:, logo:) | ||
Personal::Registration.new(public_key:, name:, description:, contact_person:, phone:, email:, logo:, auth:).call | ||
end | ||
|
||
def registration_status(public_key:) | ||
Personal::RegistrationStatus.new(public_key:, auth:).call | ||
end | ||
|
||
def set_webhook(url:) | ||
Personal::CorporateWebhook.new(url: url, auth:).call | ||
end | ||
|
||
def settings | ||
Personal::Settings.new(auth:).call | ||
end | ||
|
||
def auth_request(callback: nil) | ||
Personal::AuthRequest.new(callback:, auth:).call | ||
end | ||
|
||
def auth_check(request_id:) | ||
Personal::AuthCheck.new(auth: auth(request_id:)).call | ||
end | ||
|
||
def client_info(request_id:) | ||
Personal::ClientInfo.new(auth: auth(request_id:)).call | ||
end | ||
|
||
def statement(request_id:, account_id:, from:, to: nil) | ||
Personal::Statement.new(account_id:, from:, to:, auth: auth(request_id:)).call | ||
end | ||
|
||
private | ||
|
||
attr_reader :private_key, :key_id | ||
|
||
def auth(request_id: nil) | ||
Auth::Corporate.new(private_key:, key_id:, request_id:) | ||
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
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,22 @@ | ||
require 'monobank/methods/get' | ||
require 'monobank/resources/personal/auth_check' | ||
|
||
module Monobank | ||
module Personal | ||
class AuthCheck < Methods::Get | ||
ENDPOINT = '/personal/auth/request'.freeze | ||
|
||
private | ||
|
||
attr_reader :request_id | ||
|
||
def pathname | ||
ENDPOINT | ||
end | ||
|
||
def define_resources(attributes) | ||
Monobank::Resources::Personal::AuthCheck.new(attributes) | ||
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,31 @@ | ||
require 'monobank/methods/post' | ||
require 'monobank/resources/personal/auth_request' | ||
|
||
module Monobank | ||
module Personal | ||
class AuthRequest < Methods::Post | ||
ENDPOINT = '/personal/auth/request'.freeze | ||
|
||
def initialize(callback: nil, **rest) | ||
super(**rest) | ||
@callback = callback | ||
end | ||
|
||
private | ||
|
||
attr_reader :callback | ||
|
||
def pathname | ||
ENDPOINT | ||
end | ||
|
||
def headers | ||
{'X-Callback' => callback} if callback | ||
end | ||
|
||
def define_resources(attributes) | ||
Monobank::Resources::Personal::AuthRequest.new(attributes) | ||
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
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,15 @@ | ||
require 'monobank/personal/webhook' | ||
|
||
module Monobank | ||
module Personal | ||
class CorporateWebhook < Webhook | ||
ENDPOINT = '/personal/corp/webhook'.freeze | ||
|
||
private | ||
|
||
def pathname | ||
ENDPOINT | ||
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,46 @@ | ||
require 'monobank/methods/post' | ||
require 'monobank/resources/personal/registration' | ||
|
||
module Monobank | ||
module Personal | ||
class Registration < Methods::Post | ||
ENDPOINT = '/personal/auth/registration'.freeze | ||
|
||
def initialize(public_key:, name:, description:, contact_person:, phone:, email:, logo:, **rest) | ||
super(**rest) | ||
|
||
@public_key = public_key | ||
@name = name | ||
@description = description | ||
@contact_person = contact_person | ||
@phone = phone | ||
@email = email | ||
@logo = logo | ||
end | ||
|
||
def pathname | ||
ENDPOINT | ||
end | ||
|
||
private | ||
|
||
attr_reader :public_key, :name, :description, :contact_person, :phone, :email, :logo | ||
|
||
def body | ||
{ | ||
pubkey: public_key, | ||
name:, | ||
description:, | ||
contactPerson: contact_person, | ||
phone:, | ||
email:, | ||
logo: | ||
} | ||
end | ||
|
||
def define_resources(attributes) | ||
Resources::Personal::Registration.new(attributes) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.