Back

Convert this code into appwrite cloud function

  • 1
  • Functions
  • Web
bharath
30 May, 2023, 14:36
TypeScript

const Insta = require('instamojo-nodejs')

const bodyParser = require('body-parser')

const API_KEY="02d2514bbb73fb7cc9f66959dad905d"

const AUTH_KEY="385c76863481a25d0eb298508f8647d"
Insta.setKeys(API_KEY,AUTH_KEY)


const app=express()

app.use(bodyParser.urlencoded({extended:false}))
app.use(bodyParser.json())

const PORT = process.env.PORT || 5001

app.get('/',(req,res) =>{
    res.sendFile(__dirname+"/Frontend/index.html")
})

app.post('/pay',(req,res) =>{

let name= req.body.name;
let email=req.body.email;
let amount = req.body.amount;
console.log(name);
console.log(email);
console.log(amount);

let data = new Insta.PaymentData();

const REDIRECT_URL = "http://localhost:5001/success";
 
data.setRedirectUrl(REDIRECT_URL);
data.send_email="True";
data.purpose = "printfc";
data.amount=amount;
data.name=name;
data.email=email;

Insta.createPayment(data, function(error, response){
    if(error){
        
    }else{
console.log(response)
        res.send("please check email")
    }
})
})
app.get('/success',(req,res) =>{
    res.send("successful")
})

app.listen(PORT,() =>{
    console.log(`App is listening on ${PORT}`)
})```
TL;DR
The user wants to convert some code into an Appwrite cloud function. They mention that the documentation is not beginner-friendly and they need help connecting the frontend to the cloud function. A response suggests learning how to write Appwrite Functions by looking at the syntax in the documentation. Additionally, the user is advised to take responsibility for creating their own solutions. The code provided is not mentioned in the response. No solution is provided in the support thread.
Aditya Oberai
30 May, 2023, 15:21

Hi @bharath You can learn how to write Appwrite Functions by looking at the syntax of our functions here in our documentation: https://appwrite.io/docs/functions#writingYourOwnFunction

I will additionally mention that while we have created the documentation for our services, at the end of the day, it is important that you must create the solutions for problems you're solving on your own.

You can look at the functions syntax for Node.js in our documentation, and in case you come across Appwrite-related issues in the process, we're here to help. However, the rest is your responsibility.

bharath
30 May, 2023, 15:25

Ok

bharath
30 May, 2023, 15:27

But how do I connect frontend with cloud function . When user clicks on checkout button how that function will be executed

bharath
30 May, 2023, 15:27

There is no documentation that a beginner can understand

Aditya Oberai
30 May, 2023, 16:40

If you scroll down in the Functions guide I sent, earlier, there is section on how to execute a function as well: https://appwrite.io/docs/functions#execute

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more