Procuret API JavaScript (PJS) allows you to perform Procuret API operations in JavaScript code. For example, you might like to look up the prices of Procuret Instalment Plan products, and present them to customers in your e-commerce software.
The only dependency PJS requires is a "typical" browser-like environment.
That is, it must run in an environment that has browser-like APIs available,
such as XMLHTTPRequest
. This might be a literal web browser, or a browser
derivative like NodeJS.
PJS is provided as raw JavaScript files which you can manually package as you see fit. For example, you might copy and paste relevant files for your use case and include them in your software. You can also use included Python tools to package PJS for include in HTML documents or for provision via a web server. (See "Packaging Tools" below.)
Tests are provided for verification of functionality.
PJS follows Semantic Versioning conventions. At any time,
the repository may included an undocumented type in the source
directory.
These types should be considered unavailable and their function is not
guaranteed.
A theoretical payment amount, and the number of months over which that payment would be made, if an applicant successfully applied for a Procuret Instalment Plan.
.periods
-Number
- The number of months over which payment would be made.amount
-PR_Amount
- The monthly payment amount.supplierId
-String
- The ID of the Procuret supplier for which this price is valid.
Retrieve a single PR_ProspectivePayment
for given parameters. To use this
method, you must know a valid months
value in advance. If you don't know
a valid months
value in advance, prefer .retrieveAllAvailable
.
callback
-Function<Error?, PR_ProspectivePayment?>
- A function taking optional error and result parameters, in which you can handle the API response.principal
-String
- A string-encoded number representing the principal value of the prospective loan. For example, a total invoice value. Minimum value500
currency units.supplierId
-String
- Your Supplier ID. Consult your Procuret partnership manager if you are unsure of this value.denomination
-PR_Currency
- The monetary denomination of theprincipal
value.months
-Number
- The integer number of months over which the instalment plan would be paid.endpoint
-Optional<String>
- Optionally override the API endpoint. Useful in testing a demonstration environments.- [undocumented, do not use, do not provide a value]
PR_ProspectivePayment.retrieve(
(error, prospectivePayment) => {
if (error) { console.log('An error occurred'); return; }
console.log('A successful applicant would pay \
' + payment.amount.asDenominatedString + ' per month');
return;
},
"600", // $600
"511291212", // some Supplier ID
PR_Currency.AUD, // Australian dollars
12 // 12 months
);
Retrieve all available PR_ProspectivePayment
for given parameters. This is
a convenient way to display all potential instalment plan payment amounts to
a potential applicant.
callback
-Function<Error?, PR_ProspectivePayment?>
- A function taking optional error and result parameters, in which you can handle the API response.principal
-String
- A string-encoded number representing the principal value of the prospective loan. For example, a total invoice value. Minimum value500
currency units.denomination
-PR_Currency
- The monetary denomination of theprincipal
value.supplierId
-String
- Your Supplier ID. Consult your Procuret partnership manager if you are unsure of this value.endpoint
-Optional<String>
- Optionally override the API endpoint. Useful in testing a demonstration environments.- [undocumented, do not use, do not provide a value]
PR_ProspectivePayment.retrieveAllAvailable(
(error, availablePayments) => {
if (error) { console.log('An error occurred'); return; }
const availablePayments = payments.map((p) => {
return p.amount.asDenominatedString
});
console.log('Applicants may choose from the following payments \
' + availablePayments);
return;
},
"600", // $600
PR_Currency.AUD, // Australian dollars
"511291212", // some Supplier ID
12 // 12 months
);
A unit of monetary denomination
iso_4217
-String
- The ISO 4217 code of this currencysymbol
-String
- The common-use symbol for this currencyexponent
-Number
- The integer exponent of the currency's subunitsname
-String
- The full-form name of this currencyindexid
-Number
- A unique integer identifier for the currency in the Procure context
.AUD
-PR_Currency
- Australian dollars.NZD
-PR_Currency
- New Zealand dollars.allAvailable
-Array<PR_Currency>
- All available currencies
A monetary amount, a combination of magnitude and currency denomination
asNumber
-Number
- The amount magnitude cast to a JavaScriptNumber
asLocaleString
-String
- A Locale-defined string representationasSymbolisedString
-String
- The amount prefixed by its currency symbolasDenominatedString
-String
- The amount prefixed by its ISO 4217 codemagnitude
-String
- The undenominated magnitude of the amountdenomination
-PR_Currency
- The denomination of the amountisGreaterThanZero
-Boolean
-true
if the magnitude of the amount is greater than zero, elsefalse
PJS includes built in Python tools for packaging. To compile the entire PJS
library into a single JavaScript file, invoke the following Python commands
from the tools
directory:
$ cd tools
$ python3 compile.py
A procuret.js
file will appear in the tools
directory.
PJS includes a built in test GUI.
To run the tests, first compile the test tool:
$ cd tools
$ python3 compile_tests.py
A test.html
document will appear in the tools
directory. Serve test.html
from a web server, and then interact with the tool via a web browser. For
example, you can locally serve the tools directory using...
$ python3 -m http.server
... Whereupon the test tool is available at http://127.0.0.1:8000/test.html.
Note that you cannot open test.html
in your browser from the file system
with a modern security-standards-compliant browser. All tests will fail due to browser's Cross-Origin-Resource-Sharing requirements being unmet.
To get help integrating PJS into your software, write to your Procuret partnership manager, or write to our team at [email protected].