@prezzee/ts-v2-sdks
Advanced tools
Comparing version 1.8.0 to 1.9.0
@@ -1,4 +0,4 @@ | ||
import { createPrezzeeClient } from "../src"; | ||
// import { createPrezzeeClient } from "@prezzee/ts-v2-sdks"; | ||
import { createPrezzeeClient } from "../src/index"; | ||
function generateUUID() { | ||
@@ -31,5 +31,6 @@ // Public Domain/MIT | ||
env: "sandbox", | ||
region: "AU", | ||
}); | ||
const products = await prezzeeClient.listProducts(); | ||
const styles = await prezzeeClient.listStyles(); | ||
@@ -36,0 +37,0 @@ |
import { ApiV2Client, Order } from "../generated"; | ||
declare const environments: { | ||
sandbox: { | ||
baseUrl: string; | ||
}; | ||
production: { | ||
baseUrl: string; | ||
}; | ||
}; | ||
type Regions = "AU" | "UK"; | ||
type Environments = "sandbox" | "production"; | ||
export type PrezzeeClientConfig = { | ||
env: keyof typeof environments; | ||
env: Environments; | ||
token: string; | ||
region: Regions; | ||
}; | ||
@@ -18,3 +13,3 @@ type Params<T extends (param: any) => any> = Omit<Parameters<T>[0], "version">; | ||
private client; | ||
constructor({ env, token }: PrezzeeClientConfig); | ||
constructor({ env, token, region }: PrezzeeClientConfig); | ||
listProducts: (params?: Params<ApiV2Client["default"]["listProducts"]>) => import("../generated").CancelablePromise<{ | ||
@@ -42,3 +37,13 @@ count?: number | undefined; | ||
}>; | ||
retrieveProductDetails: (params: Params<ApiV2Client["default"]["retrieveProductDetails"]>) => import("../generated").CancelablePromise<import("../generated").Product>; | ||
retrieveFloatBalance: (params: Params<ApiV2Client["default"]["retrieveFloatBalance"]>) => import("../generated").CancelablePromise<import("../generated").FloatBalance>; | ||
retrieveInvoice: (params: Params<ApiV2Client["default"]["retrieveInvoice"]>) => import("../generated").CancelablePromise<import("../generated").APIV2InvoicePDFGeneration>; | ||
retrieveConsolidatedInvoices: (params: Params<ApiV2Client["default"]["retrieveConsolidatedInvoices"]>) => import("../generated").CancelablePromise<{ | ||
count?: number | undefined; | ||
next?: string | null | undefined; | ||
previous?: string | null | undefined; | ||
results?: import("../generated").APIV2ConsolidatedInvoicesPDFGeneration[] | undefined; | ||
}>; | ||
retrieveSenderProfiles: (params: Params<ApiV2Client["default"]["retrieveSenderProfiles"]>) => import("../generated").CancelablePromise<import("../generated").SenderProfile[]>; | ||
} | ||
export {}; |
@@ -14,8 +14,18 @@ "use strict"; | ||
const generated_1 = require("../generated"); | ||
const environments = { | ||
const CONFIG = { | ||
sandbox: { | ||
baseUrl: "https://stg.prezzee.com.au", | ||
AU: { | ||
baseUrl: "https://stg.prezzee.com.au", | ||
}, | ||
UK: { | ||
baseUrl: "https://stg.prezzee.uk", | ||
}, | ||
}, | ||
production: { | ||
baseUrl: "https://stg.prezzee.com.au", | ||
AU: { | ||
baseUrl: "https://www.prezzee.com.au", | ||
}, | ||
UK: { | ||
baseUrl: "https://www.prezzee.uk", | ||
}, | ||
}, | ||
@@ -26,3 +36,3 @@ }; | ||
class PrezzeeClient { | ||
constructor({ env, token }) { | ||
constructor({ env, token, region }) { | ||
this.version = "v2"; | ||
@@ -58,4 +68,9 @@ this.listProducts = (params) => this.client.default.listProducts(Object.assign({ version: this.version }, params)); | ||
this.listOrderItems = (params) => this.client.default.listOrderItems(Object.assign({ version: this.version }, params)); | ||
this.retrieveProductDetails = (params) => this.client.default.retrieveProductDetails(Object.assign({ version: this.version }, params)); | ||
this.retrieveFloatBalance = (params) => this.client.default.retrieveFloatBalance(Object.assign({ version: this.version }, params)); | ||
this.retrieveInvoice = (params) => this.client.default.retrieveInvoice(Object.assign({ version: this.version }, params)); | ||
this.retrieveConsolidatedInvoices = (params) => this.client.default.retrieveConsolidatedInvoices(Object.assign({ version: this.version }, params)); | ||
this.retrieveSenderProfiles = (params) => this.client.default.retrieveSenderProfiles(Object.assign({ version: this.version }, params)); | ||
this.client = new generated_1.ApiV2Client({ | ||
BASE: environments[env].baseUrl, | ||
BASE: CONFIG[env][region].baseUrl, | ||
TOKEN: token, | ||
@@ -62,0 +77,0 @@ }); |
{ | ||
"name": "@prezzee/ts-v2-sdks", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"description": "", | ||
@@ -18,2 +18,3 @@ "main": "lib/src/index.js", | ||
"@prezzee/shared-ts-config": "^2.0.0", | ||
"@prezzee/ts-v2-sdks": "^1.7.0", | ||
"commitizen": "^4.3.0", | ||
@@ -20,0 +21,0 @@ "cz-conventional-changelog": "^3.3.0", |
@@ -16,64 +16,55 @@ # Welcome to Prezzee SDKs | ||
- Retrieve Consolidated Invoices | ||
- Retrieve Discounts available | ||
## Install | ||
`npm install @prezzee/ts-v2-sdks` | ||
``` | ||
npm install @prezzee/ts-v2-sdks | ||
``` | ||
Install dependencies as well: | ||
`npm install axios` | ||
``` | ||
npm install axios | ||
``` | ||
## Usage | ||
To use the functions, you need a Business API token as part of your config. Add an environment variable TOKEN={business API token you must have received}. Example token: `sJ0uOIDRYexgfL2M7BgLiPjb6xkPAi` | ||
To use the SDK, you need to acquire Business API token by contacting Prezzee. | ||
### Initialise Client | ||
Example API token: `sJ0uOIDRYexgfL2M7BgLiPjb6xddfdskPAi` | ||
`const prezzeeClient = createPrezzeeClient({ token: process.env.TOKEN, env: "sandbox" });` | ||
### Initialize the Client | ||
Once initialised, you can use it as per following examples: | ||
```typescript | ||
const prezzeeClient = createPrezzeeClient({ | ||
token: "<Your API Token>", | ||
// Select the correct environnement | ||
env: "sandbox", | ||
// Select the target region | ||
region: "AU", | ||
}); | ||
``` | ||
### List Products | ||
### Use APIs | ||
Once initialized, the client can be used as below: | ||
`const products = await prezzeeClient.listProducts();` | ||
Returns a list of products currently available for purchase. | ||
```typescript | ||
const products = await prezzeeClient.listProducts(); | ||
``` | ||
For a complete list of available API calls refer to the [API documentation](https://www.prezzee.com.au/api/v2/docs/). | ||
### List Styles | ||
`const styles = await prezzeeClient.listStyles();` | ||
Returns a list of gift styles for use with the product creation endpoint. | ||
## Examples | ||
Below are a few examples | ||
### Create order | ||
In Prezzee API, orders are fulfilled in the background (asynchronously). Therefore, it is important to note that, `prezzeeClient.createOrder()` API always returns order status `PROCESSING`, indicating that the order is successfully being processed in the background. | ||
### Create Order | ||
~~~ | ||
const product = products.results[0]; | ||
Order items (i.e. gift cards), can only be retrieved once the order has moved into the `COMPLETE` status. The API `prezzeeClient.retrieveOrder()` can be used to poll the order details to check if a order has moved to `COMPLETE` status. Our SDK provides a convenient way handle this by simply specifying a configuration `awaitCompletion`. When specified, API will poll retrieve order endpoint until order moves `COMPLETE` with incremental delays. This method will throw `TimeoutError`, if the order does not move to completion within 20 seconds. | ||
const style = styles.results[0]; | ||
```typescript | ||
await prezzeeClient.retrieveOrder( | ||
{ | ||
orderUuid: order.uuid, | ||
}, | ||
{ awaitCompletion: true } | ||
); | ||
``` | ||
const order = await prezzeeClient.createOrder({ | ||
reference: generateUUID(), | ||
payment_method: "POSTPAID_CREDIT", | ||
wait_for_stock: false, | ||
items: [ | ||
{ | ||
reference: generateUUID(), | ||
product_code: product.code, | ||
product_theme_code: product.themes[0].code, | ||
amount: product.denominations[0].amount, | ||
currency: product.denominations[0].currency, | ||
delivery_method: "LINK", | ||
delivery_details: { | ||
style_code: style.code, | ||
message: "Hello Prezzee SDK", | ||
recipient_name: "Prezzee SDK Recipient", | ||
recipient_email: "dhanushka.krishnaith@prezzee.com", | ||
sender_name: "Prezzee SDK Sender", | ||
}, | ||
}, | ||
], | ||
}); | ||
~~~ | ||
This will return order_uuid in response which can be used in the following example to retrieve the order details. | ||
### Retrieve Order | ||
`await prezzeeClient.retrieveOrder({ | ||
orderUuid: order.uuid, | ||
});` | ||
To find complete examples please go to `/examples` directory in the [code](https://www.npmjs.com/package/@prezzee/ts-v2-sdks?activeTab=explore). |
import { ApiV2Client, Order } from "../generated"; | ||
const environments = { | ||
type Regions = "AU" | "UK"; | ||
type Environments = "sandbox" | "production"; | ||
const CONFIG: { | ||
[key in Environments]: { | ||
[key in Regions]: { | ||
baseUrl: string; | ||
}; | ||
}; | ||
} = { | ||
sandbox: { | ||
baseUrl: "https://stg.prezzee.com.au", | ||
AU: { | ||
baseUrl: "https://stg.prezzee.com.au", | ||
}, | ||
UK: { | ||
baseUrl: "https://stg.prezzee.uk", | ||
}, | ||
}, | ||
production: { | ||
baseUrl: "https://stg.prezzee.com.au", | ||
AU: { | ||
baseUrl: "https://www.prezzee.com.au", | ||
}, | ||
UK: { | ||
baseUrl: "https://www.prezzee.uk", | ||
}, | ||
}, | ||
@@ -13,4 +32,5 @@ }; | ||
export type PrezzeeClientConfig = { | ||
env: keyof typeof environments; | ||
env: Environments; | ||
token: string; | ||
region: Regions; | ||
}; | ||
@@ -27,5 +47,5 @@ | ||
constructor({ env, token }: PrezzeeClientConfig) { | ||
constructor({ env, token, region }: PrezzeeClientConfig) { | ||
this.client = new ApiV2Client({ | ||
BASE: environments[env].baseUrl, | ||
BASE: CONFIG[env][region].baseUrl, | ||
TOKEN: token, | ||
@@ -90,2 +110,42 @@ }); | ||
this.client.default.listOrderItems({ version: this.version, ...params }); | ||
retrieveProductDetails = ( | ||
params: Params<ApiV2Client["default"]["retrieveProductDetails"]> | ||
) => | ||
this.client.default.retrieveProductDetails({ | ||
version: this.version, | ||
...params, | ||
}); | ||
retrieveFloatBalance = ( | ||
params: Params<ApiV2Client["default"]["retrieveFloatBalance"]> | ||
) => | ||
this.client.default.retrieveFloatBalance({ | ||
version: this.version, | ||
...params, | ||
}); | ||
retrieveInvoice = ( | ||
params: Params<ApiV2Client["default"]["retrieveInvoice"]> | ||
) => | ||
this.client.default.retrieveInvoice({ | ||
version: this.version, | ||
...params, | ||
}); | ||
retrieveConsolidatedInvoices = ( | ||
params: Params<ApiV2Client["default"]["retrieveConsolidatedInvoices"]> | ||
) => | ||
this.client.default.retrieveConsolidatedInvoices({ | ||
version: this.version, | ||
...params, | ||
}); | ||
retrieveSenderProfiles = ( | ||
params: Params<ApiV2Client["default"]["retrieveSenderProfiles"]> | ||
) => | ||
this.client.default.retrieveSenderProfiles({ | ||
version: this.version, | ||
...params, | ||
}); | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
293514
4621
6
69