mardi 6 février 2018

Stripe Error Must provide source or customer laravel and Stripe token response null

I integrate stripe payment gateway to my laravel application. In another laravel application it's working fine but if I do the same for my live server its giving error Must provide source or customer. when i print Stripetoken request its look like null.

Below is the code snippets.

ProductController.php

 public function postCheckout(Request $request) {
        if (!Session::has('cart')) {
            return redirect()->route('shoppingcart');
        }
        $oldCart = Session::get('cart');
        $cart = new Cart($oldCart);

        Stripe::setApiKey('sk_test_GK6GUk5Ig7w4KN9QOyXLukRx');
        dd($token = $request->stripeToken);
        try {
            $charges = Charge::create(array(
                "amount" => $cart->totalPrice * 100,
                "currency" => "usd",
                "source" => $request->input('stripeToken'),
                "description" => "Test Charges"
            ));
            //dd($charges);
            $order = new Order();
            $order->cart = serialize($cart);
            $order->address = $request->input('address');
            $order->name = $request->input('name');
            $order->payment_id = $charges->id;

            Auth::user()->orders()->save($order);
        } catch (\Exception $e) {
            return redirect()->route('checkout')->with('error', $e->getMessage());
        }

        Session::forget('cart');

        return redirect()->route('home')->with('success','Successfully purchased products!');
    }

Charge.js

Stripe.setPublishableKey('pk_test_ZvR5SYlEMdQTQ3opI9y4huUm');

var $form = $('#checkout-form2');

$form.submit(function (event) {
    $('#checkout-error').addClass('hidden');
    $form.find('button').prop('disabled', true);
    Stripe.card.createToken({
        number: $('#card-number').val(),
        cvc: $('#card-cvc').val(),
        exp_month: $('#card-expiry-month').val(),
        exp_year: $('#card-expiry-year').val(),
        name: $('#card-name').val()
    }, stripeResponseHandler);
    return false;
});

function stripeResponseHandler(status, response) {
    if(response.error) {
        $('#checkout-error').removeClass('hidden');
        $('#checkout-error').text(response.error.message);
        $form.find('button').prop('disabled', false);
    } else {
        var token = response.id;
        $form.append($('<input type="hidden" name="stripeToken" />').val(token));
        $form.get(0).submit();
    }
}

View - check.blade.php

@extends('layouts.app')

@section('title')
    Shopping checkout
@endsection


@section('content')
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <h1 class="page-header">Checkout</h1>
            <h3>Your total: $ </h3>
            <div id="checkout-error" class="alert alert-danger ">
                
            </div>
            <form action="" method="post" id="checkout-form2">
                
                <div class="row">
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label for="name">Name:</label>
                            <input type="text" id="name" class="form-control" name="name" required>
                        </div>
                    </div>
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label for="address">Address:</label>
                            <input type="text" id="address" class="form-control" name="address" required>
                        </div>
                    </div>
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label for="card-name">Card Holder Name:</label>
                            <input type="text" id="card-name" class="form-control" required>
                        </div>
                    </div>
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label for="card-number">Credit card number:</label>
                            <input type="text" id="card-number" class="form-control" required>
                        </div>
                    </div>
                    <div class="col-xs-12">
                        <div class="row">
                            <div class="col-xs-6">
                                <div class="form-group">
                                    <label for="card-expiry-month">Expiration month:</label>
                                    <input type="text" id="card-expiry-month" class="form-control" required>
                                </div>
                            </div>
                            <div class="col-xs-6">
                                <div class="form-group">
                                    <label for="card-expiry-year">Expiration year:</label>
                                    <input type="text" id="card-expiry-year" class="form-control" required>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-12">
                        <div class="form-group">
                            <label for="card-cvc">CVC:</label>
                            <input type="text" id="card-cvc" class="form-control" required>
                        </div>
                    </div>
                </div>
                <button type="submit" class="btn btn-success">Buy now</button>
            </form>

        </div>
    </div>


@endsection

@section('scripts')
    <script type="text/javascript" src="https://js.stripe.com/v2/"></script>
    <script type="text/javascript" src=""></script>
@endsection

In another laravel application it's working fine but if I do the same for my live server its giving error Must provide source or customer. when i print Stripetoken request its look like null.

Anybody have ever experienced such issues.

Please help

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire