Skip to content

Commit

Permalink
Etiqueta del User-Agent para identificación de plugins Openpay.
Browse files Browse the repository at this point in the history
  • Loading branch information
jose-openpay committed Jun 17, 2020
1 parent ff2b78a commit e04f1bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 13 additions & 1 deletion data/OpenpayApi.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Openpay API v1 Client for PHP (version 1.0.3)
* Openpay API v1 Client for PHP (version 1.4.0)
*
* Copyright © Openpay SAPI de C.V. All rights reserved.
* http://www.openpay.mx/
Expand All @@ -13,6 +13,7 @@ class Openpay
private static $instance = null;
private static $id = '';
private static $apiKey = '';
private static $userAgent = '';
private static $apiEndpoint = 'https://api.openpay.mx/v1';
private static $apiSandboxEndpoint = 'https://sandbox-api.openpay.mx/v1';
private static $sandboxMode = true;
Expand All @@ -32,6 +33,17 @@ public static function getInstance($id = '', $apiKey = '') {
return $instance;
}

public static function setUserAgent($userAgent){
if ($userAgent != '') {
self::$userAgent = $userAgent;
}
}

public static function getUserAgent(){
$userAgent = self::$userAgent;
return $userAgent;
}

public static function setApiKey($key = '') {
if ($key != '') {
self::$apiKey = $key;
Expand Down
10 changes: 8 additions & 2 deletions data/OpenpayApiConnector.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Openpay API v1 Client for PHP (version 1.0.0)
* Openpay API v1 Client for PHP (version 1.4.0)
*
* Copyright © Openpay SAPI de C.V. All rights reserved.
* http://www.openpay.mx/
Expand Down Expand Up @@ -54,7 +54,13 @@ private function _request($method, $url, $params) {
$absUrl .= '/'.$myId.$url;

//$params = self::_encodeObjects($params);
$headers = array('User-Agent: OpenpayPhp/v1');

$userAgent = Openpay::getUserAgent();

if(empty($userAgent))
$headers = array('User-Agent: OpenpayPhp/v1');
else
$headers = array('User-Agent: '.$userAgent);

list($rbody, $rcode) = $this->_curlRequest($method, $absUrl, $headers, $params, $myApiKey);
return $this->interpretResponse($rbody, $rcode);
Expand Down

0 comments on commit e04f1bd

Please sign in to comment.