fix(core): update
This commit is contained in:
@ -1,3 +1 @@
|
||||
import * as plugins from './ppal.plugins'
|
||||
|
||||
export let standardExport = 'Hi there! :) This is a exported string'
|
||||
export * from './paypal.classes.paypal';
|
||||
|
51
ts/paypal.classes.paypal.ts
Normal file
51
ts/paypal.classes.paypal.ts
Normal 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);
|
||||
}
|
||||
}
|
1
ts/paypal.classes.transaction.ts
Normal file
1
ts/paypal.classes.transaction.ts
Normal file
@ -0,0 +1 @@
|
||||
import * as plugins from './paypal.plugins'
|
5
ts/paypal.plugins.ts
Normal file
5
ts/paypal.plugins.ts
Normal file
@ -0,0 +1,5 @@
|
||||
// pupshrocks scope
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
import * as smartstring from '@pushrocks/smartstring';
|
||||
|
||||
export { smartrequest, smartstring };
|
@ -1 +0,0 @@
|
||||
import 'typings-global'
|
Reference in New Issue
Block a user