b2b-sprinque-tools
v1.10.12
Published
UI lib to reuse Sprinque B2B solutions
Downloads
355
Maintainers
Readme
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.
Codepen demo for b2b-sprinque-tools
This package allows you to:
1. Validate B2B company reg.number
- Validate B2B company registration number;
- Display error message translated to different languages;
- Support different reg. number format per country;
- Supported countries: 'nl', 'be', 'es', 'fr', 'de', 'pl'.
- 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...'