UNPKG

securepay

Version:

https://www.securepay.com.au/

77 lines (76 loc) 3.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PaypalTransactionService = void 0; var paypal_endpoints_const_1 = require("../../../../constants/paypal-endpoints.const"); var enums_1 = require("../../../../enums"); var request_service_1 = require("../../../common/request/request.service"); var PaypalTransactionService = /** @class */ (function () { function PaypalTransactionService(options) { this._http = new request_service_1.RequestService(options); this.sandbox = options.sandbox || false; this.debugLevel = options.debugLevel || enums_1.DebugLevel.NONE; this.clientId = options.clientId; this.clientSecret = options.clientSecret; this.merchantCode = options.merchantCode; } /** * Initiates a PayPal express checkout transaction. * * @param {PaypalTransactionInitial} payload */ PaypalTransactionService.prototype.initialTransaction = function (payload) { if (!payload.merchantCode) payload.merchantCode = this.merchantCode; return this._http.post({ url: paypal_endpoints_const_1.PaypalEndpoints.INITIAL(this.sandbox), token_type: enums_1.TokenType.SECUREPAY_JWT, data: payload }); }; /** * Executes a PayPal express checkout transaction after the customer has logged into PayPal and accepted it. * * @param {string} orderId * @param {PaypalTransactionExecute} payload */ PaypalTransactionService.prototype.executeTransaction = function (orderId, payload) { if (!payload.merchantCode) payload.merchantCode = this.merchantCode; return this._http.post({ url: paypal_endpoints_const_1.PaypalEndpoints.EXECUTE(this.sandbox, orderId), token_type: enums_1.TokenType.SECUREPAY_JWT, data: payload }); }; /** * Refunds a previously executed PayPal transaction * * @param {string} orderId * @param {PaypalTransactionRefund} payload */ PaypalTransactionService.prototype.refundTransaction = function (orderId, payload) { if (!payload.merchantCode) payload.merchantCode = this.merchantCode; return this._http.post({ url: paypal_endpoints_const_1.PaypalEndpoints.REFUND(this.sandbox, orderId), token_type: enums_1.TokenType.SECUREPAY_JWT, data: payload }); }; /** * Retrieves billing & shipping details for a customer that has previously initiated/executed a PayPal transaction * * @param {string} orderId * @param {string} merchantCode */ PaypalTransactionService.prototype.retrieveTransaction = function (orderId, merchantCode) { if (!merchantCode) merchantCode = this.merchantCode; return this._http.get({ url: paypal_endpoints_const_1.PaypalEndpoints.RETRIEVE(this.sandbox, orderId, merchantCode), token_type: enums_1.TokenType.SECUREPAY_JWT }); }; return PaypalTransactionService; }()); exports.PaypalTransactionService = PaypalTransactionService;