Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@smartpay/sdk-node

Package Overview
Dependencies
Maintainers
3
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smartpay/sdk-node - npm Package Compare versions

Comparing version 0.8.0 to 0.9.0

.github/workflows/main.yml

6

build/cjs/payload.d.ts

@@ -1,2 +0,2 @@

import type { CustomerInfo, CustomerInfoLoose, SimpleLineItem, SimpleChekoutSessionPayload, ShippingInfo, Address } from './types';
import type { CustomerInfo, CustomerInfoLoose, SimpleLineItem, FlatChekoutSessionPayload, ShippingInfo, Address } from './types';
export declare const normalizeCustomerInfo: (customer?: CustomerInfoLoose) => CustomerInfo;

@@ -72,3 +72,3 @@ export declare const normalizeItem: (item: SimpleLineItem) => {

};
export declare const normalizeCheckoutSessionPayload: (payload: SimpleChekoutSessionPayload) => {
export declare const normalizeCheckoutSessionPayload: (payload: FlatChekoutSessionPayload) => {
amount: number | undefined;

@@ -123,3 +123,3 @@ currency: string | undefined;

declare const _default: {
normalizeCheckoutSessionPayload: (payload: SimpleChekoutSessionPayload) => {
normalizeCheckoutSessionPayload: (payload: FlatChekoutSessionPayload) => {
amount: number | undefined;

@@ -126,0 +126,0 @@ currency: string | undefined;

@@ -170,2 +170,8 @@ declare const _default: {

};
successUrl: {
type: string;
};
cancelUrl: {
type: string;
};
};

@@ -182,8 +188,5 @@ optionalProperties: {

};
successUrl: {
locale: {
type: string;
};
cancelUrl: {
type: string;
};
};

@@ -190,0 +193,0 @@ additionalProperties: boolean;

@@ -1,2 +0,2 @@

import { CheckoutSession, SimpleChekoutSessionPayload, ListParams, GetObjectParams, Collection } from '../types';
import { CheckoutSession, FlatChekoutSessionPayload, TokenChekoutSessionPayload, ListParams, GetObjectParams, Collection } from '../types';
import { Constructor } from './base';

@@ -14,5 +14,8 @@ declare type GetSessionURLOptions = {

export declare const CAPTURE_METHOD_MANUAL = "manual";
export declare const MODE_TOKEN = "token";
declare const checkoutSessionsMixin: <T extends Constructor>(Base: T) => {
new (...args: any[]): {
createCheckoutSession(payload: SimpleChekoutSessionPayload): Promise<CheckoutSession>;
createFlatCheckoutSession(payload: FlatChekoutSessionPayload): Promise<CheckoutSession>;
createTokenCheckoutSession(payload: TokenChekoutSessionPayload): Promise<CheckoutSession>;
createCheckoutSession(payload: FlatChekoutSessionPayload): Promise<CheckoutSession>;
listCheckoutSessions(params?: ListParams): Promise<Collection<CheckoutSession>>;

@@ -38,3 +41,6 @@ getCheckoutSession(params?: GetObjectParams): Promise<CheckoutSession>;

CAPTURE_METHOD_MANUAL: string;
normalizeCheckoutSessionPayload(payload: SimpleChekoutSessionPayload): SimpleChekoutSessionPayload;
MODE_TOKEN: string;
normalizeFlatCheckoutSessionPayload(payload: FlatChekoutSessionPayload): FlatChekoutSessionPayload;
normalizeTokenCheckoutSessionPayload(payload: TokenChekoutSessionPayload): TokenChekoutSessionPayload;
normalizeCheckoutSessionPayload(payload: FlatChekoutSessionPayload): FlatChekoutSessionPayload | TokenChekoutSessionPayload;
getSessionUrl(session: CheckoutSession, options?: GetSessionURLOptions | undefined): string;

@@ -41,0 +47,0 @@ getSessionURL(session: CheckoutSession, options?: GetSessionURLOptions | undefined): string;

@@ -1,2 +0,2 @@

import { Order, ListParams, GetObjectParams, CancelOrderParams, Collection } from '../types';
import { Order, ListParams, GetObjectParams, CommonUpdateParams, Collection, OrderPayload } from '../types';
import { Constructor } from './base';

@@ -10,4 +10,5 @@ export declare const ORDER_STATUS_SUCCEEDED = "succeeded";

new (...args: any[]): {
createOrder(payload: OrderPayload): Promise<Order>;
getOrder(params?: GetObjectParams): Promise<Order>;
cancelOrder(params?: CancelOrderParams): Promise<Order>;
cancelOrder(params?: CommonUpdateParams): Promise<Order>;
listOrders(params?: ListParams): Promise<Collection<Order>>;

@@ -30,3 +31,4 @@ _secretKey: string;

ORDER_STATUS_REQUIRES_AUTHORIZATION: string;
normalizeOrderPayload(payload: OrderPayload): OrderPayload;
} & T;
export default ordersMixin;

@@ -130,3 +130,4 @@ export interface LooseObject {

};
export declare type SimpleChekoutSessionPayload = {
export declare type FlatChekoutSessionPayload = {
mode?: 'token';
amount?: number;

@@ -136,4 +137,4 @@ currency?: string;

items: SimpleLineItem[];
shippingInfo?: ShippingInfo;
customerInfo?: CustomerInfo;
shippingInfo: ShippingInfo;
customerInfo: CustomerInfo;
locale?: string;

@@ -148,2 +149,24 @@ successUrl?: string;

};
export declare type TokenChekoutSessionPayload = {
mode: 'token';
customerInfo?: CustomerInfo;
locale?: string;
successUrl?: string;
cancelUrl?: string;
metadata?: MetaData;
reference?: string;
idempotencyKey?: string;
};
export declare type OrderPayload = {
token?: string;
amount: number;
currency: string;
captureMethod?: 'automatic' | 'manual';
items: SimpleLineItem[];
shippingInfo: ShippingInfo;
customerInfo: CustomerInfo;
metadata?: MetaData;
reference?: string;
idempotencyKey?: string;
};
export declare type RefundPayload = {

@@ -289,2 +312,11 @@ payment: string;

};
export declare type Token = {
id: string;
object: string;
createdAt: number;
status: string;
reference?: string;
test: boolean;
updatedAt: number;
};
export declare type JTDError = {

@@ -303,3 +335,3 @@ instancePath: string[];

};
export declare type CancelOrderParams = {
export declare type CommonUpdateParams = {
id?: string;

@@ -306,0 +338,0 @@ idempotencyKey?: string;

@@ -1,2 +0,2 @@

import type { KeyString, SimpleChekoutSessionPayload, ErrorDetails, LooseObject } from './types';
import type { KeyString, FlatChekoutSessionPayload, TokenChekoutSessionPayload, ErrorDetails, LooseObject, OrderPayload } from './types';
export declare class SmartpayError extends Error {

@@ -22,8 +22,11 @@ statusCode?: number;

export declare const isValidPromotionCodeId: (input: string) => boolean;
export declare const validateCheckoutSessionPayload: (payload: SimpleChekoutSessionPayload) => ErrorDetails;
export declare const isValidTokenId: (input: string) => boolean;
export declare const validateFlatCheckoutSessionPayload: (payload: FlatChekoutSessionPayload) => ErrorDetails;
export declare const validateTokenCheckoutSessionPayload: (payload: TokenChekoutSessionPayload) => ErrorDetails;
export declare const validateTokenOrderPayload: (payload: OrderPayload) => ErrorDetails;
/**
* Try to get the currency of this checkout
*/
export declare const getCurrency: (payload: SimpleChekoutSessionPayload) => string;
export declare const normalizeCheckoutSessionPayload: (input: SimpleChekoutSessionPayload) => {
export declare const getCurrency: (payload: FlatChekoutSessionPayload) => string;
export declare const normalizeFlatCheckoutSessionPayload: (input: FlatChekoutSessionPayload) => {
amount: number | undefined;

@@ -30,0 +33,0 @@ currency: string | undefined;

@@ -233,4 +233,4 @@ var __defProp = Object.defineProperty;

// src/schemas/simple-checkout-session-payload.jtd.ts
var simple_checkout_session_payload_jtd_default = {
// src/schemas/flat-checkout-session-payload.jtd.ts
var flat_checkout_session_payload_jtd_default = {
definitions: {

@@ -307,3 +307,5 @@ address: {

additionalProperties: true
}
},
successUrl: { type: "string" },
cancelUrl: { type: "string" }
},

@@ -314,8 +316,142 @@ optionalProperties: {

reference: { type: "string" },
locale: { type: "string" }
},
additionalProperties: true
};
// src/schemas/token-checkout-session-payload.jtd.ts
var token_checkout_session_payload_jtd_default = {
definitions: {
address: {
properties: {
line1: { type: "string" },
locality: { type: "string" },
country: { type: "string" },
postalCode: { type: "string" }
},
optionalProperties: {
line2: { type: "string" },
line3: { type: "string" },
line4: { type: "string" },
line5: { type: "string" },
administrativeArea: { type: "string" },
subLocality: { type: "string" },
addressType: { type: "string" }
},
additionalProperties: true
},
customer: {
optionalProperties: {
accountAge: { type: "uint32" },
emailAddress: { type: "string" },
firstName: { type: "string" },
lastName: { type: "string" },
phoneNumber: { type: "string" },
firstNameKana: { type: "string" },
lastNameKana: { type: "string" },
address: { ref: "address" },
dateOfBirth: { type: "string" },
legalGender: { type: "string" },
reference: { type: "string" }
},
additionalProperties: true
}
},
properties: {
mode: { type: "string" },
customerInfo: { ref: "customer" },
successUrl: { type: "string" },
cancelUrl: { type: "string" }
},
optionalProperties: {
description: { type: "string" },
reference: { type: "string" },
locale: { type: "string" }
},
additionalProperties: true
};
// src/schemas/token-order-payload.jtd.ts
var token_order_payload_jtd_default = {
definitions: {
address: {
properties: {
line1: { type: "string" },
locality: { type: "string" },
country: { type: "string" },
postalCode: { type: "string" }
},
optionalProperties: {
line2: { type: "string" },
line3: { type: "string" },
line4: { type: "string" },
line5: { type: "string" },
administrativeArea: { type: "string" },
subLocality: { type: "string" },
addressType: { type: "string" }
},
additionalProperties: true
},
customer: {
optionalProperties: {
accountAge: { type: "uint32" },
emailAddress: { type: "string" },
firstName: { type: "string" },
lastName: { type: "string" },
phoneNumber: { type: "string" },
firstNameKana: { type: "string" },
lastNameKana: { type: "string" },
address: { ref: "address" },
dateOfBirth: { type: "string" },
legalGender: { type: "string" },
reference: { type: "string" }
},
additionalProperties: true
},
lineItem: {
optionalProperties: {
kind: { type: "string" },
name: { type: "string" },
quantity: { type: "uint16" },
amount: { type: "uint32" },
currency: { type: "string" },
description: { type: "string" },
priceDescription: { type: "string" },
productDescription: { type: "string" },
label: { type: "string" },
brand: { type: "string" },
categories: { elements: { type: "string" } },
gtin: { type: "string" },
images: { elements: { type: "string" } },
reference: { type: "string" },
url: { type: "string" }
},
additionalProperties: true
}
},
properties: {
token: { type: "string" },
amount: { type: "uint32" },
currency: { type: "string" },
items: { elements: { ref: "lineItem" } },
customerInfo: { ref: "customer" },
shippingInfo: {
properties: {
address: { ref: "address" }
},
optionalProperties: {
addressType: { type: "string" },
feeAmount: { type: "uint32" },
feeCurrency: { type: "string" }
},
additionalProperties: true
}
},
optionalProperties: {
captureMethod: { type: "string" },
reference: { type: "string" }
},
additionalProperties: true
};
// src/utils.ts

@@ -331,2 +467,3 @@ var publicKeyRegExp = /^pk_(test|live)_[0-9a-zA-Z]+$/;

var promotionCodeIdRegExp = /^promotioncode_(test|live)_[0-9a-zA-Z]+$/;
var tokenIdRegExp = /^paytok_(test|live)_[0-9a-zA-Z]+$/;
var SmartpayError = class extends Error {

@@ -374,4 +511,7 @@ constructor({

};
var validateCheckoutSessionPayload = (payload) => {
const errors = validate(simple_checkout_session_payload_jtd_default, JSON.parse(JSON.stringify(payload)));
var isValidTokenId = (input) => {
return tokenIdRegExp.test(input);
};
var validateFlatCheckoutSessionPayload = (payload) => {
const errors = validate(flat_checkout_session_payload_jtd_default, JSON.parse(JSON.stringify(payload)));
if (payload.items.length === 0) {

@@ -382,2 +522,10 @@ errors.push("payload.items is required.");

};
var validateTokenCheckoutSessionPayload = (payload) => {
const errors = validate(token_checkout_session_payload_jtd_default, JSON.parse(JSON.stringify(payload)));
return errors;
};
var validateTokenOrderPayload = (payload) => {
const errors = validate(token_order_payload_jtd_default, JSON.parse(JSON.stringify(payload)));
return errors;
};
var getCurrency = (payload) => {

@@ -391,3 +539,3 @@ var _a2;

};
var normalizeCheckoutSessionPayload2 = (input) => {
var normalizeFlatCheckoutSessionPayload = (input) => {
const payload = normalizeCheckoutSessionPayload(input);

@@ -482,3 +630,3 @@ const { shippingInfo } = payload;

"dev-lang": "nodejs",
"sdk-version": "0.8.0"
"sdk-version": "0.9.0"
})

@@ -506,19 +654,26 @@ });

default:
return response.json().catch((error) => {
throw new SmartpayError({
errorCode: "unexpected_error",
statusCode: response.status,
message: `${response.status} ${error.message}`
});
}).then((data) => {
if (response.ok) {
return data;
}
throw new SmartpayError({
errorCode: data.errorCode,
statusCode: response.status,
message: `${response.status} ${data.message}`,
details: data.details
});
});
switch ((response.headers.get("Content-Type") || "").split(";")[0]) {
case "application/json":
case "text/json":
return response.json().catch((error) => {
throw new SmartpayError({
errorCode: "unexpected_error",
statusCode: response.status,
message: `${response.status} ${error.message}`
});
}).then((data) => {
if (response.ok) {
return data;
}
throw new SmartpayError({
errorCode: data.errorCode,
statusCode: response.status,
message: `${response.status} ${data.message}`,
details: data.details
});
});
default:
return Promise.resolve("");
}
return Promise.resolve("");
}

@@ -555,7 +710,14 @@ });

var CAPTURE_METHOD_MANUAL = "manual";
var MODE_TOKEN = "token";
var checkoutSessionsMixin = (Base) => {
const _SmartpayWithCheckoutSession = class extends Base {
static normalizeCheckoutSessionPayload(payload) {
const normalizedPayload = normalizeCheckoutSessionPayload2(payload);
const errors = validateCheckoutSessionPayload(normalizedPayload);
static normalizeFlatCheckoutSessionPayload(payload) {
if (!payload) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Payload is required"
});
}
const normalizedPayload = normalizeFlatCheckoutSessionPayload(payload);
const errors = validateFlatCheckoutSessionPayload(normalizedPayload);
if (errors.length) {

@@ -570,4 +732,39 @@ throw new SmartpayError({

}
createCheckoutSession(payload) {
const normalizedPayload = _SmartpayWithCheckoutSession.normalizeCheckoutSessionPayload(payload);
static normalizeTokenCheckoutSessionPayload(payload) {
if (!payload) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Payload is required"
});
}
const errors = validateTokenCheckoutSessionPayload(payload);
if (errors.length) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Payload invalid",
details: jtdErrorToDetails(errors, "payload")
});
}
return payload;
}
static normalizeCheckoutSessionPayload(payload) {
if (!payload) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Payload is required"
});
}
if (payload.mode === _SmartpayWithCheckoutSession.MODE_TOKEN) {
return _SmartpayWithCheckoutSession.normalizeTokenCheckoutSessionPayload(payload);
}
return _SmartpayWithCheckoutSession.normalizeFlatCheckoutSessionPayload(payload);
}
createFlatCheckoutSession(payload) {
if (!payload) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Payload is required"
});
}
const normalizedPayload = _SmartpayWithCheckoutSession.normalizeFlatCheckoutSessionPayload(payload);
const req = this.request(`/checkout-sessions`, {

@@ -590,2 +787,29 @@ method: POST,

}
createTokenCheckoutSession(payload) {
if (!payload) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Payload is required"
});
}
const normalizedPayload = _SmartpayWithCheckoutSession.normalizeTokenCheckoutSessionPayload(payload);
const req = this.request(`/checkout-sessions`, {
method: POST,
idempotencyKey: payload.idempotencyKey,
payload: omit(normalizedPayload, ["idempotencyKey"])
});
return req;
}
createCheckoutSession(payload) {
if (!payload) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Payload is required"
});
}
if (payload.mode === MODE_TOKEN) {
return this.createTokenCheckoutSession(payload);
}
return this.createFlatCheckoutSession(payload);
}
listCheckoutSessions(params = {}) {

@@ -646,2 +870,3 @@ const req = this.request(`/checkout-sessions`, {

SmartpayWithCheckoutSession.CAPTURE_METHOD_MANUAL = CAPTURE_METHOD_MANUAL;
SmartpayWithCheckoutSession.MODE_TOKEN = MODE_TOKEN;
return SmartpayWithCheckoutSession;

@@ -771,2 +996,34 @@ };

return _a2 = class extends Base {
static normalizeOrderPayload(payload) {
if (!payload) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Payload is required"
});
}
const errors = validateTokenOrderPayload(payload);
if (errors.length) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Payload invalid",
details: jtdErrorToDetails(errors, "payload")
});
}
return payload;
}
createOrder(payload) {
if (!payload) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Payload is required"
});
}
const normalizedPayload = _a2.normalizeOrderPayload(payload);
const req = this.request(`/orders`, {
method: POST,
idempotencyKey: payload.idempotencyKey,
payload: omit(normalizedPayload, ["idempotencyKey"])
});
return req;
}
getOrder(params = {}) {

@@ -1112,2 +1369,102 @@ const { id } = params;

// src/Smartpay/tokens.ts
var TOKEN_STATUS_ACTIVE = "active";
var TOKEN_STATUS_DISABLED = "disabled";
var TOKEN_STATUS_REJECTED = "rejected";
var TOKEN_STATUS_REQUIRES_AUTHORIZATION = "requires_authorization";
var tokensMixin = (Base) => {
var _a2;
return _a2 = class extends Base {
getToken(params = {}) {
const { id } = params;
if (!id) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Token Id is required"
});
}
if (!isValidTokenId(id)) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Token Id is invalid"
});
}
const req = this.request(`/tokens/${id}`, {
method: GET,
params: omit(params, ["id"])
});
return req;
}
enableToken(params = {}) {
const { id } = params;
if (!id) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Token Id is required"
});
}
if (!isValidTokenId(id)) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Token Id is invalid"
});
}
const req = this.request(`/tokens/${id}/enable`, {
method: PUT,
idempotencyKey: params.idempotencyKey
});
return req;
}
disableToken(params = {}) {
const { id } = params;
if (!id) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Token Id is required"
});
}
if (!isValidTokenId(id)) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Token Id is invalid"
});
}
const req = this.request(`/tokens/${id}/disable`, {
method: PUT,
idempotencyKey: params.idempotencyKey
});
return req;
}
deleteToken(params = {}) {
const { id } = params;
if (!id) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Token Id is required"
});
}
if (!isValidTokenId(id)) {
throw new SmartpayError({
errorCode: "request.invalid",
message: "Token Id is invalid"
});
}
const req = this.request(`/tokens/${id}`, {
method: DELETE,
params: omit(params, ["id"]),
idempotencyKey: params.idempotencyKey
});
return req;
}
listTokens(params = {}) {
const req = this.request(`/tokens`, {
method: GET,
params
});
return req;
}
}, _a2.TOKEN_STATUS_ACTIVE = TOKEN_STATUS_ACTIVE, _a2.TOKEN_STATUS_DISABLED = TOKEN_STATUS_DISABLED, _a2.TOKEN_STATUS_REJECTED = TOKEN_STATUS_REJECTED, _a2.TOKEN_STATUS_REQUIRES_AUTHORIZATION = TOKEN_STATUS_REQUIRES_AUTHORIZATION, _a2;
};
var tokens_default = tokensMixin;
// src/Smartpay/webhooks.ts

@@ -1269,3 +1626,4 @@ import { createHmac } from "crypto";

coupons_default,
promotion_codes_default
promotion_codes_default,
tokens_default
];

@@ -1272,0 +1630,0 @@ var Smartpay = mixins.reduce((previousClass, mixin) => mixin(previousClass), base_default);

@@ -1,2 +0,2 @@

import type { CustomerInfo, CustomerInfoLoose, SimpleLineItem, SimpleChekoutSessionPayload, ShippingInfo, Address } from './types';
import type { CustomerInfo, CustomerInfoLoose, SimpleLineItem, FlatChekoutSessionPayload, ShippingInfo, Address } from './types';
export declare const normalizeCustomerInfo: (customer?: CustomerInfoLoose) => CustomerInfo;

@@ -72,3 +72,3 @@ export declare const normalizeItem: (item: SimpleLineItem) => {

};
export declare const normalizeCheckoutSessionPayload: (payload: SimpleChekoutSessionPayload) => {
export declare const normalizeCheckoutSessionPayload: (payload: FlatChekoutSessionPayload) => {
amount: number | undefined;

@@ -123,3 +123,3 @@ currency: string | undefined;

declare const _default: {
normalizeCheckoutSessionPayload: (payload: SimpleChekoutSessionPayload) => {
normalizeCheckoutSessionPayload: (payload: FlatChekoutSessionPayload) => {
amount: number | undefined;

@@ -126,0 +126,0 @@ currency: string | undefined;

@@ -170,2 +170,8 @@ declare const _default: {

};
successUrl: {
type: string;
};
cancelUrl: {
type: string;
};
};

@@ -182,8 +188,5 @@ optionalProperties: {

};
successUrl: {
locale: {
type: string;
};
cancelUrl: {
type: string;
};
};

@@ -190,0 +193,0 @@ additionalProperties: boolean;

@@ -1,2 +0,2 @@

import { CheckoutSession, SimpleChekoutSessionPayload, ListParams, GetObjectParams, Collection } from '../types';
import { CheckoutSession, FlatChekoutSessionPayload, TokenChekoutSessionPayload, ListParams, GetObjectParams, Collection } from '../types';
import { Constructor } from './base';

@@ -14,5 +14,8 @@ declare type GetSessionURLOptions = {

export declare const CAPTURE_METHOD_MANUAL = "manual";
export declare const MODE_TOKEN = "token";
declare const checkoutSessionsMixin: <T extends Constructor>(Base: T) => {
new (...args: any[]): {
createCheckoutSession(payload: SimpleChekoutSessionPayload): Promise<CheckoutSession>;
createFlatCheckoutSession(payload: FlatChekoutSessionPayload): Promise<CheckoutSession>;
createTokenCheckoutSession(payload: TokenChekoutSessionPayload): Promise<CheckoutSession>;
createCheckoutSession(payload: FlatChekoutSessionPayload): Promise<CheckoutSession>;
listCheckoutSessions(params?: ListParams): Promise<Collection<CheckoutSession>>;

@@ -38,3 +41,6 @@ getCheckoutSession(params?: GetObjectParams): Promise<CheckoutSession>;

CAPTURE_METHOD_MANUAL: string;
normalizeCheckoutSessionPayload(payload: SimpleChekoutSessionPayload): SimpleChekoutSessionPayload;
MODE_TOKEN: string;
normalizeFlatCheckoutSessionPayload(payload: FlatChekoutSessionPayload): FlatChekoutSessionPayload;
normalizeTokenCheckoutSessionPayload(payload: TokenChekoutSessionPayload): TokenChekoutSessionPayload;
normalizeCheckoutSessionPayload(payload: FlatChekoutSessionPayload): FlatChekoutSessionPayload | TokenChekoutSessionPayload;
getSessionUrl(session: CheckoutSession, options?: GetSessionURLOptions | undefined): string;

@@ -41,0 +47,0 @@ getSessionURL(session: CheckoutSession, options?: GetSessionURLOptions | undefined): string;

@@ -1,2 +0,2 @@

import { Order, ListParams, GetObjectParams, CancelOrderParams, Collection } from '../types';
import { Order, ListParams, GetObjectParams, CommonUpdateParams, Collection, OrderPayload } from '../types';
import { Constructor } from './base';

@@ -10,4 +10,5 @@ export declare const ORDER_STATUS_SUCCEEDED = "succeeded";

new (...args: any[]): {
createOrder(payload: OrderPayload): Promise<Order>;
getOrder(params?: GetObjectParams): Promise<Order>;
cancelOrder(params?: CancelOrderParams): Promise<Order>;
cancelOrder(params?: CommonUpdateParams): Promise<Order>;
listOrders(params?: ListParams): Promise<Collection<Order>>;

@@ -30,3 +31,4 @@ _secretKey: string;

ORDER_STATUS_REQUIRES_AUTHORIZATION: string;
normalizeOrderPayload(payload: OrderPayload): OrderPayload;
} & T;
export default ordersMixin;

@@ -130,3 +130,4 @@ export interface LooseObject {

};
export declare type SimpleChekoutSessionPayload = {
export declare type FlatChekoutSessionPayload = {
mode?: 'token';
amount?: number;

@@ -136,4 +137,4 @@ currency?: string;

items: SimpleLineItem[];
shippingInfo?: ShippingInfo;
customerInfo?: CustomerInfo;
shippingInfo: ShippingInfo;
customerInfo: CustomerInfo;
locale?: string;

@@ -148,2 +149,24 @@ successUrl?: string;

};
export declare type TokenChekoutSessionPayload = {
mode: 'token';
customerInfo?: CustomerInfo;
locale?: string;
successUrl?: string;
cancelUrl?: string;
metadata?: MetaData;
reference?: string;
idempotencyKey?: string;
};
export declare type OrderPayload = {
token?: string;
amount: number;
currency: string;
captureMethod?: 'automatic' | 'manual';
items: SimpleLineItem[];
shippingInfo: ShippingInfo;
customerInfo: CustomerInfo;
metadata?: MetaData;
reference?: string;
idempotencyKey?: string;
};
export declare type RefundPayload = {

@@ -289,2 +312,11 @@ payment: string;

};
export declare type Token = {
id: string;
object: string;
createdAt: number;
status: string;
reference?: string;
test: boolean;
updatedAt: number;
};
export declare type JTDError = {

@@ -303,3 +335,3 @@ instancePath: string[];

};
export declare type CancelOrderParams = {
export declare type CommonUpdateParams = {
id?: string;

@@ -306,0 +338,0 @@ idempotencyKey?: string;

@@ -1,2 +0,2 @@

import type { KeyString, SimpleChekoutSessionPayload, ErrorDetails, LooseObject } from './types';
import type { KeyString, FlatChekoutSessionPayload, TokenChekoutSessionPayload, ErrorDetails, LooseObject, OrderPayload } from './types';
export declare class SmartpayError extends Error {

@@ -22,8 +22,11 @@ statusCode?: number;

export declare const isValidPromotionCodeId: (input: string) => boolean;
export declare const validateCheckoutSessionPayload: (payload: SimpleChekoutSessionPayload) => ErrorDetails;
export declare const isValidTokenId: (input: string) => boolean;
export declare const validateFlatCheckoutSessionPayload: (payload: FlatChekoutSessionPayload) => ErrorDetails;
export declare const validateTokenCheckoutSessionPayload: (payload: TokenChekoutSessionPayload) => ErrorDetails;
export declare const validateTokenOrderPayload: (payload: OrderPayload) => ErrorDetails;
/**
* Try to get the currency of this checkout
*/
export declare const getCurrency: (payload: SimpleChekoutSessionPayload) => string;
export declare const normalizeCheckoutSessionPayload: (input: SimpleChekoutSessionPayload) => {
export declare const getCurrency: (payload: FlatChekoutSessionPayload) => string;
export declare const normalizeFlatCheckoutSessionPayload: (input: FlatChekoutSessionPayload) => {
amount: number | undefined;

@@ -30,0 +33,0 @@ currency: string | undefined;

@@ -64,2 +64,3 @@ # Checkout Session Payload

| ------------------------ | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| mode | String | `token` mode of normal mode. |
| amount | Number | The total amount of the order. If not present. The SDK will calculate the amount based on the line items and shipping fee. |

@@ -66,0 +67,0 @@ | currency | String | Three-letter ISO currency code, in uppercase. Must be a supported currency. |

@@ -33,2 +33,7 @@ # Smartpay NodeJS SDK Reference

- [List Promotion Codes](#list-promotion-codes)
- [Get Token](#get-token)
- [List Tokens](#list-tokens)
- [Enable Token](#enable-token)
- [Disable Token](#disable-token)
- [Delete Token](#delete-token)
- [Collection](#collection)

@@ -113,3 +118,3 @@ - [Properties](#properties)

[CheckoutSession object][]
[Checkout session object][]

@@ -912,3 +917,3 @@ #### Exceptions

```javascript
const promotionCode = await smartpay.listPromotionCodes({
const promotionCodes = await smartpay.listPromotionCodes({
maxResults,

@@ -936,2 +941,138 @@ pageToken,

### Get Token
**Async** method, get the token object by coupon id.
```javascript
const token = await smartpay.getToken({
id,
});
```
#### Arguments
| Name | Type | Description |
| ---- | ------ | ------------ |
| id | String | The token id |
#### Return
[Token object][]
#### Exceptions
[Common exceptions][]
### List Tokens
**Async** method, list the token objects.
```javascript
const tokens = await smartpay.listTokens({
maxResults,
pageToken,
expand,
});
```
#### Arguments
| Name | Type | Description |
| --------------------------------- | ------ | ------------------------------------------------------------------------------------------ |
| maxResults (optional, defualt=20) | Number | Number of objects to return. |
| pageToken (optional) | String | The token for the page of the collection of objects. |
| expand (optional, default=no) | String | Set to `all` if the references within the response need to be expanded to the full objects |
#### Return
[Collection][] of [token object][]
#### Exceptions
[Common exceptions][]
### Enable Token
**Async** method, enable the token by token id.
```javascript
const coupon = await smartpay.enableToken({
id,
});
```
#### Arguments
| Name | Type | Description |
| ---- | ------ | ------------ |
| id | String | The token id |
#### Return
Empty response body with 200
#### Exceptions
[Common exceptions][]
| Type | Error Code | Description |
| ------------- | ----------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| SmartpayError | `token.not-found` | No token was found meeting the requirements. Try to enable token under `requires_authorization` status throws this error too. |
### Disable Token
**Async** method, disable the token by token id.
```javascript
const coupon = await smartpay.disableToken({
id,
});
```
#### Arguments
| Name | Type | Description |
| ---- | ------ | ------------ |
| id | String | The token id |
#### Return
Empty response body with 200
#### Exceptions
[Common exceptions][]
| Type | Error Code | Description |
| ------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| SmartpayError | `token.not-found` | No token was found meeting the requirements. Try to disable token under `requires_authorization` status throws this error too. |
### Delete Token
**Async** method, delete the token by token id.
```javascript
const coupon = await smartpay.deleteToken({
id,
});
```
#### Arguments
| Name | Type | Description |
| ---- | ------ | ------------ |
| id | String | The token id |
#### Return
Empty response body with 204
#### Exceptions
[Common exceptions][]
| Type | Error Code | Description |
| ------------- | ----------------- | -------------------------------------------- |
| SmartpayError | `token.not-found` | No token was found meeting the requirements. |
## Collection

@@ -981,2 +1122,11 @@

### Token Status
```
Smartpay.TOKEN_STATUS_ACTIVE
Smartpay.TOKEN_STATUS_DISABLED
Smartpay.TOKEN_STATUS_REJECTED
Smartpay.TOKEN_STATUS_REQUIRES_AUTHORIZATION
```
### Cancel Remainder

@@ -1013,3 +1163,3 @@

[checkout session object]: https://en.docs.smartpay.co/reference/the-checkout-session-object
[order object]: https://ja.docs.smartpay.co/reference/the-order-object
[order object]: https://en.docs.smartpay.co/reference/the-order-object
[payment object]: https://en.docs.smartpay.co/reference/the-payment-object

@@ -1020,2 +1170,3 @@ [refund object]: https://en.docs.smartpay.co/reference/the-refund-object

[promotion code object]: https://en.docs.smartpay.co/reference/the-promotion-code-object
[token object]: https://en.docs.smartpay.co/reference/the-token-object
[capture]: https://en.docs.smartpay.co/docs/capture-an-order#using-the-smartpay-api

@@ -1022,0 +1173,0 @@ [refund]: https://en.docs.smartpay.co/docs/refund-a-purchase#using-the-smartpay-api

@@ -7,3 +7,3 @@ {

},
"version": "0.8.0",
"version": "0.9.0",
"description": "Smartpay SDK NodeJS",

@@ -32,3 +32,3 @@ "main": "./build/cjs/index.cjs",

"test:live": "tape test/live.js",
"test": "yarn test:unit && yarn test:nock"
"test": "yarn test:unit && yarn test:live"
},

@@ -73,3 +73,2 @@ "repository": {

"jsonfile": "^6.1.0",
"nock": "^13.1.1",
"prettier": "^2.3.2",

@@ -76,0 +75,0 @@ "replace-in-file": "^6.3.2",

@@ -0,1 +1,23 @@

<div id="top"></div>
<br />
<div align="center">
<a href="https://github.com/smartpay-co/sdk-node">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://assets.smartpay.co/logo/banner/smartpay-logo-dark.png" />
<source media="(prefers-color-scheme: light)" srcset="https://assets.smartpay.co/logo/banner/smartpay-logo.png" />
<img alt="Smartpay" src="https://assets.smartpay.co/logo/banner/smartpay-logo.png" style="width: 797px;" />
</picture>
</a>
<p align="center">
<a href="https://docs.smartpay.co/"><strong>Explore the docs »</strong></a>
<br />
<br />
<a href="https://github.com/smartpay-co/sdk-node/issues">Report Bug</a>
·
<a href="https://github.com/smartpay-co/sdk-node/issues">Request Feature</a>
</p>
</div>
# Smartpay Nodejs SDK

@@ -2,0 +24,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc