So here is what I got: I created two certificates both a signerCertificate and a signerKey and converted them to .pem files. They work, and I am able to sign the pass in the console on my Mac terminal to create a pkpass. So the certificates work and I need to add this to my app and edit some of the fields in the pass so I decided to use https://github.com/walletpass/pass-js to setup my backend certificate signage. So I implemented all of the necessary documentation steps and before you know it, I could create what I think is a pass bc it prints in our console logs as seen in below code.
So here is where the problem starts. I am trying to return the pass data to the front end as seen below. It does not cast as Data or NSData no matter what variation I return from their documentation on the front end. So what is my goal? I have generated the pass template and it returns some sort of pass data, but Im stuck trying to cast it as data in the front end to make it into a pkpass that I can open for users in the app! Me and my coworker have tried everything we can to figure this out but we are at a dead end.
If you have any advice please leave it below. Please see all the attached screenshots and code below as well.
NODE JS Api Call
const { Template } = require("@walletpass/pass-js");
exports.createTicket = functions.https.onCall(async (data, context) => {
const key = "-----BEGIN CERTIFICATE-----MIIF/jCCBOagaeYE=-----END CERTIFICATE-----"
const template = new Template("eventTicket", {
passTypeIdentifier: "pass.com.passllc.eventCard",
teamIdentifier: "ABCDEFGHI",
organizationName : "Scenes",
backgroundColor: "red",
sharingProhibited: true
});
await template.images.add("icon", "./models/icon.png");
await template.images.add("logo", "./models/logo.png");
template.setCertificate(key);
template.setPrivateKey("-----BEGIN ENCRYPTED PRIVATE KEY-----MIIFDj0I=-----END ENCRYPTED PRIVATE KEY-----", "passphrase");
const pass = template.createPass({
serialNumber: "123456",
description: "20% off"
});
console.log(pass);
return {
status: '200',
type: "application/vnd.apple.pkpass",
body: await pass.asBuffer(),
};
});
Front End Code
functions.httpsCallable("createTicket").call(["test": "dummytext"]) { (result, error) in
if let data = result?.data as? [String: Any] {
let jsonData = try? JSONSerialization.data(withJSONObject: data)
do {
var passError: NSError?
var newPass = try PKPass(data: jsonData as! Data, error: &passError)
print("pkpassage: \(newPass)")
let addController = PKAddPassesViewController(pass: newPass)
addController.delegate = self
self.present(addController, animated: true)
} catch {
}
}
if (error as NSError?) != nil {
print("\(error?.localizedDescription) lower error")
}
}
What is currently outputting
Front end console (Xcode) errorOutput
Backend Console (Server logs) just a small snippet of the whole log for an individual call console server log beginning; console server log end
I also tried both of these cases btw and they still cannot convert to something to cast as a pkpass: creating the file for api
I would also like to add when I print the returned pass in front end Xcode console as string: any it prints something like [234434, 45549, 3828]. As you can see it looks like a pass is generating because the console is logging it, just I cant get it to convert into data that I can convert to a pkpass. I really appreciate any help, thank you guys!