Add makecommerce-sdk
to your packages.json to include the library.
Makecommerce SDK returns only promises and promise chains. You can not use callbacks.
To use the library you need to provide shop_id, public_key, secret_key of the store that you get from Makecommerce portal.
const MKSDK = require('makecommerce-sdk');
const MKAPI = new MKSDK('shop_id', 'public_key', 'secret_key', true /* false or omit for live environment */);
To create payment or initialize checkout.js payment, you need transaction ID, easiest way to get it is to call createTransaction
.
MKAPI.createTransaction({
transaction: {
amount: '1.00',
currency: 'EUR',
reference: 'My reference ID'
},
customer: {
email: 'customer@email.com',
ip: '123.123.123.123',
country: 'EE',
locale: 'en'
}
}).then((transaction) => {
console.log('Transaction ['+transaction.id+'] created');
}).catch((err) => {
console.error(err.toString())
});
For payment creation on server side with payment token you use createPayment
call.
MKAPI.createPayment(transaction.id, {amount: '1.00', currency: 'EUR', token: 'payment-token-from-checkout'}).then((payment) => {
console.log('Payment ['+payment.id+'] created');
}).catch((err) => {
console.error('Error creating payment ['+err.toString()+']');
});