InvalidConfigException в строке 139 Spreedly.php в Spreedly-> validateConfig () в строке 93 Spreedly.php - PullRequest
0 голосов
/ 12 февраля 2019

$this->config['spreedly']['key'] ----! Isset условие не выполняется даже после получения данных в массиве.По умолчанию написано $ this-> config ['key'], но оно дает мне неопределенный индекс: key.

Я не могу найти соответствующую документацию для spreedly.Будем благодарны за любую помощь.

Примечание: я успешно получаю токен от curl, поэтому я не думаю, что есть какие-либо проблемы с моим ключом или секретом.

services.php

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://core.spreedly.com/v1/gateways.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n        \"gateway\": {\n          \"gateway_type\": \"test\"\n        }\n      }");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, 'key' . ':' . 'secret');

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);

// print_r($result);
$token = json_decode($result,true);

$token = $token['gateway']['token'];
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);

///////////CURL ENDS///////////

$config =  [

    'spreedly' => [
        'key' => 'added my key here', // (required) Environment key
        'secret' => 'secret here', // (required) Signing Secret
        'gateway' => $token, // (required) Default gateway
        'timeout' => '64', // (optional) Default 64 seconds (recommended by Spreedly)
        'connect_timeout' => '10', // (optional) Default 10 seconds
    ]

];

$spreedly = new Tuurbo\Spreedly\Spreedly($config);
?>

Spreedly.php

<?php

namespace Tuurbo\Spreedly;

use GuzzleHttp\Client as Guzzle;

class Spreedly
{
    protected $config;

    public function __construct($config)
    {
        $this->setConfig($config);
    }


    public function gateway($token = null)
    {
        return new Gateway($this->client(), $this->config, $token);
    }

    public function payment($paymentToken = null)
    {
        return new Payment($this->client(), $this->config, $paymentToken, $this->gateway()->getToken());
    }

    public function transaction($token = null)
    {
        return new Transaction($this->client(), $this->config, $token);
    }


    public function setConfig(array $config)
    { 
        $this->config = $config;    
        $this->validateConfig(); // this is where I have problem

        return $this;
    }

    protected function validateConfig()
    {

        // if (!isset($this->config['key'])) { 

           if(!isset(($this->config['spreedly']['key']))){ // this is suppose to be fail
            throw new Exceptions\InvalidConfigException(); // this is thrown
        }

        if (!isset($this->config['secret'])) {
            throw new Exceptions\InvalidConfigException();
        }
    }

    public function client()
    {
        return new Client(new Guzzle(), $this->config);
    }
}
...