Skip to content
Snippets Groups Projects

Updated README.txt to README.md

20 files
+ 314
433
Compare changes
  • Side-by-side
  • Inline
Files
20
@@ -19,14 +19,14 @@ class OutvoiceApi {
*
* @var string
*/
protected $apiVersion = 'api/v1.0/';
protected $apiVersion = 'v1.1/';
/**
* The OutVoice module version.
*
* @var string
*/
protected $moduleVersion = 'drupal8.x-1.1';
protected $moduleVersion = 'drupal7.x-1.0';
/**
* The OutVoice Client ID.
@@ -69,17 +69,20 @@ class OutvoiceApi {
*/
public function generateTokens($username, $password) {
$data = [
'form_params' => [
'grant_type' => 'password',
'client_id' => $this->clientID,
],
];
$data['form_params']['username'] = $username;
$data['form_params']['password'] = $password;
$client = \Drupal::httpClient();
$request = $client->post($this->apiUrl . "oauth/token", $data);
$tokens = json_decode($request->getBody());
$data = array(
'grant_type' => 'password',
'client_id' => $this->clientID,
'username' => $username,
'password' => $password,
);
$options = array(
'method' => 'POST',
'data' => http_build_query($data),
'timeout' => 15,
'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);
$client = drupal_http_request($this->apiUrl . "oauth/token", $options);
$tokens = json_decode($client->data);
if (isset($tokens->access_token)) {
$this->accessToken = $tokens->access_token;
$this->refreshToken = $tokens->refresh_token;
@@ -98,16 +101,20 @@ class OutvoiceApi {
*/
public function refreshTokens() {
$data = [
'form_params' => [
'grant_type' => 'refresh_token',
'client_id' => $this->clientID,
],
];
$data['form_params']['refresh_token'] = $this->refreshToken;
$client = \Drupal::httpClient();
$request = $client->post($this->apiUrl . "oauth/token", $data);
$tokens = json_decode($request->getBody());
$data = array(
'grant_type' => 'refresh_token',
'client_id' => $this->clientID,
'refresh_token' => $this->refreshToken,
);
$options = array(
'method' => 'POST',
'data' => http_build_query($data),
'timeout' => 15,
'headers' => array('Content-Type' => 'application/x-www-form-urlencoded'),
);
$client = drupal_http_request($this->apiUrl . "oauth/token", $options);
$tokens = json_decode($client->data);
if (isset($tokens->access_token)) {
$this->accessToken = $tokens->access_token;
$this->refreshToken = $tokens->refresh_token;
@@ -166,25 +173,19 @@ class OutvoiceApi {
*/
public function payment(array $info) {
$data = [
"headers" => [
'Authorization' => "Bearer " . $this->getAccessToken(),
'Content-Type' => "application/json",
],
"body" => [
0 => [
$data = array(
0 => array(
"freelancer" => $info['freelancer'],
"amount" => self::outvoiceFormatAmount($info['amount']),
"currency" => $info['currency'],
"url" => $info['url'],
"title" => $info['title'],
"version" => $this->moduleVersion,
],
],
];
),
);
// Add second contributor.
if (!empty($info['amount1'])) {
$data['body'][1] = [
$data[1] = [
"freelancer" => $info['freelancer1'],
"amount" => self::outvoiceFormatAmount($info['amount1']),
"currency" => $info['currency1'],
@@ -193,12 +194,22 @@ class OutvoiceApi {
"version" => $this->moduleVersion,
];
}
$data['body'] = json_encode($data['body']);
$client = \Drupal::httpClient();
$request = $client->post($this->apiUrl . $this->apiVersion . "transaction", $data);
$data = json_encode($data);
$options = array(
'method' => 'POST',
'data' => $data,
'timeout' => 15,
'headers' => array(
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $this->getAccessToken()
),
);
$request = drupal_http_request($this->apiUrl . $this->apiVersion . "transaction", $options);
$message = "There was an error. Please log into your OutVoice account to confirm payment.";
if ($request->getStatusCode() == 200) {
$message = "OutVoice payment successful. " . $request->getBody();
if ($request->code == 200) {
$message = $request->data;
}
return $message;
@@ -213,14 +224,13 @@ class OutvoiceApi {
*/
public function listContributors() {
$data = [
'headers' => [
'Authorization' => 'Bearer ' . $this->getAccessToken(),
],
];
$client = \Drupal::httpClient();
$request = $client->get($this->apiUrl . $this->apiVersion . "list-freelancers", $data);
$contributorList = json_decode($request->getBody());
$options = array(
'method' => 'GET',
'timeout' => 15,
'headers' => array('Authorization' => 'Bearer ' . $this->getAccessToken()),
);
$client = drupal_http_request($this->apiUrl . $this->apiVersion . "list-freelancers", $options);
$contributorList = json_decode($client->data,TRUE);
return $contributorList;
}
Loading