Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: strlen(): Argument #1 ($string) must be of type string, Thenextweb\PassGenerator given #47

Open
pascualkoko opened this issue Sep 28, 2023 · 0 comments

Comments

@pascualkoko
Copy link

pascualkoko commented Sep 28, 2023

Hello, I am trying to create a pass but I am receiving the error of the title. If I use a dd to see it I receive that error but not using it and trying to do the return I am receiving this error:

Symfony\Component\HttpFoundation\Response::setContent(): Argument #1 ($content) must be of type ?string, Illuminate\Support\Facades\Response given, called in /var/app/current/vendor/laravel/framework/src/Illuminate/Http/Response.php on line 72

I checked it all my identifiers and is all ok so I don't know what's happening. Sorry for my english, I am not a native english speaker. This is my code:

// Start here

public function generateAppleWalletPass(Request $request)
    {
        $validator = Validator::make(['kokoId' => $request->kokoId], [
            'kokoId' => ['required', 'string', 'min:1'],
        ]);
        if ($validator->fails()) {
            abort(404);
        }
        $koko = Koko::find(Hashids::decode($request->kokoId)[0]);
        if (isset($koko)) {
            $pass_identifier = $koko->uid;
            $pass = new PassGenerator($pass_identifier);
            $pass_definition = [
                "description"       => "example",
                "formatVersion"     => 1,
                "organizationName"  => "xxxxxxxxx",
                "passTypeIdentifier" => "pass.com.wallet.xxxxxxx",
                "serialNumber"      => "xxxxxxxxxx",
                "teamIdentifier"    => "xxxxxxxxx",
                "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);

            $pass->addAsset(public_path('img/qr-logo.png'));

            $pkpass = $pass->create();

            dd($pkpass); // Here is where I am receiving first error

            // Second error down here
            return new Response($pkpass, 200, [
                'Content-Transfer-Encoding' => 'binary',
                'Content-Description' => 'File Transfer',
                'Content-Disposition' => 'attachment; filename="pass.pkpass"',
                'Content-length' => strlen($pkpass),
                'Content-Type' => PassGenerator::getPassMimeType(),
                'Pragma' => 'no-cache',
            ]);
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant