· 6 years ago · Oct 09, 2019, 04:02 PM
1'use strict'
2
3/* eslint no-underscore-dangle: ["error", { "allowAfterThis": true }] */
4const JsonException = use('App/Exceptions/JsonException')
5const axios = require('axios')
6
7/** Class representing an instance of Bakery.
8 @property {string} apiKey - Bakery api key
9 @property {string} signature - Bakery signature
10 @property {string} service - Bakery service uuid
11 @property {Object} axios - Axios instance
12*/
13
14class Bakery {
15 /**
16 * Create the instance of Bakery.
17 * @param {string} apiKey - Bakery api key
18 * @param {string} signature - Bakery signature
19 * @param {string} service - Bakery service uuid
20 */
21 constructor(apiKey, signature, service) {
22 const baseURL = 'https://api.paylands.com/v1/sandbox/payment'
23
24 this.signature = signature
25 this.apiKey = apiKey
26 this.service = service
27 this.axios = axios
28 this.axios.defaults.baseURL = baseURL
29 this.axios.defaults.headers['Content-Type'] = 'application/json'
30 this.axios.defaults.headers.Authorization = `bearer ${apiKey}`
31 }
32
33 /**
34 * Create the a customer.
35 * @param {string} externalId - Customer id (lead id)
36 * @return {object}
37 */
38 await createCustomer(externalId) {
39 const data = {
40 customer_ext_id: externalId,
41 signature: this.signature
42 }
43 const res = await this.axios.send('/customer', data)
44
45 return res.data
46 }
47}
48
49module.exports = Bakery