Skip to content

Latest commit

 

History

History
755 lines (592 loc) · 73.7 KB

File metadata and controls

755 lines (592 loc) · 73.7 KB

Transactions

Overview

Available Operations

  • list - List transactions
  • create - Create transaction
  • get - Get transaction
  • update - Manually update a transaction
  • capture - Capture transaction
  • void - Void transaction
  • cancel - Cancel transaction
  • sync - Sync transaction

list

Returns a paginated list of transactions for the merchant account, sorted by most recently updated. You can filter, sort, and search transactions using query parameters.

Example Usage

import { Gr4vy, withToken } from "@gr4vy/sdk";
import fs from "fs";

const gr4vy = new Gr4vy({
    id: "example",
    server: "sandbox",
    merchantAccountId: "default",
    bearerAuth: withToken({
      privateKey: fs.readFileSync("private_key.pem", "utf8"),
    }),
});

async function run() {
  const result = await gr4vy.transactions.list();

  for await (const page of result) {
    console.log(page);
  }
}

run();

Standalone function

The standalone function version of this method:

import { Gr4vyCore } from "@gr4vy/sdk/core.js";
import { transactionsList } from "@gr4vy/sdk/funcs/transactionsList.js";

// Use `Gr4vyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const gr4vy = new Gr4vyCore({
  merchantAccountId: "<id>",
  bearerAuth: process.env["GR4VY_BEARER_AUTH"] ?? "",
});

async function run() {
  const res = await transactionsList(gr4vy);
  if (res.ok) {
    const { value: result } = res;
    for await (const page of result) {
    console.log(page);
  }
  } else {
    console.log("transactionsList failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.ListTransactionsRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.ListTransactionsResponse>

Errors

Error Type Status Code Content Type
errors.Error400 400 application/json
errors.Error401 401 application/json
errors.Error403 403 application/json
errors.Error404 404 application/json
errors.Error405 405 application/json
errors.Error409 409 application/json
errors.HTTPValidationError 422 application/json
errors.Error425 425 application/json
errors.Error429 429 application/json
errors.Error500 500 application/json
errors.Error502 502 application/json
errors.Error504 504 application/json
errors.SDKError 4XX, 5XX */*

create

Create a new transaction using a supported payment method. If additional buyer authorization is required, an approval URL will be returned. Duplicated gift card numbers are not supported.

Example Usage

import { Gr4vy, withToken } from "@gr4vy/sdk";
import fs from "fs";

const gr4vy = new Gr4vy({
    id: "example",
    server: "sandbox",
    merchantAccountId: "default",
    bearerAuth: withToken({
      privateKey: fs.readFileSync("private_key.pem", "utf8"),
    }),
});

async function run() {
  const result = await gr4vy.transactions.create({
    amount: 1299,
    currency: "EUR",
    store: true,
    isSubsequentPayment: true,
    merchantInitiated: true,
    asyncCapture: true,
    accountFundingTransaction: true,
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { Gr4vyCore } from "@gr4vy/sdk/core.js";
import { transactionsCreate } from "@gr4vy/sdk/funcs/transactionsCreate.js";

// Use `Gr4vyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const gr4vy = new Gr4vyCore({
  merchantAccountId: "<id>",
  bearerAuth: process.env["GR4VY_BEARER_AUTH"] ?? "",
});

async function run() {
  const res = await transactionsCreate(gr4vy, {
    amount: 1299,
    currency: "EUR",
    store: true,
    isSubsequentPayment: true,
    merchantInitiated: true,
    asyncCapture: true,
    accountFundingTransaction: true,
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("transactionsCreate failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description Example
transactionCreate components.TransactionCreate ✔️ N/A
merchantAccountId string The ID of the merchant account to use for this request.
idempotencyKey string A unique key that identifies this request. Providing this header will make this an idempotent request. We recommend using V4 UUIDs, or another random string with enough entropy to avoid collisions. request-12345
xForwardedFor string The IP address to forward from the customer. Use this when calling
our API from the server side to ensure the customer's address is
passed to downstream services, rather than your server IP.
192.168.0.2
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.Transaction>

Errors

Error Type Status Code Content Type
errors.Error400 400 application/json
errors.Error401 401 application/json
errors.Error403 403 application/json
errors.Error404 404 application/json
errors.Error405 405 application/json
errors.Error409 409 application/json
errors.HTTPValidationError 422 application/json
errors.Error425 425 application/json
errors.Error429 429 application/json
errors.Error500 500 application/json
errors.Error502 502 application/json
errors.Error504 504 application/json
errors.SDKError 4XX, 5XX */*

get

Retrieve the details of a transaction by its unique identifier.

Example Usage

import { Gr4vy, withToken } from "@gr4vy/sdk";
import fs from "fs";

const gr4vy = new Gr4vy({
    id: "example",
    server: "sandbox",
    merchantAccountId: "default",
    bearerAuth: withToken({
      privateKey: fs.readFileSync("private_key.pem", "utf8"),
    }),
});

async function run() {
  const result = await gr4vy.transactions.get("7099948d-7286-47e4-aad8-b68f7eb44591");

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { Gr4vyCore } from "@gr4vy/sdk/core.js";
import { transactionsGet } from "@gr4vy/sdk/funcs/transactionsGet.js";

// Use `Gr4vyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const gr4vy = new Gr4vyCore({
  merchantAccountId: "<id>",
  bearerAuth: process.env["GR4VY_BEARER_AUTH"] ?? "",
});

async function run() {
  const res = await transactionsGet(gr4vy, "7099948d-7286-47e4-aad8-b68f7eb44591");
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("transactionsGet failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description Example
transactionId string ✔️ The ID of the transaction 7099948d-7286-47e4-aad8-b68f7eb44591
merchantAccountId string The ID of the merchant account to use for this request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.Transaction>

Errors

Error Type Status Code Content Type
errors.Error400 400 application/json
errors.Error401 401 application/json
errors.Error403 403 application/json
errors.Error404 404 application/json
errors.Error405 405 application/json
errors.Error409 409 application/json
errors.HTTPValidationError 422 application/json
errors.Error425 425 application/json
errors.Error429 429 application/json
errors.Error500 500 application/json
errors.Error502 502 application/json
errors.Error504 504 application/json
errors.SDKError 4XX, 5XX */*

update

Manually updates a transaction.

Example Usage

import { Gr4vy, withToken } from "@gr4vy/sdk";
import fs from "fs";

const gr4vy = new Gr4vy({
    id: "example",
    server: "sandbox",
    merchantAccountId: "default",
    bearerAuth: withToken({
      privateKey: fs.readFileSync("private_key.pem", "utf8"),
    }),
});

async function run() {
  const result = await gr4vy.transactions.update({}, "7099948d-7286-47e4-aad8-b68f7eb44591");

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { Gr4vyCore } from "@gr4vy/sdk/core.js";
import { transactionsUpdate } from "@gr4vy/sdk/funcs/transactionsUpdate.js";

// Use `Gr4vyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const gr4vy = new Gr4vyCore({
  merchantAccountId: "<id>",
  bearerAuth: process.env["GR4VY_BEARER_AUTH"] ?? "",
});

async function run() {
  const res = await transactionsUpdate(gr4vy, {}, "7099948d-7286-47e4-aad8-b68f7eb44591");
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("transactionsUpdate failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description Example
transactionId string ✔️ The ID of the transaction 7099948d-7286-47e4-aad8-b68f7eb44591
transactionUpdate components.TransactionUpdate ✔️ N/A
merchantAccountId string The ID of the merchant account to use for this request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.Transaction>

Errors

Error Type Status Code Content Type
errors.Error400 400 application/json
errors.Error401 401 application/json
errors.Error403 403 application/json
errors.Error404 404 application/json
errors.Error405 405 application/json
errors.Error409 409 application/json
errors.HTTPValidationError 422 application/json
errors.Error425 425 application/json
errors.Error429 429 application/json
errors.Error500 500 application/json
errors.Error502 502 application/json
errors.Error504 504 application/json
errors.SDKError 4XX, 5XX */*

capture

Captures a previously authorized transaction. You can capture the full or a partial amount, as long as it does not exceed the authorized amount (unless over-capture is enabled).

Example Usage

import { Gr4vy, withToken } from "@gr4vy/sdk";
import fs from "fs";

const gr4vy = new Gr4vy({
    id: "example",
    server: "sandbox",
    merchantAccountId: "default",
    bearerAuth: withToken({
      privateKey: fs.readFileSync("private_key.pem", "utf8"),
    }),
});

async function run() {
  const result = await gr4vy.transactions.capture({
    transactionId: "7099948d-7286-47e4-aad8-b68f7eb44591",
    transactionCaptureCreate: {},
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { Gr4vyCore } from "@gr4vy/sdk/core.js";
import { transactionsCapture } from "@gr4vy/sdk/funcs/transactionsCapture.js";

// Use `Gr4vyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const gr4vy = new Gr4vyCore({
  merchantAccountId: "<id>",
  bearerAuth: process.env["GR4VY_BEARER_AUTH"] ?? "",
});

async function run() {
  const res = await transactionsCapture(gr4vy, {
    transactionId: "7099948d-7286-47e4-aad8-b68f7eb44591",
    transactionCaptureCreate: {},
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("transactionsCapture failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.CaptureTransactionRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.CaptureTransactionResponse200CaptureTransaction>

Errors

Error Type Status Code Content Type
errors.Error400 400 application/json
errors.Error401 401 application/json
errors.Error403 403 application/json
errors.Error404 404 application/json
errors.Error405 405 application/json
errors.Error409 409 application/json
errors.HTTPValidationError 422 application/json
errors.Error425 425 application/json
errors.Error429 429 application/json
errors.Error500 500 application/json
errors.Error502 502 application/json
errors.Error504 504 application/json
errors.SDKError 4XX, 5XX */*

void

Voids a previously authorized transaction. If the transaction was not yet successfully authorized, or was already captured, the void will not be processed. This operation releases the hold on the buyer's funds. Captured transactions can be refunded instead.

Example Usage

import { Gr4vy, withToken } from "@gr4vy/sdk";
import fs from "fs";

const gr4vy = new Gr4vy({
    id: "example",
    server: "sandbox",
    merchantAccountId: "default",
    bearerAuth: withToken({
      privateKey: fs.readFileSync("private_key.pem", "utf8"),
    }),
});

async function run() {
  const result = await gr4vy.transactions.void("7099948d-7286-47e4-aad8-b68f7eb44591");

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { Gr4vyCore } from "@gr4vy/sdk/core.js";
import { transactionsVoid } from "@gr4vy/sdk/funcs/transactionsVoid.js";

// Use `Gr4vyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const gr4vy = new Gr4vyCore({
  merchantAccountId: "<id>",
  bearerAuth: process.env["GR4VY_BEARER_AUTH"] ?? "",
});

async function run() {
  const res = await transactionsVoid(gr4vy, "7099948d-7286-47e4-aad8-b68f7eb44591");
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("transactionsVoid failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description Example
transactionId string ✔️ The ID of the transaction 7099948d-7286-47e4-aad8-b68f7eb44591
prefer string[] The preferred resource type in the response.
merchantAccountId string The ID of the merchant account to use for this request.
idempotencyKey string A unique key that identifies this request. Providing this header will make this an idempotent request. We recommend using V4 UUIDs, or another random string with enough entropy to avoid collisions. request-12345
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.VoidTransactionResponse200VoidTransaction>

Errors

Error Type Status Code Content Type
errors.Error400 400 application/json
errors.Error401 401 application/json
errors.Error403 403 application/json
errors.Error404 404 application/json
errors.Error405 405 application/json
errors.Error409 409 application/json
errors.HTTPValidationError 422 application/json
errors.Error425 425 application/json
errors.Error429 429 application/json
errors.Error500 500 application/json
errors.Error502 502 application/json
errors.Error504 504 application/json
errors.SDKError 4XX, 5XX */*

cancel

Cancels a pending transaction. If the transaction was successfully authorized, or was already captured, the cancel will not be processed.

Example Usage

import { Gr4vy, withToken } from "@gr4vy/sdk";
import fs from "fs";

const gr4vy = new Gr4vy({
    id: "example",
    server: "sandbox",
    merchantAccountId: "default",
    bearerAuth: withToken({
      privateKey: fs.readFileSync("private_key.pem", "utf8"),
    }),
});

async function run() {
  const result = await gr4vy.transactions.cancel("7099948d-7286-47e4-aad8-b68f7eb44591");

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { Gr4vyCore } from "@gr4vy/sdk/core.js";
import { transactionsCancel } from "@gr4vy/sdk/funcs/transactionsCancel.js";

// Use `Gr4vyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const gr4vy = new Gr4vyCore({
  merchantAccountId: "<id>",
  bearerAuth: process.env["GR4VY_BEARER_AUTH"] ?? "",
});

async function run() {
  const res = await transactionsCancel(gr4vy, "7099948d-7286-47e4-aad8-b68f7eb44591");
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("transactionsCancel failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description Example
transactionId string ✔️ The ID of the transaction 7099948d-7286-47e4-aad8-b68f7eb44591
merchantAccountId string The ID of the merchant account to use for this request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.TransactionCancel>

Errors

Error Type Status Code Content Type
errors.Error400 400 application/json
errors.Error401 401 application/json
errors.Error403 403 application/json
errors.Error404 404 application/json
errors.Error405 405 application/json
errors.Error409 409 application/json
errors.HTTPValidationError 422 application/json
errors.Error425 425 application/json
errors.Error429 429 application/json
errors.Error500 500 application/json
errors.Error502 502 application/json
errors.Error504 504 application/json
errors.SDKError 4XX, 5XX */*

sync

Synchronizes the status of a transaction with the underlying payment service provider. This is useful for transactions in a pending state to check if they've been completed or failed. Only available for some payment service providers.

Example Usage

import { Gr4vy, withToken } from "@gr4vy/sdk";
import fs from "fs";

const gr4vy = new Gr4vy({
    id: "example",
    server: "sandbox",
    merchantAccountId: "default",
    bearerAuth: withToken({
      privateKey: fs.readFileSync("private_key.pem", "utf8"),
    }),
});

async function run() {
  const result = await gr4vy.transactions.sync("2ee546e0-3b11-478e-afec-fdb362611e22");

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { Gr4vyCore } from "@gr4vy/sdk/core.js";
import { transactionsSync } from "@gr4vy/sdk/funcs/transactionsSync.js";

// Use `Gr4vyCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const gr4vy = new Gr4vyCore({
  merchantAccountId: "<id>",
  bearerAuth: process.env["GR4VY_BEARER_AUTH"] ?? "",
});

async function run() {
  const res = await transactionsSync(gr4vy, "2ee546e0-3b11-478e-afec-fdb362611e22");
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("transactionsSync failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
transactionId string ✔️ N/A
merchantAccountId string The ID of the merchant account to use for this request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.Transaction>

Errors

Error Type Status Code Content Type
errors.Error400 400 application/json
errors.Error401 401 application/json
errors.Error403 403 application/json
errors.Error404 404 application/json
errors.Error405 405 application/json
errors.Error409 409 application/json
errors.HTTPValidationError 422 application/json
errors.Error425 425 application/json
errors.Error429 429 application/json
errors.Error500 500 application/json
errors.Error502 502 application/json
errors.Error504 504 application/json
errors.SDKError 4XX, 5XX */*