Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement access_token in header's requests #290

Merged
merged 1 commit into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The SDK supports PHP 5.6 or major
#### Using Composer

1. Download [Composer](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos) if not already installed
2. Go to your project directory and run `composer require "mercadopago/dx-php:1.9.0"` on the command line.
2. Go to your project directory and run `composer require "mercadopago/dx-php:1.10.0"` on the command line.
3. This how your directory structure would look like.
4. Thats all, you have Mercado Pago SDK installed.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "library",
"homepage": "https://github.com/mercadopago/dx-php",
"license": "MIT",
"version": "1.9.0",
"version": "1.10.0",
"config": {
"platform": {
"php": "5.6"
Expand Down
7 changes: 2 additions & 5 deletions src/MercadoPago/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,13 @@ public function set($key, $value)
/**
* @return mixed
*/
public function getUserId($access_token)
public function getUserId()
{
if (!$this->_restclient) {
$this->_restclient = new RestClient();
$this->_restclient->setHttpParam('address', $this->get('base_url'));
}
$response = $this->_restclient->get("/users/me", array(
"url_query" => array("access_token" => $access_token)
)
);
$response = $this->_restclient->get("/users/me");

return $response["body"];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* @RestMethod(resource="/v1/advanced_payments/search", method="search")
* @RestMethod(resource="/v1/advanced_payments/:id", method="update")
* @RestMethod(resource="/v1/advanced_payments/:id/refunds", method="refund")
* @RequestParam(param="access_token")
*/
class AdvancedPayment extends Entity
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
/**
* @RestMethod(resource="/v1/advanced_payments/:advanced_payment_id/disbursements/:disbursement_id/refunds", method="create")
* @RestMethod(resource="/v1/advanced_payments/:advanced_payment_id/disbursements/:disbursement_id/refunds/:refund_id", method="read")
* @RequestParam(param="access_token")
*/
class DisbursementRefund extends Entity {

Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/AdvancedPayments/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
/**
* @RestMethod(resource="/v1/advanced_payments/:advanced_payment_id/refunds", method="create")
* @RestMethod(resource="/v1/advanced_payments/:advanced_payment_id/refunds/:refund_id", method="read")
* @RequestParam(param="access_token")
*/
class Refund extends Entity {

Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/AuthorizedPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* @RestMethod(resource="/authorized_payment/:id", method="read")
* @RestMethod(resource="/authorized_payment/search", method="search")
* @RestMethod(resource="/authorized_payment/:id", method="update")
* @RequestParam(param="access_token")
*/

class AuthorizedPayment extends Entity
Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* @RestMethod(resource="/v1/customers/:customer_id/cards/:id", method="read")
* @RestMethod(resource="/v1/customers/:customer_id/cards/:id", method="update")
* @RestMethod(resource="/v1/customers/:customer_id/cards/:id", method="delete")
* @RequestParam(param="access_token")
*/

class Card extends Entity
Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/Chargeback.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/**
* @RestMethod(resource="/v1/chargebacks/:id", method="read")
* @RequestParam(param="access_token")
*/
class Chargeback extends Entity
{
Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* @RestMethod(resource="/v1/customers/", method="create")
* @RestMethod(resource="/v1/customers/:id", method="update")
* @RestMethod(resource="/v1/customers/:id", method="delete")
* @RequestParam(param="access_token")
*/

class Customer extends Entity
Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/DiscountCampaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/**
* @RestMethod(resource="/v1/discount_campaigns", method="read")
* @RequestParam(param="access_token")
*/


Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/InstoreOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

/**
* @RestMethod(resource="/mpmobile/instore/qr/:user_id/:external_id", method="create")
* @RequestParam(param="access_token")
*/
class InstoreOrder extends Entity
{
Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

/**
* @RestMethod(resource="/v1/invoices/:id", method="read")
* @RequestParam(param="access_token")
*/

class Invoice extends Entity
Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/MerchantOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* @RestMethod(resource="/merchant_orders/:id", method="read")
* @RestMethod(resource="/merchant_orders/", method="create")
* @RestMethod(resource="/merchant_orders/:id", method="update")
* @RequestParam(param="access_token")
*/

class MerchantOrder extends Entity
Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/Plan.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* @RestMethod(resource="/v1/plans/:id", method="read")
* @RestMethod(resource="/v1/plans/", method="create")
* @RestMethod(resource="/v1/plans/:id", method="update")
* @RequestParam(param="access_token")
*/

class Plan extends Entity
Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/Pos.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* @RestMethod(resource="/pos/:id", method="update")
* @RestMethod(resource="/pos/:id", method="delete")
* @RestMethod(resource="/pos", method="search")
* @RequestParam(param="access_token")
*/
class POS extends Entity
{
Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/Preapproval.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* @RestMethod(resource="/preapproval/search", method="search")
* @RestMethod(resource="/preapproval/", method="create")
* @RestMethod(resource="/preapproval/:id", method="update")
* @RequestParam(param="access_token")
*/

class Preapproval extends Entity
Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/Preference.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* @RestMethod(resource="/checkout/preferences", method="create")
* @RestMethod(resource="/checkout/preferences/:id", method="read")
* @RestMethod(resource="/checkout/preferences/:id", method="update")
* @RequestParam(param="access_token")
*/
class Preference extends Entity
{
Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/**
* @RestMethod(resource="/v1/payments/:payment_id/refunds", method="create")
* @RestMethod(resource="/v1/payments/:payment_id/refunds/:id", method="read")
* @RequestParam(param="access_token")
*/
class Refund extends Entity {

Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/Shared/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* @RestMethod(resource="/v1/payments/search", method="search")
* @RestMethod(resource="/v1/payments/:id", method="update")
* @RestMethod(resource="/v1/payments/:id/refunds", method="refund")
* @RequestParam(param="access_token")
*/
class Payment extends Entity
{
Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/Shared/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

/**
* @RestMethod(resource="/v1/payment_methods", method="list")
* @RequestParam(param="access_token")
*/

class PaymentMethod extends Entity
Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/Shipments.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/**
* @RestMethod(resource="/v1/payments/:payment_id/refunds", method="create")
* @RestMethod(resource="/v1/payments/:payment_id/refunds/:id", method="read")
* @RequestParam(param="access_token")
*/
class Shipments extends Entity {

Expand Down
1 change: 0 additions & 1 deletion src/MercadoPago/Entities/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* @RestMethod(resource="/v1/subscriptions/:id", method="read")
* @RestMethod(resource="/v1/subscriptions/", method="create")
* @RestMethod(resource="/v1/subscriptions/:id", method="update")
* @RequestParam(param="access_token")
*/

class Subscription extends Entity
Expand Down
11 changes: 1 addition & 10 deletions src/MercadoPago/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,7 @@ public function processOptions($options, $configuration)
$configuration_vars = $this->_config->all();

foreach($options as $option => $value) {
switch ($option) {
case "custom_access_token":
if (array_key_exists($value, $configuration_vars)) {
$configuration->query["url_query"]["access_token"] = $configuration_vars[$value];
} else {
$configuration->query["url_query"]["access_token"] = $value;
}
default:
$configuration->query["url_query"][$option] = $value;
}
$configuration->query["url_query"][$option] = $value;
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/MercadoPago/RestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,19 @@ protected function setHeaders(Http\HttpRequest $connect, $customHeaders)
'x-product-id' => 'BC32A7RU643001OI3940',
'x-tracking-id' => 'platform:' . PHP_MAJOR_VERSION .'|' . PHP_VERSION . ',type:SDK' . Version::$_VERSION . ',so;'
);

if ($customHeaders) {
$default_header = array_merge($default_header, $customHeaders);
}

if(!isset($default_header['Authorization'])){
$default_header['Authorization'] = 'Bearer '.SDK::getAccessToken();
}

foreach ($default_header as $key => $value) {
$headers[] = $key . ': ' . $value;
}

$connect->setOption(CURLOPT_HTTPHEADER, $headers);
}

Expand Down
12 changes: 0 additions & 12 deletions src/MercadoPago/SDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,33 +131,21 @@ public static function addCustomTrackingParam($key, $value)

public static function get($uri, $options=[])
{
if ($token = self::$_config->get('ACCESS_TOKEN')) {
$uri = $uri . "?access_token=" . $token;
}
return self::$_restClient->get($uri, $options);
}

public static function post($uri, $options=[])
{
if ($token = self::$_config->get('ACCESS_TOKEN')) {
$uri = $uri . "?access_token=" . $token;
}
return self::$_restClient->post($uri, $options);
}

public static function put($uri, $options=[])
{
if ($token = self::$_config->get('ACCESS_TOKEN')) {
$uri = $uri . "?access_token=" . $token;
}
return self::$_restClient->put($uri, $options);
}

public static function delete($uri, $options=[])
{
if ($token = self::$_config->get('ACCESS_TOKEN')) {
$uri = $uri . "?access_token=" . $token;
}
return self::$_restClient->delete($uri, $options);
}

Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
class Version
{
public static
$_VERSION = '1.8.0';
$_VERSION = '1.10.0';
}
2 changes: 1 addition & 1 deletion tests/DummyEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @RestMethod(resource="/dummy/:id", method="update")
* @RestMethod(resource="/v1/payments", method="create")
* @RestMethod(resource="/v1/dummies/search", method="search")
* @RequestParam(param="access_token")
*
*/
class DummyEntity extends Entity
{
Expand Down
3 changes: 2 additions & 1 deletion tests/resources/POSTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ public function testSearchPos(MercadoPago\POS $pos) {
"external_id" => $pos->external_id
);
$poss = MercadoPago\POS::search($filters);
$poss = $poss->getArrayCopy();
$last_pos = end($poss);

$this->assertEquals($last_pos->external_id, $pos->external_id);
$this->assertEquals($pos->external_id, $pos->external_id);
}


Expand Down
1 change: 1 addition & 0 deletions tests/resources/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public function testPaymentsSearch(MercadoPago\Payment $payment_created_previous
);

$payments = MercadoPago\Payment::search($filters);
$payments = $payments->getArrayCopy();
$payment = end($payments);

$this->assertEquals($payment->external_reference, $payment_created_previously->external_reference);
Expand Down