Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Payment flows APIs #275

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
56 changes: 55 additions & 1 deletion src/fireblocks-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ import {
ScreeningSupportedAssetResponse,
ScreeningSupportedProviders,
RegisterAssetResponse,
UnspentInputsResponse,
UnspentInputsResponse
} from "./types";
import { AxiosProxyConfig, AxiosResponse, InternalAxiosRequestConfig } from "axios";
import { PIIEncryption } from "./pii-client";
Expand All @@ -162,6 +162,9 @@ import {
WithdrawResponse
} from "./staking";

import { PaymentsApiClient } from "./payments/payments-api-client";
import { Payments } from "./payments/payments-types"

export * from "./types";

export interface SDKOptions {
Expand Down Expand Up @@ -208,6 +211,7 @@ export class FireblocksSDK {
private readonly apiClient: ApiClient;
private readonly apiNcw: NcwApiClient;
private readonly stakingApiClient: StakingApiClient;
private readonly paymentsApiClient: PaymentsApiClient;

private piiClient: PIIEncryption;

Expand Down Expand Up @@ -235,6 +239,8 @@ export class FireblocksSDK {
this.apiNcw = new NcwApiClient(this.apiClient);

this.stakingApiClient = new StakingApiClient(this.apiClient);

this.paymentsApiClient = new PaymentsApiClient(this.apiClient);
}

/**
Expand Down Expand Up @@ -2447,4 +2453,52 @@ export class FireblocksSDK {
};
return this.apiClient.issuePostRequest(`/v1/vault/assets/bulk`, body, requestOptions);
}

/**
* Creates new payment workflow configuration
* @param request - Payments.CreateWorkflowConfigurationRequest
*/
public async createPaymentWorkflowConfiguration(request: Payments.CreateWorkflowConfigurationRequest): Promise<Payments.WorkflowConfiguration> {
return await this.paymentsApiClient.createPaymentWorkflowConfiguration(request);
}

/**
* Get payment workflow configuration
* @param configId - configuration id
*/
public async getPaymentWorkflowConfiguration(configId: string): Promise<Payments.WorkflowConfiguration> {
return await this.paymentsApiClient.getPaymentWorkflowConfiguration(configId);
}

/**
* Delete payment workflow configuration
* @param configId - configuration id
*/
public async deletePaymentWorkflowConfiguration(configId: string): Promise<Payments.WorkflowConfigurationId> {
return await this.paymentsApiClient.deletePaymentWorkflowConfiguration(configId);
}

/**
* Creates new payment workflow execution
* @param request - Payments.CreateWorkflowExecutionRequest
*/
public async createPaymentWorkflowExecution(request: Payments.CreateWorkflowExecutionRequest): Promise<Payments.WorkflowExecution> {
return await this.paymentsApiClient.createPaymentWorkflowExecution(request);
}

/**
* Get payment workflow execution
* @param workflowExeuctionId
*/
public async getPaymentWorkflowExecution(workflowExeuctionId: string): Promise<Payments.WorkflowExecution> {
return await this.paymentsApiClient.getPaymentWorkflowExecution(workflowExeuctionId);
}

/**
* Execute payment workflow
* @param workflowExeuctionId
*/
public async executePaymentFlow(workflowExeuctionId: string): Promise<Payments.WorkflowExecution> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to keep the same pattern, this is the only endpoint with the word Flow instead of Workflow.
I guess it came from our code but maybe it's better to change it here.

return await this.paymentsApiClient.executePaymentFlow(workflowExeuctionId);
}
}
37 changes: 37 additions & 0 deletions src/payments/payments-api-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Payments } from "./payments-types";
import { ApiClient } from "../api-client";
import CreateWorkflowConfigurationRequest = Payments.CreateWorkflowConfigurationRequest;
import WorkflowConfiguration = Payments.WorkflowConfiguration;
import WorkflowConfigurationId = Payments.WorkflowConfigurationId;
import CreateWorkflowExecutionRequest = Payments.CreateWorkflowExecutionRequest;
import WorkflowExecution = Payments.WorkflowExecution;

const PAYMENTS_BASE_PATH = "/v1/payments";

export class PaymentsApiClient {
constructor(private readonly apiClient: ApiClient) {}

public async createPaymentWorkflowConfiguration(request: CreateWorkflowConfigurationRequest): Promise<WorkflowConfiguration> {
return await this.apiClient.issuePostRequest(`${PAYMENTS_BASE_PATH}/workflow_config`, request);
}

public async getPaymentWorkflowConfiguration(configId: string): Promise<WorkflowConfiguration> {
return await this.apiClient.issueGetRequest(`${PAYMENTS_BASE_PATH}/workflow_config/${configId}`);
}

public async deletePaymentWorkflowConfiguration(configId: string): Promise<WorkflowConfigurationId> {
return await this.apiClient.issueDeleteRequest(`${PAYMENTS_BASE_PATH}/workflow_config/${configId}`);
}

public async createPaymentWorkflowExecution(request: CreateWorkflowExecutionRequest): Promise<WorkflowExecution> {
return await this.apiClient.issuePostRequest(`${PAYMENTS_BASE_PATH}/workflow_execution`, request);
}

public async getPaymentWorkflowExecution(workflowExeuctionId: string): Promise<WorkflowExecution> {
return await this.apiClient.issueGetRequest(`${PAYMENTS_BASE_PATH}/workflow_execution/${workflowExeuctionId}`);
}

public async executePaymentFlow(workflowExeuctionId: string): Promise<WorkflowExecution> {
return await this.apiClient.issuePostRequest(`${PAYMENTS_BASE_PATH}/workflow_execution/${workflowExeuctionId}/actions/execute`, {});
}
}
Loading
Loading