The example chargebee gives for Node:
const express = require('express')
const chargebee = require("chargebee")
// CORS is enabled only for demo. Please dont use this in production unless you know about CORS
const cors = require('cors')
chargebee.configure({site : "honeycomics-v3-test",
api_key : "test_jqXGuQLkBHUSR2PM0qgUV21W1VqSFJIU"});
const app = express()
app.use(express.urlencoded())
app.use(cors())
app.post("/api/generate_checkout_new_url", (req, res) => {
chargebee.hosted_page.checkout_new({
subscription : {
plan_id : req.body.plan_id
},
customer: {
first_name: req.body.first_name,
last_name: req.body.last_name,
email: req.body.email,
phone: req.body.phone,
company: req.body.company,
}
}).request(function(error,result){
if(error){
//handle error
console.log(error);
}else{
res.send(result.hosted_page);
}
});
});
My adaptation for Meteor (server side):
import { HTTP } from 'meteor/http'
import { Meteor } from 'meteor/meteor'
import chargebee from 'chargebee'
Meteor.methods({
generateCheckoutNewURL () {
HTTP.post('/api/generate_checkout_new_url', (req, res) => {
chargebee.hosted_page.checkout_new({
subscription: {
plan_id: 'monthly-plan'
},
customer: {
first_name: 'John',
last_name: 'Smith'
}
}).request(function (error, result) {
if (error) {
// handle error
console.log(error)
} else {
res.send(result.hosted_page)
}
})
})
}
})
Calling the above Meteor method results in the following error: Exception while invoking method ‘generateCheckoutNewURL’ Error: url must be absolute and start with http:// or https://
Any suggestions? I just can’t seem to get this working.