Skip to content

Instantly share code, notes, and snippets.

View amalj07's full-sized avatar

Amal Jose amalj07

View GitHub Profile
@amalj07
amalj07 / initiate_txn
Last active February 4, 2021 11:58
Route for initiating transaction. (POST req to /paynow)
app.post('/paynow', [parseUrl, parseJson], (req, res) => {
if (!req.body.amount || !req.body.email || !req.body.phone) {
res.status(400).send('Payment failed')
} else {
var params = {};
params['MID'] = config.PaytmConfig.mid;
params['WEBSITE'] = config.PaytmConfig.website;
params['CHANNEL_ID'] = 'WEB';
params['INDUSTRY_TYPE_ID'] = 'Retail';
params['ORDER_ID'] = 'TEST_' + new Date().getTime();
@amalj07
amalj07 / verify_txn
Created June 9, 2020 06:58
Route for verifying the transaction status
app.post('/callback', (req, res) => {
var body = '';
req.on('data', function (data) {
body += data;
});
req.on('end', function () {
var html = "";
var post_data = qs.parse(body);
@amalj07
amalj07 / initiateTransaction.js
Last active September 11, 2020 16:24
Order creation and Initiate transaction method for Paytm payment gateway
let body = ''
const orderId = 'TEST_' + new Date().getTime()
req.on('error', (err) => {
console.error(err.stack)
}).on('data', (chunk) => {
body += chunk
}).on('end', () => {
let data = qs.parse(body)
@amalj07
amalj07 / verifyTransaction.js
Last active September 11, 2020 16:23
Code for checksum and transaction verification
let callbackResponse = ''
req.on('error', (err) => {
console.error(err.stack)
}).on('data', (chunk) => {
callbackResponse += chunk
}).on('end', () => {
let data = qs.parse(callbackResponse)
console.log(data)
const admin = require('firebase-admin')
// Initialize firebase admin SDK
admin.initializeApp({
credential: admin.credential.cert(<path to your firebase credentials file>),
storageBucket: <firebaseprojectid>.appspot.com
})
// Cloud storage
const bucket = admin.storage().bucket()
@amalj07
amalj07 / index.js
Last active November 26, 2020 15:24
const express = require('express')
const multer = require('multer')
const app = express()
const upload = multer({
storage: multer.memoryStorage()
})
app.post('/upload', upload.single('file'), (req, res) => {
@amalj07
amalj07 / uploadfile.js
Last active November 26, 2020 17:16
Node.js API to upload file to firebase cloud storage
const express = require('express')
const multer = require('multer')
const firebase = require('./firebase')
const app = express()
const upload = multer({
storage: multer.memoryStorage()
})
<template>
<div id="app">
<input type="file" ref="file" v-on:change="handleUpload()"/>
<button v-on:click="uploadFile()">Upload</button> <br>
</div>
</template>
<script>
import axios from 'axios'
export default {