├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── build-master.yml │ ├── build-pull-request.yml │ ├── build-release.yml │ └── codeql-analysis.yml ├── .gitignore ├── .npmignore ├── .prettierrc ├── LICENSE ├── README.md ├── example.js ├── package-lock.json ├── package.json ├── src ├── Checkout.js ├── api │ ├── access │ │ └── access.js │ ├── apm-specific │ │ ├── baloto.js │ │ ├── boleto.js │ │ ├── fawry.js │ │ ├── giropay.js │ │ ├── ideal.js │ │ ├── klarna.js │ │ ├── oxxo.js │ │ ├── pagofacil.js │ │ ├── rapipago.js │ │ └── sepa.js │ ├── apple-pay │ │ └── apple-pay.js │ ├── balances │ │ └── balances.js │ ├── card-metadata │ │ └── card-metadata.js │ ├── customers │ │ └── customers.js │ ├── disputes │ │ └── disputes.js │ ├── events │ │ └── events.js │ ├── files │ │ └── files.js │ ├── financial │ │ └── financial.js │ ├── forex │ │ └── forex.js │ ├── hosted-payments │ │ └── hosted-payments.js │ ├── instruments │ │ └── instruments.js │ ├── issuing │ │ └── issuing.js │ ├── payment-contexts │ │ └── payment-contexts.js │ ├── payment-sessions │ │ └── payment-sessions.js │ ├── payments-links │ │ └── payments-links.js │ ├── payments │ │ └── payments.js │ ├── platforms │ │ └── platforms.js │ ├── reconciliation │ │ └── reconciliation.js │ ├── reports │ │ └── reports.js │ ├── risk │ │ └── risk.js │ ├── sessions │ │ └── sessions.js │ ├── sources │ │ └── sources.js │ ├── tokens │ │ └── tokens.js │ ├── transfers │ │ └── transfers.js │ ├── webhooks │ │ └── webhooks.js │ └── workflows │ │ └── workflows.js ├── config.js ├── index.js └── services │ ├── errors.js │ ├── http.js │ ├── utils.js │ └── validation.js ├── test ├── access │ └── access.js ├── apm-specific │ ├── baloto.js │ ├── boleto.js │ ├── fawry.js │ ├── giropay.js │ ├── ideal.js │ ├── klarna.js │ ├── oxxo.js │ ├── pagofacil.js │ ├── rapipago.js │ └── sepa.js ├── apple-pay │ └── apple-pay.js ├── balances │ └── balances.js ├── card-metadata │ └── card-metadata.js ├── config │ └── config.js ├── customers │ └── customers.js ├── disputes │ └── disputes.js ├── errors │ └── apiError.js ├── events │ └── events.js ├── files │ ├── evidence.jpg │ └── files.js ├── financial │ └── financial.js ├── forex │ └── forex.js ├── hosted-payments │ ├── hosted-payments-it.js │ └── hosted-payments.js ├── http │ ├── additionalHeaders.js │ └── httpClient-it.js ├── instruments │ ├── instruments-it.js │ └── instruments.js ├── issuing │ ├── issuing-it.js │ └── issuing-unit.js ├── payment-contexts │ ├── payment-contexts-it.js │ └── payment-contexts-unit.js ├── payment-sessions │ ├── payment-sessions-common.js │ ├── payment-sessions-it.js │ └── payment-sessions-unit.js ├── payments-links │ └── payments-links.js ├── payments │ ├── cancelPayment.js │ ├── capturePayment.js │ ├── getPayment.js │ ├── getPaymentActions.js │ ├── getPaymentList.js │ ├── incrementPayment.js │ ├── refundPayment.js │ ├── requestPayment.js │ ├── reversePayment.js │ ├── searchPayment.js │ └── voidPayment.js ├── platforms │ ├── evidence.jpg │ ├── platforms-reserve-rules-it.js │ └── platforms.js ├── reconciliation │ ├── reconciliation.js │ └── report.csv ├── reports │ ├── report.csv │ └── reports.js ├── risk │ └── risk.js ├── sessions │ └── sessions.js ├── sources │ └── addSource.js ├── tokens │ └── requestToken.js ├── transfers │ └── transfers.js ├── utils.js ├── webhooks │ └── webhooks.js └── workflows │ └── workflows.js └── types └── dist ├── Checkout.d.ts ├── api ├── access │ └── access.d.ts ├── apm-specific │ ├── baloto.d.ts │ ├── boleto.d.ts │ ├── fawry.d.ts │ ├── giropay.d.ts │ ├── ideal.d.ts │ ├── klarna.d.ts │ ├── oxxo.d.ts │ ├── pagofacil.d.ts │ ├── rapipago.d.ts │ └── sepa.d.ts ├── apple-pay │ └── apple-pay.d.ts ├── balances │ └── balances.d.ts ├── card-metadata │ └── card-metadata.d.ts ├── customers │ └── customers.d.ts ├── disputes │ └── disputes.d.ts ├── events │ └── events.d.ts ├── files │ └── files.d.ts ├── financial │ └── financial.d.ts ├── forex │ └── forex.d.ts ├── hosted-payments │ └── hosted-payments.d.ts ├── instruments │ └── instruments.d.ts ├── issuing │ └── issuing.d.ts ├── payment-contexts │ └── payment-contexts.d.ts ├── payment-links │ └── payment-links.d.ts ├── payment-sessions │ └── payment-sessions.d.ts ├── payments-links │ └── payments-links.d.ts ├── payments │ └── payments.d.ts ├── platforms │ └── platforms.d.ts ├── reconciliation │ └── reconciliation.d.ts ├── reports │ └── reports.d.ts ├── risk │ └── risk.d.ts ├── sessions │ └── sessions.d.ts ├── sources │ └── sources.d.ts ├── tokens │ └── tokens.d.ts ├── transfers │ └── transfers.d.ts ├── webhooks │ └── webhooks.d.ts └── workflows │ └── workflows.d.ts ├── config.d.ts ├── index.d.ts └── services ├── errors.d.ts ├── http.d.ts ├── utils.d.ts └── validation.d.ts /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [{src,scripts}/**.{ts,json,js}] 4 | end_of_line = crlf 5 | charset = utf-8 6 | trim_trailing_whitespace = true 7 | insert_final_newline = true 8 | indent_style = space 9 | indent_size = 4 -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | test/ 2 | example.js -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "@babel/eslint-parser", 3 | "extends": ["airbnb/base", "prettier"], 4 | "plugins": ["prettier","@babel"], 5 | "rules": { 6 | "prettier/prettier": ["error"], 7 | "no-use-before-define": "off", 8 | "no-underscore-dangle": "off" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "Bug report" 3 | about: Create a bug report 4 | --- 5 | 6 | 7 | 8 | 9 | ### Environment 10 | 11 | * Checkout SDK version: 12 | * Platform and version: 13 | * Operating System and version: 14 | 15 | 16 | ### Description 17 | 18 | 19 | 20 | ### Expected behavior 21 | 22 | 23 | 24 | ### Current behavior 25 | 26 | 27 | 28 | 29 | ### Steps to reproduce 30 | 31 | 32 | 33 | 34 | ### Possible solution 35 | 36 | 37 | 38 | - [ ] I may be able to implement this bug fix 39 | 40 | ### Additional information 41 | 42 | 43 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "Feature request" 3 | about: Request a new future or an improvement to an existing feature 4 | --- 5 | 6 | 7 | 8 | 9 | ### Environment 10 | 11 | * Checkout SDK version: 12 | * Platform and version: 13 | * Operating System and version: 14 | 15 | 16 | ### Description 17 | 18 | 19 | 20 | ## Proposed Solution 21 | 22 | 23 | 24 | 25 | - [ ] I may be able to implement this feature 26 | -------------------------------------------------------------------------------- /.github/workflows/build-master.yml: -------------------------------------------------------------------------------- 1 | name: build-master 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build: 10 | if: "!contains(github.event.commits[0].message, 'Release')" 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v3 14 | - id: setup-node 15 | uses: actions/setup-node@v2.5.1 16 | with: 17 | node-version: 12 18 | registry-url: https://registry.npmjs.org/ 19 | - id: build-and-analyse 20 | env: 21 | CHECKOUT_PROCESSING_CHANNEL_ID: ${{ secrets.IT_CHECKOUT_PROCESSING_CHANNEL_ID }} 22 | CHECKOUT_PREVIOUS_SECRET_KEY: ${{ secrets.IT_CHECKOUT_PREVIOUS_SECRET_KEY }} 23 | CHECKOUT_PREVIOUS_PUBLIC_KEY: ${{ secrets.IT_CHECKOUT_PREVIOUS_PUBLIC_KEY }} 24 | CHECKOUT_DEFAULT_SECRET_KEY: ${{ secrets.IT_CHECKOUT_DEFAULT_SECRET_KEY }} 25 | CHECKOUT_DEFAULT_PUBLIC_KEY: ${{ secrets.IT_CHECKOUT_DEFAULT_PUBLIC_KEY }} 26 | CHECKOUT_DEFAULT_OAUTH_CLIENT_ID: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_CLIENT_ID }} 27 | CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET }} 28 | CHECKOUT_DEFAULT_OAUTH_PAYOUT_SCHEDULE_CLIENT_ID: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_PAYOUT_SCHEDULE_CLIENT_ID }} 29 | CHECKOUT_DEFAULT_OAUTH_PAYOUT_SCHEDULE_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_PAYOUT_SCHEDULE_CLIENT_SECRET }} 30 | CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_ID: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_ID }} 31 | CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_SECRET }} 32 | CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_ID: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_ID }} 33 | CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_SECRET }} 34 | run: | 35 | npm ci 36 | npm test 37 | npm run build -------------------------------------------------------------------------------- /.github/workflows/build-pull-request.yml: -------------------------------------------------------------------------------- 1 | name: build-pull-request 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v3 13 | - id: setup-node 14 | uses: actions/setup-node@v2.5.1 15 | with: 16 | node-version: 12 17 | registry-url: https://registry.npmjs.org/ 18 | - id: build-and-analyse 19 | env: 20 | CHECKOUT_PROCESSING_CHANNEL_ID: ${{ secrets.IT_CHECKOUT_PROCESSING_CHANNEL_ID }} 21 | CHECKOUT_PREVIOUS_SECRET_KEY: ${{ secrets.IT_CHECKOUT_PREVIOUS_SECRET_KEY }} 22 | CHECKOUT_PREVIOUS_PUBLIC_KEY: ${{ secrets.IT_CHECKOUT_PREVIOUS_PUBLIC_KEY }} 23 | CHECKOUT_DEFAULT_SECRET_KEY: ${{ secrets.IT_CHECKOUT_DEFAULT_SECRET_KEY }} 24 | CHECKOUT_DEFAULT_PUBLIC_KEY: ${{ secrets.IT_CHECKOUT_DEFAULT_PUBLIC_KEY }} 25 | CHECKOUT_DEFAULT_OAUTH_CLIENT_ID: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_CLIENT_ID }} 26 | CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET }} 27 | CHECKOUT_DEFAULT_OAUTH_PAYOUT_SCHEDULE_CLIENT_ID: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_PAYOUT_SCHEDULE_CLIENT_ID }} 28 | CHECKOUT_DEFAULT_OAUTH_PAYOUT_SCHEDULE_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_PAYOUT_SCHEDULE_CLIENT_SECRET }} 29 | CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_ID: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_ID }} 30 | CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_SECRET }} 31 | CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_ID: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_ID }} 32 | CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_SECRET }} 33 | run: | 34 | npm ci 35 | npm test 36 | npm run build 37 | 38 | -------------------------------------------------------------------------------- /.github/workflows/build-release.yml: -------------------------------------------------------------------------------- 1 | name: build-release 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | paths: 8 | - package.json 9 | 10 | jobs: 11 | deploy: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v3 15 | - id: setup-node 16 | uses: actions/setup-node@v2.5.1 17 | with: 18 | node-version: 12 19 | registry-url: https://registry.npmjs.org/ 20 | - id: build-and-analyse 21 | env: 22 | CHECKOUT_PROCESSING_CHANNEL_ID: ${{ secrets.IT_CHECKOUT_PROCESSING_CHANNEL_ID }} 23 | CHECKOUT_PREVIOUS_SECRET_KEY: ${{ secrets.IT_CHECKOUT_PREVIOUS_SECRET_KEY }} 24 | CHECKOUT_PREVIOUS_PUBLIC_KEY: ${{ secrets.IT_CHECKOUT_PREVIOUS_PUBLIC_KEY }} 25 | CHECKOUT_DEFAULT_SECRET_KEY: ${{ secrets.IT_CHECKOUT_DEFAULT_SECRET_KEY }} 26 | CHECKOUT_DEFAULT_PUBLIC_KEY: ${{ secrets.IT_CHECKOUT_DEFAULT_PUBLIC_KEY }} 27 | CHECKOUT_DEFAULT_OAUTH_CLIENT_ID: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_CLIENT_ID }} 28 | CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET }} 29 | CHECKOUT_DEFAULT_OAUTH_PAYOUT_SCHEDULE_CLIENT_ID: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_PAYOUT_SCHEDULE_CLIENT_ID }} 30 | CHECKOUT_DEFAULT_OAUTH_PAYOUT_SCHEDULE_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_PAYOUT_SCHEDULE_CLIENT_SECRET }} 31 | CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_ID: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_ID }} 32 | CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ACCOUNTS_CLIENT_SECRET }} 33 | CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_ID: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_ID }} 34 | CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_SECRET: ${{ secrets.IT_CHECKOUT_DEFAULT_OAUTH_ISSUING_CLIENT_SECRET }} 35 | run: | 36 | npm ci 37 | npm test 38 | npm run build 39 | - id: rsync 40 | run: rsync -avh --progress ./types/ ./ 41 | - id: read-version 42 | run: echo "CURRENT_VERSION=$( awk -F'"' '/version/ {print $4}' package.json )" >> $GITHUB_ENV 43 | - id: print-version 44 | run: echo "Releasing $CURRENT_VERSION" 45 | - id: publish-to-npm 46 | env: 47 | NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}} 48 | run: npm publish 49 | - id: create-release 50 | uses: actions/create-release@v1 51 | env: 52 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 53 | with: 54 | tag_name: ${{ env.CURRENT_VERSION }} 55 | release_name: ${{ env.CURRENT_VERSION }} 56 | body: ${{ github.event.head_commit.message }} 57 | draft: false 58 | prerelease: false -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | schedule: 21 | - cron: '34 2 * * 0' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'javascript' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v3 42 | with: 43 | submodules: recursive 44 | 45 | # Initializes the CodeQL tools for scanning. 46 | - name: Initialize CodeQL 47 | uses: github/codeql-action/init@v3 48 | with: 49 | languages: ${{ matrix.language }} 50 | queries: security-and-quality 51 | 52 | # If you wish to specify custom queries, you can do so here or in a config file. 53 | # By default, queries listed here will override any specified in a config file. 54 | # Prefix the list here with "+" to use these queries and those in the config file. 55 | 56 | # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 57 | # queries: security-extended,security-and-quality 58 | - name: Autobuild 59 | uses: github/codeql-action/autobuild@v3 60 | 61 | - name: Perform CodeQL Analysis 62 | uses: github/codeql-action/analyze@v3 63 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | .nyc_output 17 | coverage.* 18 | 19 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 20 | .grunt 21 | 22 | # node-waf configuration 23 | .lock-wscript 24 | 25 | # Compiled binary addons (http://nodejs.org/api/addons.html) 26 | build/Release 27 | 28 | # Dependency directory 29 | node_modules 30 | 31 | # Optional npm cache directory 32 | .npm 33 | 34 | # Optional REPL history 35 | .node_repl_history 36 | 37 | typings/ 38 | lib/*.js 39 | lib/ 40 | *.map 41 | 42 | .DS_Store 43 | /.vscode/ 44 | 45 | doc 46 | out 47 | .idea 48 | 49 | /dist/ 50 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | ./nyc_output 2 | coverage 3 | src 4 | test 5 | types 6 | .DS_Store 7 | website 8 | documentation -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": true, 3 | "singleQuote": true, 4 | "tabWidth": 4, 5 | "useTabs": false, 6 | "printWidth": 100 7 | } 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Checkout.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![build-status](https://github.com/checkout/checkout-sdk-node/workflows/build-master/badge.svg)](https://github.com/checkout/checkout-sdk-node/actions/workflows/build-master.yml) 2 | ![CI Tests](https://github.com/checkout/checkout-sdk-node/workflows/CI%20Tests/badge.svg) 3 | ![CodeQL](https://github.com/checkout/checkout-sdk-node/workflows/CodeQL/badge.svg) 4 | [![codecov](https://codecov.io/gh/checkout/checkout-sdk-node/branch/master/graph/badge.svg?token=POL9EXI2IS)](https://codecov.io/gh/checkout/checkout-sdk-node) 5 | 6 | [![build-status](https://github.com/checkout/checkout-sdk-net/workflows/build-release/badge.svg)](https://github.com/checkout/checkout-sdk-net/actions/workflows/build-release.yml) 7 | [![GitHub release](https://img.shields.io/github/release/checkout/checkout-sdk-node.svg)](https://GitHub.com/checkout/checkout-sdk-node/releases/) 8 | 9 | [![zip badge](https://badgen.net/bundlephobia/minzip/checkout-sdk-node)](https://badgen.net/bundlephobia/minzip/action-test) 10 | 11 |

12 | 13 |

14 | npm start 15 |

16 | 17 | # :rocket: Install 18 | 19 | ```bash 20 | npm install checkout-sdk-node 21 | ``` 22 | 23 | # :computer: Import 24 | 25 | ```js 26 | // ES6: 27 | import { Checkout } from 'checkout-sdk-node'; 28 | // Common JS: 29 | const { Checkout } = require('checkout-sdk-node'); 30 | ``` 31 | 32 | > If you don't have your API keys, you can sign up for a test account [here](https://www.checkout.com/get-test-account). 33 | 34 | # :clapper: Initialize SDK 35 | 36 | ## With api keys or access credentials 37 | Based on how your account was set up, you will either have a pair or API key or a set of access credentials. Here is how you can use the SDK in both scenarios: 38 | ```js 39 | // API Keys 40 | const cko = new Checkout('sk_XXXXXXXXX', { 41 | pk: 'pk_XXXXXXX' 42 | }); 43 | 44 | // Access credentials 45 | const cko = new Checkout('your api secret here', { 46 | client: 'ack_XXXXXXXX', 47 | scope: ['gateway'], // or whatever scope required 48 | environment: 'sandbox', // or 'production' 49 | }); 50 | ``` 51 | 52 | ## With environment variables 53 | If your account uses API Keys (pk_XXX + sk_XXX), you can set the following environment variables, and the SK will pick them up: 54 | - *CKO_SECRET_KEY* (with a value like sk_XXX) 55 | - *CKO_PUBLIC_KEY* (with a value like pk_XXX) 56 | 57 | If you use access credentials (ack_XXXX), you can set the following environment variables, and the SK will pick them up: 58 | - *CKO_SECRET* 59 | - *CKO_CLIENT* (with a value like ack_XXXX) 60 | - *CKO_SCOPE* (with a value of the scope or semicolon separated scopes in case you use multiple) 61 | - *CKO_ENVIRONMENT* (with a value like sandbox or production) 62 | 63 | ## Set custom config 64 | Basides the authentication, you also have the option to configure some extra elements about the SDK 65 | ```js 66 | const cko = new Checkout('...', { 67 | ..., //other authentication config 68 | host: "https://myProxyExample.com", // in case you need to use a custom host for tests 69 | timeout: 60000, // HTTP request timout in ms 70 | agent: new http.Agent({ keepAlive: true }), // custom HTTP agent 71 | httpClient: 'axios' // specify axios httpClient, by default fetch. Optional 72 | }); 73 | ``` 74 | 75 | # :wrench: SDK Environment (Sandbox/Production) 76 | When using API Keys (pk_XXX + sk_XXX) the SDK will automatically figure out what environment you are using however, if you use access credentials (ack_XXXX), make sure you set the "environment" in the config, as shown above in the initialization. 77 | 78 | # :interrobang: Error handling 79 | The SDK is using promises, and you can handle errors similar to any other HTTP call. 80 | 81 | ```js 82 | try { 83 | // some async request made with the SDK 84 | const action = await cko.payments.request({...}); 85 | ... 86 | } catch (error) { 87 | console.log(error.name, error.http_code, error.body) 88 | switch (error.name) { 89 | ... 90 | } 91 | } 92 | ``` 93 | Here you have all the possible SDK specific errors: 94 | 95 | | error.name | error.http_code | error.body | 96 | | -------------------- | --------------- | ----------------------- | 97 | | AuthenticationError | 401 | undefined | 98 | | ActionNotAllowed | 403 | undefined | 99 | | UrlAlreadyRegistered | 409 | undefined | 100 | | NotFoundError | 404 | undefined | 101 | | BadGateway | 502 | undefined | 102 | | ValidationError | 422 | object | 103 | | TooManyRequestsError | 429 | object/undefined | 104 | | ValueError | 429 | string describing error | 105 | 106 | 107 | # :book: Examples of usage 108 | 109 | You can see examples of how to use the SDK for every endpoint documented in our [API Reference](https://api-reference.checkout.com/). All you have to do is to navigate to the endpoint you want to use, and select "Node" for the example on the right side. 110 | > NOTE: If you use access credentials (ack_XXXX) the link to the API reference relevant to you will be shared by your Solutions Engineers. 111 | 112 | # :eyeglasses: Try it on RunKit 113 | 114 | You can try the SDK [here](https://npm.runkit.com/checkout-sdk-node). 115 | -------------------------------------------------------------------------------- /example.js: -------------------------------------------------------------------------------- 1 | const { Checkout } = require('checkout-sdk-node'); 2 | 3 | /** Go to checkout.com and sign up for a test account to get your own key.*/ 4 | const cko = new Checkout('sk_test_3e1ad21b-ac23-4eb3-ad1f-375e9fb56481'); 5 | 6 | /** 7 | * Keep in mind that requests with raw card details 8 | * requre a high level of PCI Compliance. 9 | */ 10 | (async () => { 11 | const transaction = await cko.payments.request({ 12 | source: { 13 | number: '4242424242424242', 14 | expiry_month: 6, 15 | expiry_year: 2029, 16 | cvv: '100' 17 | }, 18 | currency: 'USD', 19 | amount: 100 20 | }); 21 | 22 | console.log(transaction.status); 23 | })(); 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "checkout-sdk-node", 3 | "version": "2.7.0", 4 | "description": "", 5 | "type": "commonjs", 6 | "main": "./dist/index.js", 7 | "types": "./dist/index.d.ts", 8 | "devDependencies": { 9 | "@babel/cli": "^7.16.8", 10 | "@babel/core": "^7.16.7", 11 | "@babel/eslint-parser": "^7.16.5", 12 | "@babel/eslint-plugin": "^7.16.5", 13 | "@babel/node": "^7.16.8", 14 | "@babel/preset-env": "^7.16.8", 15 | "@types/mocha": "^10.0.10", 16 | "chai": "^4.3.4", 17 | "codecov": "^3.8.2", 18 | "eslint": "^8.34.0", 19 | "eslint-config-airbnb": "^19.0.4", 20 | "eslint-config-prettier": "^8.3.0", 21 | "eslint-plugin-chai-friendly": "^0.7.1", 22 | "eslint-plugin-import": "^2.22.1", 23 | "eslint-plugin-prettier": "^3.4.0", 24 | "esm": "^3.2.25", 25 | "mocha": "^8.4.0", 26 | "mocha-junit-reporter": "^2.0.0", 27 | "nock": "^13.0.11", 28 | "nyc": "^15.1.0", 29 | "prettier": "^2.1.2", 30 | "uuid": "^8.3.2" 31 | }, 32 | "runkitExampleFilename": "example.js", 33 | "scripts": { 34 | "start": "nodemon --exec babel-node ./src/index.js", 35 | "lint": "eslint --fix --ext .js src/", 36 | "test": "nyc --reporter=html mocha --timeout 300000 'test/**/*.js' --require esm", 37 | "posttest": "nyc report --reporter=json", 38 | "test:watch": "mocha --timeout 300000 'test/**/*.js' --watch --require esm", 39 | "build": "babel src --out-dir ./dist --source-maps", 40 | "codecov": "codecov -f coverage/*.json", 41 | "tsc": "tsc" 42 | }, 43 | "dependencies": { 44 | "axios": "^0.30.0", 45 | "form-data": "^4.0.0", 46 | "node-fetch": "^2.6.12" 47 | }, 48 | "babel": { 49 | "presets": [ 50 | [ 51 | "@babel/preset-env", 52 | { 53 | "targets": { 54 | "node": 6 55 | } 56 | } 57 | ] 58 | ] 59 | }, 60 | "author": "Ioan Ghisoi", 61 | "license": "MIT" 62 | } 63 | -------------------------------------------------------------------------------- /src/api/access/access.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { createAccessToken } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the access api 6 | * 7 | * @export 8 | * @class Access 9 | */ 10 | export default class Access { 11 | constructor(config) { 12 | this.config = config; 13 | } 14 | 15 | /** 16 | * Request an access token 17 | * 18 | * @param {Object} body Access object body. 19 | * @return {Promise} A promise to the Access response. 20 | */ 21 | async request(body) { 22 | try { 23 | const response = await createAccessToken( 24 | this.config, 25 | this.config.httpClient, 26 | body 27 | ); 28 | return await response.json; 29 | } catch (err) { 30 | const error = await determineError(err); 31 | throw error; 32 | } 33 | } 34 | 35 | /** 36 | * Update the access details in the config. 37 | * 38 | * @param {Object} body Access response body. 39 | * @return {void} 40 | */ 41 | updateAccessToken(body) { 42 | this.config.access = { 43 | token: body.access_token, 44 | type: body.token_type, 45 | scope: body.scope, 46 | expires: new Date(new Date().getTime() + body.expires_in), 47 | }; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/api/apm-specific/baloto.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { post } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /apms/baloto endpoint 6 | * 7 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 8 | * @export 9 | * @class Baloto 10 | */ 11 | export default class Baloto { 12 | constructor(config) { 13 | this.config = config; 14 | } 15 | 16 | /** 17 | * Succeed a Baloto payment 18 | * 19 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 20 | * @param {string} id Payment id. 21 | * @memberof Baloto 22 | * @return {Promise} A promise to the Baloto response. 23 | */ 24 | async succeed(id) { 25 | try { 26 | const response = await post( 27 | this.config.httpClient, 28 | `${this.config.host}/apms/baloto/payments/${id}/succeed`, 29 | this.config, 30 | this.config.sk 31 | ); 32 | return await response.json; 33 | } catch (err) { 34 | const error = await determineError(err); 35 | throw error; 36 | } 37 | } 38 | 39 | /** 40 | * Cancel Baloto payment 41 | * 42 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 43 | * @param {string} id Payment id. 44 | * @memberof Baloto 45 | * @return {Promise} A promise to the Baloto response. 46 | */ 47 | async expire(id) { 48 | try { 49 | const response = await post( 50 | this.config.httpClient, 51 | `${this.config.host}/apms/baloto/payments/${id}/expire`, 52 | this.config, 53 | this.config.sk 54 | ); 55 | return await response.json; 56 | } catch (err) { 57 | const error = await determineError(err); 58 | throw error; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/api/apm-specific/boleto.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { post } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /apms/boleto endpoint 6 | * 7 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 8 | * @export 9 | * @class Boleto 10 | */ 11 | export default class Boleto { 12 | constructor(config) { 13 | this.config = config; 14 | } 15 | 16 | /** 17 | * Succeed a Boleto payment 18 | * 19 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 20 | * @param {string} id Payment id. 21 | * @memberof Boleto 22 | * @return {Promise} A promise to the Boleto response. 23 | */ 24 | async succeed(id) { 25 | try { 26 | const response = await post( 27 | this.config.httpClient, 28 | `${this.config.host}/apms/boleto/payments/${id}/succeed`, 29 | this.config, 30 | this.config.sk 31 | ); 32 | return await response.json; 33 | } catch (err) { 34 | const error = await determineError(err); 35 | throw error; 36 | } 37 | } 38 | 39 | /** 40 | * Cancel Boleto payment 41 | * 42 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 43 | * @param {string} id Payment id. 44 | * @memberof Boleto 45 | * @return {Promise} A promise to the Boleto response. 46 | */ 47 | async expire(id) { 48 | try { 49 | const response = await post( 50 | this.config.httpClient, 51 | `${this.config.host}/apms/boleto/payments/${id}/expire`, 52 | this.config, 53 | this.config.sk 54 | ); 55 | return await response.json; 56 | } catch (err) { 57 | const error = await determineError(err); 58 | throw error; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/api/apm-specific/fawry.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { put } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /fawry endpoint 6 | * 7 | * @deprecated - Since version 2.1.2 - To be removed in future versions. 8 | * Should use Payments client instead 9 | * @export 10 | * @class Fawry 11 | */ 12 | export default class Fawry { 13 | constructor(config) { 14 | this.config = config; 15 | } 16 | 17 | /** 18 | * Approve Fawry payment 19 | * 20 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 21 | * @param {string} reference Reference. 22 | * @memberof Fawry 23 | * @return {Promise} A promise to the Fawry response. 24 | */ 25 | async approve(reference) { 26 | try { 27 | const response = await put( 28 | this.config.httpClient, 29 | `${this.config.host}/fawry/payments/${reference}/approval`, 30 | this.config, 31 | this.config.sk 32 | ); 33 | return await response.json; 34 | } catch (err) { 35 | const error = await determineError(err); 36 | throw error; 37 | } 38 | } 39 | 40 | /** 41 | * Cancel Fawry payment 42 | * 43 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 44 | * @param {string} reference Reference. 45 | * @memberof Fawry 46 | * @return {Promise} A promise to the Fawry response. 47 | */ 48 | async cancel(reference) { 49 | try { 50 | const response = await put( 51 | this.config.httpClient, 52 | `${this.config.host}/fawry/payments/${reference}/cancellation`, 53 | this.config, 54 | this.config.sk 55 | ); 56 | return await response.json; 57 | } catch (err) { 58 | const error = await determineError(err); 59 | throw error; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/api/apm-specific/giropay.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { get } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /giropay endpoint 6 | * 7 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 8 | * @export 9 | * @class Giropay 10 | */ 11 | export default class Giropay { 12 | constructor(config) { 13 | this.config = config; 14 | } 15 | 16 | /** 17 | * Get Giropay EPS banks 18 | * 19 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 20 | * @memberof Giropay 21 | * @return {Promise} A promise to the banks response. 22 | */ 23 | async getEpsBanks() { 24 | try { 25 | const response = await get( 26 | this.config.httpClient, 27 | `${this.config.host}/giropay/eps/banks`, 28 | this.config, 29 | this.config.sk 30 | ); 31 | return await response.json; 32 | } catch (err) { 33 | const error = await determineError(err); 34 | throw error; 35 | } 36 | } 37 | 38 | /** 39 | * Get Giropay banks 40 | * 41 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 42 | * @memberof Giropay 43 | * @return {Promise} A promise to the banks response. 44 | */ 45 | async getBanks() { 46 | try { 47 | const response = await get( 48 | this.config.httpClient, 49 | `${this.config.host}/giropay/banks`, 50 | this.config, 51 | this.config.sk 52 | ); 53 | return await response.json; 54 | } catch (err) { 55 | const error = await determineError(err); 56 | throw error; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/api/apm-specific/ideal.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { get } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /ideal-external endpoint 6 | * 7 | * @export 8 | * @class Ideal 9 | */ 10 | export default class Ideal { 11 | constructor(config) { 12 | this.config = config; 13 | } 14 | 15 | /** 16 | * Get Ideal details 17 | * 18 | * @memberof Ideal 19 | * @return {Promise} A promise to the iDeal response. 20 | */ 21 | async get() { 22 | try { 23 | const response = await get( 24 | this.config.httpClient, 25 | `${this.config.host}/ideal-external`, 26 | this.config, 27 | this.config.sk 28 | ); 29 | return await response.json; 30 | } catch (err) { 31 | const error = await determineError(err); 32 | throw error; 33 | } 34 | } 35 | 36 | /** 37 | * Get Ideal issuers 38 | * 39 | * @memberof Ideal 40 | * @return {Promise} A promise to the iDeal response. 41 | */ 42 | async getIssuers() { 43 | try { 44 | const response = await get( 45 | this.config.httpClient, 46 | `${this.config.host}/ideal-external/issuers`, 47 | this.config, 48 | this.config.sk 49 | ); 50 | return await response.json; 51 | } catch (err) { 52 | const error = await determineError(err); 53 | throw error; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/api/apm-specific/klarna.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { get, post } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /klarna and /klarna-external endpoint 6 | * 7 | * @export 8 | * @class Klarna 9 | */ 10 | export default class Klarna { 11 | constructor(config) { 12 | this.config = config; 13 | } 14 | 15 | /** 16 | * Create a session 17 | * 18 | * @param {Object} body Sessions details. 19 | * @return {Promise} A promise to the Klarna response. 20 | */ 21 | async createSession(body) { 22 | const url = this.config.host.includes('sandbox') 23 | ? `${this.config.host}/klarna-external/credit-sessions` 24 | : `${this.config.host}/klarna/credit-sessions`; 25 | try { 26 | const response = await post( 27 | this.config.httpClient, 28 | url, 29 | this.config, 30 | this.config.sk, 31 | body 32 | ); 33 | return await response.json; 34 | } catch (err) { 35 | const error = await determineError(err); 36 | throw error; 37 | } 38 | } 39 | 40 | /** 41 | * Get a session 42 | * 43 | * @param {string} id Session id. 44 | * @return {Promise} A promise to the Klarna response. 45 | */ 46 | async getSession(id) { 47 | const url = this.config.host.includes('sandbox') 48 | ? `${this.config.host}/klarna-external/credit-sessions/${id}` 49 | : `${this.config.host}/klarna/credit-sessions/${id}`; 50 | try { 51 | const response = await get( 52 | this.config.httpClient, 53 | url, 54 | this.config, 55 | this.config.sk 56 | ); 57 | return await response.json; 58 | } catch (err) { 59 | const error = await determineError(err); 60 | throw error; 61 | } 62 | } 63 | 64 | /** 65 | * Capture a klarna payment 66 | * 67 | * @param {string} id Payment id. 68 | * @param {Object} body Capture details. 69 | * @return {Promise} A promise to the Klarna response. 70 | */ 71 | async capture(id, body) { 72 | const url = this.config.host.includes('sandbox') 73 | ? `${this.config.host}/klarna-external/orders/${id}/captures` 74 | : `${this.config.host}/klarna/orders/${id}/captures`; 75 | try { 76 | const response = await post( 77 | this.config.httpClient, 78 | url, 79 | this.config, 80 | this.config.sk, 81 | body 82 | ); 83 | return await response.json; 84 | } catch (err) { 85 | const error = await determineError(err); 86 | throw error; 87 | } 88 | } 89 | 90 | /** 91 | * Void a klarna payment 92 | * 93 | * @param {string} id Payment id. 94 | * @param {Object} [body] Void details. 95 | * @return {Promise} A promise to the Klarna response. 96 | */ 97 | async void(id, body) { 98 | const url = this.config.host.includes('sandbox') 99 | ? `${this.config.host}/klarna-external/orders/${id}/voids` 100 | : `${this.config.host}/klarna/orders/${id}/voids`; 101 | try { 102 | const response = await post( 103 | this.config.httpClient, 104 | url, 105 | this.config, 106 | this.config.sk, 107 | body 108 | ); 109 | return await response.json; 110 | } catch (err) { 111 | const error = await determineError(err); 112 | throw error; 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/api/apm-specific/oxxo.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { post } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /apms/oxxo endpoint 6 | * 7 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 8 | * @export 9 | * @class Oxxo 10 | */ 11 | export default class Oxxo { 12 | constructor(config) { 13 | this.config = config; 14 | } 15 | 16 | /** 17 | * Succeed a Oxxo payment 18 | * 19 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 20 | * @param {string} id Payment id. 21 | * @memberof Oxxo 22 | * @return {Promise} A promise to the Oxxo response. 23 | */ 24 | async succeed(id) { 25 | try { 26 | const response = await post( 27 | this.config.httpClient, 28 | `${this.config.host}/apms/oxxo/payments/${id}/succeed`, 29 | this.config, 30 | this.config.sk 31 | ); 32 | return await response.json; 33 | } catch (err) { 34 | const error = await determineError(err); 35 | throw error; 36 | } 37 | } 38 | 39 | /** 40 | * Cancel Oxxo payment 41 | * 42 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 43 | * @param {string} id Payment id. 44 | * @memberof Oxxo 45 | * @return {Promise} A promise to the Oxxo response. 46 | */ 47 | async expire(id) { 48 | try { 49 | const response = await post( 50 | this.config.httpClient, 51 | `${this.config.host}/apms/oxxo/payments/${id}/expire`, 52 | this.config, 53 | this.config.sk 54 | ); 55 | return await response.json; 56 | } catch (err) { 57 | const error = await determineError(err); 58 | throw error; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/api/apm-specific/pagofacil.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { post } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /apms/pagofacil endpoint 6 | * 7 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 8 | * @export 9 | * @class PagoFacil 10 | */ 11 | export default class PagoFacil { 12 | constructor(config) { 13 | this.config = config; 14 | } 15 | 16 | /** 17 | * Succeed a PagoFacil payment 18 | * 19 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 20 | * @param {string} id Payment id. 21 | * @memberof PagoFacil 22 | * @return {Promise} A promise to the PagoFacil response. 23 | */ 24 | async succeed(id) { 25 | try { 26 | const response = await post( 27 | this.config.httpClient, 28 | `${this.config.host}/apms/pagofacil/payments/${id}/succeed`, 29 | this.config, 30 | this.config.sk 31 | ); 32 | return await response.json; 33 | } catch (err) { 34 | const error = await determineError(err); 35 | throw error; 36 | } 37 | } 38 | 39 | /** 40 | * Cancel PagoFacil payment 41 | * 42 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 43 | * @param {string} id Payment id. 44 | * @memberof PagoFacil 45 | * @return {Promise} A promise to the PagoFacil response. 46 | */ 47 | async expire(id) { 48 | try { 49 | const response = await post( 50 | this.config.httpClient, 51 | `${this.config.host}/apms/pagofacil/payments/${id}/expire`, 52 | this.config, 53 | this.config.sk 54 | ); 55 | return await response.json; 56 | } catch (err) { 57 | const error = await determineError(err); 58 | throw error; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/api/apm-specific/rapipago.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { post } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /apms/rapipago endpoint 6 | * 7 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 8 | * @export 9 | * @class Rapipago 10 | */ 11 | export default class Rapipago { 12 | constructor(config) { 13 | this.config = config; 14 | } 15 | 16 | /** 17 | * Succeed a Rapipago payment 18 | * 19 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 20 | * @param {string} id Payment id. 21 | * @memberof Rapipago 22 | * @return {Promise} A promise to the Rapipago response. 23 | */ 24 | async succeed(id) { 25 | try { 26 | const response = await post( 27 | this.config.httpClient, 28 | `${this.config.host}/apms/rapipago/payments/${id}/succeed`, 29 | this.config, 30 | this.config.sk 31 | ); 32 | return await response.json; 33 | } catch (err) { 34 | const error = await determineError(err); 35 | throw error; 36 | } 37 | } 38 | 39 | /** 40 | * Cancel Rapipago payment 41 | * 42 | * @deprecated - Since version 2.1.2 - Should use Payments client instead 43 | * @param {string} id Payment id. 44 | * @memberof Rapipago 45 | * @return {Promise} A promise to the Rapipago response. 46 | */ 47 | async expire(id) { 48 | try { 49 | const response = await post( 50 | this.config.httpClient, 51 | `${this.config.host}/apms/rapipago/payments/${id}/expire`, 52 | this.config, 53 | this.config.sk 54 | ); 55 | return await response.json; 56 | } catch (err) { 57 | const error = await determineError(err); 58 | throw error; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/api/apm-specific/sepa.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { get, post } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /sepa and /ppro/sepa endpoint 6 | * 7 | * @export 8 | * @class Sepa 9 | */ 10 | export default class Sepa { 11 | constructor(config) { 12 | this.config = config; 13 | } 14 | 15 | /** 16 | * Get mandate 17 | * 18 | * @param {string} id Source id 19 | * @return {Promise} A promise to the Sepa response. 20 | */ 21 | async getMandate(id) { 22 | const url = this.config.host.includes('sandbox') 23 | ? `${this.config.host}/sepa-external/mandates/${id}` 24 | : `${this.config.host}/sepa/mandates/${id}`; 25 | try { 26 | const response = await get( 27 | this.config.httpClient, 28 | url, 29 | this.config, 30 | this.config.sk 31 | ); 32 | return await response.json; 33 | } catch (err) { 34 | const error = await determineError(err); 35 | throw error; 36 | } 37 | } 38 | 39 | /** 40 | * Cancel mandate 41 | * 42 | * @param {string} id Source id 43 | * @return {Promise} A promise to the Sepa response. 44 | */ 45 | async cancelMandate(id) { 46 | const url = this.config.host.includes('sandbox') 47 | ? `${this.config.host}/sepa-external/mandates/${id}/cancel` 48 | : `${this.config.host}/sepa/mandates/${id}/cancel`; 49 | 50 | try { 51 | const response = await post( 52 | this.config.httpClient, 53 | url, 54 | this.config, 55 | this.config.sk 56 | ); 57 | return await response.json; 58 | } catch (err) { 59 | const error = await determineError(err); 60 | throw error; 61 | } 62 | } 63 | 64 | /** 65 | * Get mandate via PPRO 66 | * 67 | * @param {string} id Source id 68 | * @return {Promise} A promise to the Sepa response. 69 | */ 70 | async getPPROMandate(id) { 71 | const url = this.config.host.includes('sandbox') 72 | ? `${this.config.host}/ppro/sepa-external/mandates/${id}` 73 | : `${this.config.host}/ppro/sepa/mandates/${id}`; 74 | try { 75 | const response = await get( 76 | this.config.httpClient, 77 | url, 78 | this.config, 79 | this.config.sk 80 | ); 81 | return await response.json; 82 | } catch (err) { 83 | const error = await determineError(err); 84 | throw error; 85 | } 86 | } 87 | 88 | /** 89 | * Cancel mandate via PPRO 90 | * 91 | * @param {string} id Source id 92 | * @return {Promise} A promise to the Sepa response. 93 | */ 94 | async cancelPPROMandate(id) { 95 | const url = this.config.host.includes('sandbox') 96 | ? `${this.config.host}/ppro/sepa-external/mandates/${id}/cancel` 97 | : `${this.config.host}/ppro/sepa/mandates/${id}/cancel`; 98 | 99 | try { 100 | const response = await post( 101 | this.config.httpClient, 102 | url, 103 | this.config, 104 | this.config.sk 105 | ); 106 | return await response.json; 107 | } catch (err) { 108 | const error = await determineError(err); 109 | throw error; 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/api/apple-pay/apple-pay.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { post } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the Apple Pay api 6 | * 7 | * @export 8 | * @class Apple Pay 9 | */ 10 | export default class ApplePay { 11 | constructor(config) { 12 | this.config = config; 13 | } 14 | 15 | /** 16 | * Request an access token 17 | * 18 | * @param {Object} body Apple Pay object body. 19 | * @return {Promise} A promise to the Apple Pay response. 20 | */ 21 | async upload(body) { 22 | try { 23 | const response = await post( 24 | this.config.httpClient, 25 | `${this.config.host}/applepay/certificates`, 26 | this.config, 27 | this.config.pk, 28 | body 29 | ); 30 | return await response.json; 31 | } catch (err) { 32 | const error = await determineError(err); 33 | throw error; 34 | } 35 | } 36 | 37 | /** 38 | * Generate a certificate signing request 39 | * 40 | * @return {Promise} A promise to the Apple Pay response. 41 | */ 42 | async generate() { 43 | try { 44 | const response = await post( 45 | this.config.httpClient, 46 | `${this.config.host}/applepay/signing-requests`, 47 | this.config, 48 | this.config.pk 49 | ); 50 | return await response.json; 51 | } catch (err) { 52 | const error = await determineError(err); 53 | throw error; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/api/balances/balances.js: -------------------------------------------------------------------------------- 1 | import { 2 | BALANCES_LIVE_URL, 3 | BALANCES_SANDBOX_URL 4 | } from '../../config'; 5 | import { determineError } from '../../services/errors'; 6 | import { get } from '../../services/http'; 7 | 8 | /** 9 | * Class dealing with the /balances endpoint 10 | * 11 | * @export 12 | * @class Balances 13 | */ 14 | export default class Balances { 15 | constructor(config) { 16 | this.config = config; 17 | } 18 | 19 | /** 20 | * Use this endpoint to retrieve balances for each currency account belonging to an entity. 21 | * 22 | * @memberof Balances 23 | * @param {string} id The ID of the entity. 24 | * @param {string} currency The query to apply to limit the currency accounts. 25 | * @return {Promise} A promise to the balances response. 26 | */ 27 | async retrieve(id, currency) { 28 | try { 29 | const url = `${ 30 | this.config.host.includes('sandbox') ? BALANCES_SANDBOX_URL : BALANCES_LIVE_URL 31 | }/${id}${currency ? `?query=currency:${currency}` : ''}`; 32 | const response = await get( 33 | this.config.httpClient, 34 | url, 35 | this.config, 36 | this.config.sk 37 | ); 38 | return await response.json; 39 | } catch (err) { 40 | const error = await determineError(err); 41 | throw error; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/api/card-metadata/card-metadata.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { post } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /metadata/card endpoint 6 | * 7 | * @export 8 | * @class CardMetadata 9 | */ 10 | export default class CardMetadata { 11 | constructor(config) { 12 | this.config = config; 13 | } 14 | 15 | /** 16 | * Returns a single metadata record for the card specified by the Primary Account Number (PAN), 17 | * Bank Identification Number (BIN), token, or instrument supplied. 18 | * 19 | * @param {Object} body Card Metadata request body. 20 | * @return {Promise} A promise to the add Card Metadata response. 21 | */ 22 | async get(body) { 23 | try { 24 | const response = await post( 25 | this.config.httpClient, 26 | `${this.config.host}/metadata/card`, 27 | this.config, 28 | this.config.sk, 29 | body 30 | ); 31 | return await response.json; 32 | } catch (err) { 33 | const error = await determineError(err); 34 | throw error; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/api/customers/customers.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { _delete, get, patch, post } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /customers endpoint 6 | * 7 | * @export 8 | * @class Customers 9 | */ 10 | export default class Customers { 11 | constructor(config) { 12 | this.config = config; 13 | } 14 | 15 | /** 16 | * Create a customer 17 | * 18 | * @memberof Customers 19 | * @param {Object} customer Customer object body. 20 | * @return {Promise} A promise to the create customer response. 21 | */ 22 | async create(customer) { 23 | try { 24 | const response = await post( 25 | this.config.httpClient, 26 | `${this.config.host}/customers`, 27 | this.config, 28 | this.config.sk, 29 | customer 30 | ); 31 | return await response.json; 32 | } catch (err) { 33 | const error = await determineError(err); 34 | throw error; 35 | } 36 | } 37 | 38 | /** 39 | * Get a customer 40 | * 41 | * @memberof Customers 42 | * @param {string} id Customer id. 43 | * @return {Promise} A promise to the customer details response. 44 | */ 45 | async get(id) { 46 | try { 47 | const response = await get( 48 | this.config.httpClient, 49 | `${this.config.host}/customers/${id}`, 50 | this.config, 51 | this.config.sk 52 | ); 53 | return await response.json; 54 | } catch (err) { 55 | const error = await determineError(err); 56 | throw error; 57 | } 58 | } 59 | 60 | /** 61 | * Update details of a customer 62 | * 63 | * @memberof Customers 64 | * @param {string} id Customer id. 65 | * @param {Object} body Customer object body. 66 | * @return {Promise} A promise to the request customer response. 67 | */ 68 | async update(id, body) { 69 | try { 70 | const response = await patch( 71 | this.config.httpClient, 72 | `${this.config.host}/customers/${id}`, 73 | this.config, 74 | this.config.sk, 75 | body 76 | ); 77 | return await response.json; 78 | } catch (err) { 79 | const error = await determineError(err); 80 | throw error; 81 | } 82 | } 83 | 84 | /** 85 | * Delete a customer 86 | * 87 | * @memberof Customers 88 | * @param {string} id Customer id. 89 | * @return {Promise} A promise to the customer response. 90 | */ 91 | async delete(id) { 92 | try { 93 | const response = await _delete( 94 | this.config.httpClient, 95 | `${this.config.host}/customers/${id}`, 96 | this.config, 97 | this.config.sk 98 | ); 99 | 100 | return await response.json; 101 | } catch (err) { 102 | const error = await determineError(err); 103 | throw error; 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/api/events/events.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { get, post } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /events endpoint 6 | * 7 | * @export 8 | * @class Events 9 | */ 10 | export default class Events { 11 | constructor(config) { 12 | this.config = config; 13 | } 14 | 15 | /** 16 | * Retrieve a list of event types grouped by their respective version that you can 17 | * configure on your webhooks. 18 | * 19 | * @memberof Events 20 | * @param {string} version Events Version. 21 | * @return {Promise} A promise to the request events response. 22 | */ 23 | async retrieveEventTypes(version) { 24 | try { 25 | let url = `${this.config.host}/event-types`; 26 | if (version) { 27 | url += `?version=${version}`; 28 | } 29 | const response = await get( 30 | this.config.httpClient, 31 | url, 32 | this.config, 33 | this.config.sk 34 | ); 35 | return await response.json; 36 | } catch (err) { 37 | const error = await determineError(err); 38 | throw error; 39 | } 40 | } 41 | 42 | /** 43 | * Retrieves events ordered by the event date in descending order (latest first). 44 | * Results can be paged by specifying the skip and limit query parameters. 45 | * 46 | * @memberof Events 47 | * @param {Object} body Events request body. 48 | * @return {Promise} A promise to the request events response. 49 | */ 50 | async retrieveEvents(body) { 51 | try { 52 | let url = `${this.config.host}/events`; 53 | 54 | if (body) { 55 | const queryString = Object.keys(body) 56 | .map((key) => `${key}=${body[key]}`) 57 | .join('&'); 58 | url += `?${queryString}`; 59 | } 60 | 61 | const response = await get(this.config.httpClient, url, this.config, this.config.sk); 62 | return await response.json; 63 | } catch (err) { 64 | const error = await determineError(err); 65 | throw error; 66 | } 67 | } 68 | 69 | /** 70 | * Retrieves the event with the specified identifier string. The event data includes the full event 71 | * details, the schema of which will vary based on the type. 72 | * 73 | * @memberof Events 74 | * @param {string} eventId Event id. 75 | * @return {Promise} A promise to the request event response. 76 | */ 77 | async retrieveEvent(eventId) { 78 | try { 79 | const response = await get( 80 | this.config.httpClient, 81 | `${this.config.host}/events/${eventId}`, 82 | this.config, 83 | this.config.sk 84 | ); 85 | return await response.json; 86 | } catch (err) { 87 | const error = await determineError(err); 88 | throw error; 89 | } 90 | } 91 | 92 | /** 93 | * Retrieves the attempts for a specific event notification 94 | * 95 | * @memberof Events 96 | * @param {Object} body Event request body. 97 | * @return {Promise} A promise to the request event notifications response. 98 | */ 99 | async retrieveEventNotification(body) { 100 | try { 101 | const response = await get( 102 | this.config.httpClient, 103 | `${this.config.host}/events/${body.eventId}/notifications/${body.notificationId}`, 104 | this.config, 105 | this.config.sk 106 | ); 107 | return await response.json; 108 | } catch (err) { 109 | const error = await determineError(err); 110 | throw error; 111 | } 112 | } 113 | 114 | /** 115 | * Retries a specific webhook notification for the given event 116 | * 117 | * @memberof Events 118 | * @param {Object} body Event request body. 119 | * @return {Promise} A promise to the retry event response. 120 | */ 121 | async retry(body) { 122 | try { 123 | const response = await post( 124 | this.config.httpClient, 125 | `${this.config.host}/events/${body.eventId}/webhooks/${body.webhookId}/retry`, 126 | this.config, 127 | this.config.sk 128 | ); 129 | return await response.json; 130 | } catch (err) { 131 | const error = await determineError(err); 132 | throw error; 133 | } 134 | } 135 | 136 | /** 137 | * Retries all webhook notifications configured for the specified event 138 | * 139 | * @memberof Events 140 | * @param {string} eventId Event id. 141 | * @return {Promise} A promise to the retry events response. 142 | */ 143 | async retryAll(eventId) { 144 | try { 145 | const response = await post( 146 | this.config.httpClient, 147 | `${this.config.host}/events/${eventId}/webhooks/retry`, 148 | this.config, 149 | this.config.sk 150 | ); 151 | return await response.json; 152 | } catch (err) { 153 | const error = await determineError(err); 154 | throw error; 155 | } 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /src/api/files/files.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { get, post } from '../../services/http'; 3 | 4 | import FormData from 'form-data'; 5 | 6 | /** 7 | * Class dealing with the /files endpoint 8 | * 9 | * @export 10 | * @class Files 11 | */ 12 | export default class Files { 13 | constructor(config) { 14 | this.config = config; 15 | } 16 | 17 | /** 18 | * Upload a file to use as evidence in a dispute. Your file must be in either JPEG/JPG, 19 | * PNG or PDF format, and be no larger than 4MB. 20 | * 21 | * @memberof Files 22 | * @param {Object} body Files request body. 23 | * @return {Promise} A promise to the files response. 24 | */ 25 | async upload(body) { 26 | try { 27 | const form = new FormData(); 28 | 29 | // Handle local files and remote files 30 | if (isUrl(body.file)) { 31 | // use file and file name from remote 32 | form.append('file', body.file, { 33 | filename: body.file.split('/').pop().split('#')[0].split('?')[0], 34 | }); 35 | } else { 36 | // use the local file 37 | form.append('file', body.file || body.path); 38 | } 39 | form.append('purpose', 'dispute_evidence'); 40 | 41 | const response = await post( 42 | this.config.httpClient, 43 | `${this.config.host}/files`, 44 | { ...this.config, formData: true }, 45 | this.config.sk, 46 | form 47 | ); 48 | return await response.json; 49 | } catch (err) { 50 | const error = await determineError(err); 51 | throw error; 52 | } 53 | } 54 | 55 | /** 56 | * Retrieve information about a file that was previously uploaded. 57 | * 58 | * @memberof Files 59 | * @param {string} fileId Files id. 60 | * @return {Promise} A promise to the files response. 61 | */ 62 | async getFile(fileId) { 63 | try { 64 | const response = await get( 65 | this.config.httpClient, 66 | `${this.config.host}/files/${fileId}`, 67 | this.config, 68 | this.config.sk 69 | ); 70 | return await response.json; 71 | } catch (err) { 72 | const error = await determineError(err); 73 | throw error; 74 | } 75 | } 76 | } 77 | 78 | const isUrl = (string) => { 79 | let url; 80 | 81 | try { 82 | url = new URL(string); 83 | } catch (_) { 84 | return false; 85 | } 86 | 87 | return url.protocol === 'http:' || url.protocol === 'https:'; 88 | }; 89 | -------------------------------------------------------------------------------- /src/api/financial/financial.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { get } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /financial-actions api endpoint 6 | * 7 | * @export 8 | * @class Financial 9 | */ 10 | export default class Financial { 11 | constructor(config) { 12 | this.config = config; 13 | } 14 | 15 | /** 16 | * Returns the list of financial actions and their details. 17 | * 18 | * @memberof Financial 19 | * @param {Object} parameters Parameters. 20 | * @return {Promise} A promise to the Financial Actions response. 21 | */ 22 | async query(parameters) { 23 | try { 24 | let url = `${this.config.host}/financial-actions`; 25 | 26 | if (parameters) { 27 | const queryString = Object.keys(parameters) 28 | .map((key) => `${key}=${parameters[key]}`) 29 | .join('&'); 30 | url += `?${queryString}`; 31 | } 32 | 33 | const response = await get( 34 | this.config.httpClient, 35 | url, 36 | this.config, 37 | this.config.sk 38 | ); 39 | return await response.json; 40 | } catch (err) { 41 | const error = await determineError(err); 42 | throw error; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/api/forex/forex.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { get, post } from '../../services/http'; 3 | import { buildQueryParams } from '../../services/utils'; 4 | 5 | /** 6 | * Class dealing with the forex api 7 | * 8 | * @export 9 | * @class Forex 10 | */ 11 | export default class Forex { 12 | constructor(config) { 13 | this.config = config; 14 | } 15 | 16 | /** 17 | * Request an exchange rate between a source and destination currency 18 | * 19 | * @param {Object} body Forex object body. 20 | * @return {Promise} A promise to the Forex response. 21 | */ 22 | async request(body) { 23 | try { 24 | const response = await post( 25 | this.config.httpClient, 26 | `${this.config.host}/forex/quotes`, 27 | this.config, 28 | this.config.sk, 29 | body 30 | ); 31 | return await response.json; 32 | } catch (err) { 33 | throw await determineError(err); 34 | } 35 | } 36 | 37 | /** 38 | * Use the Forex (FX) rates API to get the indicative foreign exchange rates that Checkout.com 39 | * uses to process payments for card payouts 40 | * 41 | * @param {Object} body Forex params. 42 | * @return {Promise} A promise to the Forex response. 43 | */ 44 | async getRates(body) { 45 | try { 46 | const url = buildQueryParams(`${this.config.host}/forex/rates`, body); 47 | 48 | const response = await get( 49 | this.config.httpClient, 50 | url, 51 | this.config, 52 | this.config.sk 53 | ); 54 | return await response.json; 55 | } catch (err) { 56 | throw await determineError(err); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/api/hosted-payments/hosted-payments.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { get, post } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /hosted-payments endpoint 6 | * 7 | * @export 8 | * @class HostedPayments 9 | */ 10 | export default class HostedPayments { 11 | constructor(config) { 12 | this.config = config; 13 | } 14 | 15 | /** 16 | * Update details of a customer 17 | * 18 | * @memberof HostedPayments 19 | * @param {Object} body 20 | * @return {Promise} A promise to the Hosted Payment response. 21 | */ 22 | async create(body) { 23 | try { 24 | const response = await post( 25 | this.config.httpClient, 26 | `${this.config.host}/hosted-payments`, 27 | this.config, 28 | this.config.sk, 29 | body 30 | ); 31 | return await response.json; 32 | } catch (err) { 33 | const error = await determineError(err); 34 | throw error; 35 | } 36 | } 37 | 38 | /** 39 | * Returns details of an instrument 40 | * 41 | * @memberof HostedPayments 42 | * @param {string} id Hosted payment id. 43 | * @return {Promise} A promise to the Hosted Payment response. 44 | */ 45 | async get(id) { 46 | try { 47 | const response = await get( 48 | this.config.httpClient, 49 | `${this.config.host}/hosted-payments/${id}`, 50 | this.config, 51 | this.config.sk 52 | ); 53 | return await response.json; 54 | } catch (err) { 55 | const error = await determineError(err); 56 | throw error; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/api/instruments/instruments.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { _delete, get, patch, post } from '../../services/http'; 3 | import { setInstrumentType } from '../../services/validation'; 4 | 5 | /** 6 | * Class dealing with the /instruments endpoint 7 | * 8 | * @export 9 | * @class Instruments 10 | */ 11 | export default class Instruments { 12 | constructor(config) { 13 | this.config = config; 14 | } 15 | 16 | /** 17 | * Exchange a single use Checkout.com token for a payment instrument reference, 18 | * that can be used at any time to request one or more payments. 19 | * 20 | * @memberof Instruments 21 | * @param {Object} body Instruments request body. 22 | * @return {Promise} A promise to the request instruments response. 23 | */ 24 | async create(body) { 25 | setInstrumentType(body); 26 | try { 27 | const response = await post( 28 | this.config.httpClient, 29 | `${this.config.host}/instruments`, 30 | this.config, 31 | this.config.sk, 32 | body 33 | ); 34 | return await response.json; 35 | } catch (err) { 36 | const error = await determineError(err); 37 | throw error; 38 | } 39 | } 40 | 41 | /** 42 | * Returns details of an instrument 43 | * 44 | * @memberof Instruments 45 | * @param {string} id Instrument id. 46 | * @return {Promise} A promise to the instrument response. 47 | */ 48 | async get(id) { 49 | try { 50 | const response = await get( 51 | this.config.httpClient, 52 | `${this.config.host}/instruments/${id}`, 53 | this.config, 54 | this.config.sk 55 | ); 56 | return await response.json; 57 | } catch (err) { 58 | const error = await determineError(err); 59 | throw error; 60 | } 61 | } 62 | 63 | /** 64 | * Update details of an instrument 65 | * 66 | * @memberof Instruments 67 | * @param {string} id Instrument id. 68 | * @param {Object} body Instruments request body. 69 | * @return {Promise} A promise to the instrument response. 70 | */ 71 | async update(id, body) { 72 | try { 73 | const response = await patch( 74 | this.config.httpClient, 75 | `${this.config.host}/instruments/${id}`, 76 | this.config, 77 | this.config.sk, 78 | body 79 | ); 80 | return await response.json; 81 | } catch (err) { 82 | const error = await determineError(err); 83 | throw error; 84 | } 85 | } 86 | 87 | /** 88 | * Delete a payment instrument. 89 | * 90 | * @memberof Instruments 91 | * @param {string} id Instrument id. 92 | * @return {Promise} A promise to the instrument response. 93 | */ 94 | async delete(id) { 95 | try { 96 | const response = await _delete( 97 | this.config.httpClient, 98 | `${this.config.host}/instruments/${id}`, 99 | this.config, 100 | this.config.sk 101 | ); 102 | return await response.json; 103 | } catch (err) { 104 | const error = await determineError(err); 105 | throw error; 106 | } 107 | } 108 | 109 | /** 110 | * Delete a payment instrument. 111 | * 112 | * @memberof Instruments 113 | * @param {string} country Country 2 character ISO. 114 | * @param {string} currency Currency 3 character ISO. 115 | * @return {Promise} A promise to the instrument response. 116 | */ 117 | async getBankAccountFieldFormatting(country, currency) { 118 | try { 119 | const response = await get( 120 | this.config.httpClient, 121 | `${this.config.host}/validation/bank-accounts/${country}/${currency}`, 122 | this.config, 123 | this.config.sk 124 | ); 125 | return await response.json; 126 | } catch (err) { 127 | const error = await determineError(err); 128 | throw error; 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/api/payment-contexts/payment-contexts.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { get, post } from '../../services/http'; 3 | import { validatePayment } from '../../services/validation'; 4 | 5 | /* 6 | * Class dealing with the /payment-contexts endpoint 7 | * 8 | * @export 9 | * @class PaymentContexts 10 | */ 11 | export default class PaymentContexts { 12 | constructor(config) { 13 | this.config = config; 14 | } 15 | 16 | /** 17 | * Sends payment contexts requests. 18 | * 19 | * @memberof PaymentContexts 20 | * @param {object} body PaymentContexts Request body. 21 | * @return {Promise} A promise to payment context response. 22 | */ 23 | async request(body) { 24 | try { 25 | validatePayment(body); 26 | 27 | const response = await post( 28 | this.config.httpClient, 29 | `${this.config.host}/payment-contexts`, 30 | this.config, 31 | this.config.sk, 32 | body 33 | ); 34 | return await response.json; 35 | } catch (error) { 36 | throw await determineError(error); 37 | } 38 | } 39 | 40 | /** 41 | * Returns a payment-context details with the specified identifier string. 42 | * 43 | * @memberof PaymentContexts 44 | * @param {string} id /^(pay|sid)_(\w{26})$/ The payment or payment session identifier. 45 | * @return {Promise} A promise to the get payment context response. 46 | */ 47 | async get(id) { 48 | try { 49 | const response = await get( 50 | this.config.httpClient, 51 | `${this.config.host}/payment-contexts/${id}`, 52 | this.config, 53 | this.config.sk 54 | ); 55 | return await response.json; 56 | } catch (error) { 57 | throw await determineError(error); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/api/payment-sessions/payment-sessions.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { post } from '../../services/http'; 3 | import { validatePayment } from '../../services/validation'; 4 | 5 | /** 6 | * Class dealing with the /payment-sessions endpoint 7 | * 8 | * @export 9 | * @class PaymentSessions 10 | */ 11 | export default class PaymentSessions { 12 | constructor(config) { 13 | this.config = config; 14 | } 15 | 16 | /** 17 | * Creates a payment session. 18 | * 19 | * @memberof PaymentSessions 20 | * @param {object} body PaymentSessions Request body. 21 | * @return {Promise} A promise to payment context response. 22 | */ 23 | async request(body) { 24 | try { 25 | validatePayment(body); 26 | 27 | const response = await post( 28 | this.config.httpClient, 29 | `${this.config.host}/payment-sessions`, 30 | this.config, 31 | this.config.sk, 32 | body 33 | ); 34 | return await response.json; 35 | } catch (error) { 36 | throw await determineError(error); 37 | } 38 | } 39 | 40 | /** 41 | * Submit a payment attempt for a payment session. 42 | * 43 | * @memberof PaymentSessions 44 | * @param {string} id The payment session ID. 45 | * @param {object} body PaymentSessions Request body. 46 | * @return {Promise} A promise to payment context response. 47 | */ 48 | async submit(id, body) { 49 | try { 50 | const response = await post( 51 | this.config.httpClient, 52 | `${this.config.host}/payment-sessions/${id}/submit`, 53 | this.config, 54 | this.config.sk, 55 | body 56 | ); 57 | return await response.json; 58 | } catch (error) { 59 | throw await determineError(error); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/api/payments-links/payments-links.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { get, post } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /payment-links endpoint 6 | * 7 | * @export 8 | * @class PaymentLinks 9 | */ 10 | export default class PaymentLinks { 11 | constructor(config) { 12 | this.config = config; 13 | } 14 | 15 | /** 16 | * Create a Payment Link and pass through all the payment information, like the amount, currency, country and reference. 17 | * 18 | * @memberof PaymentLinks 19 | * @param {Object} body 20 | * @return {Promise} A promise to the Payment Link response. 21 | */ 22 | async create(body) { 23 | try { 24 | const response = await post( 25 | this.config.httpClient, 26 | `${this.config.host}/payment-links`, 27 | this.config, 28 | this.config.sk, 29 | body 30 | ); 31 | return await response.json; 32 | } catch (err) { 33 | const error = await determineError(err); 34 | throw error; 35 | } 36 | } 37 | 38 | /** 39 | * Retrieve details about a specific Payment Link using its ID returned when the link was created. In the response, you will see the status of the Payment Link. 40 | * 41 | * @memberof PaymentLinks 42 | * @param {string} id 43 | * @return {Promise} A promise to the Payment Link response. 44 | */ 45 | async get(id) { 46 | try { 47 | const response = await get( 48 | this.config.httpClient, 49 | `${this.config.host}/payment-links/${id}`, 50 | this.config, 51 | this.config.sk 52 | ); 53 | return await response.json; 54 | } catch (err) { 55 | const error = await determineError(err); 56 | throw error; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/api/reports/reports.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { get } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /reports api endpoint 6 | * 7 | * @export 8 | * @class Reports 9 | */ 10 | export default class Reports { 11 | constructor(config) { 12 | this.config = config; 13 | } 14 | 15 | /** 16 | * Returns the list of reports and their details. 17 | * 18 | * @memberof Reports 19 | * @param {Object} parameters Parameters. 20 | * @return {Promise} A promise to the Reports response. 21 | */ 22 | async getAllReports(parameters) { 23 | try { 24 | let url = `${this.config.host}/reports`; 25 | 26 | if (parameters) { 27 | const queryString = Object.keys(parameters) 28 | .map((key) => `${key}=${parameters[key]}`) 29 | .join('&'); 30 | url += `?${queryString}`; 31 | } 32 | 33 | const response = await get( 34 | this.config.httpClient, 35 | url, 36 | this.config, 37 | this.config.sk 38 | ); 39 | return await response.json; 40 | } catch (err) { 41 | const error = await determineError(err); 42 | throw error; 43 | } 44 | } 45 | 46 | /** 47 | * Use this endpoint to retrieve a specific report using its ID. 48 | * 49 | * @memberof Reports 50 | * @param {string} id The ID of the report to retrieve. 51 | * @return {Promise} A promise to the Reports response. 52 | */ 53 | async getReportDetails(id) { 54 | try { 55 | const response = await get( 56 | this.config.httpClient, 57 | `${this.config.host}/reports/${id}`, 58 | this.config, 59 | this.config.sk 60 | ); 61 | return await response.json; 62 | } catch (err) { 63 | const error = await determineError(err); 64 | throw error; 65 | } 66 | } 67 | 68 | /** 69 | * Use this endpoint to retrieve a specific file from a given report using their respective IDs. 70 | * 71 | * @memberof Reports 72 | * @param {string} id The ID of the report that the file belongs to. 73 | * @param {Object} fileId The ID of the file to retrieve. 74 | * @return {Promise} A promise to the Reports response. 75 | */ 76 | async getReportFile(id, fileId) { 77 | try { 78 | const response = await get( 79 | this.config.httpClient, 80 | `${this.config.host}/reports/${id}/files/${fileId}`, 81 | { ...this.config, csv: true }, 82 | this.config.sk 83 | ); 84 | return await response.csv; 85 | } catch (err) { 86 | const error = await determineError(err); 87 | throw error; 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/api/risk/risk.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { post } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /risk endpoint 6 | * 7 | * @export 8 | * @class Risk 9 | */ 10 | export default class Risk { 11 | constructor(config) { 12 | this.config = config; 13 | } 14 | 15 | /** 16 | * Perform a pre-authentication fraud assessment using your defined risk settings. 17 | * 18 | * @memberof Risk 19 | * @param {Object} body Risk request body. 20 | * @return {Promise} A promise to the risk response. 21 | */ 22 | async requestPreAuthentication(body) { 23 | try { 24 | const response = await post( 25 | this.config.httpClient, 26 | `${this.config.host}/risk/assessments/pre-authentication`, 27 | this.config, 28 | this.config.sk, 29 | body 30 | ); 31 | return await response.json; 32 | } catch (err) { 33 | const error = await determineError(err); 34 | throw error; 35 | } 36 | } 37 | 38 | /** 39 | * Perform a pre-capture fraud assessment using your defined risk settings. 40 | * 41 | * @memberof Risk 42 | * @param {Object} body Risk request body. 43 | * @return {Promise} A promise to the risk response. 44 | */ 45 | async requestPreCapture(body) { 46 | try { 47 | const response = await post( 48 | this.config.httpClient, 49 | `${this.config.host}/risk/assessments/pre-capture`, 50 | this.config, 51 | this.config.sk, 52 | body 53 | ); 54 | return await response.json; 55 | } catch (err) { 56 | const error = await determineError(err); 57 | throw error; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/api/sessions/sessions.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { get, post, put } from '../../services/http'; 3 | 4 | /** 5 | * Class dealing with the /sessions endpoint 6 | * 7 | * @export 8 | * @class Sessions 9 | */ 10 | export default class Sessions { 11 | constructor(config) { 12 | this.config = config; 13 | } 14 | 15 | /** 16 | * Create a payment session to authenticate a cardholder before requesting a payment. 17 | * 18 | * @memberof Sessions 19 | * @param {Object} body Sessions request body. 20 | * @return {Promise} A promise to the sessions response. 21 | */ 22 | async request(body) { 23 | try { 24 | const response = await post( 25 | this.config.httpClient, 26 | `${this.config.host}/sessions`, 27 | this.config, 28 | this.config.sk, 29 | body 30 | ); 31 | return await response.json; 32 | } catch (err) { 33 | const error = await determineError(err); 34 | throw error; 35 | } 36 | } 37 | 38 | /** 39 | * Returns the details of the session with the specified identifier string. 40 | * 41 | * @memberof Sessions 42 | * @param {string} id Sessions id. 43 | * @param {string} channel Type of channnel. 44 | * @return {Promise} A promise to the sessions response. 45 | */ 46 | async get(id, channel) { 47 | try { 48 | this.config.headers = { ...this.config.headers, channel }; 49 | 50 | const response = await get( 51 | this.config.httpClient, 52 | `${this.config.host}/sessions/${id}`, 53 | this.config, 54 | this.config.sk 55 | ); 56 | return await response.json; 57 | } catch (err) { 58 | const error = await determineError(err); 59 | throw error; 60 | } 61 | } 62 | 63 | /** 64 | * Update a session by providing information about the environment. 65 | * 66 | * @memberof Sessions 67 | * @param {string} id Sessions id. 68 | * @param {Object} body Sessions request body. 69 | * @return {Promise} A promise to the sessions response. 70 | */ 71 | async update(id, body) { 72 | try { 73 | const response = await put( 74 | this.config.httpClient, 75 | `${this.config.host}/sessions/${id}/collect-data`, 76 | this.config, 77 | this.config.sk, 78 | body 79 | ); 80 | return await response.json; 81 | } catch (err) { 82 | const error = await determineError(err); 83 | throw error; 84 | } 85 | } 86 | 87 | /** 88 | * Completes a session by posting the the following request to the callback URL 89 | * (only relevant for non hosted sessions) 90 | * 91 | * @memberof Sessions 92 | * @param {string} id Sessions id. 93 | * @return {Promise} A promise to the sessions response. 94 | */ 95 | async complete(id) { 96 | try { 97 | const response = await post( 98 | this.config.httpClient, 99 | `${this.config.host}/sessions/${id}/complete`, 100 | this.config, 101 | this.config.sk 102 | ); 103 | return await response.json; 104 | } catch (err) { 105 | const error = await determineError(err); 106 | throw error; 107 | } 108 | } 109 | 110 | /** 111 | * Completes a session by posting the the following request to the callback URL 112 | * (only relevant for non hosted sessions) 113 | * 114 | * @memberof Sessions 115 | * @param {string} id Sessions id. 116 | * @param {string} threeDsMethodCompletion 3DS Method completion indicator 117 | * @return {Promise} A promise to the sessions response. 118 | */ 119 | async update3DSMethodCompletionIndicator(id, threeDsMethodCompletion) { 120 | try { 121 | const body = { 122 | three_ds_method_completion: threeDsMethodCompletion, 123 | }; 124 | 125 | const response = await put( 126 | this.config.httpClient, 127 | `${this.config.host}/sessions/${id}/issuer-fingerprint`, 128 | this.config, 129 | this.config.sk, 130 | body 131 | ); 132 | 133 | return await response.json; 134 | } catch (err) { 135 | const error = await determineError(err); 136 | throw error; 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/api/sources/sources.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { post } from '../../services/http'; 3 | import { setSourceType } from '../../services/validation'; 4 | 5 | /** 6 | * Class dealing with the /sources endpoint 7 | * 8 | * @export 9 | * @class Sources 10 | */ 11 | export default class Sources { 12 | constructor(config) { 13 | this.config = config; 14 | } 15 | 16 | /** 17 | * Add a reusable payment source that can be used later to make one or more payments. 18 | * Payment sources are linked to a specific customer and cannot be shared between customers. 19 | * 20 | * @memberof Sources 21 | * @param {Object} body Source request body. 22 | * @return {Promise} A promise to the add source response. 23 | */ 24 | async add(body) { 25 | setSourceType(body); 26 | try { 27 | const response = await post( 28 | this.config.httpClient, 29 | `${this.config.host}/sources`, 30 | this.config, 31 | this.config.sk, 32 | body 33 | ); 34 | return await response.json; 35 | } catch (err) { 36 | const error = await determineError(err); 37 | throw error; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/api/tokens/tokens.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { post } from '../../services/http'; 3 | import { setTokenType } from '../../services/validation'; 4 | 5 | /** 6 | * Class dealing with the /tokens endpoint 7 | * 8 | * @export 9 | * @class Tokens 10 | */ 11 | export default class Tokens { 12 | constructor(config) { 13 | this.config = config; 14 | } 15 | 16 | /** 17 | * Exchange card details or a digital wallet payment token for a reference token 18 | * that can be used later to request a card payment. 19 | * 20 | * @memberof Tokens 21 | * @param {Object} body Token request body. 22 | * @return {Promise} A promise to the request token response. 23 | */ 24 | async request(body) { 25 | setTokenType(body); 26 | try { 27 | const response = await post( 28 | this.config.httpClient, 29 | `${this.config.host}/tokens`, 30 | this.config, 31 | this.config.pk, 32 | body 33 | ); 34 | return await response.json; 35 | } catch (err) { 36 | const error = await determineError(err); 37 | throw error; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/api/transfers/transfers.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { get, post } from '../../services/http'; 3 | import { 4 | TRANSFERS_LIVE_URL, 5 | TRANSFERS_SANDBOX_URL 6 | } from '../../config'; 7 | 8 | /** 9 | * Class dealing with the /transfers endpoint 10 | * 11 | * @export 12 | * @class Transfers 13 | */ 14 | export default class Transfers { 15 | constructor(config) { 16 | this.config = config; 17 | } 18 | 19 | /** 20 | * Initiate a transfer of funds from source entity to destination entity. 21 | * 22 | * @memberof Transfers 23 | * @param {Object} body Transfers request body. 24 | * @param {string} [idempotencyKey] Idempotency Key. 25 | * @return {Promise} A promise to the request transfers response. 26 | */ 27 | async initiate(body, idempotencyKey) { 28 | try { 29 | const url = `${this.config.host.includes('sandbox') ? TRANSFERS_SANDBOX_URL : TRANSFERS_LIVE_URL 30 | }`; 31 | 32 | const response = await post( 33 | this.config.httpClient, 34 | url, 35 | this.config, 36 | this.config.sk, 37 | body, 38 | idempotencyKey 39 | ); 40 | return await response.json; 41 | } catch (err) { 42 | const error = await determineError(err); 43 | throw error; 44 | } 45 | } 46 | 47 | /** 48 | * Retrieve transfer details using the transfer identifier. 49 | * 50 | * @memberof Transfers 51 | * @param {string} id tra_XXX The transfer identifier. 52 | * @return {Promise} A promise to the transfer response. 53 | */ 54 | async retrieve(id) { 55 | try { 56 | const url = `${this.config.host.includes('sandbox') 57 | ? TRANSFERS_SANDBOX_URL 58 | : TRANSFERS_LIVE_URL}/${id}`; 59 | 60 | const response = await get( 61 | this.config.httpClient, 62 | url, 63 | this.config, 64 | this.config.sk 65 | ); 66 | return await response.json; 67 | } catch (err) { 68 | const error = await determineError(err); 69 | throw error; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/api/webhooks/webhooks.js: -------------------------------------------------------------------------------- 1 | import { determineError } from '../../services/errors'; 2 | import { _delete, get, patch, post, put } from '../../services/http'; 3 | 4 | /** 5 | * Create and manage the webhook notifications you receive to keep up to date with 6 | * the status of your transactions. 7 | * 8 | * @export 9 | * @class Webhooks 10 | */ 11 | export default class Webhooks { 12 | constructor(config) { 13 | this.config = config; 14 | } 15 | 16 | /** 17 | * Retrieves the webhooks configured for the channel identified by your API key 18 | * 19 | * @memberof Webhooks 20 | * @return {Promise} A promise to the request webhooks response. 21 | */ 22 | async retrieveWebhooks() { 23 | try { 24 | const response = await get( 25 | this.config.httpClient, 26 | `${this.config.host}/webhooks`, 27 | this.config, 28 | this.config.sk 29 | ); 30 | return await response.json; 31 | } catch (err) { 32 | const error = await determineError(err); 33 | throw error; 34 | } 35 | } 36 | 37 | /** 38 | * Register a new webhook endpoint that Checkout.com will post all or selected events to 39 | * 40 | * @memberof Webhooks 41 | * @return {Promise} A promise to the register webhook response. 42 | */ 43 | async registerWebhook(body) { 44 | try { 45 | const response = await post( 46 | this.config.httpClient, 47 | `${this.config.host}/webhooks`, 48 | this.config, 49 | this.config.sk, 50 | body 51 | ); 52 | return await response.json; 53 | } catch (err) { 54 | const error = await determineError(err); 55 | throw error; 56 | } 57 | } 58 | 59 | /** 60 | * Retrieves the webhook with the specified identifier string 61 | * 62 | * @memberof Webhooks 63 | * @return {Promise} A promise to the retrieve webhook response. 64 | */ 65 | async retrieveWebhook(id) { 66 | try { 67 | const response = await get( 68 | this.config.httpClient, 69 | `${this.config.host}/webhooks/${id}`, 70 | this.config, 71 | this.config.sk 72 | ); 73 | return await response.json; 74 | } catch (err) { 75 | const error = await determineError(err); 76 | throw error; 77 | } 78 | } 79 | 80 | /** 81 | * Updates an existing webhook 82 | * 83 | * @memberof Webhooks 84 | * @return {Promise} A promise to the update webhook response. 85 | */ 86 | async updateWebhook(id, body) { 87 | try { 88 | const response = await put( 89 | this.config.httpClient, 90 | `${this.config.host}/webhooks/${id}`, 91 | this.config, 92 | this.config.sk, 93 | body 94 | ); 95 | return await response.json; 96 | } catch (err) { 97 | const error = await determineError(err); 98 | throw error; 99 | } 100 | } 101 | 102 | /** 103 | * Updates all or some of the registered webhook details 104 | * 105 | * @memberof Webhooks 106 | * @return {Promise} A promise to the update webhook response. 107 | */ 108 | async partiallyUpdateWebhook(id, body) { 109 | try { 110 | const response = await patch( 111 | this.config.httpClient, 112 | `${this.config.host}/webhooks/${id}`, 113 | this.config, 114 | this.config.sk, 115 | body 116 | ); 117 | return await response.json; 118 | } catch (err) { 119 | const error = await determineError(err); 120 | throw error; 121 | } 122 | } 123 | 124 | /** 125 | * Removes an existing webhook 126 | * 127 | * @memberof Webhooks 128 | * @return {Promise} A promise to the remove webhook response. 129 | */ 130 | async removeWebhook(id) { 131 | try { 132 | const response = await _delete( 133 | this.config.httpClient, 134 | `${this.config.host}/webhooks/${id}`, 135 | this.config, 136 | this.config.sk 137 | ); 138 | return await response.json; 139 | } catch (err) { 140 | const error = await determineError(err); 141 | throw error; 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /src/config.js: -------------------------------------------------------------------------------- 1 | export const SANDBOX_BASE_URL = 'https://api.sandbox.checkout.com'; 2 | export const LIVE_BASE_URL = 'https://api.checkout.com'; 3 | export const SANDBOX_ACCESS_URL = 'https://access.sandbox.checkout.com/connect/token'; 4 | export const LIVE_ACCESS_URL = 'https://access.checkout.com/connect/token'; 5 | 6 | export const PLATFORMS_FILES_LIVE_URL = 'https://files.checkout.com/files'; 7 | export const PLATFORMS_FILES_SANDBOX_URL = 'https://files.sandbox.checkout.com/files'; 8 | 9 | export const TRANSFERS_SANDBOX_URL = 'https://transfers.sandbox.checkout.com/transfers'; 10 | export const TRANSFERS_LIVE_URL = 'https://transfers.checkout.com/transfers'; 11 | 12 | export const BALANCES_SANDBOX_URL = 'https://balances.sandbox.checkout.com/balances'; 13 | export const BALANCES_LIVE_URL = 'https://balances.checkout.com/balances'; 14 | 15 | export const REQUEST_ID_HEADER = 'cko-request-id'; 16 | export const API_VERSION_HEADER = 'cko-version'; 17 | 18 | export const DEFAULT_TIMEOUT = 15000; 19 | 20 | export const MBC_LIVE_SECRET_KEY_REGEX = /^sk_?(\w{8})-(\w{4})-(\w{4})-(\w{4})-(\w{12})$/; 21 | export const NAS_LIVE_SECRET_KEY_REGEX = /^sk_?[a-z2-7]{26}[a-z2-7*#$=]$/; 22 | export const NAS_SANDBOX_SECRET_KEY_REGEX = /^sk_sbox_?[a-z2-7]{26}[a-z2-7*#$=]$/; 23 | export const NAS_LIVE_PUBLIC_KEY_REGEX = /^pk_?[a-z2-7]{26}[a-z2-7*#$=]$/; 24 | export const NAS_SANDBOX_PUBLIC_KEY_REGEX = /^pk_sbox_?[a-z2-7]{26}[a-z2-7*#$=]$/; 25 | export const PAYMENT_TYPES = { 26 | regular: 'Regular', 27 | recurring: 'Recurring', 28 | moto: 'MOTO', 29 | installment: 'Installment', 30 | unscheduled: 'Unscheduled' 31 | }; 32 | export const CURRENCIES = { 33 | ALL: 'ALL', 34 | STN: 'STN', 35 | EEK: 'EEK', 36 | BHD: 'BHD', 37 | SCR: 'SCR', 38 | DJF: 'DJF', 39 | EGP: 'EGP', 40 | MDL: 'MDL', 41 | MZN: 'MZN', 42 | BND: 'BND', 43 | ZMK: 'ZMK', 44 | SHP: 'SHP', 45 | LBP: 'LBP', 46 | AWG: 'AWG', 47 | JMD: 'JMD', 48 | KES: 'KES', 49 | BYN: 'BYN', 50 | KHR: 'KHR', 51 | LAK: 'LAK', 52 | MVR: 'MVR', 53 | AOA: 'AOA', 54 | TJS: 'TJS', 55 | SVC: 'SVC', 56 | GNF: 'GNF', 57 | BRL: 'BRL', 58 | MOP: 'MOP', 59 | BOB: 'BOB', 60 | CDF: 'CDF', 61 | NAD: 'NAD', 62 | LYD: 'LYD', 63 | VUV: 'VUV', 64 | QAR: 'QAR', 65 | CLP: 'CLP', 66 | HRK: 'HRK', 67 | ISK: 'ISK', 68 | FKP: 'FKP', 69 | XCD: 'XCD', 70 | NOK: 'NOK', 71 | CUP: 'CUP', 72 | VND: 'VND', 73 | PEN: 'PEN', 74 | KMF: 'KMF', 75 | LVL: 'LVL', 76 | MMK: 'MMK', 77 | TRY: 'TRY', 78 | VEF: 'VEF', 79 | AUD: 'AUD', 80 | TWD: 'TWD', 81 | PKR: 'PKR', 82 | SLL: 'SLL', 83 | BGN: 'BGN', 84 | LRD: 'LRD', 85 | LKR: 'LKR', 86 | XAF: 'XAF', 87 | JOD: 'JOD', 88 | ANG: 'ANG', 89 | BSD: 'BSD', 90 | CAD: 'CAD', 91 | GIP: 'GIP', 92 | MNT: 'MNT', 93 | LTL: 'LTL', 94 | BBD: 'BBD', 95 | CLF: 'CLF', 96 | BWP: 'BWP', 97 | COP: 'COP', 98 | PHP: 'PHP', 99 | HUF: 'HUF', 100 | FJD: 'FJD', 101 | MWK: 'MWK', 102 | THB: 'THB', 103 | XPF: 'XPF', 104 | RSD: 'RSD', 105 | SAR: 'SAR', 106 | UYU: 'UYU', 107 | BZD: 'BZD', 108 | SYP: 'SYP', 109 | GMD: 'GMD', 110 | SZL: 'SZL', 111 | SBD: 'SBD', 112 | ETB: 'ETB', 113 | CHF: 'CHF', 114 | MXN: 'MXN', 115 | ARS: 'ARS', 116 | GTQ: 'GTQ', 117 | GHS: 'GHS', 118 | NIO: 'NIO', 119 | JPY: 'JPY', 120 | BDT: 'BDT', 121 | UZS: 'UZS', 122 | SOS: 'SOS', 123 | BTN: 'BTN', 124 | NZD: 'NZD', 125 | TZS: 'TZS', 126 | IQD: 'IQD', 127 | MGA: 'MGA', 128 | DZD: 'DZD', 129 | GYD: 'GYD', 130 | USD: 'USD', 131 | KWD: 'KWD', 132 | CNY: 'CNY', 133 | PYG: 'PYG', 134 | SGD: 'SGD', 135 | KZT: 'KZT', 136 | PGK: 'PGK', 137 | AMD: 'AMD', 138 | GBP: 'GBP', 139 | AFN: 'AFN', 140 | CRC: 'CRC', 141 | XOF: 'XOF', 142 | YER: 'YER', 143 | MRU: 'MRU', 144 | DKK: 'DKK', 145 | TOP: 'TOP', 146 | INR: 'INR', 147 | SDG: 'SDG', 148 | DOP: 'DOP', 149 | ZWL: 'ZWL', 150 | UGX: 'UGX', 151 | SEK: 'SEK', 152 | LSL: 'LSL', 153 | MYR: 'MYR', 154 | TMT: 'TMT', 155 | OMR: 'OMR', 156 | BMD: 'BMD', 157 | KRW: 'KRW', 158 | HKD: 'HKD', 159 | KGS: 'KGS', 160 | BAM: 'BAM', 161 | NGN: 'NGN', 162 | ILS: 'ILS', 163 | MUR: 'MUR', 164 | RON: 'RON', 165 | TND: 'TND', 166 | AED: 'AED', 167 | PAB: 'PAB', 168 | NPR: 'NPR', 169 | TTD: 'TTD', 170 | RWF: 'RWF', 171 | HTG: 'HTG', 172 | IDR: 'IDR', 173 | EUR: 'EUR', 174 | KYD: 'KYD', 175 | IRR: 'IRR', 176 | KPW: 'KPW', 177 | MKD: 'MKD', 178 | SRD: 'SRD', 179 | HNL: 'HNL', 180 | AZN: 'AZN', 181 | ERN: 'ERN', 182 | CZK: 'CZK', 183 | CVE: 'CVE', 184 | BIF: 'BIF', 185 | MAD: 'MAD', 186 | RUB: 'RUB', 187 | UAH: 'UAH', 188 | WST: 'WST', 189 | PLN: 'PLN', 190 | ZAR: 'ZAR', 191 | GEL: 'GEL', 192 | ZMW: 'ZMW', 193 | }; 194 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable import/no-cycle */ 2 | export { default as Payments } from './api/payments/payments'; 3 | export { default as Sources } from './api/sources/sources'; 4 | export { default as Tokens } from './api/tokens/tokens'; 5 | export { default as Instruments } from './api/instruments/instruments'; 6 | export { default as Webhooks } from './api/webhooks/webhooks'; 7 | export { default as Events } from './api/events/events'; 8 | export { default as Disputes } from './api/disputes/disputes'; 9 | export { default as Files } from './api/files/files'; 10 | export { default as Reconciliation } from './api/reconciliation/reconciliation'; 11 | export { default as Customers } from './api/customers/customers'; 12 | export { default as HostedPayments } from './api/hosted-payments/hosted-payments'; 13 | export { default as PaymentLinks } from './api/payments-links/payments-links'; 14 | export { default as Risk } from './api/risk/risk'; 15 | export { default as Giropay } from './api/apm-specific/giropay'; 16 | export { default as Ideal } from './api/apm-specific/ideal'; 17 | export { default as Fawry } from './api/apm-specific/fawry'; 18 | export { default as PagoFacil } from './api/apm-specific/pagofacil'; 19 | export { default as Rapipago } from './api/apm-specific/rapipago'; 20 | export { default as Boleto } from './api/apm-specific/boleto'; 21 | export { default as Baloto } from './api/apm-specific/baloto'; 22 | export { default as Oxxo } from './api/apm-specific/oxxo'; 23 | export { default as Klarna } from './api/apm-specific/klarna'; 24 | export { default as Sepa } from './api/apm-specific/sepa'; 25 | export { default as Access } from './api/access/access'; 26 | export { default as Forex } from './api/forex/forex'; 27 | export { default as ApplePay } from './api/apple-pay/apple-pay'; 28 | export { default as Sessions } from './api/sessions/sessions'; 29 | export { default as Workflows } from './api/workflows/workflows'; 30 | export { default as Platforms } from './api/platforms/platforms'; 31 | export { default as Transfers } from './api/transfers/transfers'; 32 | export { default as Balances } from './api/balances/balances'; 33 | export { default as CardMetadata } from './api/card-metadata/card-metadata'; 34 | export { default as Reports } from './api/reports/reports'; 35 | export { default as Financial } from './api/financial/financial'; 36 | export { default as Issuing } from './api/issuing/issuing'; 37 | export { default as PaymentContexts } from './api/payment-contexts/payment-contexts'; 38 | export { default as PaymentSessions } from './api/payment-sessions/payment-sessions'; 39 | export { default as Checkout } from './Checkout'; 40 | export { default } from './Checkout'; 41 | -------------------------------------------------------------------------------- /src/services/utils.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line import/prefer-default-export 2 | export const buildQueryParams = (path, params) => { 3 | let url = path; 4 | if (params) { 5 | const queryString = Object.keys(params) 6 | .map((key) => `${key}=${params[key]}`) 7 | .join('&'); 8 | url += `?${queryString}`; 9 | } 10 | 11 | return url; 12 | }; 13 | -------------------------------------------------------------------------------- /src/services/validation.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable prefer-template */ 2 | import { ValueError } from './errors'; 3 | import { 4 | CURRENCIES, 5 | PAYMENT_TYPES 6 | } from '../config'; 7 | 8 | export const validatePayment = (request) => { 9 | if (request.amount && ('' + request.amount).indexOf('.') !== -1) { 10 | throw new ValueError('The amount can not contain decimals.'); 11 | } 12 | 13 | if (!(request.currency in CURRENCIES)) { 14 | throw new ValueError('The currency value is not valid.'); 15 | } 16 | 17 | if (request.payment_type && !(request.payment_type.toLowerCase() in PAYMENT_TYPES)) { 18 | throw new ValueError('The payment type is not valid.'); 19 | } 20 | 21 | if (request.source && request.source.type && !(typeof request.source.type === 'string')) { 22 | throw new ValueError('The source type needs to be a string.'); 23 | } 24 | 25 | if (request.reference && !(typeof request.reference === 'string')) { 26 | throw new ValueError('The reference needs to be a string.'); 27 | } 28 | }; 29 | 30 | export const setSourceOrDestinationType = (request) => { 31 | if (request.source) { 32 | if (request.source.type) { 33 | return request; 34 | } 35 | if ('number' in request.source) { 36 | request.source.type = 'card'; 37 | } else if ( 38 | 'email' in request.source || 39 | ('id' in request.source && request.source.id.startsWith('cus_')) 40 | ) { 41 | request.source.type = 'customer'; 42 | } else if ('id' in request.source && request.source.id.startsWith('src_')) { 43 | request.source.type = 'id'; 44 | } else if ('token' in request.source && !('cryptogram' in request.source)) { 45 | request.source.type = 'token'; 46 | } else if ('token' in request.source && 'cryptogram' in request.source) { 47 | request.source.type = 'network_token'; 48 | } 49 | } else if (request.destination) { 50 | if (request.destination.type) { 51 | return request; 52 | } 53 | if ('number' in request.destination) { 54 | request.destination.type = 'card'; 55 | } else if ('token' in request.destination) { 56 | request.destination.type = 'token'; 57 | } else if ('id' in request.destination) { 58 | request.destination.type = 'id'; 59 | } 60 | } 61 | return request; 62 | }; 63 | 64 | export const setTokenType = (request) => { 65 | if (request.type) { 66 | return request; 67 | } 68 | if ('number' in request) { 69 | request.type = 'card'; 70 | } else if ('token_data' in request && 'header' in request.token_data) { 71 | request.type = 'applepay'; 72 | } else if ('token_data' in request && 'signedMessage' in request.token_data) { 73 | request.type = 'googlepay'; 74 | } 75 | return request; 76 | }; 77 | 78 | export const setSourceType = (request) => { 79 | if (request.type) { 80 | return request; 81 | } 82 | if ('source_data' in request && 'account_type' in request.source_data) { 83 | request.type = 'ach'; 84 | } else if ('source_data' in request && 'account_iban' in request.source_data) { 85 | request.type = 'sepa'; 86 | } 87 | return request; 88 | }; 89 | 90 | export const setInstrumentType = (request) => { 91 | if (request.type) { 92 | return request; 93 | } 94 | request.type = 'token'; 95 | 96 | return request; 97 | }; 98 | -------------------------------------------------------------------------------- /test/access/access.js: -------------------------------------------------------------------------------- 1 | import { AuthenticationError, } from '../../src/services/errors'; 2 | import { Checkout } from '../../src/index'; 3 | import { expect } from 'chai'; 4 | import nock from 'nock'; 5 | 6 | describe('Access', () => { 7 | it('should create access token', async () => { 8 | nock('https://access.sandbox.checkout.com').post('/connect/token').reply(201, { 9 | access_token: 10 | 'eyJhbGciOiJSUzI1NiIsImtpZCI6ImFybjphd3M6a21zOmV1LXdlc3QtMTo2ODY0OTY3NDc3MTU6a2V5LzAyYThmYWM5LWE5MjItNGNkNy05MDk1LTg0ZjA5YjllNTliZCIsInR5cCI6ImF0K2p3dCJ9.eyJuYmYiOjE2NDA1NTMzNDksImV4cCI6MTY0MDU1Njk0OSwiaXNzIjoiaHR0cHM6Ly9hY2Nlc3Muc2FuZGJveC5jaGVja291dC5jb20iLCJhdWQiOiJnYXRld2F5IiwiY2xpZW50X2lkIjoiYWNrX3Z2emhvYWk0NjZzdTNqM3ZieGI0N3RzNW9lIiwiY2tvX2NsaWVudF9pZCI6ImNsaV9nNnJvZ2IzaGhmZXUzZ2h0eGN2M2J3NHFweSIsImNrb19lbnRpdHlfaWQiOiJlbnRfZGppZ2NxeDRjbG11Zm8yc2FzZ29tZ3Bxc3EiLCJqdGkiOiI3RDRCQTRBNEJBQUYzQ0E5MjYwMzlDRTNGQTc1ODVEMCIsImlhdCI6MTY0MDU1MzM0OSwic2NvcGUiOlsiZ2F0ZXdheSJdfQ.U4S2YQDZtRb5WsKA6P8eiHyoqH_KN_1MabiNG5LAOeyYwRiIdyuzWJlYJg-wJlly84Eo68P1rcEB0Pac90PRiDBfSPNh0rIFJvFrA1fHE95EWjwER8UBvYT6yr-yI4JlrTnjeU6f5mJpxWbuN2ywE36x5eWPBdBs3w_j_x8FU62-UYwPOy5LIyZLR_JRxHMU81r7chOD9113CTGzJG9CGzKDMN53iciLdLPXUCFH2AlLHm9-YFh46WMIz85i4nVG0aKI_fIW9gjsLIvG0j-8shf-k4D1LLP0R3juX6twULVbrDuZqacC0TqGI6bAahVJ37Old74He7Ft6j3cx9Hi8A', 11 | expires_in: 3600, 12 | token_type: 'Bearer', 13 | scope: 'gateway', 14 | }); 15 | 16 | let cko = new Checkout( 17 | '2p7YQ37fHiRr8O6lQAikl8enICesB1dvAJrpmE2nZfEOpxzE-J_Gho7wDy0HY9951RfdUr0vSaQCzRKP0-o5Xg', 18 | { 19 | client: 'ack_vvzhoai466su3j3vbxb47ts5oe', 20 | scope: ['gateway'], 21 | environment: 'sandbox', 22 | } 23 | ); 24 | 25 | const tkn = await cko.access.request({ 26 | grant_type: 'client_credentials', 27 | client_id: 'ack_vvzhoai466su3j3vbxb47ts5oe', 28 | client_secret: 29 | '2p7YQ37fHiRr8O6lQAikl8enICesB1dvAJrpmE2nZfEOpxzE-J_Gho7wDy0HY9951RfdUr0vSaQCzRKP0-o5Xg', 30 | scope: 'gateway', 31 | }); 32 | 33 | expect(tkn.token_type).to.equals('Bearer'); 34 | }); 35 | 36 | it('should be able to updat the access token in the config from the access class', async () => { 37 | nock('https://access.sandbox.checkout.com').post('/connect/token').reply(201, { 38 | access_token: '1234', 39 | expires_in: 3600, 40 | token_type: 'Bearer', 41 | scope: 'gateway', 42 | }); 43 | let cko = new Checkout( 44 | '2p7YQ37fHiRr8O6lQAikl8enICesB1dvAJrpmE2nZfEOpxzE-J_Gho7wDy0HY9951RfdUr0vSaQCzRKP0-o5Xg', 45 | { 46 | client: 'ack_vvzhoai466su3j3vbxb47ts5oe', 47 | scope: ['gateway'], 48 | environment: 'sandbox', 49 | } 50 | ); 51 | 52 | const tkn = await cko.access.request({ 53 | grant_type: 'client_credentials', 54 | client_id: 'ack_vvzhoai466su3j3vbxb47ts5oe', 55 | client_secret: 56 | '2p7YQ37fHiRr8O6lQAikl8enICesB1dvAJrpmE2nZfEOpxzE-J_Gho7wDy0HY9951RfdUr0vSaQCzRKP0-o5Xg', 57 | scope: 'gateway', 58 | }); 59 | 60 | cko.access.updateAccessToken(tkn); 61 | 62 | expect(cko.config.access.token).to.exist; 63 | }); 64 | 65 | it('should throw AuthenticationError in pre-capture', async () => { 66 | nock('https://access.checkout.com').post('/connect/token').reply(401); 67 | let cko = new Checkout( 68 | '2p7YQ37fHiRr8O6lQAikl8enICesB1dvAJrpmE2nZfEOpxzE-J_Gho7wDy0HY9951RfdUr0vSaQCzRKP0-o5Xg', 69 | { 70 | client: 'ack_vvzhoai466su3j3vbxb47ts5oe', 71 | scope: ['gateway'], 72 | environment: 'live', 73 | } 74 | ); 75 | 76 | try { 77 | const tkn = await cko.access.request({ 78 | grant_type: 'client_credentials', 79 | client_id: 'ack_vvzhoai466su3j3vbxb47ts5oe', 80 | client_secret: 81 | '2p7YQ37fHiRr8O6lQAikl8enICesB1dvAJrpmE2nZfEOpxzE-J_Gho7wDy0HY9951RfdUr0vSaQCzRKP0-o5Xg', 82 | scope: 'gateway', 83 | }); 84 | } catch (err) { 85 | expect(err).to.be.instanceOf(AuthenticationError); 86 | } 87 | }); 88 | }); 89 | -------------------------------------------------------------------------------- /test/apm-specific/fawry.js: -------------------------------------------------------------------------------- 1 | import { NotFoundError } from '../../src/services/errors'; 2 | import { Checkout } from '../../src/index'; 3 | import { expect } from 'chai'; 4 | import nock from 'nock'; 5 | 6 | const SK = 'sk_test_0b9b5db6-f223-49d0-b68f-f6643dd4f808'; 7 | 8 | describe('Fawry', () => { 9 | it('should approve Fawry payment', async () => { 10 | nock('https://api.sandbox.checkout.com') 11 | .post('/payments') 12 | .reply(202, { 13 | id: 'pay_bvoryvj7bktuvdv7aajab6zixu', 14 | status: 'Pending', 15 | customer: { 16 | id: 'cus_pjot3pvirqfu5p7e2tvoblrjgi', 17 | }, 18 | _links: { 19 | self: { 20 | href: 'https://api.sandbox.checkout.com/payments/pay_bvoryvj7bktuvdv7aajab6zixu', 21 | }, 22 | approve: { 23 | href: 'https://api.sandbox.checkout.com/fawry/payments/661440940/approval', 24 | }, 25 | cancel: { 26 | href: 'https://api.sandbox.checkout.com/fawry/payments/661440940/cancellation', 27 | }, 28 | }, 29 | }); 30 | 31 | nock('https://api.sandbox.checkout.com') 32 | .put('/fawry/payments/661440940/approval') 33 | .reply(200); 34 | 35 | const cko = new Checkout(SK); 36 | 37 | const payment = await cko.payments.request({ 38 | amount: 1000, 39 | currency: 'EGP', 40 | source: { 41 | type: 'fawry', 42 | description: 'Fawry Demo Payment', 43 | customer_mobile: '01058375055', 44 | customer_email: 'bruce@wayne-enterprises.com', 45 | products: [ 46 | { 47 | product_id: '0123456789', 48 | quantity: 1, 49 | price: 1000, 50 | description: 'Fawry Demo Product', 51 | }, 52 | ], 53 | }, 54 | }); 55 | 56 | let ref = payment._links.approve.href.match(/payments\/([^&]*)/)[1]; 57 | ref = ref.substring(0, ref.length - 9); 58 | 59 | const fawry = await cko.fawry.approve(ref); 60 | }); 61 | 62 | it('should throw NotFoundError trying to approve Fawry payment', async () => { 63 | nock('https://api.sandbox.checkout.com').put('/fawry/payments/1234/approval').reply(404); 64 | 65 | const cko = new Checkout(SK); 66 | 67 | try { 68 | const fawry = await cko.fawry.approve('1234'); 69 | } catch (err) { 70 | expect(err).to.be.instanceOf(NotFoundError); 71 | } 72 | }); 73 | 74 | it('should cancel Fawry payment', async () => { 75 | nock('https://api.sandbox.checkout.com') 76 | .post('/payments') 77 | .reply(202, { 78 | id: 'pay_bvoryvj7bktuvdv7aajab6zixu', 79 | status: 'Pending', 80 | customer: { 81 | id: 'cus_pjot3pvirqfu5p7e2tvoblrjgi', 82 | }, 83 | _links: { 84 | self: { 85 | href: 'https://api.sandbox.checkout.com/payments/pay_bvoryvj7bktuvdv7aajab6zixu', 86 | }, 87 | approve: { 88 | href: 'https://api.sandbox.checkout.com/fawry/payments/661440940/approval', 89 | }, 90 | cancel: { 91 | href: 'https://api.sandbox.checkout.com/fawry/payments/661440940/cancellation', 92 | }, 93 | }, 94 | }); 95 | 96 | nock('https://api.sandbox.checkout.com') 97 | .put('/fawry/payments/661440940/cancellation') 98 | .reply(200); 99 | 100 | const cko = new Checkout(SK); 101 | 102 | const payment = await cko.payments.request({ 103 | amount: 1000, 104 | currency: 'EGP', 105 | source: { 106 | type: 'fawry', 107 | description: 'Fawry Demo Payment', 108 | customer_mobile: '01058375055', 109 | customer_email: 'bruce@wayne-enterprises.com', 110 | products: [ 111 | { 112 | product_id: '0123456789', 113 | quantity: 1, 114 | price: 1000, 115 | description: 'Fawry Demo Product', 116 | }, 117 | ], 118 | }, 119 | }); 120 | 121 | let ref = payment._links.cancel.href.match(/payments\/([^&]*)/)[1]; 122 | ref = ref.substring(0, ref.length - 13); 123 | 124 | const fawry = await cko.fawry.cancel(ref); 125 | }); 126 | 127 | it('should throw NotFoundError trying to cancel Fawry payment', async () => { 128 | nock('https://api.sandbox.checkout.com') 129 | .put('/fawry/payments/1234/cancellation') 130 | .reply(404); 131 | 132 | const cko = new Checkout(SK); 133 | 134 | try { 135 | const fawry = await cko.fawry.cancel('1234'); 136 | } catch (err) { 137 | expect(err).to.be.instanceOf(NotFoundError); 138 | } 139 | }); 140 | }); 141 | -------------------------------------------------------------------------------- /test/apm-specific/giropay.js: -------------------------------------------------------------------------------- 1 | import { AuthenticationError } from '../../src/services/errors'; 2 | import { Checkout } from '../../src/index'; 3 | import { expect } from 'chai'; 4 | import nock from 'nock'; 5 | 6 | const SK = 'sk_test_0b9b5db6-f223-49d0-b68f-f6643dd4f808'; 7 | 8 | describe('Giropay', () => { 9 | it('should get EPS banks', async () => { 10 | nock('https://api.sandbox.checkout.com') 11 | .get('/giropay/eps/banks') 12 | .reply(200, { 13 | _links: { self: { href: 'https://api.sandbox.checkout.com/giropay/eps/banks' } }, 14 | banks: { BKAUATWWXXX: 'Bank Austria Creditanstalt AG' }, 15 | }); 16 | 17 | const cko = new Checkout(SK); 18 | 19 | const banks = await cko.giropay.getEpsBanks(); 20 | expect(banks.banks['BKAUATWWXXX']).to.equal('Bank Austria Creditanstalt AG'); 21 | }); 22 | 23 | it('should throw Authentication error trying to get EPS banks', async () => { 24 | nock('https://api.sandbox.checkout.com').get('/giropay/eps/banks').reply(401); 25 | 26 | const cko = new Checkout(SK); 27 | 28 | try { 29 | const banks = await cko.giropay.getEpsBanks(); 30 | } catch (err) { 31 | expect(err).to.be.instanceOf(AuthenticationError); 32 | } 33 | }); 34 | 35 | it('should get banks', async () => { 36 | nock('https://api.sandbox.checkout.com') 37 | .get('/giropay/banks') 38 | .reply(200, { 39 | _links: { self: { href: 'https://api.sandbox.checkout.com/giropay/eps/banks' } }, 40 | banks: { GENODEF1PL1: 'Volksbank Vogtland' }, 41 | }); 42 | 43 | const cko = new Checkout(SK); 44 | 45 | const banks = await cko.giropay.getBanks(); 46 | expect(banks.banks['GENODEF1PL1']).to.equal('Volksbank Vogtland'); 47 | }); 48 | 49 | it('should throw Authentication error trying to get banks', async () => { 50 | nock('https://api.sandbox.checkout.com').get('/giropay/banks').reply(401); 51 | 52 | const cko = new Checkout(SK); 53 | 54 | try { 55 | const banks = await cko.giropay.getBanks(); 56 | } catch (err) { 57 | expect(err).to.be.instanceOf(AuthenticationError); 58 | } 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /test/apm-specific/ideal.js: -------------------------------------------------------------------------------- 1 | import { AuthenticationError } from '../../src/services/errors'; 2 | import { Checkout } from '../../src/index'; 3 | import { expect } from 'chai'; 4 | import nock from 'nock'; 5 | 6 | const SK = 'sk_test_0b9b5db6-f223-49d0-b68f-f6643dd4f808'; 7 | 8 | describe('iDEal', () => { 9 | it('should get iDeal details', async () => { 10 | nock('https://api.sandbox.checkout.com') 11 | .get('/ideal-external') 12 | .reply(200, { 13 | _links: { 14 | self: { 15 | href: 'https://api.sandbox.checkout.com/ideal-external/', 16 | }, 17 | curies: [ 18 | { 19 | name: 'ideal', 20 | href: 21 | 'https://api.sandbox.checkout.com/ideal-external/relations/ideal/{rel}', 22 | templated: true, 23 | }, 24 | ], 25 | 'ideal:issuers': { 26 | href: 'https://api.sandbox.checkout.com/ideal-external/issuers', 27 | }, 28 | }, 29 | }); 30 | 31 | const cko = new Checkout(SK); 32 | 33 | const ideal = await cko.ideal.get(); 34 | expect(ideal._links.curies[0].name).to.equal('ideal'); 35 | }); 36 | 37 | it('should throw Authentication error trying to get iDeal details', async () => { 38 | nock('https://api.sandbox.checkout.com').get('/ideal-external').reply(401); 39 | 40 | const cko = new Checkout(SK); 41 | 42 | try { 43 | const ideal = await cko.ideal.get(); 44 | } catch (err) { 45 | expect(err).to.be.instanceOf(AuthenticationError); 46 | } 47 | }); 48 | 49 | it('should get iDeal issuers', async () => { 50 | nock('https://api.sandbox.checkout.com') 51 | .get('/ideal-external/issuers') 52 | .reply(200, { 53 | countries: [ 54 | { 55 | name: 'Nederland', 56 | issuers: [ 57 | { 58 | bic: 'INGBNL2A', 59 | name: 'Issuer Simulation V3 - ING', 60 | }, 61 | { 62 | bic: 'RABONL2U', 63 | name: 'Issuer Simulation V3 - RABO', 64 | }, 65 | ], 66 | }, 67 | ], 68 | _links: { 69 | self: { 70 | href: 'https://api.sandbox.checkout.com/ideal-external/issuers', 71 | }, 72 | }, 73 | }); 74 | 75 | const cko = new Checkout(SK); 76 | 77 | const issuers = await cko.ideal.getIssuers(); 78 | expect(issuers.countries[0].name).to.equal('Nederland'); 79 | }); 80 | 81 | it('should throw Authentication error trying to get iDeal issuers', async () => { 82 | nock('https://api.sandbox.checkout.com').get('/ideal-external/issuers').reply(401); 83 | 84 | const cko = new Checkout(SK); 85 | 86 | try { 87 | const issuers = await cko.ideal.getIssuers(); 88 | } catch (err) { 89 | expect(err).to.be.instanceOf(AuthenticationError); 90 | } 91 | }); 92 | }); 93 | -------------------------------------------------------------------------------- /test/balances/balances.js: -------------------------------------------------------------------------------- 1 | import { AuthenticationError, ValidationError, } from '../../src/services/errors'; 2 | import { Checkout } from '../../src/index'; 3 | import { expect } from 'chai'; 4 | import nock from 'nock'; 5 | 6 | const SK = 'sk_sbox_o2nulev2arguvyf6w7sc5fkznas'; 7 | 8 | describe('Balances', () => { 9 | it('should retrive balance', async () => { 10 | nock('https://balances.sandbox.checkout.com') 11 | .get('/balances/ent_djigcqx4clmufo2sasgomgpqsq?query=currency:EUR') 12 | .reply(200, { 13 | data: [{ descriptor: 'EUR', holding_currency: 'EUR', balances: [Object] }], 14 | _links: { 15 | self: { 16 | href: 'https://balances.sandbox.checkout.com/balances/ent_djigcqx4clmufo2sasgomgpqsq?query=currency:EUR', 17 | }, 18 | }, 19 | }); 20 | 21 | const cko = new Checkout(SK); 22 | 23 | const balance = await cko.balances.retrieve('ent_djigcqx4clmufo2sasgomgpqsq', 'EUR'); 24 | 25 | expect(balance.data[0].descriptor).to.equal('EUR'); 26 | }); 27 | 28 | it('should retrive balance in prod', async () => { 29 | nock('https://balances.checkout.com') 30 | .get('/balances/ent_djigcqx4clmufo2sasgomgpqsq?query=currency:EUR') 31 | .reply(200, { 32 | data: [{ descriptor: 'EUR', holding_currency: 'EUR', balances: [Object] }], 33 | _links: { 34 | self: { 35 | href: 'https://balances.sandbox.checkout.com/balances/ent_djigcqx4clmufo2sasgomgpqsq?query=currency:EUR', 36 | }, 37 | }, 38 | }); 39 | 40 | // fake key 41 | const cko = new Checkout('sk_o2nulev2arguvyf6w7sc5fkznas'); 42 | 43 | const balance = await cko.balances.retrieve('ent_djigcqx4clmufo2sasgomgpqsq', 'EUR'); 44 | 45 | expect(balance.data[0].descriptor).to.equal('EUR'); 46 | }); 47 | 48 | it('should throw authentication error', async () => { 49 | nock('https://balances.sandbox.checkout.com') 50 | .get('/balances/ent_djigcqx4clmufo2sasgomgpqsq') 51 | .reply(401); 52 | 53 | try { 54 | // fake SK 55 | const cko = new Checkout('test'); 56 | 57 | const balance = await cko.balances.retrieve('ent_djigcqx4clmufo2sasgomgpqsq'); 58 | } catch (err) { 59 | expect(err).to.be.instanceOf(AuthenticationError); 60 | } 61 | }); 62 | 63 | it('should throw ValidationError error', async () => { 64 | nock('https://balances.sandbox.checkout.com') 65 | .get('/balances/123') 66 | .reply(422, { 67 | request_id: '8daac099-b8e5-428c-8374-11c9c0f42d2f', 68 | error_type: 'processing_error', 69 | error_codes: ['example'], 70 | }); 71 | 72 | try { 73 | const cko = new Checkout(SK); 74 | 75 | const balance = await cko.balances.retrieve('123'); 76 | } catch (err) { 77 | expect(err).to.be.instanceOf(ValidationError); 78 | } 79 | }); 80 | }); 81 | -------------------------------------------------------------------------------- /test/card-metadata/card-metadata.js: -------------------------------------------------------------------------------- 1 | import { AuthenticationError, } from '../../src/services/errors'; 2 | import { Checkout } from '../../src/index'; 3 | import { expect } from 'chai'; 4 | import nock from 'nock'; 5 | 6 | const SK = 'sk_sbox_o2nulev2arguvyf6w7sc5fkznas'; 7 | 8 | describe('Card Metadata', () => { 9 | it('should get card metadata', async () => { 10 | nock('https://api.sandbox.checkout.com').post('/metadata/card').reply(200, { 11 | scheme: 'visa', 12 | card_type: 'credit', 13 | card_category: 'consumer', 14 | issuer: 'UNICAJA BANCO', 15 | issuer_country: 'ES', 16 | product_type: 'CLASSIC', 17 | issuer_country_name: 'Spain', 18 | bin: '453946', 19 | }); 20 | 21 | const cko = new Checkout(SK); 22 | 23 | const metadata = await cko.cardMetadata.get({ 24 | source: { 25 | type: 'card', 26 | number: '4539467987109256', 27 | }, 28 | format: 'basic', 29 | }); 30 | 31 | expect(metadata.scheme).to.equal('visa'); 32 | }); 33 | 34 | it('should throw auth error getting card metadata', async () => { 35 | nock('https://api.sandbox.checkout.com').post('/metadata/card').reply(401); 36 | 37 | try { 38 | const cko = new Checkout(SK); 39 | 40 | const metadata = await cko.cardMetadata.get({ 41 | source: { 42 | type: 'card', 43 | number: '4539467987109256', 44 | }, 45 | format: 'basic', 46 | }); 47 | 48 | expect(metadata.scheme).to.equal('visa'); 49 | } catch (err) { 50 | expect(err).to.be.instanceOf(AuthenticationError); 51 | } 52 | }); 53 | }); 54 | -------------------------------------------------------------------------------- /test/customers/customers.js: -------------------------------------------------------------------------------- 1 | import { Checkout } from '../../src/index'; 2 | import { AuthenticationError, NotFoundError } from '../../src/services/errors'; 3 | import { expect } from 'chai'; 4 | import nock from 'nock'; 5 | 6 | const SK = 'sk_test_0b9b5db6-f223-49d0-b68f-f6643dd4f808'; 7 | 8 | describe('Customers', () => { 9 | it('should update a customer', async () => { 10 | nock('https://api.sandbox.checkout.com') 11 | .patch('/customers/cus_2tvaccfvs3lulevzg42vgyvtdq') 12 | .reply(200, {}); 13 | 14 | const cko = new Checkout(SK); 15 | 16 | const customerResponse = await cko.customers.update('cus_2tvaccfvs3lulevzg42vgyvtdq', { 17 | name: 'James Bond', 18 | }); 19 | }); 20 | 21 | it('should create a customer', async () => { 22 | nock('https://api.sandbox.checkout.com') 23 | .post('/customers') 24 | .reply(200, { id: 'cus_zbgrqmm6s5ne7lszegj5iu4lci' }); 25 | 26 | const cko = new Checkout(SK); 27 | 28 | const customerResponse = await cko.customers.create({ 29 | email: 'JohnTest@test.com', 30 | name: 'John Test', 31 | phone: { 32 | country_code: '+1', 33 | number: '4155552671', 34 | }, 35 | metadata: { 36 | coupon_code: 'NY2018', 37 | partner_id: 123989, 38 | }, 39 | }); 40 | }); 41 | 42 | it('should throw when creating a customer', async () => { 43 | nock('https://api.sandbox.checkout.com').post('/customers').reply(401); 44 | 45 | const cko = new Checkout('sk_123'); 46 | 47 | try { 48 | const customerResponse = await cko.customers.create({ 49 | email: 'JohnTest@test.com', 50 | name: 'John Test', 51 | phone: { 52 | country_code: '+1', 53 | number: '4155552671', 54 | }, 55 | metadata: { 56 | coupon_code: 'NY2018', 57 | partner_id: 123989, 58 | }, 59 | }); 60 | } catch (err) { 61 | expect(err).to.be.instanceOf(AuthenticationError); 62 | } 63 | }); 64 | 65 | it('should get a customer', async () => { 66 | nock('https://api.sandbox.checkout.com') 67 | .get('/customers/cus_zbgrqmm6s5ne7lszegj5iu4lci') 68 | .reply(200, { 69 | id: 'cus_zbgrqmm6s5ne7lszegj5iu4lci', 70 | email: 'JohnTest@test.com', 71 | name: 'John Test', 72 | phone: { country_code: '1', number: '4155552671' }, 73 | metadata: { coupon_code: 'NY2018', partner_id: '123989' }, 74 | instruments: [], 75 | }); 76 | 77 | const cko = new Checkout(SK); 78 | 79 | const customerResponse = await cko.customers.get('cus_zbgrqmm6s5ne7lszegj5iu4lci'); 80 | 81 | expect(customerResponse.name).to.equal('John Test'); 82 | }); 83 | 84 | it('should throw when getting a customer', async () => { 85 | nock('https://api.sandbox.checkout.com') 86 | .get('/customers/cus_zbgrqmm6s5ne7lszegj5iu4lci') 87 | .reply(404); 88 | 89 | const cko = new Checkout('sk_123'); 90 | 91 | try { 92 | const customerResponse = await cko.customers.get('cus_zbgrqmm6s5ne7lszegj5iu4lci'); 93 | } catch (err) { 94 | expect(err).to.be.instanceOf(NotFoundError); 95 | } 96 | }); 97 | 98 | it('should delete a customer', async () => { 99 | nock('https://api.sandbox.checkout.com') 100 | .delete('/customers/cus_zbgrqmm6s5ne7lszegj5iu4lci') 101 | .reply(200, {}); 102 | 103 | const cko = new Checkout(SK); 104 | 105 | const customerResponse = await cko.customers.delete('cus_zbgrqmm6s5ne7lszegj5iu4lci'); 106 | }); 107 | 108 | it('should throw when deleting a customer', async () => { 109 | nock('https://api.sandbox.checkout.com') 110 | .delete('/customers/cus_zbgrqmm6s5ne7lszegj5iu4lci') 111 | .reply(401); 112 | 113 | const cko = new Checkout('sk_123'); 114 | 115 | try { 116 | const customerResponse = await cko.customers.delete('cus_zbgrqmm6s5ne7lszegj5iu4lci'); 117 | } catch (err) { 118 | expect(err).to.be.instanceOf(AuthenticationError); 119 | } 120 | }); 121 | 122 | it('should throw not found error', async () => { 123 | nock('https://api.sandbox.checkout.com') 124 | .patch('/customers/cus_2tvaccfvs3lulevzg42vgyvtdqa') 125 | .reply(404); 126 | 127 | const cko = new Checkout(SK); 128 | 129 | try { 130 | const customerResponse = await cko.customers.update('cus_2tvaccfvs3lulevzg42vgyvtdqa', { 131 | name: 'James Bond', 132 | }); 133 | } catch (err) { 134 | expect(err).to.be.instanceOf(NotFoundError); 135 | } 136 | }); 137 | }); 138 | -------------------------------------------------------------------------------- /test/errors/apiError.js: -------------------------------------------------------------------------------- 1 | import { Checkout } from '../../src/index'; 2 | import { expect } from 'chai'; 3 | import nock from 'nock'; 4 | 5 | const PK = 'pk_test_4296fd52-efba-4a38-b6ce-cf0d93639d8a'; 6 | 7 | describe('Handling Errors', () => { 8 | const mockErrorResponse = { error: true }; 9 | const mockErrorCode = 500; 10 | 11 | afterEach(() => { 12 | nock.cleanAll(); 13 | }); 14 | 15 | it('should handle API error', async () => { 16 | nock('https://api.sandbox.checkout.com') 17 | .post('/tokens') 18 | .reply(mockErrorCode, mockErrorResponse); 19 | 20 | const cko = new Checkout(); 21 | cko.config.pk = PK; 22 | 23 | let errorWasThrown = false; 24 | 25 | try { 26 | await cko.tokens.request({ 27 | type: 'card', 28 | number: '4242424242424242', 29 | expiry_month: 6, 30 | expiry_year: 2029, 31 | cvv: '100' 32 | }); 33 | } catch (error) { 34 | errorWasThrown = true; 35 | 36 | expect(error.http_code).to.equal(mockErrorCode); 37 | expect(error.body).to.deep.equal(mockErrorResponse); 38 | } 39 | 40 | expect(errorWasThrown).to.equal(true); 41 | }); 42 | }); 43 | -------------------------------------------------------------------------------- /test/files/evidence.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/checkout/checkout-sdk-node/98639d19b933f1f6c10942b9d6f1f1ff8f1decea/test/files/evidence.jpg -------------------------------------------------------------------------------- /test/files/files.js: -------------------------------------------------------------------------------- 1 | import { AuthenticationError, ValidationError } from '../../src/services/errors'; 2 | import { Checkout } from '../../src/index'; 3 | import fs from 'fs'; 4 | import { expect } from 'chai'; 5 | import nock from 'nock'; 6 | 7 | const SK = 'sk_test_0b9b5db6-f223-49d0-b68f-f6643dd4f808'; 8 | 9 | describe('Files', () => { 10 | it('should upload file', async () => { 11 | nock('https://api.sandbox.checkout.com') 12 | .post('/files') 13 | .reply(200, { 14 | id: 'file_zna32sccqbwevd3ldmejtplbhu', 15 | _links: { 16 | self: { 17 | href: 18 | 'https://api.sandbox.checkout.com/files/file_zna32sccqbwevd3ldmejtplbhu', 19 | }, 20 | }, 21 | }); 22 | 23 | const cko = new Checkout(SK); 24 | 25 | const file = await cko.files.upload({ 26 | path: fs.createReadStream('./test/files/evidence.jpg'), 27 | purpose: 'dispute_evidence', 28 | }); 29 | expect(file.id) 30 | .to.be.a('string') 31 | .and.satisfy((msg) => msg.startsWith('file_')); 32 | }).timeout(120000); 33 | 34 | it('should upload file from the external source', async () => { 35 | nock('https://api.sandbox.checkout.com') 36 | .post('/files') 37 | .reply(200, { 38 | id: 'file_qzhaicujhxme3fe5g75sscmqme', 39 | _links: { 40 | self: { 41 | href: 42 | 'https://api.sandbox.checkout.com/files/file_qzhaicujhxme3fe5g75sscmqme', 43 | }, 44 | }, 45 | }); 46 | 47 | const cko = new Checkout(SK); 48 | 49 | const file = await cko.files.upload({ 50 | file: 'https://media.ethicalads.io/media/images/2020/12/ethicalads_2.jpg', 51 | purpose: 'dispute_evidence', 52 | }); 53 | 54 | expect(file.id) 55 | .to.be.a('string') 56 | .and.satisfy((msg) => msg.startsWith('file_')); 57 | }).timeout(120000); 58 | 59 | it('should throw ValidationError when trying to upload file', async () => { 60 | nock('https://api.sandbox.checkout.com') 61 | .post('/files') 62 | .reply(422, { 63 | request_id: '0HM3QH3MKNCKA:00000001', 64 | error_type: 'request_unprocessable', 65 | error_codes: ['file_required'], 66 | }); 67 | const cko = new Checkout(SK); 68 | 69 | try { 70 | const file = await cko.files.upload({ 71 | path: '', 72 | purpose: 'dispute_evidence', 73 | }); 74 | } catch (err) { 75 | expect(err).to.be.instanceOf(ValidationError); 76 | } 77 | }); 78 | 79 | it('should get file', async () => { 80 | nock('https://api.sandbox.checkout.com') 81 | .post('/files') 82 | .reply(200, { 83 | id: 'file_zna32sccqbwevd3ldmejtplbhu', 84 | _links: { 85 | self: { 86 | href: 87 | 'https://api.sandbox.checkout.com/files/file_zna32sccqbwevd3ldmejtplbhu', 88 | }, 89 | }, 90 | }); 91 | 92 | nock('https://api.sandbox.checkout.com') 93 | .get('/files/file_zna32sccqbwevd3ldmejtplbhu') 94 | .reply(200, { 95 | id: 'file_zna32sccqbwevd3ldmejtplbhu', 96 | filename: 'evidence.jpg', 97 | purpose: 'dispute_evidence', 98 | size: 4307, 99 | uploaded_on: '2020-04-27T05:17:37Z', 100 | _links: { 101 | self: { 102 | href: 103 | 'https://api.sandbox.checkout.com/files/file_zna32sccqbwevd3ldmejtplbhu', 104 | }, 105 | download: { 106 | href: 'https://example.com/evidence.jpg', 107 | }, 108 | }, 109 | }); 110 | 111 | const cko = new Checkout(SK); 112 | 113 | const file = await cko.files.upload({ 114 | path: fs.createReadStream('./test/files/evidence.jpg'), 115 | purpose: 'dispute_evidence', 116 | }); 117 | expect(file.id) 118 | .to.be.a('string') 119 | .and.satisfy((msg) => msg.startsWith('file_')); 120 | 121 | const getFile = await cko.files.getFile(file.id); 122 | expect(getFile.id).to.equal(file.id); 123 | }).timeout(120000); 124 | 125 | it('should throw Authentication error', async () => { 126 | nock('https://api.sandbox.checkout.com') 127 | .get('/files/file_zna32sccqbwevd3ldmejtplbhu') 128 | .reply(401); 129 | const cko = new Checkout(); 130 | 131 | try { 132 | const disputes = await cko.files.getFile('file_zna32sccqbwevd3ldmejtplbhu'); 133 | } catch (err) { 134 | expect(err).to.be.instanceOf(AuthenticationError); 135 | } 136 | }); 137 | }); 138 | -------------------------------------------------------------------------------- /test/financial/financial.js: -------------------------------------------------------------------------------- 1 | import { AuthenticationError } from '../../src/services/errors'; 2 | import { Checkout } from '../../src/index'; 3 | import { expect } from 'chai'; 4 | import nock from 'nock'; 5 | 6 | const SK = 'sk_sbox_o2nulev2arguvyf6w7sc5fkznas'; 7 | 8 | describe('Financial', () => { 9 | it('should get financial actions', async () => { 10 | nock('https://api.sandbox.checkout.com') 11 | .get('/financial-actions?payment_id=pay_l5rvkbinxztepjskr7vwlovzsq&limit=5') 12 | .reply(200, { 13 | count: 1, 14 | limit: 5, 15 | data: [ 16 | { 17 | payment_id: 'pay_l5rvkbinxztepjskr7vwlovzsq', 18 | action_id: 'act_wsnyzbzmr2huxcekoj7qqhxwuy', 19 | action_type: 'Capture', 20 | entity_id: 'ent_xozz5q2yvxsetbslrvjxugbsyy', 21 | sub_entity_id: 'ent_6akzb5simnkejihbnw6udjpecq', 22 | currency_account_id: 'ca_oo5z564in66ujcsxlbhjsar3p4', 23 | payment_method: 'MASTERCARD', 24 | processing_channel_id: 'pc_y7hikmc5flhuvav47blunjsdui', 25 | reference: 'SAMPLE6V6OR', 26 | mid: 'mid-12345', 27 | response_code: 10000, 28 | response_description: 'Approved', 29 | region: 'International', 30 | card_type: 'Debit', 31 | card_category: 'Consumer', 32 | issuer_country: 'US', 33 | merchant_category_code: 5311, 34 | fx_trade_id: 'trd_intsaxljgi6uzkxnv6lex3xayu', 35 | processed_on: '2022-02-18T13:00:12.357Z', 36 | requested_on: '2022-02-18T13:00:11.724Z', 37 | breakdown: [ 38 | { 39 | breakdown_type: 'Scheme Fixed Fee', 40 | fx_rate_applied: 1.24, 41 | holding_currency: 'USD', 42 | holding_currency_amount: 0.19526938, 43 | processing_currency: 'GBP', 44 | processing_currency_amount: 0.1581682, 45 | transaction_currency: 'EUR', 46 | transaction_currency_account: 0.18031175, 47 | processing_to_transaction_currency_fx_rate: 1.14, 48 | transaction_to_holding_currency_fx_rate: 1.08, 49 | fee_detail: 'Visa Fixed Acquirer Network Fee', 50 | reserve_rate: '5%', 51 | reserve_release_date: '2023-06-21T09:15:34.782Z', 52 | reserve_deducted_date: '2022-02-18T13:00:12.357Z', 53 | tax_fx_rate: 1.45, 54 | entity_country_tax_currency: 'AUD', 55 | tax_currency_amount: 'AUD' 56 | } 57 | ] 58 | }, 59 | ], 60 | _links: { 61 | self: { 62 | href: 'https://api.checkout.com/financial-actions?payment_id=pay_l5rvkbinxztepjskr7vwlovzsq&limit=5', 63 | }, 64 | next: { 65 | href: 'https://api.checkout.com/financial-actions?payment_id=pay_l5rvkbinxztepjskr7vwlovzsq&limit=5', 66 | }, 67 | }, 68 | }); 69 | 70 | const cko = new Checkout(SK); 71 | 72 | const actions = await cko.financial.query({ 73 | limit: 5, 74 | payment_id: 'pay_l5rvkbinxztepjskr7vwlovzsq', 75 | }); 76 | 77 | expect(actions.limit).to.equal(5); 78 | expect(actions.data).to.not.be.empty; 79 | }); 80 | 81 | it('should throw auth error getting financial actions', async () => { 82 | nock('https://api.sandbox.checkout.com').get('/financial-actions').reply(401); 83 | 84 | try { 85 | const cko = new Checkout(); 86 | 87 | const reports = await cko.financial.query(); 88 | } catch (err) { 89 | expect(err).to.be.instanceOf(AuthenticationError); 90 | } 91 | }); 92 | }); -------------------------------------------------------------------------------- /test/http/additionalHeaders.js: -------------------------------------------------------------------------------- 1 | import { Checkout } from '../../src/index'; 2 | import { expect } from 'chai'; 3 | import nock from 'nock'; 4 | 5 | const PK = 'pk_test_4296fd52-efba-4a38-b6ce-cf0d93639d8a'; 6 | 7 | describe('HTTP', () => { 8 | // Nice feature of `reqheaders` is that the value can be a function returning a boolean. 9 | // Since we don't care about the actual value of the headers, returning true has the effect 10 | // of matching if the header simply exists. 11 | const mockHeadersMatcher = { 12 | 'additional-header-a': () => true, 13 | 'additional-Header-b': () => true, 14 | }; 15 | 16 | const mockToken = { 17 | type: 'card', 18 | token: 'tok_pmjyslgaam4uzmvaiwqyhovvsy', 19 | expires_on: '2020-01-30T15:08:33Z', 20 | expiry_month: 6, 21 | expiry_year: 2029 22 | } 23 | 24 | it('should be able to pass additional headers', async () => { 25 | nock('https://api.sandbox.checkout.com', { 26 | reqheaders: mockHeadersMatcher 27 | }) 28 | .post('/tokens') 29 | .reply(201, mockToken); 30 | 31 | const cko = new Checkout(null, { 32 | headers: { 33 | 'additional-header-a': 'valueA', 34 | 'additional-Header-b': 'valueB', 35 | } 36 | }); 37 | cko.config.pk = PK; 38 | 39 | const token = await cko.tokens.request({ 40 | type: 'card', 41 | number: '4242424242424242', 42 | expiry_month: 6, 43 | expiry_year: 2029, 44 | cvv: '100' 45 | }); 46 | 47 | expect(token).to.deep.equal(mockToken); 48 | }); 49 | 50 | it('should not match a request when additional headers are not provided', async () => { 51 | nock('https://api.sandbox.checkout.com', { 52 | reqheaders: mockHeadersMatcher 53 | }) 54 | .post('/tokens') 55 | .reply(201, mockToken); 56 | 57 | const cko = new Checkout(); 58 | cko.config.pk = PK; 59 | 60 | let errorWasThrown = false; 61 | 62 | try { 63 | await cko.tokens.request({ 64 | type: 'card', 65 | number: '4242424242424242', 66 | expiry_month: 6, 67 | expiry_year: 2029, 68 | cvv: '100' 69 | }); 70 | } catch (error) { 71 | errorWasThrown = true; 72 | } 73 | 74 | expect(errorWasThrown).to.equal(true); 75 | }); 76 | }); 77 | -------------------------------------------------------------------------------- /test/instruments/instruments-it.js: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import nock from "nock"; 3 | import Checkout from '../../src/Checkout.js' 4 | import { ValidationError } from "../../src/services/errors.js"; 5 | 6 | afterEach(() => { 7 | nock.cleanAll(); 8 | nock.enableNetConnect(); 9 | }); 10 | 11 | const cko = new Checkout(process.env.CHECKOUT_DEFAULT_SECRET_KEY, { 12 | pk: process.env.CHECKOUT_PREVIOUS_PUBLIC_KEY, 13 | environment: 'sandbox', 14 | }); 15 | 16 | const sepaRequest = { 17 | "type": "sepa", 18 | "instrument_data": { 19 | "account_number": "FR2810096000509685512959O86", 20 | "country": "FR", 21 | "currency": "EUR", 22 | "payment_type": "recurring", 23 | "mandate_id": "1234567890", 24 | "date_of_signature": "2020-01-01" 25 | }, 26 | "account_holder": { 27 | "first_name": "John", 28 | "last_name": "Smith", 29 | "billing_address": { 30 | "address_line1": "Cloverfield St.", 31 | "address_line2": "23A", 32 | "city": "London", 33 | "zip": "SW1A 1AA", 34 | "country": "GB" 35 | } 36 | } 37 | } 38 | 39 | describe('Instruments::Create', () => { 40 | describe('Sepa', () => { 41 | 42 | it('Should create a Sepa Instrument', async () => { 43 | const response = await cko.instruments.create(sepaRequest); 44 | 45 | expect(response).to.not.be.null; 46 | expect(response.id).to.not.be.null; 47 | expect(response.fingerprint).to.not.be.null; 48 | }); 49 | 50 | it('Should return a ValidationError with invalid Sepa Instrument Request', async () => { 51 | try { 52 | await cko.instruments.create({}); 53 | } catch (error) { 54 | expect(error).to.be.instanceOf(ValidationError); 55 | } 56 | }); 57 | }); 58 | }); -------------------------------------------------------------------------------- /test/payment-contexts/payment-contexts-it.js: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import nock from "nock"; 3 | import Checkout from '../../src/Checkout.js' 4 | import { NotFoundError, ValidationError } from "../../src/services/errors.js"; 5 | 6 | afterEach(() => { 7 | nock.cleanAll(); 8 | nock.enableNetConnect(); 9 | }); 10 | 11 | const cko = new Checkout(process.env.CHECKOUT_DEFAULT_SECRET_KEY); 12 | const processingChannelId = process.env.CHECKOUT_PROCESSING_CHANNEL_ID; 13 | 14 | describe('Integration::Payment-Contexts', () => { 15 | describe('Paypal request', () => { 16 | const request = { 17 | source: { 18 | type: "paypal" 19 | }, 20 | amount: 2000, 21 | currency: "EUR", 22 | paymentType: "Regular", 23 | capture: true, 24 | processing_channel_id: processingChannelId, 25 | success_url: "https://example.com/payments/success", 26 | failure_url: "https://example.com/payments/fail", 27 | items: [ 28 | { 29 | name: "mask", 30 | quantity: 1, 31 | unit_price: 2000, 32 | } 33 | ] 34 | } 35 | 36 | it('should request a payment context', async () => { 37 | const response = await cko.paymentContexts.request(request); 38 | 39 | expect(response.id).not.to.be.null; 40 | expect(response.partner_metadata.order_id).not.to.be.null; 41 | }); 42 | 43 | it('should get a payment context', async () => { 44 | const responseRequest = await cko.paymentContexts.request(request); 45 | const response = await cko.paymentContexts.get(responseRequest.id); 46 | 47 | expect(response.payment_request.source.type).to.equal('paypal'); 48 | expect(response.payment_request.amount).to.equal(2000); 49 | expect(response.payment_request.currency).to.equal("EUR"); 50 | expect(response.payment_request.currency.items).to.not.be.null; 51 | expect(response.payment_request.success_url).to.equal('https://example.com/payments/success'); 52 | expect(response.payment_request.failure_url).to.equal('https://example.com/payments/fail'); 53 | }); 54 | 55 | it('should throw NotFoundError when getting an unexistant payment context', async () => { 56 | try { 57 | await cko.paymentContexts.get('not_found'); 58 | } catch (err) { 59 | expect(err).to.be.instanceOf(NotFoundError); 60 | } 61 | }); 62 | }); 63 | 64 | describe('Klarna request', () => { 65 | const request = { 66 | source: { 67 | type: "klarna", 68 | account_holder: { 69 | billing_address: { 70 | country: 'DE', 71 | }, 72 | }, 73 | }, 74 | amount: 1000, 75 | currency: "EUR", 76 | paymentType: "Regular", 77 | processing_channel_id: processingChannelId, 78 | items: [ 79 | { 80 | name: "mask", 81 | quantity: 1, 82 | unit_price: 1000, 83 | total_amount: 1000, 84 | reference: "BA67A" 85 | } 86 | ], 87 | processing: { 88 | locale: "en-GB" 89 | } 90 | } 91 | 92 | it('should request a payment context and get apm service unavailable', async () => { 93 | try { 94 | await cko.paymentContexts.request(request); 95 | } catch (error) { 96 | expect(error).to.be.instanceOf(ValidationError); 97 | expect(error.http_code).to.equal(422); 98 | expect(error.body.error_codes).to.contain("apm_service_unavailable"); 99 | } 100 | 101 | }); 102 | 103 | it.skip('should request a payment context', async () => { 104 | const response = await cko.paymentContexts.request(request); 105 | 106 | expect(response.id).not.to.be.null; 107 | expect(response.partner_metadata.order_id).not.to.be.null; 108 | }); 109 | 110 | it.skip('should get a payment context', async () => { 111 | const responseRequest = await cko.paymentContexts.request(request); 112 | const response = await cko.paymentContexts.get(responseRequest.id); 113 | 114 | expect(response.payment_request.source.type).to.equal('klarna'); 115 | expect(response.payment_request.source.account_holder).to.not.be.null; 116 | expect(response.payment_request.amount).to.equal(2000); 117 | expect(response.payment_request.currency).to.equal("EUR"); 118 | expect(response.payment_request.currency.items).to.not.be.null; 119 | expect(response.payment_request.success_url).to.equal('https://example.com/payments/success'); 120 | expect(response.payment_request.failure_url).to.equal('https://example.com/payments/fail'); 121 | }); 122 | }); 123 | }); -------------------------------------------------------------------------------- /test/payment-sessions/payment-sessions-common.js: -------------------------------------------------------------------------------- 1 | export const commonRequest = { 2 | amount: 1000, 3 | currency: 'GBP', 4 | reference: 'ORD-123A', 5 | billing: { 6 | address: { 7 | country: 'GB' 8 | } 9 | }, 10 | customer: { 11 | name: 'John Smith', 12 | email: 'john.smith@example.com' 13 | }, 14 | success_url: 'https://example.com/payments/success', 15 | failure_url: 'https://example.com/payments/failure' 16 | }; 17 | 18 | export const commonResponse = { 19 | id: 'ps_2aOig7knIeGNYPlyuxUEPQyOmxN', 20 | amount: 1000, 21 | locale: 'en-GB', 22 | currency: 'GBP', 23 | payment_methods: [ 24 | { 25 | type: 'card', 26 | scheme_choice_enabled: false, 27 | store_payment_details: 'disabled' 28 | }, 29 | { 30 | type: 'applepay', 31 | display_name: 'Parser Digital', 32 | country_code: 'GB', 33 | currency_code: 'GBP', 34 | }, 35 | { 36 | type: 'googlepay', 37 | } 38 | ], 39 | feature_flags: [], 40 | risk: { enabled: true }, 41 | _links: { 42 | self: { 43 | href: 'https://api.sandbox.checkout.com/payment-sessions/ps_2aOig7knIeGNYPlyuxUEPQyOmxN' 44 | } 45 | } 46 | }; 47 | 48 | export const commonSubmitRequest = { 49 | session_data: "string", 50 | amount: 1000, 51 | reference: "ORD-123A", 52 | items: [ 53 | { 54 | reference: "string", 55 | commodity_code: "string", 56 | unit_of_measure: "string", 57 | total_amount: 1000, 58 | tax_amount: 1000, 59 | discount_amount: 1000, 60 | url: "string", 61 | image_url: "string", 62 | name: "Gold Necklace", 63 | quantity: 1, 64 | unit_price: 1000 65 | } 66 | ], 67 | "3ds": { 68 | enabled: false, 69 | attempt_n3d: false, 70 | challenge_indicator: "no_preference", 71 | exemption: "low_value", 72 | allow_upgrade: true 73 | }, 74 | ip_address: "90.197.169.245" 75 | }; 76 | 77 | export const commonSubmitResponseCreated = { 78 | id: "pay_mbabizu24mvu3mela5njyhpit4", 79 | status: "Approved", 80 | type: "alipay_cn" 81 | }; 82 | 83 | export const commonSubmitResponseAccepted = { 84 | id: "pay_mbabizu24mvu3mela5njyhpit4", 85 | status: "Action Required", 86 | type: "string", 87 | action: {} 88 | }; -------------------------------------------------------------------------------- /test/payment-sessions/payment-sessions-it.js: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import nock from "nock"; 3 | import Checkout from '../../src/Checkout.js' 4 | import { commonRequest, commonSubmitRequest } from "./payment-sessions-common.js"; 5 | 6 | afterEach(() => { 7 | nock.cleanAll(); 8 | nock.enableNetConnect(); 9 | }); 10 | 11 | const cko = new Checkout(process.env.CHECKOUT_DEFAULT_SECRET_KEY); 12 | 13 | describe('Integration::Payment-Sessions', () => { 14 | 15 | it('should request a payment session', async () => { 16 | const response = await cko.paymentSessions.request(commonRequest); 17 | 18 | expect(response.id).not.to.be.null; 19 | expect(response._links).not.to.be.null; 20 | }); 21 | 22 | it.skip('should submit a payment session', async () => { 23 | const response1 = await cko.paymentSessions.request(commonRequest); 24 | const response2 = await cko.paymentSessions.submit(response1.id, commonSubmitRequest); 25 | 26 | expect(response2.id).not.to.be.null; 27 | }); 28 | 29 | }); -------------------------------------------------------------------------------- /test/payment-sessions/payment-sessions-unit.js: -------------------------------------------------------------------------------- 1 | import nock from "nock"; 2 | import { expect } from "chai"; 3 | import Checkout from "../../src/Checkout.js"; 4 | import { commonRequest, commonResponse, commonSubmitRequest, commonSubmitResponseAccepted, commonSubmitResponseCreated } from "./payment-sessions-common.js"; 5 | 6 | 7 | describe('Unit::Payment-Sessions', () => { 8 | const SK = 'sk_test_0b9b5db6-f223-49d0-b68f-f6643dd4f808'; 9 | 10 | it('should request a payment session', async () => { 11 | nock('https://api.sandbox.checkout.com') 12 | .post('/payment-sessions') 13 | .reply(201, commonResponse); 14 | 15 | const cko = new Checkout(SK); 16 | 17 | const paymentContextResponse = await cko.paymentSessions.request(commonRequest); 18 | 19 | expect(paymentContextResponse.id).to.equal('ps_2aOig7knIeGNYPlyuxUEPQyOmxN'); 20 | expect(paymentContextResponse.amount).to.equal(1000); 21 | expect(paymentContextResponse.locale).to.equal('en-GB'); 22 | expect(paymentContextResponse.currency).to.equal('GBP'); 23 | expect(paymentContextResponse.payment_methods[0].type).to.equal('card'); 24 | expect(paymentContextResponse.risk.enabled).to.equal(true); 25 | expect(paymentContextResponse._links.self.href).to.equal('https://api.sandbox.checkout.com/payment-sessions/ps_2aOig7knIeGNYPlyuxUEPQyOmxN'); 26 | }); 27 | 28 | it('should submit and create a payment session', async () => { 29 | nock('https://api.sandbox.checkout.com') 30 | .post('/payment-sessions/pay_mbabizu24mvu3mela5njyhpit4/submit') 31 | .reply(201, commonSubmitResponseCreated); 32 | 33 | const cko = new Checkout(SK); 34 | 35 | const paymentContextResponse = await cko.paymentSessions.submit('pay_mbabizu24mvu3mela5njyhpit4', commonSubmitRequest); 36 | 37 | expect(paymentContextResponse.id).to.equal('pay_mbabizu24mvu3mela5njyhpit4'); 38 | expect(paymentContextResponse.status).to.equal('Approved'); 39 | expect(paymentContextResponse.type).to.equal("alipay_cn"); 40 | }); 41 | 42 | it('should submit and accept payment session', async () => { 43 | nock('https://api.sandbox.checkout.com') 44 | .post('/payment-sessions/pay_mbabizu24mvu3mela5njyhpit4/submit') 45 | .reply(202, commonSubmitResponseAccepted); 46 | 47 | const cko = new Checkout(SK); 48 | 49 | const paymentContextResponse = await cko.paymentSessions.submit('pay_mbabizu24mvu3mela5njyhpit4', commonSubmitRequest); 50 | 51 | expect(paymentContextResponse.id).to.equal('pay_mbabizu24mvu3mela5njyhpit4'); 52 | expect(paymentContextResponse.status).to.equal('Action Required'); 53 | }); 54 | 55 | }); -------------------------------------------------------------------------------- /test/payments/cancelPayment.js: -------------------------------------------------------------------------------- 1 | import { Checkout } from '../../src/index'; 2 | import { expect } from 'chai'; 3 | import nock from 'nock'; 4 | 5 | const SK = 'sk_test_0b9b5db6-f223-49d0-b68f-f6643dd4f808'; 6 | 7 | describe('Cancel a scheduled retry', () => { 8 | it('should cancel payment with a body', async () => { 9 | nock('https://api.sandbox.checkout.com') 10 | .post('/payments') 11 | .reply( 12 | 201, 13 | { 14 | id: 'pay_6ndp5facelxurne7gloxkxm57u', 15 | action_id: 'act_6ndp5facelxurne7gloxkxm57u', 16 | amount: 100, 17 | currency: 'USD', 18 | approved: true, 19 | status: 'Authorized', 20 | auth_code: '277368', 21 | response_code: '10000', 22 | response_summary: 'Approved', 23 | '3ds': undefined, 24 | risk: { flagged: false }, 25 | source: { 26 | id: 'src_mtagg5kktcoerkwloibzfuilpy', 27 | type: 'card', 28 | expiry_month: 6, 29 | expiry_year: 2029, 30 | scheme: 'Visa', 31 | last4: '4242', 32 | fingerprint: 33 | '107A352DFAE35E3EEBA5D0856FCDFB88ECF91E8CFDE4275ABBC791FD9579AB2C', 34 | bin: '424242', 35 | card_type: 'Credit', 36 | card_category: 'Consumer', 37 | issuer: 'JPMORGAN CHASE BANK NA', 38 | issuer_country: 'US', 39 | product_id: 'A', 40 | product_type: 'Visa Traditional', 41 | avs_check: 'S', 42 | cvv_check: 'Y', 43 | }, 44 | customer: { id: 'cus_leu5pp2zshpuvbt6yjxl5xcrdi' }, 45 | processed_on: '2019-06-09T22:43:54Z', 46 | reference: undefined, 47 | eci: '05', 48 | scheme_id: '638284745624527', 49 | _links: { 50 | self: { 51 | href: 'https://api.sandbox.checkout.com/payments/pay_6ndp5facelxurne7gloxkxm57u', 52 | }, 53 | actions: { 54 | href: 'https://api.sandbox.checkout.com/payments/pay_6ndp5facelxurne7gloxkxm57u/actions', 55 | }, 56 | capture: { 57 | href: 'https://api.sandbox.checkout.com/payments/pay_6ndp5facelxurne7gloxkxm57u/captures', 58 | }, 59 | void: { 60 | href: 'https://api.sandbox.checkout.com/payments/pay_6ndp5facelxurne7gloxkxm57u/voids', 61 | }, 62 | }, 63 | }, 64 | { 65 | 'cko-request-id': ['1695a930-09cf-4db0-a91e-a772e6ee076g'], 66 | 'cko-version': ['3.31.4'], 67 | } 68 | ); 69 | 70 | nock('https://api.sandbox.checkout.com') 71 | .post(/cancellations$/) 72 | .reply(202, { 73 | action_id: 'act_y3oqhf46pyzuxjbcn2giaqnb44', 74 | reference: 'ORD-5023-4E89', 75 | _links: { 76 | payment: { 77 | href: 'https://api.checkout.com/payments/pay_y3oqhf46pyzuxjbcn2giaqnb44', 78 | }, 79 | }, 80 | }); 81 | 82 | const cko = new Checkout(SK); 83 | 84 | const transaction = await cko.payments.request({ 85 | source: { 86 | number: '4242424242424242', 87 | expiry_month: 6, 88 | expiry_year: 2029, 89 | cvv: '100', 90 | }, 91 | currency: 'USD', 92 | capture: false, 93 | reference: 'ORD-5023-4E89', 94 | amount: 100, 95 | }); 96 | const paymentId = transaction.id; 97 | const cancel = await cko.payments.cancelScheduledRetry(paymentId, { 98 | reference: 'ORD-5023-4E89', 99 | }); 100 | 101 | expect(cancel.reference).to.equal('ORD-5023-4E89'); 102 | }); 103 | 104 | it('should throw AuthenticationError', async () => { 105 | nock('https://api.sandbox.checkout.com') 106 | .post('/payments/pay_7enxra4adw6evgalvfabl6nbqy/cancellations') 107 | .reply(401); 108 | 109 | try { 110 | const cko = new Checkout('sk_test_0b9b5db6-f223-49d0-b68f-f6643dd4f809'); 111 | await cko.payments.cancelScheduledRetry('pay_7enxra4adw6evgalvfabl6nbqy', { 112 | reference: 'ORD-5023-4E89', 113 | }); 114 | } catch (err) { 115 | expect(err.name).to.equal('AuthenticationError'); 116 | } 117 | }); 118 | 119 | it('should throw action not allowed error', async () => { 120 | nock('https://api.sandbox.checkout.com') 121 | .post('/payments/pay_7enxra4adw6evgalvfabl6nbaa/cancellations') 122 | .reply(403); 123 | 124 | try { 125 | const cko = new Checkout(SK); 126 | await cko.payments.cancelScheduledRetry('pay_7enxra4adw6evgalvfabl6nbaa', { 127 | reference: 'ORD-5023-4E89', 128 | }); 129 | } catch (err) { 130 | expect(err.name).to.equal('ActionNotAllowed'); 131 | } 132 | }); 133 | 134 | it('should throw payment not found error', async () => { 135 | nock('https://api.sandbox.checkout.com') 136 | .post('/payments/pay_7enxra4adw6evgalvfabl6nbaa/cancellations') 137 | .reply(404); 138 | 139 | try { 140 | const cko = new Checkout(SK); 141 | await cko.payments.cancelScheduledRetry('pay_7enxra4adw6evgalvfabl6nbaa', { 142 | reference: 'ORD-5023-4E89', 143 | }); 144 | } catch (err) { 145 | expect(err.name).to.equal('NotFoundError'); 146 | } 147 | }); 148 | }); -------------------------------------------------------------------------------- /test/payments/getPayment.js: -------------------------------------------------------------------------------- 1 | import { AuthenticationError, NotFoundError } from "../../src/services/errors.js"; 2 | import { Checkout } from "../../src/index.js"; 3 | import { expect } from "chai"; 4 | import nock from "nock"; 5 | 6 | const SK = "sk_test_0b9b5db6-f223-49d0-b68f-f6643dd4f808"; 7 | 8 | describe("Get payment details", () => { 9 | it("should get payment details with payment id", async () => { 10 | nock("https://api.sandbox.checkout.com") 11 | .get("/payments/pay_je5hbbb4u3oe7k4u3lbwlu3zkq") 12 | .reply(200, { 13 | id: "pay_je5hbbb4u3oe7k4u3lbwlu3zkq", 14 | requested_on: "2020-01-29T11:20:06Z", 15 | source: { 16 | id: "src_yiorsxzfwy4uzkl5excqum4r6m", 17 | type: "card", 18 | expiry_month: 10, 19 | expiry_year: 2029, 20 | scheme: "Visa", 21 | last4: "4242", 22 | fingerprint: 23 | "511233E01627B17FB2823C37A8AEFBEB71B673671756B30B646111EAC2A70E86", 24 | bin: "424242", 25 | card_type: "Credit", 26 | card_category: "Consumer", 27 | issuer: "JPMORGAN CHASE BANK NA", 28 | issuer_country: "US", 29 | product_id: "A", 30 | product_type: "Visa Traditional", 31 | avs_check: "S", 32 | cvv_check: "Y", 33 | payouts: true, 34 | fast_funds: "d" 35 | }, 36 | amount: 0, 37 | currency: "GBP", 38 | payment_type: "Regular", 39 | status: "Card Verified", 40 | approved: true, 41 | '3ds': { 42 | downgraded: false, 43 | enrolled: 'Y', 44 | signature_valid: 'Y', 45 | authentication_response: 'Y', 46 | authentication_status_reason: 'string', 47 | cryptogram: 'hv8mUFzPzRZoCAAAAAEQBDMAAAA=', 48 | xid: 'MDAwMDAwMDAwMDAwMDAwMzIyNzY=', 49 | version: '2.1.0', 50 | exemption: 'low_value', 51 | exemption_applied: 'string', 52 | challenged: true, 53 | upgrade_reason: 'sca_retry' 54 | }, 55 | risk: { 56 | flagged: false 57 | }, 58 | customer: { 59 | id: "cus_4tq74vh6u7zuvnnvkzimznkauu" 60 | }, 61 | eci: "05", 62 | scheme_id: "650050831378549", 63 | _links: { 64 | self: { 65 | href: 66 | "https://api.sandbox.checkout.com/payments/pay_je5hbbb4u3oe7k4u3lbwlu3zkq" 67 | }, 68 | actions: { 69 | href: 70 | "https://api.sandbox.checkout.com/payments/pay_je5hbbb4u3oe7k4u3lbwlu3zkq/actions" 71 | } 72 | } 73 | }); 74 | 75 | const cko = new Checkout(SK); 76 | 77 | const transaction = await cko.payments.get( 78 | "pay_je5hbbb4u3oe7k4u3lbwlu3zkq" 79 | ); 80 | 81 | /* eslint-disable no-unused-expressions */ 82 | expect(transaction.approved).to.be.true; 83 | expect(transaction.id).to.equal("pay_je5hbbb4u3oe7k4u3lbwlu3zkq"); 84 | expect(transaction['3ds'].cryptogram).to.equal("hv8mUFzPzRZoCAAAAAEQBDMAAAA="); 85 | expect(transaction['3ds'].authentication_status_reason).to.equal("string"); 86 | }); 87 | 88 | it("should throw authentication error", async () => { 89 | nock("https://api.sandbox.checkout.com") 90 | .get("/payments/pay_je5hbbb4u3oe7k4u3lbwlu3zkq") 91 | .reply(401, {}); 92 | 93 | try { 94 | const cko = new Checkout("sk_test_0b9b5db6-f223-49d0-b68f-f6643dd4f809"); 95 | const transaction = await cko.payments.get( 96 | "pay_je5hbbb4u3oe7k4u3lbwlu3zkq" 97 | ); 98 | } catch (err) { 99 | expect(err).to.be.instanceOf(AuthenticationError); 100 | } 101 | }); 102 | 103 | it("should throw payment not found error", async () => { 104 | nock("https://api.sandbox.checkout.com") 105 | .get("/payments/pay_je5hbbb4u3oe7k4u3lbwlu3zkv") 106 | .reply(404); 107 | 108 | try { 109 | const cko = new Checkout(SK); 110 | const transaction = await cko.payments.get( 111 | "pay_je5hbbb4u3oe7k4u3lbwlu3zkv" 112 | ); 113 | } catch (err) { 114 | expect(err).to.be.instanceOf(NotFoundError); 115 | } 116 | }); 117 | }); 118 | -------------------------------------------------------------------------------- /test/payments/getPaymentActions.js: -------------------------------------------------------------------------------- 1 | import { NotFoundError } from "../../src/services/errors.js"; 2 | import { Checkout } from "../../src/index.js"; 3 | import { expect } from "chai"; 4 | import nock from "nock"; 5 | 6 | const SK = "sk_test_0b9b5db6-f223-49d0-b68f-f6643dd4f808"; 7 | 8 | describe("Get payment actions", () => { 9 | it("should get payment acrtions", async () => { 10 | nock("https://api.sandbox.checkout.com") 11 | .get("/payments/pay_juevt3h5mcjulir2t5g3wfug6u/actions") 12 | .reply(200, [ 13 | { 14 | id: "act_t6ksnbs3tguu7iblmk22jjimca", 15 | type: "Capture", 16 | processed_on: "2020-01-29T11:53:40Z", 17 | amount: 100, 18 | approved: true, 19 | response_code: "10000", 20 | response_summary: "Approved", 21 | processing: { 22 | acquirer_transaction_id: "7290001341", 23 | acquirer_reference_number: "175286612147" 24 | } 25 | }, 26 | { 27 | id: "act_juevt3h5mcjulir2t5g3wfug6u", 28 | type: "Authorization", 29 | processed_on: "2020-01-29T11:53:40Z", 30 | amount: 100, 31 | approved: true, 32 | auth_code: "745837", 33 | response_code: "10000", 34 | response_summary: "Approved", 35 | processing: { 36 | acquirer_transaction_id: "9691257557", 37 | retrieval_reference_number: "564911204253" 38 | } 39 | } 40 | ]); 41 | const cko = new Checkout(SK); 42 | const transaction = await cko.payments.getActions( 43 | "pay_juevt3h5mcjulir2t5g3wfug6u" 44 | ); 45 | /* eslint-disable no-unused-expressions */ 46 | expect(transaction.length).to.equal(2); 47 | expect(transaction[0].type).to.equal("Capture"); 48 | }); 49 | 50 | it("should throw AuthenticationError", async () => { 51 | nock("https://api.sandbox.checkout.com") 52 | .get("/payments/pay_juevt3h5mcjulir2t5g3wfug6u/actions") 53 | .reply(401); 54 | 55 | try { 56 | const cko = new Checkout("sk_test_0b9b5db6-f223-49d0-b68f-f6643dd4f801"); 57 | const transaction = await cko.payments.getActions( 58 | "pay_juevt3h5mcjulir2t5g3wfug6u" 59 | ); 60 | } catch (err) { 61 | expect(err.name).to.equal("AuthenticationError"); 62 | } 63 | }); 64 | 65 | it("should throw payment not found error", async () => { 66 | nock("https://api.sandbox.checkout.com") 67 | .get("/payments/pay_juevt3h5mcjulir2t5g3wfug6u/actions") 68 | .reply(404); 69 | 70 | try { 71 | const cko = new Checkout(SK); 72 | const transaction = await cko.payments.getActions( 73 | "pay_juevt3h5mcjulir2t5g3wfug6u" 74 | ); 75 | } catch (err) { 76 | expect(err).to.be.instanceOf(NotFoundError); 77 | } 78 | }); 79 | }); 80 | -------------------------------------------------------------------------------- /test/payments/getPaymentList.js: -------------------------------------------------------------------------------- 1 | import { AuthenticationError, } from '../../src/services/errors'; 2 | import { Checkout } from '../../src/index'; 3 | import { expect } from 'chai'; 4 | import nock from 'nock'; 5 | 6 | const SK = 'sk_sbox_o2nulev2arguvyf6w7sc5fkznas'; 7 | 8 | describe('Get payment list', () => { 9 | it('should get a payment list with reference', async () => { 10 | nock('https://api.sandbox.checkout.com') 11 | .get('/payments?reference=1234') 12 | .reply(200, { 13 | total_count: 1, 14 | skip: 0, 15 | limit: 10, 16 | data: [ 17 | { 18 | id: 'pay_3lird6z63jpujguvaxnjyqsu4e', 19 | requested_on: '2022-11-16T11:49:05.7569066Z', 20 | source: { 21 | id: 'src_tau2xntwuseurnshye5fp722g4', 22 | type: 'card', 23 | expiry_month: 11, 24 | expiry_year: 2024, 25 | scheme: 'Visa', 26 | last4: '4242', 27 | fingerprint: 28 | '0418BC9FAEA9AC9630A54573D5ADEDB324F0255CE620CBA8CA62598726F3E77C', 29 | bin: '424242', 30 | card_type: 'CREDIT', 31 | card_category: 'CONSUMER', 32 | issuer_country: 'GB', 33 | product_id: 'F', 34 | product_type: 'Visa Classic', 35 | avs_check: 'G', 36 | cvv_check: 'Y', 37 | payment_account_reference: 'V001757443972836103', 38 | }, 39 | expires_on: '2022-12-16T11:49:05.867851Z', 40 | amount: 1000, 41 | currency: 'GBP', 42 | payment_type: 'Regular', 43 | reference: '1234', 44 | status: 'Authorized', 45 | approved: true, 46 | balances: { 47 | total_authorized: 1000, 48 | total_voided: 0, 49 | available_to_void: 1000, 50 | total_captured: 0, 51 | available_to_capture: 1000, 52 | total_refunded: 0, 53 | available_to_refund: 0, 54 | }, 55 | risk: { 56 | flagged: false, 57 | score: 0.0, 58 | }, 59 | scheme_id: '678355673241835', 60 | _links: { 61 | self: { 62 | href: 'https://api.sandbox.checkout.com/payments/pay_3lird6z63jpujguvaxnjyqsu4e', 63 | }, 64 | actions: { 65 | href: 'https://api.sandbox.checkout.com/payments/pay_3lird6z63jpujguvaxnjyqsu4e/actions', 66 | }, 67 | capture: { 68 | href: 'https://api.sandbox.checkout.com/payments/pay_3lird6z63jpujguvaxnjyqsu4e/captures', 69 | }, 70 | void: { 71 | href: 'https://api.sandbox.checkout.com/payments/pay_3lird6z63jpujguvaxnjyqsu4e/voids', 72 | }, 73 | }, 74 | }, 75 | ], 76 | }); 77 | 78 | const cko = new Checkout(SK); 79 | 80 | const list = await cko.payments.getPaymentList({ 81 | reference: '1234', 82 | }); 83 | 84 | expect(list.data[0].reference).to.equal('1234'); 85 | }); 86 | 87 | it('should throw authentication error', async () => { 88 | nock('https://api.sandbox.checkout.com').get('/payments?reference=1234').reply(401, {}); 89 | 90 | try { 91 | const cko = new Checkout('test'); 92 | 93 | const list = await cko.payments.getPaymentList({ 94 | reference: '1234', 95 | }); 96 | } catch (err) { 97 | expect(err).to.be.instanceOf(AuthenticationError); 98 | } 99 | }); 100 | }); 101 | -------------------------------------------------------------------------------- /test/platforms/evidence.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/checkout/checkout-sdk-node/98639d19b933f1f6c10942b9d6f1f1ff8f1decea/test/platforms/evidence.jpg -------------------------------------------------------------------------------- /test/platforms/platforms-reserve-rules-it.js: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import { createEntity, generateFutureDate } from '../utils.js'; 3 | import Checkout from '../../src/Checkout.js'; 4 | import nock from "nock"; 5 | 6 | describe('Integration::Platforms::Reserve Rules', () => { 7 | const cko_platforms = new Checkout(process.env.CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET, { 8 | client: process.env.CHECKOUT_DEFAULT_OAUTH_CLIENT_ID, 9 | scope: ['accounts'], 10 | environment: 'sandbox', 11 | }); 12 | 13 | let entityId; 14 | let reserveRuleId; 15 | 16 | before(async () => { 17 | entityId = await createEntity(); 18 | }); 19 | 20 | it('should add a reserve rule', async () => { 21 | const response = await cko_platforms.platforms.addReserveRule(entityId, { 22 | type: 'rolling', 23 | valid_from: generateFutureDate(), 24 | rolling: { 25 | percentage: 10, 26 | holding_duration: { 27 | weeks: 2 28 | } 29 | } 30 | }); 31 | 32 | expect(response).to.not.be.null; 33 | expect(response.id).to.not.be.null; 34 | reserveRuleId = response.id; 35 | }); 36 | 37 | it('should query reserve rules', async () => { 38 | const response = await cko_platforms.platforms.queryReserveRules(entityId); 39 | 40 | expect(response).to.not.be.null; 41 | expect(response.data).to.be.an('array'); 42 | expect(response.data[0].id).to.equal(reserveRuleId); 43 | }); 44 | 45 | it('should get reserve rule details', async () => { 46 | const response = await cko_platforms.platforms.getReserveRuleDetails(entityId, reserveRuleId); 47 | 48 | expect(response).to.not.be.null; 49 | expect(response.id).to.equal(reserveRuleId); 50 | expect(response.rolling.percentage).to.equal(10); 51 | }); 52 | 53 | it('should fail to update a reserve rule due to invalid If-Match header', async () => { 54 | nock(cko_platforms.config.host) 55 | .put(`/accounts/entities/${entityId}/reserve-rules/${reserveRuleId}`) 56 | .reply(412, { 57 | error: 'Precondition Failed', 58 | }, { 59 | 'If-Match': 'invalid-header-value', 60 | }); 61 | 62 | try { 63 | await cko_platforms.platforms.updateReserveRule( 64 | entityId, 65 | reserveRuleId, 66 | { 67 | type: 'rolling', 68 | valid_from: generateFutureDate(), 69 | rolling: { 70 | percentage: 15, 71 | holding_duration: { 72 | weeks: 4, 73 | }, 74 | }, 75 | }, 76 | 'invalid-header-value' 77 | ); 78 | } catch (err) { 79 | expect(err.http_code).to.equal(412); 80 | expect(err.body.error).to.equal('Precondition Failed'); 81 | } 82 | expect(nock.isDone()).to.be.true; 83 | }); 84 | }); 85 | -------------------------------------------------------------------------------- /test/reconciliation/report.csv: -------------------------------------------------------------------------------- 1 | reconciliation -------------------------------------------------------------------------------- /test/reports/report.csv: -------------------------------------------------------------------------------- 1 | reconciliation -------------------------------------------------------------------------------- /test/risk/risk.js: -------------------------------------------------------------------------------- 1 | import { AuthenticationError, } from '../../src/services/errors'; 2 | import { Checkout } from '../../src/index'; 3 | import { expect } from 'chai'; 4 | import nock from 'nock'; 5 | 6 | const SK = 'sk_test_0b9b5db6-f223-49d0-b68f-f6643dd4f808'; 7 | 8 | describe('Risk', () => { 9 | it('should request a pre-authentication risk scan', async () => { 10 | nock('https://api.sandbox.checkout.com') 11 | .post('/risk/assessments/pre-authentication') 12 | .reply(201, { 13 | assessment_id: 'ras_2r7jmh6r7urevgmouqtkjiw7ve', 14 | result: { 15 | decision: 'try_exemptions', 16 | }, 17 | _links: { 18 | pre_capture: { 19 | link: 'http://api.sandbox.checkout.com/risk/assessments/pre-capture', 20 | }, 21 | self: { 22 | link: 'http://api.sandbox.checkout.com/risk/assessments/ras_2r7jmh6r7urevgmouqtkjiw7ve', 23 | }, 24 | }, 25 | }); 26 | 27 | const cko = new Checkout(SK); 28 | 29 | const risk = await cko.risk.requestPreAuthentication({ 30 | source: { 31 | type: 'card', 32 | number: '4242424242424242', 33 | expiry_month: 6, 34 | expiry_year: 2029, 35 | cvv: '100', 36 | }, 37 | }); 38 | 39 | expect(risk.result.decision).to.equal('try_exemptions'); 40 | }); 41 | 42 | it('should request a pre-capture risk scan', async () => { 43 | nock('https://api.sandbox.checkout.com') 44 | .post('/risk/assessments/pre-capture') 45 | .reply(201, { 46 | assessment_id: 'ras_2r7jmh6r7urevgmouqtkjiw7ve', 47 | result: { 48 | decision: 'capture', 49 | }, 50 | _links: { 51 | pre_capture: { 52 | link: 'http://api.sandbox.checkout.com/risk/assessments/pre-capture', 53 | }, 54 | self: { 55 | link: 'http://api.sandbox.checkout.com/risk/assessments/ras_2r7jmh6r7urevgmouqtkjiw7ve', 56 | }, 57 | }, 58 | }); 59 | 60 | const cko = new Checkout(SK); 61 | 62 | const risk = await cko.risk.requestPreCapture({ 63 | source: { 64 | type: 'card', 65 | number: '4242424242424242', 66 | expiry_month: 6, 67 | expiry_year: 2029, 68 | cvv: '100', 69 | }, 70 | }); 71 | 72 | expect(risk.result.decision).to.equal('capture'); 73 | }); 74 | 75 | it('should throw AuthenticationError in pre-capture', async () => { 76 | nock('https://api.sandbox.checkout.com').post('/risk/assessments/pre-capture').reply(401); 77 | const cko = new Checkout(); 78 | 79 | try { 80 | const risk = await cko.risk.requestPreCapture({ 81 | source: { 82 | type: 'card', 83 | number: '4242424242424242', 84 | expiry_month: 6, 85 | expiry_year: 2029, 86 | cvv: '100', 87 | }, 88 | }); 89 | } catch (err) { 90 | expect(err).to.be.instanceOf(AuthenticationError); 91 | } 92 | }); 93 | 94 | it('should throw AuthenticationError in pre-auth', async () => { 95 | nock('https://api.sandbox.checkout.com') 96 | .post('/risk/assessments/pre-authentication') 97 | .reply(401); 98 | const cko = new Checkout(); 99 | 100 | try { 101 | const risk = await cko.risk.requestPreAuthentication({ 102 | source: { 103 | type: 'card', 104 | number: '4242424242424242', 105 | expiry_month: 6, 106 | expiry_year: 2029, 107 | cvv: '100', 108 | }, 109 | }); 110 | } catch (err) { 111 | expect(err).to.be.instanceOf(AuthenticationError); 112 | } 113 | }); 114 | }); 115 | -------------------------------------------------------------------------------- /test/utils.js: -------------------------------------------------------------------------------- 1 | import Checkout from '../src/Checkout.js'; 2 | import { v4 as uuidv4 } from 'uuid'; 3 | 4 | const cko_platforms = new Checkout(process.env.CHECKOUT_DEFAULT_OAUTH_CLIENT_SECRET, { 5 | client: process.env.CHECKOUT_DEFAULT_OAUTH_CLIENT_ID, 6 | scope: ['accounts'], 7 | environment: 'sandbox', 8 | }); 9 | 10 | /** 11 | * Generates a future ISO date string by adding days to the current date. 12 | * @param {number} days Number of days to add to the current date. 13 | * @returns {string} ISO string of the future date. 14 | */ 15 | export const generateFutureDate = (days = 1) => { 16 | const futureDate = new Date(); 17 | futureDate.setDate(futureDate.getDate() + days); // Add days 18 | return futureDate.toISOString(); // Convert to ISO format 19 | }; 20 | 21 | /** 22 | * Creates a sub-entity and returns its ID. 23 | * @returns {Promise} The ID of the created sub-entity. 24 | */ 25 | export const createEntity = async () => { 26 | const randomReference = `ref_${uuidv4().slice(0, 8)}`; 27 | const randomEmail = `user_${uuidv4().slice(0, 8)}@example.com`; 28 | 29 | const response = await cko_platforms.platforms.onboardSubEntity({ 30 | reference: randomReference, 31 | is_draft: true, 32 | contact_details: { 33 | invitee: { 34 | email: randomEmail 35 | } 36 | } 37 | }); 38 | 39 | if (!response || !response.id) { 40 | throw new Error('Failed to create entity'); 41 | } 42 | 43 | return response.id; 44 | }; 45 | -------------------------------------------------------------------------------- /types/dist/Checkout.d.ts: -------------------------------------------------------------------------------- 1 | //@ts-ignore 2 | import * as http from 'http'; 3 | 4 | import { 5 | Access, 6 | ApplePay, 7 | Balances, 8 | Baloto, 9 | Boleto, 10 | CardMetadata, 11 | Customers, 12 | Disputes, 13 | Events, 14 | Fawry, 15 | Files, 16 | Financial, 17 | Forex, 18 | Giropay, 19 | HostedPayments, 20 | Ideal, 21 | Instruments, 22 | Issuing, 23 | Klarna, 24 | Oxxo, 25 | PagoFacil, 26 | PaymentContexts, 27 | PaymentLinks, 28 | PaymentSessions, 29 | Payments, 30 | Platforms, 31 | Rapipago, 32 | Reconciliation, 33 | Reports, 34 | Sepa, 35 | Sessions, 36 | Sources, 37 | Tokens, 38 | Transfers, 39 | Webhooks, 40 | Workflows, 41 | } from './index'; 42 | 43 | export type access = { 44 | token: string; 45 | type: string; 46 | scope: string; 47 | expires: Date; 48 | }; 49 | 50 | export type config = { 51 | host: string; 52 | sk: string; 53 | pk: string; 54 | timeout: number; 55 | agent?: http.Agent; 56 | headers?: Record; 57 | access?: access; 58 | scope?: Array; 59 | client?: string; 60 | }; 61 | 62 | type options = { 63 | host?: string; 64 | timeout?: number; 65 | agent?: http.Agent; 66 | headers?: Record; 67 | httpClient?: string; 68 | } & (staticKeyOptions | oauthOptions); 69 | 70 | type staticKeyOptions = { 71 | pk: string; 72 | }; 73 | 74 | type oauthOptions = { 75 | client: string; 76 | scope?: Array; 77 | environment?: string; 78 | }; 79 | 80 | export default class Checkout { 81 | payments: Payments; 82 | sources: Sources; 83 | tokens: Tokens; 84 | instruments: Instruments; 85 | webhooks: Webhooks; 86 | events: Events; 87 | disputes: Disputes; 88 | files: Files; 89 | reconciliation: Reconciliation; 90 | customers: Customers; 91 | hostedPayments: HostedPayments; 92 | giropay: Giropay; 93 | ideal: Ideal; 94 | fawry: Fawry; 95 | pagoFacil: PagoFacil; 96 | rapipago: Rapipago; 97 | boleto: Boleto; 98 | baloto: Baloto; 99 | oxxo: Oxxo; 100 | klarna: Klarna; 101 | sepa: Sepa; 102 | paymentLinks: PaymentLinks; 103 | access: Access; 104 | forex: Forex; 105 | applePay: ApplePay; 106 | sessions: Sessions; 107 | workflows: Workflows; 108 | platforms: Platforms; 109 | transfers: Transfers; 110 | balances: Balances; 111 | cardMetadata: CardMetadata; 112 | reports: Reports; 113 | financial: Financial; 114 | issuing: Issuing; 115 | paymentContexts: PaymentContexts; 116 | paymentSessions: PaymentSessions; 117 | config: config; 118 | 119 | constructor(key?: string, options?: options); 120 | } 121 | -------------------------------------------------------------------------------- /types/dist/api/access/access.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Access { 4 | constructor(config: config); 5 | 6 | request: (body: Object) => Promise; 7 | updateAccessToken: (body: Object) => void; 8 | } 9 | -------------------------------------------------------------------------------- /types/dist/api/apm-specific/baloto.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Bolato { 4 | constructor(config: config); 5 | 6 | succeed: (id: string) => Promise; 7 | expire: (id: string) => Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/dist/api/apm-specific/boleto.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Boleto { 4 | constructor(config: config); 5 | 6 | succeed: (id: string) => Promise; 7 | expire: (id: string) => Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/dist/api/apm-specific/fawry.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Fawry { 4 | constructor(config: config); 5 | 6 | approve: (reference: string) => Promise; 7 | cancel: (reference: string) => Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/dist/api/apm-specific/giropay.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Giropay { 4 | constructor(config: config); 5 | 6 | getEpsBanks: () => Promise; 7 | getBanks: () => Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/dist/api/apm-specific/ideal.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Ideal { 4 | constructor(config: config); 5 | 6 | get: () => Promise; 7 | getIssuers: () => Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/dist/api/apm-specific/klarna.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Klarna { 4 | constructor(config: config); 5 | 6 | createSession: (body: Object) => Promise; 7 | getSession: (id: string) => Promise; 8 | capture: (id: string, body?: Object) => Promise; 9 | void: (id: string, body?: Object) => Promise; 10 | } 11 | -------------------------------------------------------------------------------- /types/dist/api/apm-specific/oxxo.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Oxxo { 4 | constructor(config: config); 5 | 6 | succeed: (id: string) => Promise; 7 | expire: (id: string) => Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/dist/api/apm-specific/pagofacil.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class PagoFacil { 4 | constructor(config: config); 5 | 6 | succeed: (id: string) => Promise; 7 | expire: (id: string) => Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/dist/api/apm-specific/rapipago.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Rapipago { 4 | constructor(config: config); 5 | 6 | succeed: (id: string) => Promise; 7 | expire: (id: string) => Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/dist/api/apm-specific/sepa.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Sepa { 4 | constructor(config: config); 5 | 6 | getMandate: (id: string) => Promise; 7 | cancelMandate: (id: string) => Promise; 8 | getPPROMandate: (id: string) => Promise; 9 | cancelPPROMandate: (id: string) => Promise; 10 | } 11 | -------------------------------------------------------------------------------- /types/dist/api/apple-pay/apple-pay.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Access { 4 | constructor(config: config); 5 | 6 | upload: (body: Object) => Promise; 7 | generate: () => Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/dist/api/balances/balances.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Balances { 4 | constructor(config: config); 5 | 6 | retrieve: (id: string, currency?: string) => Promise; 7 | } 8 | -------------------------------------------------------------------------------- /types/dist/api/card-metadata/card-metadata.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class CardMetadata { 4 | constructor(config: config); 5 | 6 | get: (body: Object) => Promise; 7 | } 8 | -------------------------------------------------------------------------------- /types/dist/api/customers/customers.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Customers { 4 | constructor(config: config); 5 | 6 | create: (customer: Object) => Promise; 7 | get: (id: string) => Promise; 8 | update: (id: string, body: Object) => Promise; 9 | delete: (id: string) => Promise; 10 | } 11 | -------------------------------------------------------------------------------- /types/dist/api/disputes/disputes.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Disputes { 4 | constructor(config: config); 5 | 6 | get: (body: Object) => Promise; 7 | getDetails: (disputeId: string) => Promise; 8 | accept: (disputeId: string) => Promise; 9 | provideEvidence: (disputeId: string, body: Object) => Promise; 10 | getEvidence: (disputeId: string) => Promise; 11 | submit: (disputeId: string) => Promise; 12 | getCompiledSubmittedEvidence: (disputeId: string) => Promise; 13 | getDisputeSchemeFiles: (disputeId: string) => Promise; 14 | } 15 | -------------------------------------------------------------------------------- /types/dist/api/events/events.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Instruments { 4 | constructor(config: config); 5 | 6 | retrieveEventTypes: (version: string) => Promise; 7 | retrieveEvents: (body: Object) => Promise; 8 | retrieveEvent: (eventId: string) => Promise; 9 | retrieveEventNotification: (body: Object) => Promise; 10 | retry: (body: Object) => Promise; 11 | retryAll: (eventId: string) => Promise; 12 | } 13 | -------------------------------------------------------------------------------- /types/dist/api/files/files.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Files { 4 | constructor(config: config); 5 | 6 | upload: (body: Object) => Promise; 7 | getFile: (fileId: string) => Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/dist/api/financial/financial.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Financial { 4 | constructor(config: config); 5 | 6 | query: (parameters: Object) => Promise; 7 | } 8 | -------------------------------------------------------------------------------- /types/dist/api/forex/forex.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Forex { 4 | constructor(config: config); 5 | 6 | request: (body: Object) => Promise; 7 | getRates: (body: Object) => Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/dist/api/hosted-payments/hosted-payments.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class HostedPayments { 4 | constructor(config: config); 5 | 6 | create: (body: Object) => Promise; 7 | get: (id: string) => Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/dist/api/instruments/instruments.d.ts: -------------------------------------------------------------------------------- 1 | import {config} from '../../Checkout'; 2 | 3 | export default class Instruments { 4 | constructor(config: config); 5 | 6 | create: (body: Object) => Promise; 7 | get: (id: string) => Promise; 8 | update: (id: string, body: Object) => Promise; 9 | delete: (id: string) => Promise; 10 | getBankAccountFieldFormatting: (country: string, currency: string) => Promise; 11 | } 12 | -------------------------------------------------------------------------------- /types/dist/api/issuing/issuing.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Issuing { 4 | constructor(config: config); 5 | 6 | createCardholder: (body: Object) => Promise; 7 | getCardholder: (id: string) => Promise; 8 | getCardholderCards: (id: string) => Promise; 9 | createCard: (body: Object) => Promise; 10 | getCardDetails: (id: string) => Promise; 11 | enrollThreeDS: (id: string, body: Object) => Promise; 12 | updateThreeDS: (id: string, body: Object) => Promise; 13 | getThreeDSDetails: (id: string) => Promise; 14 | activateCard: (id: string) => Promise; 15 | getCardCredentials: (id: string, body: Object) => Promise; 16 | revokeCard: (id: string, body: Object) => Promise; 17 | suspendCard: (id: string, body: Object) => Promise; 18 | createCardControl: (body: Object) => Promise; 19 | getCardControls: (params: Object) => Promise; 20 | getCardControlDetails: (id: string) => Promise; 21 | updateCardControl: (id: string, body: Object) => Promise; 22 | deleteCardControl: (id: string) => Promise; 23 | simulateAuthorization: (body: Object) => Promise; 24 | } -------------------------------------------------------------------------------- /types/dist/api/payment-contexts/payment-contexts.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class PaymentContexts { 4 | constructor(config: config); 5 | 6 | request: (body: object) => Promise; 7 | get: (id: string) => Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/dist/api/payment-links/payment-links.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class PaymentLinks { 4 | constructor(config: config); 5 | 6 | create: (body: Object) => Promise; 7 | get: (id: string) => Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/dist/api/payment-sessions/payment-sessions.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class PaymentSessions { 4 | constructor(config: config); 5 | 6 | request: (body: object) => Promise; 7 | } 8 | -------------------------------------------------------------------------------- /types/dist/api/payments-links/payments-links.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Class dealing with the /payment-links endpoint 3 | * 4 | * @export 5 | * @class PaymentLinks 6 | */ 7 | export default class PaymentLinks { 8 | constructor(config: any); 9 | config: any; 10 | /** 11 | * Create a Payment Link and pass through all the payment information, like the amount, currency, country and reference. 12 | * 13 | * @memberof PaymentLinks 14 | * @param {Object} body 15 | * @return {Promise} A promise to the Payment Link response. 16 | */ 17 | create(body: any): Promise; 18 | /** 19 | * Retrieve details about a specific Payment Link using its ID returned when the link was created. In the response, you will see the status of the Payment Link. 20 | * 21 | * @memberof PaymentLinks 22 | * @param {string} id 23 | * @return {Promise} A promise to the Payment Link response. 24 | */ 25 | get(id: string): Promise; 26 | } 27 | //# sourceMappingURL=payments-links.d.ts.map -------------------------------------------------------------------------------- /types/dist/api/payments/payments.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Payments { 4 | constructor(config: config); 5 | 6 | request: (body: Object, idempotencyKey?: string) => Promise; 7 | getPaymentList: (body?: Object) => Promise; 8 | get: (id: string) => Promise; 9 | getActions: (id: string) => Promise; 10 | increment: (paymentId: string, body?: Object, idempotencyKey?: string) => Promise; 11 | cancelScheduledRetry: (id: string, body?: Object, idempotencyKey?: string) => Promise; 12 | capture: (paymentId: string, body?: Object, idempotencyKey?: string) => Promise; 13 | refund: (paymentId: string, body?: Object, idempotencyKey?: string) => Promise; 14 | reverse: (paymentId: string, body?: Object, idempotencyKey?: string) => Promise; 15 | void: (paymentId: string, body?: Object, idempotencyKey?: string) => Promise; 16 | search: (body: Object) => Promise; 17 | } 18 | -------------------------------------------------------------------------------- /types/dist/api/platforms/platforms.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Platforms { 4 | constructor(config: config); 5 | 6 | uploadFile: (purpose: string, path: string) => Promise; 7 | onboardSubEntity: (body: Object) => Promise; 8 | uploadAFile: (entityId: string, body: Object) => Promise; 9 | retrieveAFile: (entityId: string, fileId: string) => Promise; 10 | getSubEntityMembers: (entityId: string) => Promise; 11 | getSubEntityDetails: (id: string) => Promise; 12 | updateSubEntityDetails: (id: string, body: Object) => Promise; 13 | getPaymentInstrumentDetails: (entityId: string, id: string) => Promise; 14 | updatePaymentInstrumentDetails: (entityId: string, id: string, body: Object) => Promise; 15 | createPaymentInstrument: (id: string, body: Object) => Promise; 16 | addPaymentInstrument: (id: string, body: Object) => Promise; 17 | queryPaymentInstruments: (id: string, status?: string) => Promise; 18 | retrieveSubEntityPayoutSchedule: (id: string) => Promise; 19 | updateSubEntityPayoutSchedule: (body: Object) => Promise; 20 | getReserveRuleDetails: (entityId: string, id: string) => Promise; 21 | updateReserveRule: (entityId: string, id: string, body: Object, ifMatch: string) => Promise; 22 | addReserveRule: (id: string, body: Object) => Promise; 23 | queryReserveRules: (id: string) => Promise; 24 | } 25 | -------------------------------------------------------------------------------- /types/dist/api/reconciliation/reconciliation.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Reconciliation { 4 | constructor(config: config); 5 | 6 | getPayments: (body: Object) => Promise; 7 | getPayment: (paymentId: string) => Promise; 8 | getPaymentsCsv: (body: Object) => Promise; 9 | getStatements: (body: Object) => Promise; 10 | getStatementCsv: (statementId: string) => Promise; 11 | getPaymentsActions: (body: Object) => Promise; 12 | getPaymentsAction: (actionId: string) => Promise; 13 | getPaymentsActionsCsv: (body: Object) => Promise; 14 | getAction: (actionId: string) => Promise; 15 | } 16 | -------------------------------------------------------------------------------- /types/dist/api/reports/reports.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Reports { 4 | constructor(config: config); 5 | 6 | getAllReports: (parameters: Object) => Promise; 7 | getReportDetails: (id: string) => Promise; 8 | getReportFile: (id: string, fileId: string) => Promise; 9 | } 10 | -------------------------------------------------------------------------------- /types/dist/api/risk/risk.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Risk { 4 | constructor(config: config); 5 | 6 | requestPreAuthentication: (body: Object) => Promise; 7 | requestPreCapture: (body: Object) => Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/dist/api/sessions/sessions.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Sessions { 4 | constructor(config: config); 5 | 6 | request: (body: Object) => Promise; 7 | get: (id: string, channel?: string) => Promise; 8 | update: (id: string, body: Object) => Promise; 9 | complete: (id: string) => Promise; 10 | update3DSMethodCompletionIndicator: (id: string, threeDsMethodCompletion: string) => Promise; 11 | } 12 | -------------------------------------------------------------------------------- /types/dist/api/sources/sources.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from "../../Checkout"; 2 | 3 | export default class Sources { 4 | constructor(config: config); 5 | 6 | add: (body: Object) => Promise; 7 | } 8 | -------------------------------------------------------------------------------- /types/dist/api/tokens/tokens.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from "../../Checkout"; 2 | 3 | export default class Tokens { 4 | constructor(config: config); 5 | 6 | request: (body: Object) => Promise; 7 | } 8 | -------------------------------------------------------------------------------- /types/dist/api/transfers/transfers.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Transfers { 4 | constructor(config: config); 5 | 6 | initiate: (body: Object) => Promise; 7 | retrieve: (id: string) => Promise; 8 | } 9 | -------------------------------------------------------------------------------- /types/dist/api/webhooks/webhooks.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Webhooks { 4 | constructor(config: config); 5 | 6 | retrieveWebhooks: () => Promise; 7 | registerWebhook: (body: Object) => Promise; 8 | retrieveWebhook: (id: string) => Promise; 9 | updateWebhook: (id: string, body?: Object) => Promise; 10 | partiallyUpdateWebhook: (id: string, body?: Object) => Promise; 11 | removeWebhook: (id: string) => Promise; 12 | } 13 | -------------------------------------------------------------------------------- /types/dist/api/workflows/workflows.d.ts: -------------------------------------------------------------------------------- 1 | import { config } from '../../Checkout'; 2 | 3 | export default class Workflows { 4 | constructor(config: config); 5 | 6 | getAll: () => Promise; 7 | add: (body: Object) => Promise; 8 | get: (id: string) => Promise; 9 | remove: (id: string) => Promise; 10 | patch: (id: string, body: Object) => Promise; 11 | addAction: (id: string, body: Object) => Promise; 12 | updateAction: (workflowId: string, workflowActionId: string, body: Object) => Promise; 13 | removeAction: (workflowId: string, workflowActionId: string) => Promise; 14 | addCondition: (id: string, body: Object) => Promise; 15 | updateCondition: ( 16 | workflowId: string, 17 | workflowConditionId: string, 18 | body: Object 19 | ) => Promise; 20 | removeCondition: (workflowId: string, workflowConditionId: string) => Promise; 21 | test: (id: string, body: Object) => Promise; 22 | getEventTypes: () => Promise; 23 | getEvent: (id: string) => Promise; 24 | getActionInvocations: (eventId: string, workflowActionId: string) => Promise; 25 | reflowByEvent: (id: string) => Promise; 26 | reflowByEventAndWorkflow: (eventId: string, workflowId: string) => Promise; 27 | reflowEventsByEventAndWorkflowIds: ( 28 | events: Array, 29 | workflows?: Array 30 | ) => Promise; 31 | reflowEventsBySubjectAndWorkflowIds: ( 32 | subjects: Array, 33 | workflows?: Array 34 | ) => Promise; 35 | getSubjectEvents: (id: string) => Promise; 36 | reflowBySubject: (id: string) => Promise; 37 | reflowBySubjectAndWorkflow: (subjectId: string, workflowId: string) => Promise; 38 | } 39 | -------------------------------------------------------------------------------- /types/dist/index.d.ts: -------------------------------------------------------------------------------- 1 | export { default as Payments } from './api/payments/payments'; 2 | export { default as Sources } from './api/sources/sources'; 3 | export { default as Tokens } from './api/tokens/tokens'; 4 | export { default as Instruments } from './api/instruments/instruments'; 5 | export { default as Webhooks } from './api/webhooks/webhooks'; 6 | export { default as Events } from './api/events/events'; 7 | export { default as Disputes } from './api/disputes/disputes'; 8 | export { default as Files } from './api/files/files'; 9 | export { default as Reconciliation } from './api/reconciliation/reconciliation'; 10 | export { default as Customers } from './api/customers/customers'; 11 | export { default as HostedPayments } from './api/hosted-payments/hosted-payments'; 12 | export { default as PaymentLinks } from './api/payment-links/payment-links'; 13 | export { default as Risk } from './api/risk/risk'; 14 | export { default as Giropay } from './api/apm-specific/giropay'; 15 | export { default as Ideal } from './api/apm-specific/ideal'; 16 | export { default as Fawry } from './api/apm-specific/fawry'; 17 | export { default as PagoFacil } from './api/apm-specific/pagofacil'; 18 | export { default as Rapipago } from './api/apm-specific/rapipago'; 19 | export { default as Boleto } from './api/apm-specific/boleto'; 20 | export { default as Baloto } from './api/apm-specific/baloto'; 21 | export { default as Oxxo } from './api/apm-specific/oxxo'; 22 | export { default as Klarna } from './api/apm-specific/klarna'; 23 | export { default as Sepa } from './api/apm-specific/sepa'; 24 | export { default as Access } from './api/access/access'; 25 | export { default as Forex } from './api/forex/forex'; 26 | export { default as ApplePay } from './api/apple-pay/apple-pay'; 27 | export { default as Sessions } from './api/sessions/sessions'; 28 | export { default as Workflows } from './api/workflows/workflows'; 29 | export { default as Platforms } from './api/platforms/platforms'; 30 | export { default as Transfers } from './api/transfers/transfers'; 31 | export { default as Balances } from './api/balances/balances'; 32 | export { default as CardMetadata } from './api/card-metadata/card-metadata'; 33 | export { default as Reports } from './api/reports/reports'; 34 | export { default as Financial } from './api/financial/financial'; 35 | export { default as Issuing } from './api/issuing/issuing'; 36 | export { default as PaymentContexts } from './api/payment-contexts/payment-contexts'; 37 | export { default as PaymentSessions } from './api/payment-sessions/payment-sessions'; 38 | export { default as Checkout } from './Checkout'; 39 | export { default } from './Checkout'; 40 | -------------------------------------------------------------------------------- /types/dist/services/errors.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Error raised for pre-api value validation 3 | * 4 | * @export 5 | * @class ApiTimeout 6 | * @extends {Error} 7 | */ 8 | export class ApiTimeout extends Error { 9 | constructor(); 10 | http_code: number; 11 | } 12 | /** 13 | * AuthenticationError 14 | * 15 | * @export 16 | * @class AuthenticationError 17 | * @extends {Error} 18 | */ 19 | export class AuthenticationError extends Error { 20 | constructor(message: any); 21 | http_code: number; 22 | } 23 | /** 24 | * ActionNotAllowed 25 | * 26 | * @export 27 | * @class ActionNotAllowed 28 | * @extends {Error} 29 | */ 30 | export class ActionNotAllowed extends Error { 31 | http_code: number; 32 | } 33 | /** 34 | * UrlAlreadyRegistered 35 | * 36 | * @export 37 | * @class UrlAlreadyRegistered 38 | * @extends {Error} 39 | */ 40 | export class UrlAlreadyRegistered extends Error { 41 | http_code: number; 42 | } 43 | /** 44 | * NotFoundError 45 | * 46 | * @export 47 | * @class NotFoundError 48 | * @extends {Error} 49 | */ 50 | export class NotFoundError extends Error { 51 | http_code: number; 52 | } 53 | /** 54 | * UnprocessableError 55 | * 56 | * @export 57 | * @class UnprocessableError 58 | * @extends {Error} 59 | */ 60 | /** 61 | * ValidationError 62 | * 63 | * @export 64 | * @class ValidationError 65 | * @extends {Error} 66 | */ 67 | export class ErrorWithBody extends Error { 68 | constructor(http_code: any, error: any, message: any); 69 | name: any; 70 | http_code: any; 71 | body: any; 72 | } 73 | /** 74 | * ValidationError 75 | * 76 | * @export 77 | * @class ValidationError 78 | * @extends {Error} 79 | */ 80 | export class ValidationError extends Error { 81 | constructor(error: any, message?: string); 82 | } 83 | /** 84 | * TooManyRequestsError 85 | * 86 | * @export 87 | * @class TooManyRequestsError 88 | * @extends {Error} 89 | */ 90 | export class TooManyRequestsError extends Error { 91 | constructor(error: any, message?: string); 92 | } 93 | /** 94 | * BadGateway 95 | * 96 | * @export 97 | * @class BadGateway 98 | * @extends {Error} 99 | */ 100 | export class BadGateway extends Error { 101 | constructor(); 102 | http_code: number; 103 | } 104 | /** 105 | * ApiError 106 | * 107 | * @export 108 | * @class HttpError 109 | * @extends {Error} 110 | */ 111 | export class ApiError extends Error { 112 | constructor(http_code: any, message: any); 113 | http_code: any; 114 | body: any; 115 | } 116 | /** 117 | * ValueError 118 | * 119 | * @export 120 | * @class ValueError 121 | * @extends {Error} 122 | */ 123 | export class ValueError extends Error { 124 | constructor(message: any); 125 | body: any; 126 | } 127 | export function determineError(err: any): Promise; 128 | //# sourceMappingURL=errors.d.ts.map -------------------------------------------------------------------------------- /types/dist/services/http.d.ts: -------------------------------------------------------------------------------- 1 | export function get(httpClient: any, path: any, config: any, auth: any): Promise; 2 | export function post(httpClient: any, path: any, config: any, auth: any, request: any, idempotencyKey: any): Promise; 3 | export function patch(httpClient: any, path: any, config: any, auth: any, request: any): Promise; 4 | export function put(httpClient: any, path: any, config: any, auth: any, request: any): Promise; 5 | export function _delete(httpClient: any, path: any, config: any, auth: any): Promise; 6 | export function createAccessToken(config: any, httpClient: any, body: any): Promise; 7 | export default createAccessToken; -------------------------------------------------------------------------------- /types/dist/services/utils.d.ts: -------------------------------------------------------------------------------- 1 | export function buildQueryParams(path: any, params: any): any; -------------------------------------------------------------------------------- /types/dist/services/validation.d.ts: -------------------------------------------------------------------------------- 1 | export function validatePayment(request: any): void; 2 | export function setSourceOrDestinationType(request: any): any; 3 | export function setTokenType(request: any): any; 4 | export function setSourceType(request: any): any; 5 | export function setInstrumentType(request: any): any; --------------------------------------------------------------------------------