thenextweb / passgenerator

A Laravel package to create Apple Wallet passes.
GNU General Public License v3.0
258 stars 43 forks source link

Generated pkpass object is invalid #43

Open aarong-dev opened 1 year ago

aarong-dev commented 1 year ago

Hi all,

I've been trying to get this working - my project is currently in a state where the pkpass generates but when I try to view it or validate it, it always comes out invalid. I can provide further info but we're sticking pretty closely to the README re setup

Cheers!

peukerjonathan commented 1 year ago

I found this site pretty useful when debugging invalid pkpass files: https://pkpassvalidator.azurewebsites.net/ It exactly lists the issues so you can work on them.

Most "invalid" errors occur due to expired certificates though...

aarong-dev commented 1 year ago

Hi,

Cheers for the fast response, that's one of the tools we've been using to validate. Currently it just spits out "Failed to process the pkpass file." with no further info. Any advice?

Here's our pkpass creation function btw:

        $pass_identifier = 'XXX';  // This, if set, it would allow for retrieval later on of the created Pass

        if ($pass = PassGenerator::getPass($pass_identifier)) {
            return $pass;
        }

        $pass = new PassGenerator($pass_identifier);

        $pass_definition = [
            'description' => 'XXX',
            'formatVersion' => 1,
            'organizationName' => 'XXX',
            'passTypeIdentifier' => 'XXX',
            'serialNumber' => 'XXX',
            'teamIdentifier' => 'XXX',
            'foregroundColor' => 'rgb(99, 99, 99)',
            'backgroundColor' => 'rgb(212, 212, 212)',
            'barcode' => [
                'message' => 'encodedmessageonQR',
                'format' => 'PKBarcodeFormatQR',
                'altText' => 'altextfortheQR',
                'messageEncoding' => 'utf-8',
            ],
            'boardingPass' => [
                'headerFields' => [
                    [
                        'key' => 'destinationDate',
                        'label' => 'Trip to: BCN-SANTS',
                        'value' => '15/09/2015',
                    ],
                ],
                'primaryFields' => [
                    [
                        'key' => 'boardingTime',
                        'label' => 'MURCIA',
                        'value' => '13:54',
                        'changeMessage' => 'Boarding time has changed to %@',
                    ],
                    [
                        'key' => 'destination',
                        'label' => 'BCN-SANTS',
                        'value' => '21:09',
                    ],

                ],
                'secondaryFields' => [
                    [
                        'key' => 'passenger',
                        'label' => 'Passenger',
                        'value' => 'J.DOE',
                    ],
                    [
                        'key' => 'bookingref',
                        'label' => 'Booking Reference',
                        'value' => '4ZK6FG',
                    ],
                ],
                'auxiliaryFields' => [
                    [
                        'key' => 'train',
                        'label' => 'Train TALGO',
                        'value' => '00264',
                    ],
                    [
                        'key' => 'car',
                        'label' => 'Car',
                        'value' => '009',
                    ],
                    [
                        'key' => 'seat',
                        'label' => 'Seat',
                        'value' => '04A',
                    ],
                    [
                        'key' => 'classfront',
                        'label' => 'Class',
                        'value' => 'Tourist',
                    ],
                ],
                'backFields' => [
                    [
                        'key' => 'ticketNumber',
                        'label' => 'Ticket Number',
                        'value' => '7612800569875',
                    ], [
                        'key' => 'passenger-name',
                        'label' => 'Passenger',
                        'value' => 'John Doe',
                    ], [
                        'key' => 'classback',
                        'label' => 'Class',
                        'value' => 'Tourist',
                    ],
                ],
                'locations' => [
                    [
                        'latitude' => 37.97479,
                        'longitude' => -1.131522,
                        'relevantText' => 'Departure station',
                    ],
                ],
                'transitType' => 'PKTransitTypeTrain',
            ],
        ];

        $pass->setPassDefinition($pass_definition);

        // Definitions can also be set from a JSON string
        // $pass->setPassDefinition(file_get_contents('/path/to/pass.json));

        // Add assets to the PKPass package
        $pass->addAsset(base_path('app/Services/qr.png'));
        //        $pass->addAsset(base_path('resources/assets/wallet/thumbnail.png'));
        //        $pass->addAsset(base_path('resources/assets/wallet/icon.png'));
        //        $pass->addAsset(base_path('resources/assets/wallet/logo.png'));

        return $pass->create();
peukerjonathan commented 1 year ago

Unfortunately my experience with boardingPass type pkpass files is somewhat limited (I mainly use them for event ticketing)

But from what I can see you are putting a LOT of information in your passes. (Header, primary, secondary, auxiliary...) My best guess is that some kind of combination of the fields are considered invalid (while each of them for themselves can still be valid on their own).

I would suggest generating a pass with only the bare minimum of information and get this to work. Once these passes validate successfully you can start adding more fields one by one. Then you know exactly on what field validation starts to act up?

aarong-dev commented 1 year ago

Interesting, we're using essentially a copy/paste of the config in the README. Do you know what the bare minimum fields are?

renepardon commented 1 year ago

I also started experimenting with this package. All fields are validated successfully on https://pkpassvalidator.azurewebsites.net/#wwdc-certificate-versions

I had the wrong (G6) version of worldwide certificate, a missing icon@2x and wrong team ID. But after fixing those the pass file still remains broken and can not be opened. Neither on Mac nor on iOS, when i move the file with Airdrop.

renepardon commented 1 year ago

Ok, for me the reason was, that I was missing a style key: https://developer.apple.com/library/archive/documentation/UserExperience/Reference/PassKit_Bundle/Chapters/TopLevel.html#//apple_ref/doc/uid/TP40012026-CH2-SW1

I just used "generic" and added "auxiliaryFields" key to it. Thanks for this package! :)