#snicserr-invoice

1 messages ยท Page 1 of 1 (latest)

graceful bison
#

@lean verge hi! what's the question?

lean verge
#

We are trying to create an invoice but we are getting a Invalid Object

#
function create_invoice_charge(Customer $customer, int $amount, string $currency, string $landCode, string $metadata, string $city, string $address, string $postalCode, string $name, string $phoneNumber, Source $sourceObject): Invoice
    {
        if ($landCode == "US" || $landCode == "GB") {
            $companyName = "Cancelled ";
            $companyNameDescription = "Cancelled subscription ";
        } else {
            $companyName = "Opzeggen ";
            $companyNameDescription = "Opgezegd bedrijf ";
        }

        $price = Price::create([
            'unit_amount' => $amount * 100,
            'currency' => $currency,
            'product_data' => [
                'name' => $companyName . $metadata,
                'metadata' => [
                    $companyNameDescription => $metadata
                ],
            ],
        ]);

        InvoiceItem::create([
            'customer' => $customer->id,
            'price' => $price->id,
        ]);

        return Invoice::create([
            'default_source' => $sourceObject->id,
            'customer' => $customer->id,
            'metadata' => [
                $companyName . $metadata,
            ],
            'description' => $companyName . $metadata,
            'auto_advance'=> true
        ]);
    }
#

Everytime in the StackTace we get line 175 and that line is:

            'product_data' => [
                'name' => $companyName . $metadata,
                'metadata' => [
                    $companyNameDescription => $metadata
                ],
            ],
#

So something is not right

#

RG is also the developer on this problem ๐Ÿ™‚

graceful bison
#

thanks, looking..

ionic ruin
#

We've got the same code in C#, which is working. So that'd imply that the properties are correct. But once we do it with the PHP code above, it won't create an invoice\

graceful bison
#

do you have a request ID req_xxx. for that 400 error? it should be in the stack trace somewhere if you look for req_

ionic ruin
#

Sure, one moment

graceful bison
ionic ruin
#

Oh wow, the logs are very usefull

#

So that'd be the product_data[metadata]

graceful bison
#

yep

#

my guess is your $metadata variable is null

#

so when you do [$companyNameDescription => $metadata] it's actually [$companyNameDescription => null] and that decomposes to a string instead of an object, I think(need to check that)

ionic ruin
#

It looks like it holds a string value, but it still breaks

#

Maybe something to do with the key pair format?

graceful bison
#

yeah sorry, it's not because it's null.

#

for what it's worth this works fine

$foo = "key";
$bar = "value";
$price = \Stripe\Price::create([
    'unit_amount' => 500,
    'currency' => "usd",
    'product_data' => [
        'name' => "example price",
        'metadata' => [
            $foo => $bar
        ],
    ],
]);
#

so either you're not running the code you think you are(for example maybe you actually do 'metadata' => $companyName which is a common mistake and would give this error), or there's something in your $metadata that breaks the formatting of the POST data)so you might need to escape it)

#

do you have the req_xxx ID so I can have a look?

ionic ruin
ionic ruin
#

In our case, it should be "Opzeggen"

graceful bison
#

yes it really looks to me like you do 'metadata' => $someString and not 'metadata' => [$key => $value]

ionic ruin
#

Maybe a cashe or something in that direction... we used the value "MijnOpzeggingen" earlier today

graceful bison
#

I don't see anything unusual in the raw POST (unit_amount=1900&currency=EUR&product_data[name]=MijnOpzeggingen++Basic+Fit&product_data[metadata]=MijnOpzeggingen++Basic+Fit) so yeah, I really think it has to be something like the code you're running is passing a string and not an object, I'd add some logging/breakpoints and see exactly what it's doing, I can't replicate this using the type of code posted above so it has to be that you're running something different

ionic ruin
#

yeah, we'll a deeper look into the values we're passing into it. This does clear a lot of things up though

lean verge
#

I think we found it

ionic ruin
graceful bison
#

great!

ionic ruin
#

There we go ๐Ÿ˜

#

Working

#

Have a nice rest of your day @graceful bison handshake

lean verge
#

Have nice day @graceful bison, good luck with supporting others ๐Ÿค