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

Bug when using automatic_payment_methods parameter #218

Open
fiter92 opened this issue Nov 15, 2023 · 2 comments
Open

Bug when using automatic_payment_methods parameter #218

fiter92 opened this issue Nov 15, 2023 · 2 comments

Comments

@fiter92
Copy link

fiter92 commented Nov 15, 2023

{
    "message": "Invalid boolean: 1",
    "exception": "Cartalyst\\Stripe\\Exception\\MissingParameterException",
    "file": "/www/vendor/cartalyst/stripe/src/Exception/Handler.php",
    "line": 125,
    "trace": [
        {
            "file": "/www/vendor/cartalyst/stripe/src/Exception/Handler.php",
            "line": 93,
            "function": "handleException",
            "class": "Cartalyst\\Stripe\\Exception\\Handler",
            "type": "->"
        },
        {
            "file": "/www/vendor/cartalyst/stripe/src/Api/Api.php",
            "line": 178,
            "function": "__construct",
            "class": "Cartalyst\\Stripe\\Exception\\Handler",
            "type": "->"
        },
        {
            "file": "/www/vendor/cartalyst/stripe/src/Api/Api.php",
            "line": 155,
            "function": "execute",
            "class": "Cartalyst\\Stripe\\Api\\Api",
            "type": "->"
        },
        {
            "file": "/www/vendor/cartalyst/stripe/src/Api/PaymentIntents.php",
            "line": 33,
            "function": "_post",
            "class": "Cartalyst\\Stripe\\Api\\Api",
            "type": "->"
        },

^ I'm getting this error when running the code below:

      $paymentIntent = $stripe->paymentIntents->create([
        'amount' => $order->amount,
        'currency' => 'usd',
        'automatic_payment_methods' => [
          'enabled' => true, // <------ boolean
        ],
      ] );

It took me an hour to figure out what the problem was. This code works:

      $paymentIntent = $stripe->paymentIntents->create([
        'amount' => $order->amount,
        'currency' => 'usd',
        'automatic_payment_methods' => [
          'enabled' => 'true', // <------ string
        ],
      ] );

Could you please fix this bug? Stripe API expects boolean, this error is really confusing.

@brunogaspar
Copy link
Member

Hey..

Can you please give this a test?

Change these lines https://github.com/cartalyst/stripe/blob/2.4/src/Utility.php#L47-L49 to the following:

        $parameters = array_map(function ($parameter) {
            if (is_array($parameter)) {
                return static::prepareParameters($parameter);
            }

            return is_bool($parameter) ? ($parameter === true ? 'true' : 'false') : $parameter;
        }, $parameters);

I think it should address it, but i can't confirm right now, but if it does if you want to submit a pull request with the fix you are more than welcome, otherwise i'll address it tomorrow :)

@armanali0786
Copy link

armanali0786 commented May 8, 2024

To address this issue:

Temporary Solution: Continue using 'true' (as a string) until the issue is resolved. This seems to be working as a workaround based on your experience.

$paymentIntent = $stripe->paymentIntents->create([
'amount' => $order->amount,
'currency' => 'usd',
'automatic_payment_methods' => [
  'enabled' => 'true', // Use string 'true'
],
]);

In the meantime, using 'true' as a string should allow your code to function correctly. However, it's important to address this with the library maintainers to ensure proper adherence to the Stripe API specifications.

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

3 participants