Last active
March 7, 2020 15:09
-
-
Save Joe8Bit/8507e2c30a81d790941e1a7602a491fa to your computer and use it in GitHub Desktop.
Example store - Full Banked request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hydrateRequest = (body) => { | |
return { | |
reference: 'Banked Demo', | |
success_url: `${process.env.BASE_URL}/cart/success`, | |
error_url: `${process.env.BASE_URL}/cart/error`, | |
line_items: body.map((item) => { | |
return { | |
name: item.name, | |
amount: item.amount * 100, // Amount is sent in whole pennies/cents | |
currency: 'GBP', | |
description: item.description, | |
quantity: item.quantity | |
} | |
}), | |
payee: { | |
name: process.env.PAYEE_NAME, | |
account_number: process.env.ACCOUNT_NUMBER, | |
sort_code: process.env.SORT_CODE | |
} | |
} | |
} | |
app.post('/checkout', async function (req, res) { | |
try { | |
const bankedResponse = await banked.payments.create(hydrateRequest(req.body)) | |
res.send({ | |
url: bankedResponse.data.url | |
}) | |
} catch (e) { | |
console.error(e) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment