Skip to content
This repository was archived by the owner on Mar 2, 2021. It is now read-only.

Commit 152f647

Browse files
committed
Format scripts
1 parent dacaf05 commit 152f647

File tree

3 files changed

+85
-74
lines changed

3 files changed

+85
-74
lines changed

src/billings/index.js

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ const keySecret = stripePrivateKey
2121

2222
const stripeApp = stripe(keySecret)
2323

24-
billings.get('/', function (req, res) {
24+
billings.get('/', function(req, res) {
2525
return noEndpoint(res)
2626
})
2727

28-
billings.post('/', function (req, res) {
28+
billings.post('/', function(req, res) {
2929
const data = req.body
3030
if (!data || !data.stripeCard) return res.sendStatus(400)
3131

@@ -40,58 +40,67 @@ billings.post('/', function (req, res) {
4040
console.log('@billings:data', data)
4141
console.log('@billings:newCustomer', newCustomer)
4242

43-
stripeApp.customers.create(newCustomer).then(customer => {
44-
console.log('@customers.create:customer', customer)
45-
46-
const charge = {
47-
customer: customer.id,
48-
source: customer.default_source,
49-
amount: 1400,
50-
currency: 'eur',
51-
description: 'Radio4000 Premium'
52-
}
53-
54-
stripeApp.charges.create(charge).then(answer => {
55-
console.log('@charges.charge:charge', charge)
56-
console.log('@charges.charge:answer', answer)
57-
58-
if (answer.paid) {
59-
const db = admin.database()
60-
const ref = db.ref(`channels/${radio4000ChannelId}`)
61-
62-
console.log('radio4000ChannelId', radio4000ChannelId)
43+
stripeApp.customers
44+
.create(newCustomer)
45+
.then(customer => {
46+
console.log('@customers.create:customer', customer)
47+
48+
const charge = {
49+
customer: customer.id,
50+
source: customer.default_source,
51+
amount: 1400,
52+
currency: 'eur',
53+
description: 'Radio4000 Premium'
54+
}
6355

64-
ref.child('isPremium')
65-
.set(true)
66-
.then(() => {
67-
res.status(200).json({
68-
message: 'charge sucess && channel.isPremium = true'
69-
})
70-
}).catch(completionError => {
71-
console.log('@firebase:isPremium-c-error', completionError)
56+
stripeApp.charges
57+
.create(charge)
58+
.then(answer => {
59+
console.log('@charges.charge:charge', charge)
60+
console.log('@charges.charge:answer', answer)
61+
62+
if (answer.paid) {
63+
const db = admin.database()
64+
const ref = db.ref(`channels/${radio4000ChannelId}`)
65+
66+
console.log('radio4000ChannelId', radio4000ChannelId)
67+
68+
ref
69+
.child('isPremium')
70+
.set(true)
71+
.then(() => {
72+
res.status(200).json({
73+
message: 'charge sucess && channel.isPremium = true'
74+
})
75+
})
76+
.catch(completionError => {
77+
console.log('@firebase:isPremium-c-error', completionError)
78+
res.status(500).json({
79+
message:
80+
'charge error: card charged, but channel not upgraded to premium'
81+
})
82+
})
83+
} else {
84+
// send error response
85+
console.log('answer.paid', answer.paid)
7286
res.status(500).json({
73-
message: 'charge error: card charged, but channel not upgraded to premium'
87+
message: 'charge error, answer.paid = false'
7488
})
89+
}
90+
})
91+
.catch(error => {
92+
console.log('error charges.create', error)
93+
res.status(500).json({
94+
message: 'charge create error'
7595
})
76-
} else {
77-
// send error response
78-
console.log('answer.paid', answer.paid)
79-
res.status(500).json({
80-
message: 'charge error, answer.paid = false'
8196
})
82-
}
83-
}).catch(error => {
84-
console.log('error charges.create', error)
97+
})
98+
.catch(error => {
99+
console.log('error customers.create', error)
85100
res.status(500).json({
86-
message: 'charge create error'
101+
message: 'customer create error'
87102
})
88103
})
89-
}).catch(error => {
90-
console.log('error customers.create', error)
91-
res.status(500).json({
92-
message: 'customer create error'
93-
})
94-
})
95104
})
96105

97106
/* Card object received

src/oembed/index.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,25 @@ route.get('/', (req, res) => {
1919

2020
if (!slug) return noEndpoint(res)
2121

22-
getChannelBySlug(slug).then(response => {
23-
const channels = JSON.parse(response.body)
24-
const id = Object.keys(channels)[0]
25-
const channel = channels[id]
26-
27-
if (!channel) return noEndpoint(res)
28-
29-
channel.id = id
30-
const embedHtml = getOEmbed(channel)
31-
res.send(embedHtml)
32-
}).catch(err => {
33-
res.status(500).send({
34-
message: `Could not fetch channel "${slug}"`,
35-
code: 500,
36-
internalError: err
22+
getChannelBySlug(slug)
23+
.then(response => {
24+
const channels = JSON.parse(response.body)
25+
const id = Object.keys(channels)[0]
26+
const channel = channels[id]
27+
28+
if (!channel) return noEndpoint(res)
29+
30+
channel.id = id
31+
const embedHtml = getOEmbed(channel)
32+
res.send(embedHtml)
33+
})
34+
.catch(err => {
35+
res.status(500).send({
36+
message: `Could not fetch channel "${slug}"`,
37+
code: 500,
38+
internalError: err
39+
})
3740
})
38-
})
3941
})
4042

4143
module.exports = route

src/utils/get-oembed.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ module.exports = function({ slug, title, body }) {
55
body = ''
66
}
77
return {
8-
'version': '1.0',
9-
'type': 'rich',
10-
'provider_name': 'Radio4000',
11-
'provider_url': 'https://radio4000.com/',
12-
'author_name': title,
13-
'author_url': `https://radio4000.com/${slug}/`,
14-
'title': title,
15-
'description': body,
16-
'thumbnail_url': `https://assets.radio4000.com/icon.png`,
17-
'html': `<iframe width="320" height="500" src="${config.apiURL}/embed?slug=${slug}" frameborder="0"></iframe>`,
18-
'width': 320,
19-
'height': 500
8+
version: '1.0',
9+
type: 'rich',
10+
provider_name: 'Radio4000',
11+
provider_url: 'https://radio4000.com/',
12+
author_name: title,
13+
author_url: `https://radio4000.com/${slug}/`,
14+
title: title,
15+
description: body,
16+
thumbnail_url: `https://assets.radio4000.com/icon.png`,
17+
html: `<iframe width="320" height="500" src="${config.apiURL}/embed?slug=${slug}" frameborder="0"></iframe>`,
18+
width: 320,
19+
height: 500
2020
}
2121
}

0 commit comments

Comments
 (0)