Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vainway 's avatar

stripe how to get amount?

i just want to get amount from database directly to stripe dashboard

$stripe = new Stripe(env('STRIPE_SECRETE'));
        $charge = $stripe->charges()->create([
	   // 'amount' => Graphic::get('amount'), i tried this but it does'nt work
            'amount' => 1000,
            'currency' => 'rwf',
            'description' => 'Your work done info',
            'source' => $request->get('stripeToken'),
            'receipt_email' => $request->get('email'),
            // Verify your integration in this guide by including this parameter
            'metadata' => [
                'order_id' => 3243,  
            ],
        ]);
0 likes
10 replies
bobbybouwmann's avatar

Graphic::get('amount') This doesn't work indeed. You need to fetch it by some identifier. Here is an example

Graphic::find(1)->amount,

1 in the find method here is the id of the Graphic model in the database.

1 like
vainway 's avatar

@bobbybouwmann i don't know why they are showing this error: The Stripe API key is not defined!

am using Cartalyst\Stripe\Stripe;

vainway 's avatar

when if also i use Stripe\Stripe; use Stripe\Charge; they show me another

error: No API key provided. (HINT: set your API key using "Stripe::setApiKey()". You can generate API keys from the Stripe web interface. See https://stripe.com/api for details, or email [email protected] if you have any questions.

i have api-key in services.php and .env every where am seposed to put api key i puted them i don't why this happens this worked later but i don't why it keeps showing me this

or should i generate new api key i don't why

Moussa Ball's avatar

Before interacting with stripe, you must specify the secret code to have before calling any method from the stripe API.

Each time you have to put it right at the start of your striped code, otherwise it doesn't work.

\Stripe\Stripe::setApiKey('STRIPE_SECRET_KEY')
\Stripe\Charge::create([
    'amount' => 1000,
    'currency' => 'rwf',
    'description' => 'Your work done info',
     'source' => $request->get('stripeToken'),
     'receipt_email' => $request->get('email'),
     // Verify your integration in this guide by including this parameter
     'metadata' => [
          'order_id' => 3243,  
      ],
]);
vainway 's avatar

i had this before it were working but i don't why it gives me this error

please help me to fix it

\Stripe\Stripe::setApiKey('STRIPE_SECRET_KEY')
\Stripe\Charge::create([
    'amount' => 1000,
    'currency' => 'rwf',
    'description' => 'Your work done info',
     'source' => $request->get('stripeToken'),
     'receipt_email' => $request->get('email'),
     // Verify your integration in this guide by including this parameter
     'metadata' => [
          'order_id' => 3243,  
      ],
]);

it steal the same

another error: Must provide source or customer.

bobbybouwmann's avatar

How do you assign the STRIPE_SECRET_KEY to the setApiKey method?

vainway 's avatar

hey right now my new error on that : Must provide source or customer.

array:6 [▼
  "amount" => 999
  "currency" => "usd"
  "description" => "Your work done info"
  "source" => null
  "receipt_email" => "[email protected]"
  "metadata" => array:1 [▶]
]

the problem is how can i get this source they show it's null

public function send(Request $request)
    {
        Stripe::setApiKey('sk_test_oql9ZKSYuxLCDg1iCkiqa00J0KLbWcd');
 
        Charge::create([
            'amount' => 999,
            'currency' => 'rwf',
            'description' => 'Your work done info',
            'source' => $request->stripeToken,
            'receipt_email' => $request->email,
            // Verify your integration in this guide by including this parameter
            'metadata' => [
                'order_id' => 3243,  
            ],
        ]);
        
        return back()->with('success', 'Thank you!! , Your payment was accepted');
    }

please help me am stuck

other problems were fixed just this one and also i have also the stripe token but i can't get it here it is

 // Submit the form with the token ID.
    function stripeTokenHandler(token) {
      // Insert the token ID into the form so it gets submitted to the server
      var form = document.getElementById('payment-form');
      var hiddenInput = document.createElement('input');
      hiddenInput.setAttribute('type', 'hidden');
      hiddenInput.setAttribute('name', 'stripeToken');
      hiddenInput.setAttribute('value', token.id);
      form.appendChild(hiddenInput);

      // Submit the form
      form.submit();
RamjithAp's avatar

By seeing your code source must come to your controller. The only possible mistake you are doing could be make sure your form has

 <form id="payment-form" method="POST">

Also before submitting open your browser console and check form got appended with stripeToken hidden input. Post your blade file for further help.

vainway 's avatar
vainway
OP
Best Answer
Level 4

when i used the console i worked that's what i use thanks yah all for your help

Please or to participate in this conversation.