-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f716e0
commit 3cde181
Showing
69 changed files
with
775 additions
and
386 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
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,317 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as environments from "../../../../environments"; | ||
import * as core from "../../../../core"; | ||
import * as Mercoa from "../../../index"; | ||
import * as serializers from "../../../../serialization/index"; | ||
import urlJoin from "url-join"; | ||
import * as errors from "../../../../errors/index"; | ||
|
||
export declare namespace Calculate { | ||
interface Options { | ||
environment?: core.Supplier<environments.MercoaEnvironment | string>; | ||
token: core.Supplier<core.BearerToken>; | ||
} | ||
|
||
interface RequestOptions { | ||
timeoutInSeconds?: number; | ||
maxRetries?: number; | ||
abortSignal?: AbortSignal; | ||
} | ||
} | ||
|
||
export class Calculate { | ||
constructor(protected readonly _options: Calculate.Options) {} | ||
|
||
/** | ||
* Calculate the estimated fees associated with an payment given the amount, payment source, and disbursement method. Can be used to calculate fees for a payment before creating an invoice. | ||
* | ||
* @param {Mercoa.CalculateFeesRequest} request | ||
* @param {Calculate.RequestOptions} requestOptions - Request-specific configuration. | ||
* | ||
* @throws {@link Mercoa.BadRequest} | ||
* @throws {@link Mercoa.Unauthorized} | ||
* @throws {@link Mercoa.Forbidden} | ||
* @throws {@link Mercoa.NotFound} | ||
* @throws {@link Mercoa.Conflict} | ||
* @throws {@link Mercoa.InternalServerError} | ||
* @throws {@link Mercoa.Unimplemented} | ||
* | ||
* @example | ||
* await client.calculate.fee({ | ||
* amount: 100, | ||
* paymentSourceId: "pm_4794d597-70dc-4fec-b6ec-c5988e759769", | ||
* paymentDestinationId: "pm_4794d597-70dc-4fec-b6ec-c5988e759769" | ||
* }) | ||
*/ | ||
public async fee( | ||
request: Mercoa.CalculateFeesRequest, | ||
requestOptions?: Calculate.RequestOptions | ||
): Promise<Mercoa.InvoiceFeesResponse> { | ||
const _response = await core.fetcher({ | ||
url: urlJoin( | ||
(await core.Supplier.get(this._options.environment)) ?? environments.MercoaEnvironment.Production, | ||
"fees" | ||
), | ||
method: "POST", | ||
headers: { | ||
Authorization: await this._getAuthorizationHeader(), | ||
"X-Fern-Language": "JavaScript", | ||
"X-Fern-SDK-Name": "@mercoa/javascript", | ||
"X-Fern-SDK-Version": "0.4.6", | ||
"X-Fern-Runtime": core.RUNTIME.type, | ||
"X-Fern-Runtime-Version": core.RUNTIME.version, | ||
}, | ||
contentType: "application/json", | ||
body: await serializers.CalculateFeesRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }), | ||
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, | ||
maxRetries: requestOptions?.maxRetries, | ||
abortSignal: requestOptions?.abortSignal, | ||
}); | ||
if (_response.ok) { | ||
return await serializers.InvoiceFeesResponse.parseOrThrow(_response.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}); | ||
} | ||
|
||
if (_response.error.reason === "status-code") { | ||
switch ((_response.error.body as any)?.["errorName"]) { | ||
case "BadRequest": | ||
throw new Mercoa.BadRequest( | ||
await serializers.BadRequest.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
case "Unauthorized": | ||
throw new Mercoa.Unauthorized( | ||
await serializers.Unauthorized.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
case "Forbidden": | ||
throw new Mercoa.Forbidden( | ||
await serializers.Forbidden.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
case "NotFound": | ||
throw new Mercoa.NotFound( | ||
await serializers.NotFound.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
case "Conflict": | ||
throw new Mercoa.Conflict( | ||
await serializers.Conflict.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
case "InternalServerError": | ||
throw new Mercoa.InternalServerError( | ||
await serializers.InternalServerError.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
case "Unimplemented": | ||
throw new Mercoa.Unimplemented( | ||
await serializers.Unimplemented.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
default: | ||
throw new errors.MercoaError({ | ||
statusCode: _response.error.statusCode, | ||
body: _response.error.body, | ||
}); | ||
} | ||
} | ||
|
||
switch (_response.error.reason) { | ||
case "non-json": | ||
throw new errors.MercoaError({ | ||
statusCode: _response.error.statusCode, | ||
body: _response.error.rawBody, | ||
}); | ||
case "timeout": | ||
throw new errors.MercoaTimeoutError(); | ||
case "unknown": | ||
throw new errors.MercoaError({ | ||
message: _response.error.errorMessage, | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Calculate the estimated payment timing given the deduction date, payment source, and disbursement method. Can be used to calculate timing for a payment. | ||
* | ||
* @param {Mercoa.CalculatePaymentTimingRequest} request | ||
* @param {Calculate.RequestOptions} requestOptions - Request-specific configuration. | ||
* | ||
* @throws {@link Mercoa.BadRequest} | ||
* @throws {@link Mercoa.Unauthorized} | ||
* @throws {@link Mercoa.Forbidden} | ||
* @throws {@link Mercoa.NotFound} | ||
* @throws {@link Mercoa.Conflict} | ||
* @throws {@link Mercoa.InternalServerError} | ||
* @throws {@link Mercoa.Unimplemented} | ||
* | ||
* @example | ||
* await client.calculate.paymentTiming({ | ||
* estimatedDeductionDate: new Date("2024-01-02T00:00:00.000Z"), | ||
* paymentSourceId: "pm_4794d597-70dc-4fec-b6ec-c5988e759769", | ||
* paymentDestinationId: "pm_4794d597-70dc-4fec-b6ec-c5988e759769" | ||
* }) | ||
*/ | ||
public async paymentTiming( | ||
request: Mercoa.CalculatePaymentTimingRequest, | ||
requestOptions?: Calculate.RequestOptions | ||
): Promise<Mercoa.CalculatePaymentTimingResponse> { | ||
const _response = await core.fetcher({ | ||
url: urlJoin( | ||
(await core.Supplier.get(this._options.environment)) ?? environments.MercoaEnvironment.Production, | ||
"paymentTiming" | ||
), | ||
method: "POST", | ||
headers: { | ||
Authorization: await this._getAuthorizationHeader(), | ||
"X-Fern-Language": "JavaScript", | ||
"X-Fern-SDK-Name": "@mercoa/javascript", | ||
"X-Fern-SDK-Version": "0.4.6", | ||
"X-Fern-Runtime": core.RUNTIME.type, | ||
"X-Fern-Runtime-Version": core.RUNTIME.version, | ||
}, | ||
contentType: "application/json", | ||
body: await serializers.CalculatePaymentTimingRequest.jsonOrThrow(request, { | ||
unrecognizedObjectKeys: "strip", | ||
}), | ||
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, | ||
maxRetries: requestOptions?.maxRetries, | ||
abortSignal: requestOptions?.abortSignal, | ||
}); | ||
if (_response.ok) { | ||
return await serializers.CalculatePaymentTimingResponse.parseOrThrow(_response.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}); | ||
} | ||
|
||
if (_response.error.reason === "status-code") { | ||
switch ((_response.error.body as any)?.["errorName"]) { | ||
case "BadRequest": | ||
throw new Mercoa.BadRequest( | ||
await serializers.BadRequest.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
case "Unauthorized": | ||
throw new Mercoa.Unauthorized( | ||
await serializers.Unauthorized.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
case "Forbidden": | ||
throw new Mercoa.Forbidden( | ||
await serializers.Forbidden.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
case "NotFound": | ||
throw new Mercoa.NotFound( | ||
await serializers.NotFound.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
case "Conflict": | ||
throw new Mercoa.Conflict( | ||
await serializers.Conflict.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
case "InternalServerError": | ||
throw new Mercoa.InternalServerError( | ||
await serializers.InternalServerError.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
case "Unimplemented": | ||
throw new Mercoa.Unimplemented( | ||
await serializers.Unimplemented.parseOrThrow(_response.error.body, { | ||
unrecognizedObjectKeys: "passthrough", | ||
allowUnrecognizedUnionMembers: true, | ||
allowUnrecognizedEnumValues: true, | ||
breadcrumbsPrefix: ["response"], | ||
}) | ||
); | ||
default: | ||
throw new errors.MercoaError({ | ||
statusCode: _response.error.statusCode, | ||
body: _response.error.body, | ||
}); | ||
} | ||
} | ||
|
||
switch (_response.error.reason) { | ||
case "non-json": | ||
throw new errors.MercoaError({ | ||
statusCode: _response.error.statusCode, | ||
body: _response.error.rawBody, | ||
}); | ||
case "timeout": | ||
throw new errors.MercoaTimeoutError(); | ||
case "unknown": | ||
throw new errors.MercoaError({ | ||
message: _response.error.errorMessage, | ||
}); | ||
} | ||
} | ||
|
||
protected async _getAuthorizationHeader(): Promise<string> { | ||
return `Bearer ${await core.Supplier.get(this._options.token)}`; | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions
26
src/api/resources/calculate/types/CalculatePaymentTimingRequest.ts
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,26 @@ | ||
/** | ||
* This file was auto-generated by Fern from our API Definition. | ||
*/ | ||
|
||
import * as Mercoa from "../../../index"; | ||
|
||
/** | ||
* @example | ||
* { | ||
* estimatedDeductionDate: new Date("2024-01-02T00:00:00.000Z"), | ||
* paymentSourceId: "pm_4794d597-70dc-4fec-b6ec-c5988e759769", | ||
* paymentDestinationId: "pm_4794d597-70dc-4fec-b6ec-c5988e759769" | ||
* } | ||
*/ | ||
export interface CalculatePaymentTimingRequest { | ||
/** Date the payment is scheduled to be deducted from the payer's account. Use this field if the payment has not yet been deducted. */ | ||
estimatedDeductionDate?: Date; | ||
/** Date the payment was processed. Use this field if the payment has already been deducted. */ | ||
processedAt?: Date; | ||
/** ID of payment source. */ | ||
paymentSourceId: Mercoa.PaymentMethodId; | ||
/** ID of payment destination. */ | ||
paymentDestinationId: Mercoa.PaymentMethodId; | ||
/** Options for the payment destination. Depending on the payment destination, this may include things such as check delivery method. */ | ||
paymentDestinationOptions?: Mercoa.PaymentDestinationOptions; | ||
} |
Oops, something went wrong.