You need to sign in or sign up before continuing.
Commit 6a87f77e authored by wazen shbair's avatar wazen shbair

update payment server

parent adbe6ede
...@@ -44,6 +44,8 @@ app.get('/payment_service/account/info', async (req,res)=>{ ...@@ -44,6 +44,8 @@ app.get('/payment_service/account/info', async (req,res)=>{
app.post('/payment_service/transfer', async (req,res)=>{ app.post('/payment_service/transfer', async (req,res)=>{
var destinationAccount = req.body.destinationAccount; var destinationAccount = req.body.destinationAccount;
var amount = req.body.amount var amount = req.body.amount
var store_name= req.body.store_name
var rewards = req.body.rewards
const instructions = {maxLedgerVersionOffset: 5}; const instructions = {maxLedgerVersionOffset: 5};
const payment = { const payment = {
...@@ -60,7 +62,12 @@ app.post('/payment_service/transfer', async (req,res)=>{ ...@@ -60,7 +62,12 @@ app.post('/payment_service/transfer', async (req,res)=>{
value: String(amount), value: String(amount),
currency: 'XRP' currency: 'XRP'
} }
} },
memos: [
{
"data": store_name +"*"+rewards
},
]
}; };
function quit(message) { function quit(message) {
res.json({'msg': message}) res.json({'msg': message})
...@@ -73,7 +80,6 @@ app.post('/payment_service/transfer', async (req,res)=>{ ...@@ -73,7 +80,6 @@ app.post('/payment_service/transfer', async (req,res)=>{
} }
api.preparePayment(masterAccount, payment, instructions).then(prepared => { api.preparePayment(masterAccount, payment, instructions).then(prepared => {
console.log('Payment transaction prepared...'); console.log('Payment transaction prepared...');
const {signedTransaction} = api.sign(prepared.txJSON, masterAccountSecret); const {signedTransaction} = api.sign(prepared.txJSON, masterAccountSecret);
...@@ -126,7 +132,48 @@ app.get('/payment_service/account/new_address', (req,res)=>{ ...@@ -126,7 +132,48 @@ app.get('/payment_service/account/new_address', (req,res)=>{
}); });
}) })
//--------------------------------------------------
// Get rewards points
//--------------------------------------------------
app.get('/payment_service/account/rewards_points', async (req,res)=>{
var account = req.body.account;
console.log(account)
const options = {
earliestFirst: true,
minLedgerVersion: 8828630
}
function quit(message) {
var o = {} // empty Object
var key = 'rewards points';
o[key] = []; // empty Array, which you can push() values into
var jsonString ="";
message.forEach(element => {
var data=element.specification.memos[0].data.split("*")
jsonString = "{\"store_name\":\""+data[0]+"\"}";
var jsonObj = JSON.parse(jsonString);
jsonObj.rewards_points = data[1]
o[key].push(jsonObj)
});
res.json(o)
}
function fail(message) {
console.error(message);
res.json({'msg': message})
}
await api.getTransactions(account, options).then(quit,fail)
})
function splitStr(str) {
var string = str.split(":");
return "{\""+string[0]+"\":\""+string[1]+"\"}"
}
app.listen(6000) app.listen(6000)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment