diff --git a/.gitignore b/.gitignore index ed9888e..d6c10dd 100755 --- a/.gitignore +++ b/.gitignore @@ -50,10 +50,8 @@ out /dist/ .tmp.* -.github/skills/ +.github/skills docs/ -*_REVIEW.md -swagger-spec.json swagger.* \ No newline at end of file diff --git a/src/api/access/access.js b/src/api/access/access.js index 2b7dd4c..5e88068 100644 --- a/src/api/access/access.js +++ b/src/api/access/access.js @@ -1,44 +1,46 @@ -import { determineError } from '../../services/errors.js'; -import { createAccessToken } from '../../services/http.js'; - -/** - * Class dealing with the access api - * - * @export - * @class Access - */ -export default class Access { - constructor(config) { - this.config = config; - } - - /** - * Request an access token - * - * @param {Object} body Access object body. - * @return {Promise} A promise to the Access response. - */ - async request(body) { - try { - const response = await createAccessToken(this.config, this.config.httpClient, body); - return await response.json; - } catch (err) { - throw await determineError(err); - } - } - - /** - * Update the access details in the config. - * - * @param {Object} body Access response body. - * @return {void} - */ - updateAccessToken(body) { - this.config.access = { - token: body.access_token, - type: body.token_type, - scope: body.scope, - expires: new Date(new Date().getTime() + body.expires_in), - }; - } -} +import { determineError } from '../../services/errors.js'; +import { createAccessToken } from '../../services/http.js'; + +/** + * Class dealing with the access api + * + * @export + * @class Access + */ +export default class Access { + constructor(config) { + this.config = config; + } + + /** + * Request an access token + * + * @memberof Access + * @param {Object} body Access object body. + * @return {Promise} A promise to the Access response. + */ + async request(body) { + try { + const response = await createAccessToken(this.config, this.config.httpClient, body); + return await response.json; + } catch (err) { + throw await determineError(err); + } + } + + /** + * Update the access details in the config. + * + * @memberof Access + * @param {Object} body Access response body. + * @return {void} + */ + updateAccessToken(body) { + this.config.access = { + token: body.access_token, + type: body.token_type, + scope: body.scope, + expires: new Date(new Date().getTime() + body.expires_in), + }; + } +} diff --git a/src/api/apple-pay/apple-pay.js b/src/api/apple-pay/apple-pay.js index 21057b8..9bcb54b 100644 --- a/src/api/apple-pay/apple-pay.js +++ b/src/api/apple-pay/apple-pay.js @@ -1,87 +1,90 @@ -import { determineError } from '../../services/errors.js'; -import { post } from '../../services/http.js'; - -/** - * Class dealing with the Apple Pay api - * - * @export - * @class Apple Pay - */ -export default class ApplePay { - constructor(config) { - this.config = config; - } - - /** - * Upload a payment processing certificate. - * This will allow you to start processing payments via Apple Pay. - * - * @param {Object} body Apple Pay certificate request. - * @param {string} body.content The payment processing certificate content. - * @return {Promise} A promise to the Apple Pay certificate response. - */ - async upload(body) { - try { - const response = await post( - this.config.httpClient, - `${this.config.host}/applepay/certificates`, - this.config, - this.config.pk, - body - ); - return await response.json; - } catch (err) { - throw await determineError(err); - } - } - - /** - * Generate a certificate signing request. - * You'll need to upload this to your Apple Developer account to download a payment processing certificate. - * - * @param {Object} body Apple Pay signing request (optional). - * @param {string} [body.protocol_version] The protocol version (ec_v1 or rsa_v1). Default: ec_v1. - * @return {Promise} A promise to the Apple Pay signing request response. - */ - async generate(body) { - try { - const response = await post( - this.config.httpClient, - `${this.config.host}/applepay/signing-requests`, - this.config, - this.config.pk, - body - ); - return await response.json; - } catch (err) { - throw await determineError(err); - } - } - - /** - * Enroll a domain to the Apple Pay Service. - * Requires OAuth authentication with scope: vault:apme-enrollment - * - * @param {Object} body Apple Pay enrollment request. - * @param {string} body.domain The domain to enroll (e.g., 'https://example.com'). - * @return {Promise} A promise that resolves when enrollment is successful (204 No Content). - */ - async enroll(body) { - try { - const response = await post( - this.config.httpClient, - `${this.config.host}/applepay/enrollments`, - this.config, - null, - body - ); - // 204 No Content - return undefined - if (response.status === 204) { - return undefined; - } - return await response.json; - } catch (err) { - throw await determineError(err); - } - } -} +import { determineError } from '../../services/errors.js'; +import { post } from '../../services/http.js'; + +/** + * Class dealing with the Apple Pay api + * + * @export + * @class Apple Pay + */ +export default class ApplePay { + constructor(config) { + this.config = config; + } + + /** + * Upload a payment processing certificate. + * This will allow you to start processing payments via Apple Pay. + * + * @memberof ApplePay + * @param {Object} body Apple Pay certificate request. + * @param {string} body.content The payment processing certificate content. + * @return {Promise} A promise to the Apple Pay certificate response. + */ + async upload(body) { + try { + const response = await post( + this.config.httpClient, + `${this.config.host}/applepay/certificates`, + this.config, + this.config.pk, + body + ); + return await response.json; + } catch (err) { + throw await determineError(err); + } + } + + /** + * Generate a certificate signing request. + * You'll need to upload this to your Apple Developer account to download a payment processing certificate. + * + * @memberof ApplePay + * @param {Object} body Apple Pay signing request (optional). + * @param {string} [body.protocol_version] The protocol version (ec_v1 or rsa_v1). Default: ec_v1. + * @return {Promise} A promise to the Apple Pay signing request response. + */ + async generate(body) { + try { + const response = await post( + this.config.httpClient, + `${this.config.host}/applepay/signing-requests`, + this.config, + this.config.pk, + body + ); + return await response.json; + } catch (err) { + throw await determineError(err); + } + } + + /** + * Enroll a domain to the Apple Pay Service. + * Requires OAuth authentication with scope: vault:apme-enrollment + * + * @memberof ApplePay + * @param {Object} body Apple Pay enrollment request. + * @param {string} body.domain The domain to enroll (e.g., 'https://example.com'). + * @return {Promise} A promise that resolves when enrollment is successful (204 No Content). + */ + async enroll(body) { + try { + const response = await post( + this.config.httpClient, + `${this.config.host}/applepay/enrollments`, + this.config, + null, + body + ); + // 204 No Content - return undefined + if (response.status === 204) { + return undefined; + } + return await response.json; + } catch (err) { + throw await determineError(err); + } + } +} diff --git a/src/api/card-metadata/card-metadata.js b/src/api/card-metadata/card-metadata.js index e6f4d95..e5f8732 100644 --- a/src/api/card-metadata/card-metadata.js +++ b/src/api/card-metadata/card-metadata.js @@ -1,36 +1,37 @@ -import { determineError } from '../../services/errors.js'; -import { post } from '../../services/http.js'; - -/** - * Class dealing with the /metadata/card endpoint - * - * @export - * @class CardMetadata - */ -export default class CardMetadata { - constructor(config) { - this.config = config; - } - - /** - * Returns a single metadata record for the card specified by the Primary Account Number (PAN), - * Bank Identification Number (BIN), token, or instrument supplied. - * - * @param {Object} body Card Metadata request body. - * @return {Promise} A promise to the add Card Metadata response. - */ - async get(body) { - try { - const response = await post( - this.config.httpClient, - `${this.config.host}/metadata/card`, - this.config, - this.config.sk, - body - ); - return await response.json; - } catch (err) { - throw await determineError(err); - } - } -} +import { determineError } from '../../services/errors.js'; +import { post } from '../../services/http.js'; + +/** + * Class dealing with the /metadata/card endpoint + * + * @export + * @class CardMetadata + */ +export default class CardMetadata { + constructor(config) { + this.config = config; + } + + /** + * Returns a single metadata record for the card specified by the Primary Account Number (PAN), + * Bank Identification Number (BIN), token, or instrument supplied. + * + * @memberof CardMetadata + * @param {Object} body Card Metadata request body. + * @return {Promise} A promise to the Card Metadata response. + */ + async get(body) { + try { + const response = await post( + this.config.httpClient, + `${this.config.host}/metadata/card`, + this.config, + this.config.sk, + body + ); + return await response.json; + } catch (err) { + throw await determineError(err); + } + } +} diff --git a/src/api/forex/forex.js b/src/api/forex/forex.js index 0e51f66..77299da 100644 --- a/src/api/forex/forex.js +++ b/src/api/forex/forex.js @@ -1,55 +1,57 @@ -import { determineError } from '../../services/errors.js'; -import { get, post } from '../../services/http.js'; -import { buildQueryParams } from '../../services/utils.js'; - -/** - * Class dealing with the forex api - * - * @export - * @class Forex - */ -export default class Forex { - constructor(config) { - this.config = config; - } - - /** - * Request an exchange rate between a source and destination currency - * - * @deprecated v2.x.x - Use the Forex rates API instead - * @param {Object} body Forex object body. - * @return {Promise} A promise to the Forex response. - */ - async request(body) { - try { - const response = await post( - this.config.httpClient, - `${this.config.host}/forex/quotes`, - this.config, - this.config.sk, - body - ); - return await response.json; - } catch (err) { - throw await determineError(err); - } - } - - /** - * Use the Forex (FX) rates API to get the indicative foreign exchange rates that Checkout.com - * uses to process payments for card payouts - * - * @param {Object} body Forex params. - * @return {Promise} A promise to the Forex response. - */ - async getRates(body) { - try { - const url = buildQueryParams(`${this.config.host}/forex/rates`, body); - - const response = await get(this.config.httpClient, url, this.config, this.config.sk); - return await response.json; - } catch (err) { - throw await determineError(err); - } - } -} +import { determineError } from '../../services/errors.js'; +import { get, post } from '../../services/http.js'; +import { buildQueryParams } from '../../services/utils.js'; + +/** + * Class dealing with the forex api + * + * @export + * @class Forex + */ +export default class Forex { + constructor(config) { + this.config = config; + } + + /** + * Request an exchange rate between a source and destination currency + * + * @deprecated v2.x.x - Use the Forex rates API instead + * @memberof Forex + * @param {Object} body Forex object body. + * @return {Promise} A promise to the Forex response. + */ + async request(body) { + try { + const response = await post( + this.config.httpClient, + `${this.config.host}/forex/quotes`, + this.config, + this.config.sk, + body + ); + return await response.json; + } catch (err) { + throw await determineError(err); + } + } + + /** + * Use the Forex (FX) rates API to get the indicative foreign exchange rates that Checkout.com + * uses to process payments for card payouts + * + * @memberof Forex + * @param {Object} body Forex params. + * @return {Promise} A promise to the Forex response. + */ + async getRates(body) { + try { + const url = buildQueryParams(`${this.config.host}/forex/rates`, body); + + const response = await get(this.config.httpClient, url, this.config, this.config.sk); + return await response.json; + } catch (err) { + throw await determineError(err); + } + } +} diff --git a/src/api/forward/forward.js b/src/api/forward/forward.js index 2d038ff..1389bc8 100644 --- a/src/api/forward/forward.js +++ b/src/api/forward/forward.js @@ -17,7 +17,7 @@ export default class Forward { * Forwards an API request to a third-party endpoint. * For example, you can forward payment credentials you've stored in our Vault to a third-party payment processor. * - * Forward an API request + * @memberof Forward * @param {Object} body Forward request body * @return {Promise} A promise to the forward response */ @@ -40,7 +40,7 @@ export default class Forward { * Retrieve the details of a successfully forwarded API request. * The details can be retrieved for up to 14 days after the request was initiated. * - * Get forward request + * @memberof Forward * @param {string} id The unique identifier of the forward request * @return {Promise} A promise to the forward request details */ @@ -66,7 +66,7 @@ export default class Forward { * - value: max 8KB * - entity_id (optional): when provided, secret is scoped to this entity * - * Create secret + * @memberof Forward * @param {Object} body Secret creation body with name, value, and optional entity_id * @return {Promise} A promise to the secret metadata */ @@ -88,7 +88,7 @@ export default class Forward { /** * Returns metadata for secrets scoped for client_id. * - * List secrets + * @memberof Forward * @return {Promise} A promise to the list of secrets metadata */ async listSecrets() { @@ -112,7 +112,7 @@ export default class Forward { * - Only value and entity_id can be updated * - value: max 8KB * - * Update secret + * @memberof Forward * @param {string} name The secret name * @param {Object} body Update body with value and/or entity_id * @return {Promise} A promise to the updated secret metadata with incremented version @@ -135,7 +135,7 @@ export default class Forward { /** * Permanently delete a secret by name. * - * Delete secret + * @memberof Forward * @param {string} name The secret name to delete * @return {Promise} A promise to the deletion response */ diff --git a/src/api/network-tokens/network-tokens.js b/src/api/network-tokens/network-tokens.js index b446b52..f1a79db 100644 --- a/src/api/network-tokens/network-tokens.js +++ b/src/api/network-tokens/network-tokens.js @@ -16,7 +16,7 @@ export default class NetworkTokens { * Provision a Network Token * [BETA] * Provision a network token from a card source. - * @method provisionNetworkToken + * @memberof NetworkTokens * @param {Object} body - Request body containing the source details * @returns {Promise} A promise to the Provision a Network Token response */ @@ -40,7 +40,7 @@ export default class NetworkTokens { * Get Network Token * [BETA] * Given network token ID, this endpoint returns network token details: DPAN, expiry date, state, TRID and also card details like last four and expiry date. - * @method getNetworkToken + * @memberof NetworkTokens * @param {string} network_token_id - The network token ID * @returns {Promise} A promise to the Get Network Token response */ @@ -63,7 +63,7 @@ export default class NetworkTokens { * Request a cryptogram * [BETA] * Request a cryptogram for a network token for a specific transaction type. - * @method provisionCryptogram + * @memberof NetworkTokens * @param {string} network_token_id - The network token ID * @param {Object} body - Request body containing transaction_type * @returns {Promise} A promise to the Request a cryptogram response @@ -89,7 +89,7 @@ export default class NetworkTokens { * [Beta] This endpoint is for permanently deleting a network token. A network token should be deleted when * a payment instrument it is associated with is removed from file or if the security of the token has been compromised. * - * @method deleteNetworkToken + * @memberof NetworkTokens * @param {string} network_token_id - Unique token ID assigned by Checkout.com for each token * @returns {Promise} A promise to the Delete Network Token response */ diff --git a/src/api/payment-methods/payment-methods.js b/src/api/payment-methods/payment-methods.js index 9d996c8..e6b0484 100644 --- a/src/api/payment-methods/payment-methods.js +++ b/src/api/payment-methods/payment-methods.js @@ -16,7 +16,7 @@ export default class PaymentMethods { * Get available payment methods * [BETA] * Get a list of all available payment methods for a specific Processing Channel ID. - * @method getPaymentMethods + * @memberof PaymentMethods * @param {string} processing_channel_id - The processing channel to be used for payment methods retrieval. * @returns {Promise} A promise to the Get available payment methods response */ diff --git a/src/api/payment-setups/payment-setups.js b/src/api/payment-setups/payment-setups.js index 6605bdf..8ecc512 100644 --- a/src/api/payment-setups/payment-setups.js +++ b/src/api/payment-setups/payment-setups.js @@ -19,7 +19,7 @@ export default class PaymentSetups { * Creates a Payment Setup. * To maximize the amount of information the payment setup can use, we recommend that you create a payment setup as early * as possible in the customer's journey. For example, the first time they land on the basket page. - * @method createAPaymentSetup + * @memberof PaymentSetups * @param {Object} body - Request body * @returns {Promise<Object>} A promise to the Create a Payment Setup response */ @@ -46,7 +46,7 @@ export default class PaymentSetups { * Updates a Payment Setup. * You should update the payment setup whenever there are significant changes in the data relevant to the customer's * transaction. For example, when the customer makes a change that impacts the total payment amount. - * @method updateAPaymentSetup + * @memberof PaymentSetups * @param {string} id - The unique identifier of the Payment Setup to update. * @param {Object} body - Request body * @returns {Promise<Object>} A promise to the Update a Payment Setup response @@ -72,7 +72,7 @@ export default class PaymentSetups { * Get a Payment Setup * [BETA] * Retrieves a Payment Setup. - * @method getAPaymentSetup + * @memberof PaymentSetups * @param {string} id - The unique identifier of the Payment Setup to retrieve. * @returns {Promise<Object>} A promise to the Get a Payment Setup response */ @@ -95,7 +95,7 @@ export default class PaymentSetups { * Confirm a Payment Setup * [BETA] * Confirm a Payment Setup to begin processing the payment request with your chosen payment method option. - * @method confirmAPaymentSetup + * @memberof PaymentSetups * @param {string} id - The unique identifier of the Payment Setup. * @param {string} payment_method_option_id - The unique identifier of the payment option to process the payment with. * @returns {Promise<Object>} A promise to the Confirm a Payment Setup response diff --git a/test/access/access.js b/test/access/access-unit.js similarity index 97% rename from test/access/access.js rename to test/access/access-unit.js index 188a135..800d439 100644 --- a/test/access/access.js +++ b/test/access/access-unit.js @@ -34,7 +34,7 @@ describe('Access', () => { expect(tkn.token_type).to.equals('Bearer'); }); - it('should be able to updat the access token in the config from the access class', async () => { + it('should be able to update the access token in the config from the access class', async () => { nock('https://123456789.access.sandbox.checkout.com').post('/connect/token').reply(201, { access_token: '1234', expires_in: 3600, diff --git a/test/account-updater/account-updater-unit.js b/test/account-updater/account-updater-unit.js index 8ae7e75..56edcd9 100644 --- a/test/account-updater/account-updater-unit.js +++ b/test/account-updater/account-updater-unit.js @@ -31,7 +31,6 @@ describe('Unit::AccountUpdater', () => { const cko = new Checkout('test_client_secret', { client: 'ack_testclie123456', scope: ['vault:real-time-account-updater'], - subdomain: 'test', environment: 'sandbox', subdomain: '123456789' }); @@ -69,7 +68,6 @@ describe('Unit::AccountUpdater', () => { const cko = new Checkout('test_client_secret', { client: 'ack_testclie123456', scope: ['vault:real-time-account-updater'], - subdomain: 'test', environment: 'sandbox', subdomain: '123456789' }); diff --git a/test/apple-pay/apple-pay-unit.js b/test/apple-pay/apple-pay-unit.js index 7d33def..c02d771 100644 --- a/test/apple-pay/apple-pay-unit.js +++ b/test/apple-pay/apple-pay-unit.js @@ -89,7 +89,6 @@ describe('Apple Pay', () => { let cko = new Checkout('test_client_secret', { client: 'ack_testclie123456', scope: ['vault:apme-enrollment'], - subdomain: '123456789', environment: 'sandbox', subdomain: '123456789' }); diff --git a/test/balances/balances-unit.js b/test/balances/balances-unit.js index 15e5368..509a6cb 100644 --- a/test/balances/balances-unit.js +++ b/test/balances/balances-unit.js @@ -6,7 +6,7 @@ import nock from 'nock'; const SK = 'sk_sbox_o2nulev2arguvyf6w7sc5fkznas'; describe('Balances', () => { - it('should retrive balance', async () => { + it('should retrieve balance', async () => { nock('https://balances.sandbox.checkout.com') .get('/balances/ent_djigcqx4clmufo2sasgomgpqsq?query=currency:EUR') .reply(200, { @@ -34,7 +34,7 @@ describe('Balances', () => { expect(balance.data[0]).to.have.property('balances'); }); - it('should retrive balance in prod', async () => { + it('should retrieve balance in prod', async () => { nock('https://balances.checkout.com') .get('/balances/ent_djigcqx4clmufo2sasgomgpqsq?query=currency:EUR') .reply(200, { diff --git a/test/customers/customers-it.js b/test/customers/customers-it.js index 265018a..c1baa02 100644 --- a/test/customers/customers-it.js +++ b/test/customers/customers-it.js @@ -61,7 +61,7 @@ describe('Integration::Customers', () => { expect(customer).to.have.property('name', 'Customer'); }); - it.skip('should update a customer)', async () => { + it.skip('should update a customer', async () => { const crypto = await import('crypto'); const uuid1 = crypto.randomUUID(); const uuid2 = crypto.randomUUID(); diff --git a/test/events/events.js b/test/events/events.js index bd8ea1e..67f564a 100644 --- a/test/events/events.js +++ b/test/events/events.js @@ -397,7 +397,7 @@ describe('Events', () => { expect(notification.content_type).to.equal('json'); }); - it('should throw Not Found when trying to retrive event notification', async () => { + it('should throw Not Found when trying to retrieve event notification', async () => { nock('https://123456789.api.sandbox.checkout.com') .get( '/events/evt_pwhgncrvd3julmuutcoz4deu2q/notifications/ntf_wqjkqpgjy33uxoywcej4fnw6qm' diff --git a/test/transfers/transfers.js b/test/transfers/transfers.js index 1101b24..41a0846 100644 --- a/test/transfers/transfers.js +++ b/test/transfers/transfers.js @@ -154,7 +154,7 @@ describe('Transfers', () => { } }); - it('should retrive transfer', async () => { + it('should retrieve transfer', async () => { nock('https://transfers.sandbox.checkout.com') .get('/transfers/tra_lx6isvi4lahkrkn462bj77xnki') .reply(200, { @@ -180,7 +180,7 @@ describe('Transfers', () => { expect(transfer.id).to.equal('tra_lx6isvi4lahkrkn462bj77xnki'); }); - it('should retrive transfer in prod', async () => { + it('should retrieve transfer in prod', async () => { nock('https://transfers.checkout.com') .get('/transfers/tra_lx6isvi4lahkrkn462bj77xnki') .reply(200, { diff --git a/test/webhooks/webhooks.js b/test/webhooks/webhooks.js index 3a6e2d0..4c4e3c4 100644 --- a/test/webhooks/webhooks.js +++ b/test/webhooks/webhooks.js @@ -147,7 +147,7 @@ describe('Webhooks', () => { } }); - it('should retrive webhook', async () => { + it('should retrieve webhook', async () => { nock('https://123456789.api.sandbox.checkout.com') .get('/webhooks/wh_tdt72zlbe7cudogxdgit6nwk6i') .reply(200, { diff --git a/types/dist/api/events/events.d.ts b/types/dist/api/events/events.d.ts index 8586664..c8e1a9d 100644 --- a/types/dist/api/events/events.d.ts +++ b/types/dist/api/events/events.d.ts @@ -1,6 +1,6 @@ import { config } from '../../Checkout'; -export default class Instruments { +export default class Events { constructor(config: config); retrieveEventTypes: (version: string) => Promise;