-
-
Notifications
You must be signed in to change notification settings - Fork 75
PayPal example with Swift
Danilo edited this page Jun 7, 2020
·
3 revisions
This framework includes an integration that allows the ability to manage PayPal API services.
PayPal associates a series of API credentials with a specific PayPal account, it is possible to generate credentials from this url, finally it is necessary to convert these credentials into a p12 protected file to be included in the project, so that the framework can use it to request authorization to access to the PayPal API.
let soap = SOAPEngine()
//
// PAYPAL associates a set of API credentials with a specific PayPal account
// you can generate credentials from this https://developer.paypal.com/docs/classic/api/apiCredentials/
// and convert to a p12 use : openssl pkcs12 -export -in cert_key_pem.txt -inkey cert_key_pem.txt -out paypal_cert.p12
// other conversion instructions: https://www.sslshopper.com/ssl-converter.html
//
soap.responseHeader = true
soap.authorizationMethod = SOAPAuthorization.AUTH_PAYPAL
soap.username = "my-username"
soap.password = "my-password"
//
// API with Certificate : https://api.paypal.com/2.0/ sandbox https://api.sandbox.paypal.com/2.0/
// API with Signature : https://api-3t.paypal.com/2.0/ sandbox https://api-3t.sandbox.paypal.com/2.0/
//
soap.clientCerficateName = "my-cert.p12"
soap.clientCertificatePassword = "cert-password"
//
// API version : https://www.paypalobjects.com/wsdl/PayPalSvc.wsdl
//
soap.setValue("204.0", forKey:"paypal1:Version")
soap.setValue("0", forKey:"paypal:ReturnAllCurrencies")
soap.requestURL("https://api.paypal.com/2.0/",
soapAction: "GetBalance",
completeWithDictionary: { (statusCode: Int?, dict: [AnyHashable : Any]?) -> Void in
print(dict!)
}) { (error:Error?) -> Void in
print(error!)
}