@smartpay/sdk-node
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -91,3 +91,3 @@ // src/smartpay.ts | ||
}) => ({ | ||
price, | ||
price: typeof price === "string" ? price : void 0, | ||
priceData: normalizePriceData(priceData || { | ||
@@ -105,3 +105,3 @@ productData: { | ||
}, | ||
amount, | ||
amount: amount != null ? amount : typeof price === "number" ? price : void 0, | ||
currency, | ||
@@ -365,3 +365,3 @@ label, | ||
}; | ||
var isValidCheckoutSessionPayload = (payload) => { | ||
var validateCheckoutSessionPayload = (payload) => { | ||
const errors = validate(checkout_session_payload_jtd_default, JSON.parse(JSON.stringify(payload))); | ||
@@ -381,3 +381,2 @@ if (payload.orderData.lineItemData.length === 0) { | ||
const { currency } = orderData; | ||
console.log(orderData, orderData.amount == null); | ||
if (orderData.amount == null) { | ||
@@ -395,12 +394,10 @@ orderData.amount = orderData.lineItemData.reduce((sum, item) => { | ||
} | ||
console.log(orderData, orderData.amount == null); | ||
return payload; | ||
}; | ||
var jtdErrorToDetails = (errors, prefix) => errors.map((error) => error.instancePath && error.schemaPath ? `${prefix}.${error.instancePath.join(".")} is invalid` : error); | ||
var jtdErrorToDetails = (errors, prefix) => errors.map((error) => error.instancePath && error.schemaPath ? `${prefix}.${error.instancePath.join(".")} is invalid (${error.schemaPath})` : error); | ||
// src/smartpay.ts | ||
var API_PREFIX = "https://api.smartpay.co/smartpayments/"; | ||
var CHECKOUT_URL = "https://checkout.smartpay.ninja"; | ||
var API_PREFIX = "https://api.smartpay.co/smartpayments"; | ||
var CHECKOUT_URL = "https://checkout.smartpay.co"; | ||
var POST = "POST"; | ||
var STATUS_SUCCEEDED = "succeeded"; | ||
var Smartpay = class { | ||
@@ -431,2 +428,8 @@ constructor(key, options = {}) { | ||
body: payload ? JSON.stringify(payload) : null | ||
}).catch((error) => { | ||
throw new SmartError({ | ||
errorCode: "unexpected_error", | ||
statusCode: -1, | ||
message: error.message | ||
}); | ||
}).then((response) => { | ||
@@ -449,8 +452,2 @@ return response.json().catch(() => { | ||
}); | ||
}).catch((error) => { | ||
throw new SmartError({ | ||
errorCode: "unexpected_error", | ||
statusCode: -1, | ||
message: error.message | ||
}); | ||
}); | ||
@@ -460,3 +457,3 @@ } | ||
const normalizedPayload = normalizeCheckoutSessionPayload2(payload); | ||
const errors = isValidCheckoutSessionPayload(normalizedPayload); | ||
const errors = validateCheckoutSessionPayload(normalizedPayload); | ||
if (errors.length) { | ||
@@ -484,57 +481,2 @@ throw new SmartError({ | ||
} | ||
isOrderAuthorized(orderId) { | ||
return this.getOrder(orderId).then((order) => order.status === STATUS_SUCCEEDED); | ||
} | ||
getOrder(orderId) { | ||
if (!isValidOrderID(orderId)) { | ||
throw new SmartError({ | ||
errorCode: "request.invalid", | ||
message: "Order ID is invalid" | ||
}); | ||
} | ||
return this.request(`/orders/${orderId}`); | ||
} | ||
getPayments(orderId) { | ||
if (!isValidOrderID(orderId)) { | ||
throw new SmartError({ | ||
errorCode: "request.invalid", | ||
message: "Order ID is invalid" | ||
}); | ||
} | ||
return this.request(`/orders/${orderId}/payments`); | ||
} | ||
getPayment(paymentId) { | ||
if (!isValidPaymentID(paymentId)) { | ||
throw new SmartError({ | ||
errorCode: "request.invalid", | ||
message: "Payment ID is invalid" | ||
}); | ||
} | ||
return this.request(`/payments/${paymentId}`); | ||
} | ||
refundPayment(payload) { | ||
const { payment, currency } = payload; | ||
if (!payment) { | ||
throw new SmartError({ | ||
errorCode: "request.invalid", | ||
message: "Payload invalid", | ||
details: ["payload.payment is required"] | ||
}); | ||
} | ||
if (!isValidPaymentID(payment)) { | ||
throw new SmartError({ | ||
errorCode: "request.invalid", | ||
message: "Payload invalid", | ||
details: ["payload.payment is invalid"] | ||
}); | ||
} | ||
if (!currency) { | ||
throw new SmartError({ | ||
errorCode: "request.invalid", | ||
message: "Payload invalid", | ||
details: ["payload.currency is invalid"] | ||
}); | ||
} | ||
return this.request(`/refunds/`, POST, payload); | ||
} | ||
setPublicKey(publicKey) { | ||
@@ -570,3 +512,3 @@ if (!publicKey) { | ||
const params = { | ||
session: session.id, | ||
session_id: session.id, | ||
key: this._publicKey | ||
@@ -573,0 +515,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
import type { KeyString, SmartPayOptions, ChekoutSessionPayload, RefundPayload, CheckoutSession, Order, Payment, Refund, ChekoutSessionPayloadFlat } from './types'; | ||
import type { KeyString, SmartPayOptions, ChekoutSessionPayload, CheckoutSession, ChekoutSessionPayloadFlat } from './types'; | ||
export declare const STATUS_SUCCEEDED = "succeeded"; | ||
@@ -16,7 +16,2 @@ export declare const STATUS_REJECTED = "rejected"; | ||
createCheckoutSession(payload: ChekoutSessionPayloadFlat): Promise<CheckoutSession>; | ||
isOrderAuthorized(orderId: string): Promise<boolean>; | ||
getOrder(orderId: string): Promise<Order>; | ||
getPayments(orderId: string): Promise<Payment[]>; | ||
getPayment(paymentId: string): Promise<Payment>; | ||
refundPayment(payload: RefundPayload): Promise<Refund>; | ||
setPublicKey(publicKey: KeyString): {}; | ||
@@ -23,0 +18,0 @@ getSessionURL(session: CheckoutSession): string; |
@@ -18,3 +18,3 @@ import type { KeyString, ChekoutSessionPayload, ChekoutSessionPayloadFlat, ErrorDetails } from './types'; | ||
export declare const isValidPaymentID: (paymentID: string) => boolean; | ||
export declare const isValidCheckoutSessionPayload: (payload: ChekoutSessionPayload) => ErrorDetails; | ||
export declare const validateCheckoutSessionPayload: (payload: ChekoutSessionPayload) => ErrorDetails; | ||
export declare const normalizeCheckoutSessionPayload: (input: ChekoutSessionPayloadFlat) => { | ||
@@ -21,0 +21,0 @@ customerInfo: import("./types").CustomerInfo; |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Smartpay SDK NodeJS", | ||
@@ -10,0 +10,0 @@ "main": "./build/cjs/index.cjs", |
Sorry, the diff of this file is not supported yet
58463
1968