Saturday, 06 Apr, 2024 -100

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: 1888
img
Xampp Tutorial Create Your Own Local Test Server
02 Apr, 2024 view: 769
img
How to Install Laravel
02 Apr, 2024 view: 758
img
PHP is not recognized as an internal or external command
02 Apr, 2024 view: 557
img
How to Install Composer on Windows
01 Apr, 2024 view: 542
img
Summernote image upload
01 Nov, 2023 view: 494
img
How to clear select2 selected value in js
01 Nov, 2023 view: 377
img
Zipping and Unzipping Files in Linux
02 Apr, 2024 view: 342
img
How to add Datepicker in Bootstrap
26 Apr, 2024 view: 336
img
How to Import a MySQL Database using Command Line
02 Apr, 2024 view: 327
img
How to Installation Laragon
01 Apr, 2024 view: 178
img
How to Installing an SSL certificate on your server using cPanel
06 Apr, 2024 view: 146
img
Paypal Payment Gateway Integration With Laravel
06 Apr, 2024 view: 119
img
How to Use Laravel Middleware to Protect Your Application
09 Apr, 2024 view: 105
img
Laravel Cache Clear Command Php Artisan Optimize
09 Apr, 2024 view: 105
img
why important website development learn
10 Apr, 2024 view: 103
img
Laravel Authentication Tutorial
09 Apr, 2024 view: 102
img
How to Integrate Stripe Payment in Laravel
06 Apr, 2024 view: 100
img
laravel qr code generator package
18 Apr, 2024 view: 93
Trending