Saturday, 06 Apr, 2024 -133

How to Integrate Stripe Payment in Laravel

This is Laravel Stripe payment getaway

#1. Install composer command

composer require stripe/stripe-php

Create account from stripe.com

#2. Go stripe developer page and click API keys menu see this two

STRIPE_KEY=pk_test_reFxwbsm9cdCKASdTfxAR
STRIPE_SECRET=sk_test_oQMFWteJiPd4wj4AtgApY

#3. create view page method

public function gotoStripe() {

         return view('website.stripe');

}

#4. view page submit button click than create this method

public function stripepayment(Request $request) {

        $input=$request->all();
    
        // Set API key 
        $token = $request->stripeToken;
        $name = $request->cardName;
        $email ='alaminsobuj8@gmail.com';
        $card_number = $request->cardNumber;
        $card_exp_month = $request->card_exp_month;
        $card_exp_year = $request->card_exp_year;
        $card_cvc = $request->card_cvc;
        
        Stripe\Stripe::setApiKey('Secret key');
        $stripe_customer = \Stripe\Customer::create(array(
                        'email' => $email,
                        'source' => $request->stripeToken
            ));
        $charge=Stripe\Charge::create ([
                'customer' => $stripe_customer->id,
                "amount" => 100 * 100,
                "currency" => "usd",
                // "source" => $request->stripeToken,
                "description" => "Test payment from itsolutionstuff.com." 
        ]);

        $chargeJson = $charge->jsonSerialize();
        if ($chargeJson['amount_refunded'] == 0 && empty($chargeJson['failure_code']) && $chargeJson['paid'] == 1 && $chargeJson['captured'] == 1) {
        $payment_status = $chargeJson['status'];
        if ($payment_status == 'succeeded') {
            $ordStatus = 'success';
            echo "success";
            $request->session()->flash('success', 'Payment completed.');
              //                    $statusMsg = 'Your Payment has been Successful!';
            // redirect('stripe/stripe/payment_success/');
        } else {
            // $statusMsg = "Your Payment has Failed!";
            echo "fail";
            $request->session()->flash('danger', 'Payment failed.');
        }

    }else{
        $statusMsg = "Transaction has been failed!";
    }
    return response()->redirectTo('/');

}


demo card

  • visa card no: 4242424242424242
  • 123
  • Future month and year

#Thank you#

Tags
Most Popular
img
How to install WordPress
02 Apr, 2024 view: 1957
img
Xampp Tutorial Create Your Own Local Test Server
02 Apr, 2024 view: 884
img
How to Install Laravel
02 Apr, 2024 view: 818
img
PHP is not recognized as an internal or external command
02 Apr, 2024 view: 609
img
How to Install Composer on Windows
01 Apr, 2024 view: 607
img
Summernote image upload
01 Nov, 2023 view: 553
img
How to clear select2 selected value in js
01 Nov, 2023 view: 426
img
Zipping and Unzipping Files in Linux
02 Apr, 2024 view: 376
img
How to add Datepicker in Bootstrap
26 Apr, 2024 view: 371
img
How to Import a MySQL Database using Command Line
02 Apr, 2024 view: 365
img
How to Installation Laragon
01 Apr, 2024 view: 212
img
How to Installing an SSL certificate on your server using cPanel
06 Apr, 2024 view: 183
img
Paypal Payment Gateway Integration With Laravel
06 Apr, 2024 view: 152
img
How to Use Laravel Middleware to Protect Your Application
09 Apr, 2024 view: 144
img
Laravel Cache Clear Command Php Artisan Optimize
09 Apr, 2024 view: 144
img
why important website development learn
10 Apr, 2024 view: 136
img
How to Integrate Stripe Payment in Laravel
06 Apr, 2024 view: 133
img
Laravel Authentication Tutorial
09 Apr, 2024 view: 133
img
laravel qr code generator package
18 Apr, 2024 view: 131
Trending