UNPKG

marketcloud-node

Version:
64 lines (59 loc) 1.49 kB
var Marketcloud = require('./index.js'); var client = new Marketcloud.Client({ public_key : process.env.MARKETCLOUD_PUBLIC_KEY, secret_key : process.env.MARKETCLOUD_SECRET_KEY //public_key: "c88b04e9-fcd8-42a8-b68e-38413e024c1b", //secret_key: "2IAt0pF81JNP3868wgQ5Arg98FMKX/bhut4xViGYj8Y=" }) client.baseUrl ='http://localhost:5000' let order = { "shipping_address": { "email": "mattia@marketcloud.it", "full_name": "Mattia Rapazzoni", "country": "Italy", "city": "Ancona", "address1": "Fake Street 122121", "state": "Marche", "postal_code": "60125" }, "billing_address": { "email": "mattia@marketcloud.it", "full_name": "Mattia Rapazzoni", "country": "Italy", "city": "Ancona", "address1": "Fake Street 122121", "state": "Marche", "postal_code": "60125" }, "shipping_fee" : 10 }; let PRODUCTS; let CART; return client.products.list({ per_page: 3, type: "simple_product" }) .then(response => { PRODUCTS = response.data; let items = PRODUCTS.map(product => { return { product_id: product.id, quantity: 1, variant_id :0 } }) return client.carts.create({ items: items }) }) .then ( response => { return client.carts.remove(response.data.id, [{ product_id : PRODUCTS[0].id }], { currency : 'USD'}) }) .then(response => { console.log(JSON.stringify(response.data,null,2)) }) .catch( error => { console.log(error) })