I'm using PaypalSDK to add paypal payment methods to the app I'm developing, it's already working and when the payment is succesful I'm getting a response which I'm converting into a jsonObject but I don't know how to parse it in order to extract just the code from the response. This is the response I'm getting
JSON: [AnyHashable("response"): {
code = "******************* -****************-**********************";
}, AnyHashable("response_type"): authorization_code, AnyHashable("client"): {
environment = sandbox;
"paypal_sdk_version" = "2.11.5";
platform = iOS;
"product_name" = "PayPal iOS SDK";
}]
And this is what I have on my payPalFuturePaymentViewController method:
func payPalFuturePaymentViewController(_ futurePaymentViewController: PayPalFuturePaymentViewController, didAuthorizeFuturePayment futurePaymentAuthorization: [AnyHashable: Any]) {
print("PayPal Future Payment Authorization Success!")
self.resultText = futurePaymentAuthorization.description
let jsonObject = JSON(futurePaymentAuthorization.description)
print("JSON: \(jsonObject)")
// send authorization to your server to get refresh token.
futurePaymentViewController.dismiss(animated: true, completion: { () -> Void in
var paypalPago = PagoItem(noTarjeta: "", fechaExp: "", cvc: "", token: "", tipo: "PayPal")
self.metodosPago.append(paypalPago)
self.saveMetodo()
let destViewController : UIViewController = self.storyboard!.instantiateViewController(withIdentifier: "pagosLlenos")
var vcArray = self.navigationController?.viewControllers
vcArray?.removeLast()
vcArray?.append(destViewController)
self.navigationController?.setViewControllers(vcArray!, animated: true)
})
}
So what I would like to do is to get the code from the response, put it in a variable and then include that variable in the paypalPago item:
var paypalPago = PagoItem(noTarjeta: "", fechaExp: "", cvc: "", token: PayPalCode, tipo: "PayPal")
Any help on how to parse this json and extract the code I need would be much appreciated :)