skip to Main Content

Actually, the problem is simple (but not easy for me). I’ve made a backend project in Laravel 11 to handle with my DB and communicate with the Stripe API, that I have successfully achieved, the communication with stripe works well, however, when I test it using Postman, the response that I receive is the following:

{
    "error": "The amount must be greater than or equal to the minimum charge amount allowed for your account and the currency set (https://docs.stripe.com/currencies#minimum-and-maximum-charge-amounts).  If you want to save a Payment Method for future use without an immediate payment, use a Setup Intent instead: https://docs.stripe.com/payments/setup-intents"
}

And what I send from postman using the POST petition is:

{
    "amount": 2434,
    "currency": "usd"
}

As you can see, there are only two values and when the response says "The amount must be greater than or equal to the minimum charge amount allowed for your account" refers to my "amount" key from my JSON object. I’ve checked the stripe docs and they say that the minimum quantity value of of the usd currency is $0.50 dollars, so I’m in the range. but also the usd comes to my API like undefined.

In the other hand if I do hardcoding of these two values, the response I receive is the following:

{
    "message": "Payment successful"
}

which means that my code actually work but just using hardcoding, which I don’t want to use.

As far as I know, I’m not making any mistake in my code, because I’m doing what the docs say, that makes me think that the problem is something more strange like a configuration or an error into my framework’s file system, but that’s just my speculation.

This is the route I defined in mu api.php file to access the endpoint from postman:

Route::post('/create-checkout-session', [AppHttpControllerspaymentController::class, 'payment']);

and this is my controller that where stripe works:

<?php

namespace AppHttpControllers;

use Exception;
use illuminateHttpRequest;

class paymentController extends Controller
{
    public function payment(Request $request)
    {
        try {
            $stripe = new StripeStripeClient(env('STRIPE_SECRET'));

            $stripe->paymentIntents->create([
                'amount' => intval($request->input('amount')),
                'currency' => $request->input('currency'),
                'automatic_payment_methods' => ['enabled' => true],
            ]);
            return response()->json([
                'message' => 'Payment successful',
            ], 200);
        } catch (Exception $e) {
            return response()->json([
                'error' => $e->getMessage()
            ], 500);
        }
    }
}

I’ve tried using code a little bit different like this in the function, but the result was exactly the same:

            $stripe = new StripeStripeClient([
                'api_key' => env('STRIPE_SECRET')
            ]);
            $stripe->paymentIntents->create([
                'amount' => intval($request->input('amount')),
                // 'amount' => 1000,
                'currency' => $request->input('currency'),
                // 'currency' => "usd",
                'automatic_payment_methods' => ['enabled' => true],
            ]);

According to what I expect from the code, is to be able to catch the info that comes to my from the front (or postman) to send it to the stripe api avoiding using the "hardcoding" practice and continue developing my payment system, which I can’t becaUse all I receive in the request is empty (null or undefined).

This is how my petition looks like in postman:
enter image description here

2

Answers


  1. Based on the comment where both $currency and $amount variables are being logged as null, I think we can understand why these API calls are not successful.

    I recommend adding more logging of the payload from your incoming request to identify why the amount and currency parameters you are passing to your handler function are not present in the $request variable. There could be a lot of reasons on the front-end these values are not being set.

    I do still recommend using the API logs in the Stripe Dashboard when you get stuck and are not sure why your requests are failing. Looking at the request payload (scroll to the bottom of the JSON response) can help you understand what you actually sent to the API and that usually makes the API response more clear.

    Login or Signup to reply.
  2. change your code to this and convert amount to Cent (1$ = 100Cent)

     $stripe->paymentIntents->create([
                'amount' => intval($request->get('amount'))*100,
                'currency' => $request->get('currency'),
                'automatic_payment_methods' => ['enabled' => true],
            ]);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search