【发布时间】:2018-08-05 11:27:31
【问题描述】:
我只想发回一个在 POJO 类中没有定义的属性。 我的 POJO 类是这样的
public class PostData {
@SerializedName("Token")
@Expose
private String token;
@SerializedName("Amount")
@Expose
private Integer amount;
@SerializedName("AuthID")
@Expose
private String authID;
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public Integer getAmount() {
return amount;
}
public void setAmount(Integer amt) {
this.amount = amt;
}
public String getAuthID(){return authID;}
public void setAuthID(String authID){
this.authID = authID;
}
}
Amount,Token,AuthID 从客户端发送到 API。这里我使用 HTTP Cloud 函数作为 HTTP POST。我需要将 TransID 发送回客户端,这在 POJO 类中不存在。在客户端我需要读取响应并存储它。 这是我的云功能代码:
exports.Add = functions.https.onRequest((req,res)=>{
//var testPublicKey = [xxxxxxxxxxxxxxxxx]
var stripe = require("stripe")("stripe_key");
console.log("Token:"+req.body.Token)
console.log("Amount:"+req.body.Amount)
var tokenToCharge = req.body.Token;
const amountToCharge = req.body.Amount;
var authID = req.body.AuthID;
const databaseRef = admin.firestore();
const payer = databaseRef.collection('deyaPayUsers').doc(authID).collection('Wallet').doc(authID);
const balance = payer.Usd
stripe.charges.create({
amount : amountToCharge,
currency : "usd",
description : "charge created",
source : tokenToCharge,
}, function(err, charge) {
if(charge.status === "succeeded"){
var trans = databaseRef.runTransaction(t=>{
return t.get(payer)
.then(doc=>{
var updatedBalance = doc.data().Usd + parseInt(charge.amount);
t.update(payer,{Usd : updatedBalance});
});//return close
}).then(result=>{
console.log('Transaction success!');
}).catch(err=>{
console.log('Transaction Failure:',err);
});
}
});
});//end of stripe create charge
【问题讨论】:
标签: android firebase retrofit2 google-cloud-functions