mardi 7 avril 2020

PHP Laravel 5.6 -The Stripe API key is not defined! error message

Any help or suggestions will be highly appreciated it! I am trying to issue a refund in PHP Laravel 5.6 with Stripe Sandbox Enabled. I am using a table and within that table I have two text fields to define the Stripe test and live keys.

This is my services code within PHP Laravel:


return [

    /*
    |--------------------------------------------------------------------------
    | Third Party Services
    |--------------------------------------------------------------------------
    |
    | This file is for storing the credentials for third party services such
    | as Stripe, Mailgun, SparkPost and others. This file provides a sane
    | default location for this type of information, allowing packages
    | to have a conventional place to find your various credentials.
    |
    */

    'mailgun' => [
        'domain' => env('MAILGUN_DOMAIN'),
        'secret' => env('MAILGUN_SECRET'),
    ],

    'ses' => [
        'key' => env('SES_KEY'),
        'secret' => env('SES_SECRET'),
        'region' => 'us-east-1',
    ],

    'sparkpost' => [
        'secret' => env('SPARKPOST_SECRET'),
    ],

    'stripe' => [
        'model' => App\User::class,
        'key' => config('settings.stripe_sandbox_enabled') ? config('settings.stripe_test_key_pk') : config('settings.stripe_live_key_pk'),
        'secret' => config('settings.stripe_sandbox_enabled') ? config('settings.stripe_test_key_sk') : config('stripe_live_key_sk'),        
    ],

];

Here is the line of code to issue the refund via Stripe in my blade file:


            //issue refund
            $invoice = $booking->invoice()->first();

            if($invoice['payment_method'] == __('app.credit_card'))
            {
                try {
                    //refund via stripe
                    if($booking->invoice->is_partial == 1){
                        if($booking->invoice->amount_left != 0){
                        //     print_r($booking->invoice->transaction_id);
                        // exit();
                            Stripe::refunds()->create($booking->invoice->transaction_id, $booking->invoice->first_payment, [
                                'reason' => 'requested_by_customer'
                            ]);
                        }
                        else{
                            $transaction_ids = explode(',', $booking->invoice->transaction_id);
                            Stripe::refunds()->create($transaction_ids[0], $booking->invoice->first_payment, [
                                    'reason' => 'requested_by_customer'
                                ]);
                            Stripe::refunds()->create($transaction_ids[1], $booking->invoice->second_payment, [
                                    'reason' => 'requested_by_customer'
                                ]);
                        }
                    }
                    else{
                        Stripe::refunds()->create($booking->invoice->transaction_id, $booking->invoice->amount , [
                            'reason' => 'requested_by_customer'
                        ]);
                    }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire