Skip to content

Commit

Permalink
feat(api): expose giftcards api methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Terzi Eduard committed Jun 13, 2022
1 parent 113d519 commit 9dbab22
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@goparrot/square-connect-plus",
"description": "Extends the official Square Node.js SDK library with additional functionality",
"version": "1.1.0",
"version": "1.1.0-dev.gc.0",
"author": "Coroliov Oleg",
"license": "MIT",
"private": false,
Expand Down
20 changes: 20 additions & 0 deletions src/client/SquareClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
Client,
DEFAULT_CONFIGURATION,
EmployeesApi,
GiftCardActivitiesApi,
GiftCardsApi,
InventoryApi,
LaborApi,
LocationsApi,
Expand Down Expand Up @@ -144,6 +146,24 @@ export class SquareClient {
return this.proxy(new PaymentsApi(this.getOriginClient()), retryableMethods);
}

getGiftCardsApi(
retryableMethods: string[] = [
'listGiftCards',
'createGiftCard',
'retrieveGiftCardFromGAN',
'retrieveGiftCardFromNonce',
'linkCustomerToGiftCard',
'unlinkCustomerFromGiftCard',
'retrieveGiftCard',
],
): GiftCardsApi {
return this.proxy(new GiftCardsApi(this.getOriginClient()), retryableMethods);
}

getGiftCardActivitiesApi(retryableMethods: string[] = ['listGiftCardActivities', 'createGiftCardActivity']): GiftCardActivitiesApi {
return this.proxy(new GiftCardActivitiesApi(this.getOriginClient()), retryableMethods);
}

getRefundsApi(retryableMethods: string[] = ['getPaymentRefund', 'listPaymentRefunds', 'refundPayment']): RefundsApi {
return this.proxy(new RefundsApi(this.getOriginClient()), retryableMethods);
}
Expand Down
14 changes: 14 additions & 0 deletions test/unit/client/SquareClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
DEFAULT_CONFIGURATION,
CardsApi,
LoyaltyApi,
GiftCardsApi,
GiftCardActivitiesApi,
} from 'square';
import type { ISquareClientConfig } from '../../../src';
import { SquareClient, exponentialDelay } from '../../../src';
Expand Down Expand Up @@ -188,6 +190,18 @@ describe('SquareClient (unit)', (): void => {
});
});

describe('#getGiftCardsApi', (): void => {
it('should return GiftCardsApi', (): void => {
expect(new SquareClient(accessToken).getGiftCardsApi()).to.be.instanceOf(GiftCardsApi);
});
});

describe('#getGiftCardActivitiesApi', (): void => {
it('should return GiftCardActivitiesApi', (): void => {
expect(new SquareClient(accessToken).getGiftCardActivitiesApi()).to.be.instanceOf(GiftCardActivitiesApi);
});
});

describe('#getRefundsApi', (): void => {
it('should return RefundsApi', (): void => {
expect(new SquareClient(accessToken).getRefundsApi()).to.be.instanceOf(RefundsApi);
Expand Down
25 changes: 24 additions & 1 deletion test/unit/client/SquareClientFactory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { expect } from 'chai';
import { Client, CustomersApi, LocationsApi, OrdersApi, PaymentsApi, RefundsApi, Environment, DEFAULT_CONFIGURATION } from 'square';
import {
Client,
CustomersApi,
LocationsApi,
OrdersApi,
PaymentsApi,
RefundsApi,
Environment,
DEFAULT_CONFIGURATION,
GiftCardsApi,
GiftCardActivitiesApi,
} from 'square';
import type { ISquareClientConfig } from '../../../src';
import { SquareClient, SquareClientFactory, exponentialDelay } from '../../../src';

Expand Down Expand Up @@ -117,6 +128,18 @@ describe('SquareClientFactory (unit)', (): void => {
});
});

describe('#getGiftCardsApi', (): void => {
it('should return GiftCardsApi', (): void => {
expect(new SquareClient(accessToken).getGiftCardsApi()).to.be.instanceOf(GiftCardsApi);
});
});

describe('#getGiftCardActivitiesApi', (): void => {
it('should return GiftCardActivitiesApi', (): void => {
expect(new SquareClient(accessToken).getGiftCardActivitiesApi()).to.be.instanceOf(GiftCardActivitiesApi);
});
});

describe('#getRefundsApi', (): void => {
it('should return RefundsApi', (): void => {
expect(new SquareClient(accessToken).getRefundsApi()).to.be.instanceOf(RefundsApi);
Expand Down

0 comments on commit 9dbab22

Please sign in to comment.