pushok icon indicating copy to clipboard operation
pushok copied to clipboard

Question: Push Notifications for PkPass Updates

Open dee4life2005 opened this issue 3 years ago • 8 comments

Quick Question.

Have a registered device, associated push token, and the pkpass certificate etc. and have used your library to send a push notification to trigger the device to request an updated pkpass. The Client->push() method is returning a 200/OK (or a 400/DeviceTokenNotForTopic if I change settings) so it seems like APNS is happy with the request.

The device doesn't seem to be receiving the push notification though, and the AuthProvider is set with $production=true, so it's not a sandbox issue.

Before I get too deep into debugging the issue, just wanted to check that your library supports sending such push notifications, and isn't specific to app based push notifications.

dee4life2005 avatar Apr 20 '22 16:04 dee4life2005

Hello, do you have make some advances with this? I'm in the same situation. I'm sending notifications to update the pkpass but my device does nothing :(

pepoteloko avatar Jun 09 '22 06:06 pepoteloko

Remember, the certificate must be specifically for wallet, a regular certificate for push notifications will not work!

reskar avatar Jun 09 '22 08:06 reskar

@pepoteloko Unfortunately we didn't have much luck getting the pkpass update push notification to work, despite having the correct certificates etc. It looks like the library should support it, but we just couldn't get it to work - it said the message was accepted by APNS but the device just never received it (or if it did, then it didn't see it as a pkpass update trigger).

We did however manage to get it working by using CURL, with the same payload and cert details.

If you do wish to go down that route, then the snippet of code we used was as follows:

`

$payload = '{}';

$url     = "https://api.push.apple.com/3/device/".$device_token;

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_setopt($ch, CURLOPT_SSLCERT, $cert_file_path);
curl_setopt($ch, CURLOPT_SSLCERTTYPE, "P12");
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, $cert_secret);

curl_setopt($ch, CURLOPT_VERBOSE, true);
$streamVerboseHandle = fopen('php://temp', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $streamVerboseHandle);

// Set HTTP Header for POST request

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($payload))
);


$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);


rewind($streamVerboseHandle);
$verboseLog = stream_get_contents($streamVerboseHandle);
error_log('APNS_CURL_DEBUG:'.$verboseLog);

`

dee4life2005 avatar Jun 09 '22 08:06 dee4life2005

Thanks a lot!! But after a little fight against certificates and ID's I sent a push notification using this package!

I use an empty alter $payload = Payload::create()->setAlert("");

And correctly filled my options:

$options = [
   'key_id' => 'XXXX',   // The Key ID obtained from Apple developer account
   'team_id' => 'SUPER_TEAM',   // The Team ID obtained from Apple developer account
   'app_bundle_id' => 'pass.exxample',   // The bundle ID for app obtained from Apple developer account
   'private_key_path' => AuthKey_123456.p8,
   'private_key_secret' => null
];

We create the certificate for push notifications, I did not know that the certificate was different from the one used for the pkpass. We create and download it WITHOUT change the name of the file. My first try was with "certificate.p8" and fails, but with the original name it works :)

The app_bundle_id, i don't know exactly where to find inside the apple website, I was trying all the codes I found in our code. It was made before I start working on this project.

I hope this helps!

pepoteloko avatar Jun 09 '22 12:06 pepoteloko

app_bundle_id is passTypeIdentifier.

reskar avatar Jun 09 '22 12:06 reskar

Hi @pepoteloko pepoteloko , I am follow same things and get message 63C6E6A3-CE90-701B-83E2-100C94B73DBC 200 Success.

But my wallet pass did not update , can you please help me on this

tabrezahmad avatar Jul 13 '22 11:07 tabrezahmad

@tabrezahmad Great!! 200: Success the half part is done! The next important thing to receive a message is to change any value of the pkpass. To get the better (visually talking) message, only change one value and add a message.

Here I put a little example:

// This array contains all the front fields of the card, latter in the code we generate the json with this
$frontTmpFields[$fields][] = [
      'key' => "key-$countKey",
      'label' => $keyLabel,
      'value' => rand(1, 100), //$keyValue,, I just use a random one to be sure that every time I got a new value.
      'changeMessage' => "The new value is: %@"
];

If you change more than one value, you don't see your message, and a generic one like "Something has changed". Of course on your iPhone settings you must allow notifications :)

With this every time I send the push notification I see on my phone "The new value is 23", "The new value is 42", ...

pepoteloko avatar Jul 14 '22 12:07 pepoteloko

@pepoteloko Thank you , I have solved that issue , my mistake was serial number not same during update the card as creating card

tabrezahmad avatar Jul 19 '22 12:07 tabrezahmad