1.10.11 • Published 1 month ago

b2b-sprinque-tools v1.10.11

Weekly downloads
-
License
ISC
Repository
-
Last release
1 month ago

Javascript library to help you speedup Sprinque integration.

Sprinque is the most flexible B2B payment platform. This package includes some reusable code we use in our team and can share with you.

Sprinque for developers

Codepen demo for b2b-sprinque-tools

This package allows you to:

1. Validate B2B company reg.number

1) Validate B2B company registration number; 2) Display error message translated to different languages; 3) Support different reg. number format per country; 4) Supported countries: 'nl', 'be', 'es', 'fr', 'de', 'pl'. 5) For other countries just allows entering alphanumeric, "/" and empty symbol.

Example how it can be used

Usage

Script tag

<!DOCTYPE html>
<html>
  <head>
    <title>Sprinque JS SDK</title>
    <script src="https://unpkg.com/b2b-sprinque-tools/dist/index.umd.min.js" crossorigin></script>
  </head>
  <body>

    <script>
      Sprinque.checkRegNumber('56944306', 'nl', 'nl'); // {isValid: true, message: ''}
    </script>
    Or
    <script>
      Sprinque.checkRegNumber('569443060000', 'nl', 'nl'); // {isValid: true, message: ''}
    </script>
  </body>
</html>

Import

import { checkRegNumber } from "b2b-sprinque-tools";

checkRegNumber('844815263', 'be', 'en') // {isValid: true, message: ''}
checkRegNumber('invalid844815263', 'be', 'en') // {isValid: true, message: 'Registration number format should be like "071194951"'}

2. Reuse translations

import { getTranslatedLanguage } from "b2b-sprinque-tools";

getTranslatedLanguage('es', 'fr') // 'Francés'
import { getTranslatedCountry } from "b2b-sprinque-tools";

getTranslatedCountry('es', 'fr') // 'Francia'
import { getTranslatedApiError } from "b2b-sprinque-tools";
// converts Sprinque API error code to user friendly translated message
// more about Sprinque error codes - https://sprinque.readme.io/docs/error-reasons#http-error-codes
getTranslatedApiError('en', 'AuthCreditPendingError') // 'Credit limit for this buyer is not approved yet'

3. Parse Sprinque API errors

If Sprinque doesn't have translation - English version of message will be returned:

import { parseSprinqueErrorsToString } from "b2b-sprinque-tools";
parseSprinqueErrorsToString({
  address: {
    country_code: ['This field may not be blank.'],
  },
}, 'nl') // 'country_code > This field may not be blank.'

If Sprinque has translation, we'll reuse getTranslatedApiError function:

import { parseSprinqueErrorsToString } from "b2b-sprinque-tools";
parseSprinqueErrorsToString({
  AuthBuyerUnderReviewError: ['This text ignored, the one from translations is used'],
}, 'nl') // 'Het bedrijf wordt nog onderzocht'

4. Format money amount

Based on https://currency.js.org/

import {formatMoneyAmount} from "b2b-sprinque-tools";
formatMoneyAmount(1234.56); // '1,234.56'
formatMoneyAmount(1234.56, 'nl'); // '1.234,56'

4. Get current and lower payment terms

import {getEligiblePaymentTerms} from "b2b-sprinque-tools";
getEligiblePaymentTerms('NET15'); // ['NET7', 'NET15']
getEligiblePaymentTerms('NET90', ['NET60', 'NET90', 'PAY_IN_3']); // ['NET60', 'NET90']

5. Display search tips

import {getSearchTipsByCountry} from "b2b-sprinque-tools";
// 'be' - country, 'en' - language
getSearchTipsByCountry('be', 'en', false); // 'For sole proprietorship please use your last name and first name'
getSearchTipsByCountry('be', 'en', true); // 'For VAT Number use BE0+Registration number. No spaces'

6. Reuse Sprinque translations

import {getTranslatedText} from "b2b-sprinque-tools";
getTranslatedText('en', 'privacyPolicy'); // HTML like 'Sprinque B.V. conducts an automated credit check to...'
1.10.11

1 month ago

1.10.9

2 months ago

1.10.8

2 months ago

1.10.7

2 months ago

1.10.6

2 months ago

1.10.5

2 months ago

1.10.4

3 months ago

1.10.3

3 months ago

1.10.2

3 months ago

1.10.1

3 months ago

1.10.0

4 months ago

1.9.2

4 months ago

1.9.1

4 months ago

1.9.0

4 months ago

1.8.0

4 months ago

1.7.0

5 months ago

1.5.3

7 months ago

1.6.1

6 months ago

1.5.2

7 months ago

1.6.0

6 months ago

1.5.1

9 months ago

1.4.2

10 months ago

1.5.0

10 months ago

1.4.1

10 months ago

1.4.0

11 months ago

1.3.6

11 months ago

1.3.5

11 months ago

1.3.4

11 months ago

1.3.3

12 months ago

1.3.2

12 months ago

1.3.1

12 months ago

1.3.0

12 months ago

1.2.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.0.0

1 year ago