我正在将Stripe集成到我的拼车应用程序中,我想知道是否可以在Swift中向用户显示Connect Account余额?
条带有一个用于检索stripe.balance.retrieve({})
的选项,但这在控制台中显示余额。
是否可以通过GET请求将此值传递到Swift中的前端并将该值存储在UITextLabel中?
我尝试使用此GET请求进行操作,但只能使其显示在Swift控制台中?
func readBalance(userID: String)
{
var viewProfileComponents = URLComponents(string: "http://myWebsite/payment/payout")!
viewProfileComponents.queryItems = [
URLQueryItem(name: "userID", value: userID)
]
var request = URLRequest(url: viewProfileComponents.url!) // Pass Parameter in URL
print (viewProfileComponents.url!)
request.httpMethod = "GET" // GET METHOD
URLSession.shared.dataTask(with: request) { (data, response, error) -> Void in
if (error != nil){ // error handling responses.
print (error as Any)
}
else if let data = data {
print(data)
let userInfoString:NSString = NSString(data: data, encoding: String.Encoding.utf8.rawValue)!
if let data = userInfoString.data(using: String.Encoding.utf8.rawValue) {
do {
let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String:AnyObject]
print (json as Any)
if let userInfo = json!["data"]
{
DispatchQueue.main.async {
self.balanceAmount.text? = (userInfo["balance"] as! String)
}
}
} catch let error as NSError {
print(error)
}
}
}
}.resume()
}
balanceAmount
是我的UITextLabel
获取请求
router.get("/payout", function (req, res) {
var userID = req.query.userID;
console.log('get payout body ', req.body);
db.query(`select \"Users\".\"stripeAccountID\", \"Users\".\"balance\" from database.\"Users\" where \"Users\".\"userID\" ='${userID}'`)
.then(function(data) {
const accBalance = stripe.balance.retrieve({
stripe_account: data.stripeAccountID
}).then(db.any(`UPDATE database.\"Users\" set \"Users\".\"balance\" = '${accBalance}' where \"Users\".\"userID\" ='${userID}'`));
console.log(data.balance)
console.log('data: ', data)
res.status(200).json({
status: 'Success',
data: data,
message: 'Retrieved Account Balance.'
});
})
.catch(function(error){
console.log('Error fetching payout', error);
});
})
我知道Xcode GET响应不匹配,Xcode中的balance
正在从数据库值中获取。
如果还有其他信息可以帮助您,请告诉我。
提前谢谢!