我正在使用iOS客户端,并且成功获得了PaymentMethodNonce:
let dropInController = BTDropInController(authorization: client, request: request)
{ [unowned self] (controller, result, error) in
if let error = error {
print(error.localizedDescription)
UIAlertController.presentAlert(title: "Uh oh!", message: "Your payment credentials could not be registered. Try again or contact us if you keep having issues.", viewController: parent)
} else if (result?.isCancelled == true) {
print("Transaction Cancelled")
} else if let paymentNonce = result?.paymentMethod?.nonce {
self.credentialsAdded = true
print("NONCE: \(paymentNonce)")
QuAPI.Payment.getPaymentInfo(paymentNonce: paymentNonce){(paymentInfo) in
print(paymentInfo)
}
}
controller.dismiss(animated: true, completion: {
if self.credentialsAdded {
self.getPaymentInfo()
UIAlertController.presentAlert(title: "Alright!", message: "Your payment credentials have been successfully registered.", viewController: parent)
}
})
}
QuApi的方法在这里:
static func getPaymentInfo(paymentNonce: String, completion: @escaping([String: Any]?)->Void)
{
guard var paymentsUrl = URLComponents(string: Constants.BASE_URL + Constants.PAYMENTINFO_URL) else {
completion(nil)
return
}
paymentsUrl.queryItems = [URLQueryItem(name: Constants.PAYMENTINFO_PARAMS[0], value: paymentNonce)]
if let url = paymentsUrl.url {
let request = NSMutableURLRequest(url: url)
request.setValue("text/plain", forHTTPHeaderField: "Accept")
URLSession.shared.dataTask(with: request as URLRequest) { (data, response, error) -> Void in
guard let data = data, error == nil else { return }
do{
let json = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as! [String:Any]
completion(json)
}
catch _ as NSError{
completion(nil)
}
}.resume()
}
}
这成功返回了paymentMethodNonce,但是当我传递到服务器端代码时:
app.get('/payment_info', (request, response) => {
var url = require('url');
var url_parts = url.parse(request.url, true);
var query = url_parts.query;
var payment_nonce = query["payment_nonce"];
gateway.paymentMethodNonce.find(payment_nonce, function (err, paymentMethodNonce) {
var info = paymentMethodNonce.threeDSecureInfo;
if (info) {
info.enrolled;
info.status;
info.liabilityShifted;
info.liabilityShiftPossible;
response.send(paymentMethodNonce);
}
else {
// This means that the nonce was not 3D Secured
console.log("err: " + err);
response.send(err);
}
});
});
iOS的字典为空,但响应代码为
success
。不能完全确定PaymentMethodNonce.find()不能完全正常运行的原因。谢谢您的帮助。 最佳答案
我想到了。这是因为我的paymentMethodNonce不受3D保护。
关于ios - 我的Braintree有一个PaymentMethodNonce字符串,但是我似乎无法在服务器端找到它。有任何线索吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54816632/