diff --git a/application/libraries/Flutterwave_lib.php b/application/libraries/Flutterwave_lib.php new file mode 100644 index 0000000..55303a0 --- /dev/null +++ b/application/libraries/Flutterwave_lib.php @@ -0,0 +1,83 @@ +CI = & get_instance(); + $this->CI->load->helper('url'); + $this->CI->load->helper('form'); + $this->CI->load->config('flutterwave'); + + $this->payment_url = $this->CI->config->item('payment_endpoint'); + $this->verify_url = $this->CI->config->item('verify_endpoint'); + $this->PBFPubKey = $this->CI->config->item('PBFPubKey'); + $this->SECKEY = $this->CI->config->item('SECKEY'); + $this->currency = $this->CI->config->item('currency'); + $this->txn_prefix = $this->CI->config->item('txn_prefix'); + } + + function create_payment($data){ + + $data['PBFPubKey'] = $this->PBFPubKey; + $data['currency'] = $this->currency; + $data['txref'] = (!empty($this->txn_prefix))?$this->txn_prefix.'-'.time().''.mt_rand() : time().''.mt_rand(); + $response = $this->curl_post($this->payment_url, $data,TRUE); + return $response; + } + + function verify_transaction($reference){ + $data = array( + "SECKEY" => $this->SECKEY, + "txref" => $reference + ); + $response = $this->curl_post($this->verify_url, $data,TRUE); + return $response; + } + + function curl_post($url, $data,$json_encode_data = FALSE){ + + $data = ($json_encode_data)?json_encode($data):$data; + + $curl = curl_init(); + curl_setopt_array($curl, array( + CURLOPT_URL => $url, + CURLOPT_RETURNTRANSFER => true, + CURLOPT_CUSTOMREQUEST => "POST", + CURLOPT_POSTFIELDS => $data, + CURLOPT_HTTPHEADER => [ + "content-type: application/json", + "cache-control: no-cache" + ], + )); + $response = curl_exec($curl); + + if($err = curl_error($curl)){ + curl_close($curl); + return "CURL Error : ".$err; + }else{ + curl_close($curl); + return $response; + } + } +}