Code Duplication    Length = 21-25 lines in 2 locations

src/Daraja.php 2 locations

@@ 60-80 (lines=21) @@
57
     * This is used to generate tokens for the live environment
58
     * @return mixed
59
     */
60
    public function generateLiveToken(){
61
        if(!isset($this->consumer_key)||!isset($this->consumer_secret)){
62
            die("please set the consumer key and consumer secret as defined in the documentation. You can use setCredentials() before calling this function.");
63
        }
64
        $consumer_key = $this->consumer_key;
65
        $consumer_secret = $this->consumer_secret;
66
        $url = 'https://api.safaricom.co.ke/oauth/v1/generate?grant_type=client_credentials';
67
        $curl = curl_init();
68
        curl_setopt($curl, CURLOPT_URL, $url);
69
        $credentials = base64_encode($consumer_key.':'.$consumer_secret);
70
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Basic '.$credentials)); //setting a custom header
71
        curl_setopt($curl, CURLOPT_HEADER, false);
72
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
73
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
74
        $curl_response = curl_exec($curl);
75
        $this->access_token = optional(json_decode($curl_response))->access_token;
76
        if (!$this->access_token) {
77
            abort(500, "Access token could not be generated.");
78
        }
79
        return $this;
80
    }
81
82
    public function getAccessToken() {
83
        return $this->access_token;
@@ 89-113 (lines=25) @@
86
     * use this function to generate a sandbox token
87
     * @return mixed
88
     */
89
    public function generateSandBoxToken(){
90
91
        if(!isset($this->consumer_key)||!isset($this->consumer_secret)){
92
            die("please set the consumer key and consumer secret as defined in the documentation. You can use setCredentials() before calling this function.");
93
        }
94
        $consumer_key = $this->consumer_key;
95
        $consumer_secret = $this->consumer_secret;
96
        $url = 'https://sandbox.safaricom.co.ke/oauth/v1/generate?grant_type=client_credentials';
97
        $curl = curl_init();
98
        curl_setopt($curl, CURLOPT_URL, $url);
99
        $credentials = base64_encode($consumer_key.':'.$consumer_secret);
100
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Basic '.$credentials)); //setting a custom header
101
        curl_setopt($curl, CURLOPT_HEADER, false);
102
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
103
104
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
105
106
        $curl_response = curl_exec($curl);
107
108
        $this->access_token = optional(json_decode($curl_response))->access_token;
109
        if (!$this->access_token) {
110
            abort(500, "Access token could not be generated.");
111
        }
112
        return $this;
113
    }
114
115
    /**
116
     * Register Validation and Confirmation Callbacks