bc-paypal-sdk
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -20,8 +20,41 @@ "use strict"; | ||
axiosInstance.interceptors.request.use((config) => { | ||
const token = getToken(); | ||
//this is to be changed when we implement currency / language switcher | ||
if (token) { | ||
config.headers['Authorization'] = 'Bearer ' + token; | ||
} | ||
return config; | ||
/** | ||
* Error: {"status":401,"data":{"error":"invalid_token","error_description":"Access Token not found in cache"}} | ||
* Due to above error received from the gateway, generate a new token on each request. | ||
* It seems Paypal internally caches the token and returns the same token value in subsequent calls till the | ||
* time it gets expired. | ||
* | ||
* For e.g. - Receiving the same token when 10 concurrent/subsequent calls are sent on generate token API: | ||
* | ||
* ------ | ||
* Call 1 | ||
* ------ | ||
* - token: A21AAOPxbnmoPPv0f03H404UjVAnxpFldkOSBrVEm7m6o5M4jdEMcs2Bg6ET7UszYoy92BmIHckGCKw4kAWPCUryJFSLxplGA | ||
* - expires_in: 32317 | ||
* | ||
* ------ | ||
* Call 2 | ||
* ------ | ||
* - token: A21AAOPxbnmoPPv0f03H404UjVAnxpFldkOSBrVEm7m6o5M4jdEMcs2Bg6ET7UszYoy92BmIHckGCKw4kAWPCUryJFSLxplGA | ||
* - expires_in: 32333 | ||
*/ | ||
const url = new URL('v1/oauth2/token', PayPalEnvironment_1.PayPalEnvironment.getBaseUrl()); | ||
const auth = Buffer.from(`${PayPalEnvironment_1.PayPalEnvironment.getClientId()}:${PayPalEnvironment_1.PayPalEnvironment.getAppSecret()}`).toString("base64"); | ||
return (0, api_1.default)({ | ||
url: url.href, | ||
method: RequestMethod_1.RequestMethod.POST, | ||
data: `grant_type=client_credentials`, | ||
headers: { | ||
Authorization: `Basic ${auth}`, | ||
}, | ||
}).then((res) => { | ||
var _a; | ||
const token = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.access_token; | ||
if (token) { | ||
config.headers['Authorization'] = 'Bearer ' + token; | ||
} | ||
return config; | ||
}).catch((error) => { | ||
return config; | ||
}); | ||
}, (err) => Promise.reject(err)); | ||
@@ -28,0 +61,0 @@ function createAxiosResponseInterceptor() { |
export interface IOrder { | ||
get(id: string): any; | ||
/** | ||
* Show order details. Shows details for an order, by ID. | ||
* @param data {String} | ||
*/ | ||
get(data: string): any; | ||
} |
import { PayPalEnvironment } from "./base/config/PayPalEnvironment"; | ||
import { Order } from "./payPal/Order"; | ||
import { Order } from "./paypal/Order"; | ||
import { APIConnectionException, APIException, AuthenticationException, BaseException, InvalidRequestException } from "./base/entity"; | ||
export { PayPalEnvironment, Order }; | ||
export { APIConnectionException, APIException, AuthenticationException, BaseException, InvalidRequestException }; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "PayPalEnvironment", { enumerable: true, get: function () { return PayPalEnvironment_1.PayPalEnvironment; } }); | ||
const Order_1 = require("./payPal/Order"); | ||
const Order_1 = require("./paypal/Order"); | ||
Object.defineProperty(exports, "Order", { enumerable: true, get: function () { return Order_1.Order; } }); | ||
@@ -9,0 +9,0 @@ const entity_1 = require("./base/entity"); |
{ | ||
"name": "bc-paypal-sdk", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
46088
20
36
541