expresscheckout-nodejs
Version:
Juspay's official expresscheckout-nodejs sdk
137 lines • 5.8 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import JuspayResource from '../JuspayResource.js';
var Order = /** @class */ (function (_super) {
__extends(Order, _super);
function Order(juspayEnvironment) {
return _super.call(this, juspayEnvironment) || this;
}
/**
* - Create an order that is a representation of your shopping cart.
* - The order contains important information like amount, customer details, shipping address, billing address, etc.
* - Only after an order is created, payment can be started.
* - Order create is a server to server call.
*
* @param body order_id, amount is must
* @param juspayConfig override config using this params usage:- {apiKey: '', merchantId: '', ...}
* @returns Promise Response Object
*
* @link https://docs.juspay.in/api-reference/docs/express-checkout/create-order-api
*/
Order.prototype.create = function (body, juspayConfig) {
return this.makeServiceCall({
method: 'POST',
path: '/orders',
body: body,
juspayOverrideConfig: juspayConfig
});
};
/**
*
* - Retrieve the order object associated with the order_id.
* - Refer the link to include relevant version in the header - https://developer.juspay.in/reference#section-version
*
* - this route supports jwe authentiction
* - if decided auth is jwe (if jweAuth config is set) please review the data given
* - as the api is different
* - for /order/:orderId aka basic auth refer to this:- https://developer.juspay.in/reference/get-order-status
* - for jwe auth it's type is, please go through the document share with you
*
* @param orderId - Unique Identifier for the order
* @param query - request body
* @param juspayConfig override config using this params usage:- {apiKey: '', merchantId: '', ...}
* @param authMethod - to choose auth type currently supports 'JWE' and 'BASIC'
* @returns Promise Response Object
*
* @link https://docs.juspay.in/api-reference/docs/express-checkout/order-status-api
*
*/
Order.prototype.status = function (orderId, query, juspayConfig, authMethod) {
query = __assign(__assign({}, query), { order_id: orderId });
if (authMethod == 'SIGNATURE') {
throw new TypeError('this route does not support signature auth');
}
return this.makeServiceCall({
method: 'GET',
path: '/orders/' + orderId,
juspayOverrideConfig: juspayConfig,
auth: authMethod == undefined ? ['JWE', 'BASIC'] : [authMethod],
query: query,
opts: {
authPriority: 'ordered',
jwePath: '/v4/order-status'
}
});
};
/**
*
* - Update an order that has already been created.
* - The only amount, address and UDF fields can be updated.
* - Address fields can be optionally sent as explained in the /orders API.
* - The API response is similar to that of the order create API
*
* @param orderId - Unique Identifier for the order
* @param body: - amount is required
* @param juspayConfig override config using this params usage:- {apiKey: '', merchantId: '', ...}
* @returns Promise Response Object
*
* @link https://docs.juspay.in/api-reference/docs/express-checkout/update-order-api
*
*/
Order.prototype.update = function (orderId, body, juspayConfig) {
return this.makeServiceCall({
method: 'POST',
path: '/orders' + orderId,
body: body,
juspayOverrideConfig: juspayConfig
});
};
/**
*
* - Create a refund for an Order.
* - Refunds can be initiated only for transactions that are CHARGED.
*
* @param orderId - Unique Identifier for the order
* @param juspayConfig override config using this params usage:- {apiKey: '', merchantId: '', ...}
* @returns Promise Response Object
* - The response of refund initiation is similar to that of order status API Response with the addition of refund block.
*
* @link https://docs.juspay.in/api-reference/docs/express-checkout/refund-order-api
*/
Order.prototype.refund = function (orderId, body, juspayConfig) {
return this.makeServiceCall({
method: 'POST',
path: "/orders/".concat(orderId, "/refunds"),
body: body,
juspayOverrideConfig: juspayConfig,
auth: ['JWE']
});
};
return Order;
}(JuspayResource));
export default Order;
//# sourceMappingURL=Order.js.map