# @payglide/sdk-js

> PayGlide SDK for JavaScript

Latest version **0.2.0** (published 2023-12-14) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @payglide/sdk-js
pnpm add @payglide/sdk-js
yarn add @payglide/sdk-js
bun add @payglide/sdk-js
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2023-12-14 |
| First published | 2023-02-17 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 14 |
| Dependencies | 1 |
| Unpacked size | 137 KB |
| Known vulnerabilities | 0 (+24 in 1 direct dependencies) |
| Install scripts | no |
| Author | wfalcon |
| Maintainers | payglide |
| Keywords | payglide, api, sdk, rest |

## Links

- npm: https://www.npmjs.com/package/@payglide/sdk-js
- npm.io page: https://npm.io/package/@payglide/sdk-js

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) 0.27.2

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2023-12-14
- 0.1.3 — 2023-12-14
- 0.1.2 — 2023-12-14
- 0.1.1 — 2023-05-18
- 0.1.0 — 2023-02-17

## README

<div align="center">
	<h1>PayGlide SDK for JavaScript</h1>
</div>

## Installation

Use your favorite package manager to install the sdk and save to your `package.json`:

```shell
$ npm install @payglide/sdk-js

# Or, you can use yarn
$ yarn add @payglide/sdk-js
```

## Usage

Import and initialize a client using an **api key**

```typescript
import { PayGlideClient } from '@payglide/sdk-js';

// Initializing a client
const client = new PayGlideClient({
  apiKey: process.env.PAYGLIDE_API_KEY,
})
```

### **initCheckoutSession**
> CheckoutSession initCheckoutSession(initCheckoutRequest)

Create a new checkout session based on the transaction data


```typescript
const checkoutSession = await client.initCheckoutSession({
  address: '0x6f9ce307c114f443',
  code: 'test script',
  arguments: [
    {
      value: '5.0',
      type: 'UFix64',
    },
  ],
})
```

The initCheckoutSession method returns a `Promise` which resolves the checkoutSession response.

```json
{
    "id": "1234abcd-1234-abcd-8c19-1234abcd56ef",
    "expiresAt": "2023-05-25T23:23:56.360Z",
    "createdAt": "2023-05-25T23:08:56.360Z",
    "updatedAt": "2023-05-25T23:08:56.360Z",
    "status": "CHECKOUT_INITIATED",
    "transactionHash": "",
    "buyer": {
        "address": "0x6f9ce307c114f443"
    },
    "products": [
        {
            "pricing": {
                "amount": "5.00000000",
                "currency": "USDC"
            }
        }
    ],
    "quote": {
        "details": [
            {
                "description": "1 x NFT",
                "amount": "5.00",
                "currency": "USD"
            },
            {
                "description": "Processing Fee",
                "amount": "0.49",
                "currency": "USD"
            },
            {
                "description": "Network Fee",
                "amount": "0",
                "currency": "USD"
            }
        ],
        "total": {
            "description": "Total Price",
            "amount": "5.49",
            "currency": "USD"
        },
        "expiresAt": "2023-05-25T23:18:56.360Z",
        "createdAt": "2023-05-25T23:08:56.360Z",
        "updatedAt": "2023-05-25T23:18:56.360Z"
    }
}
```

### **initCheckout**
> Checkout initCheckout(initCheckoutRequest)

The initCheckout method returns a `Promise` which resolves the Checkout object.
Checkout is a helper class for polling the checkout session status and provides with other convenience methods.

```typescript
const checkout = await client.initCheckout({
  address: '0x6f9ce307c114f443',
  code: 'test script',
  arguments: [
    {
      value: '5.0',
      type: 'UFix64',
    },
  ],
})
```

### **Checkout object with convenience methods**
> getCheckoutPage(walletId)

Convenience method to get the url for the wallet specific checkout page.
```typescript
const checkoutPageUrl = checkout.getCheckoutPage(walletId)
```


> getCurrentStatus()

Convenience method to retrieve the current checkout status associated with the checkout.
```typescript
const currentStatus = await checkout.getCurrentStatus()
```
Posible checkout status:
- CHECKOUT_INITIATED
- PAYMENT_INITIATED
- PAYMENT_SUCCEEDED
- PAYMENT_FAILED
- TOKEN_TRANSFER_INITIATED
- TOKEN_TRANSFER_COMPLETED
- TOKEN_TRANSFER_FAILED


> CheckoutSession onTransactionComplete()

Convenience method to poll the checkout status and resolve the promise when the checkout is complete.
```typescript
const finalSession = await checkout.onTransactionComplete()
```

### PayGlideClient options

The `PayGlideClient` supports the following options on initialization. These options are all keys in the constructor parameter.

| Option        | Default value            | Type         | Description                                                                                                                                                  |
| ------------- | ------------------------ | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `apiKey`      | `undefined`              |   `string`   | API Key provided to individual projects.                                                      |
| `pollInterval`| `5000 (5 seconds)`       |   `number`   | Milliseconds interval between attempting to resolve the promise again.                                                 |
| `pollTimeout` | `300000 (5 minutes)`     |   `number`   | Maximum time in milliseconds to continue polling to receive a successful resolved response. If the promise doesn't resolve before the poll timeout then the poller rejects with a timeout error.                                                 |


## Requirements

This package supports the following minimum versions:

- Runtime: `node >= 14`


## LICENSE

[Apache-2.0](LICENSE)

---
_Source: https://npm.io/package/@payglide/sdk-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
