@brad-jones/cc-tokenizer-client
v1.11.0
Published
The client side component of the cc-tokenizer.
Downloads
22
Readme
Credit Card Tokenizer Client
The client side component of the cc-tokenizer.
Usage
Install with Npm/Yarn
npm install @brad-jones/cc-tokenizer-client
OR
yarn add @brad-jones/cc-tokenizer-client
Bundling into your client side app.
This package has been distributed with a CommonJs & a ES2015 build.
Older style bundlers may make use of the CommonJs build, located in the main ./dist
folder.
More modern style bundlers can make use of the ES2015 build, located in ./dist-esm
.
Using the browser build
Located in /dist-browser
is a build ready to be consumed directly in a browser via a script tag.
UnPkg CDN: For the super lazy, get it via the UnPkg CDN.
<script src="https://unpkg.com/@brad-jones/cc-tokenizer-client/dist-browser/index.js"></script>
Once loaded into the browser, the browser bundle exposes all it's exports on a namespaced window object, like this:
var pkg = window['@brad-jones/cc-tokenizer-client'];
var client = new pkg.CcTokenizerClient();
NOTE: It's actually a fuse-box module.
All bundles are transpiled down to ES5 and polyfilled.
Client Config
Regardless of how you have loaded the package into the browser, the first and most important thing to understand is how this package is coupled to the server package. Or not coupled...
Roughly the client follows this workflow:
Makes a request to what we call the
auth/token
endpoint. This is some endpoint that you are responsible for hosting. Usingcc-tokenizer-server
or not... its up to you.The
auth/token
endpoint then calls a payment gateway to get the single use auth token. And then returns this token to the client, along with a special url pointing directly to the payment gateway, that the client has to call next.The client then sends a request directly to the returned URL (via AJAX & CORS or JSONP) that includes the actual credit card details and uses the
auth/token
to authenticate the request.The payment gateway then returns a
result-token
& aredirection-url
. NOTE: This token does not yet represent the final credit card token.The client then sends a request to the
redirection-url
with theresult-token
. Theredirection-url
has been baked into the originalauth/token
request. It is what we call thetoken/receipt
endpoint. Again this is another endpoint that you are responsible for hosting. A reference implementation is also provided incc-tokenizer-server
.
So the up shot of that, the client needs to know where the very first endpoint is, the rest should be automatically discovered.
var client = new CcTokenizerClient({ authTokenEndpoint: 'https://your.api.server/v1/auth/token' });