This project is an example of how to start an integration with Node and Checkout SDK
This project uses npm as the package manager for all the requirements that a project needs, ensure that you have npm installed before running the project.
To remain comply with PCI regulations, you need to protect your card numbers, fortunately Checkout have Frames Framework that helps you to tokenize the payment card, this wrapper includes method submitCard(). In the below example, we call this when the "Pay Now" button is clicked.
<form id="payment-form" method="POST">
<div class="one-liner">
<div class="card-frame"></div>
<button id="pay-button" disabled>
PAY GBP 24.99
</button>
</div>
<p class="error-message"></p>
<p class="payment-message"></p>
</form>
<script src="https://cdn.checkout.com/js/framesv2.min.js"></script>Then we intercept the event and let Frames to tokenize the card
form.addEventListener('submit', function (event) {
event.preventDefault();
Frames.submitCard();
});Make sure to provide your correct Public Key in script.js, which is the key that authorizes to you the access to Checkout API's
Frames.init('pk_sbox_XXX');Once that Frames validates and returns the tokenized token, then you can add another event to handle the request to the backed. If you have any questions regarding the Frames events you can visit the documentation page
On the backed you need to initiate the SDK with the proper Secret Key as follows:
var router = require('express').Router();
const { Checkout } = require('checkout-sdk-node');
const cko = new Checkout('sk_sbox_XXX');
router.post('/pay', async (req, res) => {
// The token generated by Frames on the front end
const myToken = req.body.token;
const paymentResponse = await cko.payments.request({
source: {
token: myToken,
},
amount: 2499,
currency: 'GBP',
processing_channel_id: 'pc_zs5fqhybzc2e3jmq3efvybybpq',
risk: {
enabled: false,
},
});
res.send(paymentResponse);
});
module.exports = router;And that's it! Your payment has been processed.
npm install
npm startThis will run the project on localhost:4242