fix(core): update

This commit is contained in:
2020-08-21 15:40:04 +00:00
parent 59999a05b3
commit d379fce4a3
17 changed files with 11416 additions and 72 deletions

View File

@ -1,3 +1 @@
import * as plugins from './ppal.plugins'
export let standardExport = 'Hi there! :) This is a exported string'
export * from './paypal.classes.paypal';

View File

@ -0,0 +1,51 @@
import * as plugins from './paypal.plugins';
export interface IPayPalOptions {
clientId: string;
clientSecret: string;
}
export class PayPal {
public apiBaseUrl: string = 'https://api.paypal.com'
public options: IPayPalOptions;
private apiToken: string;
private apiTokenExpirationTime: number;
constructor(optionsArg: IPayPalOptions) {
this.options = optionsArg;
}
public async request() {
if (!this.apiToken || this.apiTokenExpirationTime < Date.now()) {
const authHeader = `Basic ${plugins.smartstring.base64.encode(
`${this.options.clientId}:${this.options.clientSecret}`
)}`;
const response = await plugins.smartrequest.request(
`${this.apiBaseUrl}/v1/oauth2/token?grant_type=client_credentials`,
{
method: 'POST',
headers: {
Accept: 'application/json',
'Accept-Language': 'en_US',
Authorization: authHeader,
},
keepAlive: false,
}
);
this.apiToken = response.body.access_token;
this.apiTokenExpirationTime = Date.now() + response.body.expires_in * 1000 - 600000;
}
// we have a token
const response = await plugins.smartrequest.request(`${this.apiBaseUrl}/v1/reporting/transactions?start_date=2020-05-01T00:00:00Z&end_date=2020-05-30T00:00:00Z`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Accept-Language': 'en_US',
Authorization: `Bearer ${this.apiToken}`,
},
});
console.log(response.body);
}
}

View File

@ -0,0 +1 @@
import * as plugins from './paypal.plugins'

5
ts/paypal.plugins.ts Normal file
View File

@ -0,0 +1,5 @@
// pupshrocks scope
import * as smartrequest from '@pushrocks/smartrequest';
import * as smartstring from '@pushrocks/smartstring';
export { smartrequest, smartstring };

View File

@ -1 +0,0 @@
import 'typings-global'