· 6 years ago · Sep 14, 2019, 02:56 PM
1<?php
2
3namespace App\Domain\Billing;
4
5
6class BOG
7{
8 public $creds;
9 public function __construct()
10 {
11 $secretKey = config('services.bog.secret_key');
12 $clientId = config('services.bog.client_id');
13
14 $this->creds = base64_encode($secretKey . $clientId);
15 }
16
17
18 public function startCurl($creds)
19 {
20 $ch = curl_init();
21
22 curl_setopt($ch, CURLOPT_URL, 'https://dev.ipay.ge/opay/api/v1/oauth2/token');
23 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
24 curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
25 curl_setopt($ch, CURLOPT_POST, 1);
26
27 $headers = array();
28 $headers[] = 'Accept: application/json';
29 $headers[] = 'Authorization: Basic ' . $creds;
30 $headers[] = 'Content-Type: application/x-www-form-urlencoded';
31 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
32
33 $result = curl_exec($ch);
34 if (curl_errno($ch)) {
35 echo 'Error:' . curl_error($ch);
36 }
37 curl_close($ch);
38
39 return $result;
40 }
41}