kingflamez / laravelrave

A Laravel Package for Flutterwave 🦄
MIT License
137 stars 112 forks source link

Null return #47

Closed kennyendowed closed 3 years ago

kennyendowed commented 3 years ago

am getting a null return

my route Route::get('/pay/{id?}/{name?}/{email?}/{phone?}/{amount?}/', 'ProductsController@raveinitialize')->name('pay');

callback route Route::get('/rave/callback','ProductsController@callback')->name('callback');

here is my method public function raveinitialize($reference,$name,$email,$phone,$amount) {

    // Enter the details of the payment
    $data = [
        'payment_options' => 'card,banktransfer',
        'amount' => $amount,
        'email' => $email,
        'tx_ref' => $reference,
        'currency' => "NGN",
        'redirect_url' => route('callback'),
        'customer' => [
            'email' => $email,
            "phonenumber" => $phone,
            "name" => $name
        ],

        "customizations" => [
            "title" => 'Product payment',
            "description" => $reference 
        ]
    ];

    $payment = Flutterwave::initializePayment($data);
    dd($payment); //this return a null 

    if (!$payment) {
        // notify something went wrong
        $notification = array(
         'message' =>' Product payment confirmation unsuccessful ',
         'alert-type' => 'error'
     );
        return redirect()->back()->with($notification);
    }

    return redirect($payment['link']);

   }

//callback method

public function callback() {
    // This verifies the transaction and takes the parameter of the transaction reference
    $data = Rave::verifyTransaction(request()->txref);

    $chargeResponsecode = $data->data->chargecode;
    $chargeAmount = $data->data->amount;
    $chargeCurrency = $data->data->currency;

    $amount = 4500;
    $currency = "NGN";

    if (($chargeResponsecode == "00" || $chargeResponsecode == "0") && ($chargeAmount == $amount)  && ($chargeCurrency == $currency)) {
    // transaction was successful...
    // please check other things like whether you already gave value for this ref
    // if the email matches the customer who owns the product etc
    //Give Value and return to Success page

        return redirect('/success');

    } else {
        //Dont Give Value and return to Failure page

        return redirect('/failed');
    }

    // dd($data->data);
  }
kingflamez commented 3 years ago

Hi Kenny sorry about this, are your keys present in your .env variables?

kennyendowed commented 3 years ago

yes my keys are save in my .env

FLW_PUBLIC_KEY=FLWPUBK_TEST-a796bd59a7dff674a77e1a033e83d608-X FLW_SECRET_KEY=FLWSECK_TEST-8d90633c741abb8ddbbfd8a22c23d498-X FLW_SECRET_HASH='FLWSECK_TEST16bdeeb057c4'

kingflamez commented 3 years ago

Do you mind sharing your php version

kennyendowed commented 3 years ago

PHP 7.4.15 (cli) (built: Feb 12 2021 10:46:35) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.15, Copyright (c), by Zend Technologies with Xdebug v3.0.2, Copyright (c) 2002-2021, by Derick Rethans

kennyendowed commented 3 years ago

i have even change from php v 7.4 to 7.2 still having the same responses

using this

$ sudo a2dismod php7.4 $ a2enmod php7.2 $ sudo service apache2 restart

kingflamez commented 3 years ago

Hi @kennyendowed, can you update your version to the latest version and try this. 4.2.0

$payment = Flutterwave::initializePayment($data);

        Log::info($payment);

        if ($payment['status'] !== 'success') {
            // notify something went wrong
            return;
        }

        return redirect($payment['data']['link']);
kingflamez commented 3 years ago

Hi @kennyendowed , any update?

kennyendowed commented 3 years ago

Thanks all is well now i run composer update and all is fine now

kingflamez commented 3 years ago

Thanks @kennyendowed do you mind sharing what the error message was?

kennyendowed commented 3 years ago

Ok the error message i was having was Invalid authorization key My config variable wasn't not point to config/fluttérwave.php i was still using the old one that is config/rave.php

So i had to run composer publish again since i didnt do it after updating my laravel rave package from 1.1 to 4.1