Skip to content

Commit

Permalink
chore: updating sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
gubrito committed Dec 13, 2023
1 parent 8d07bd5 commit 03a23d4
Show file tree
Hide file tree
Showing 53 changed files with 1,878 additions and 320 deletions.
78 changes: 41 additions & 37 deletions packages/sdk/composer.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
{
"name": "mp-plugins/php-sdk",
"description": "Mercado Pago Plugins PHP-SDK",
"type": "library",
"scripts": {
"lint": "./vendor/bin/phpcs -q --report=checkstyle --standard=PSR2 src",
"test": "./vendor/bin/phpunit --coverage-html coverage --coverage-clover clover.xml --coverage-text --testdox --colors=auto"
},
"autoload": {
"psr-4": {
"MercadoPago\\PP\\Sdk\\": [
"src"
]
}
},
"autoload-dev": {
"psr-4": {
"MercadoPago\\PP\\Sdk\\Tests\\": [
"tests"
]
}
},
"require": {
"php": ">=7",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": ">=7.2",
"squizlabs/php_codesniffer": ">=3"
},
"license": "proprietary",
"authors": [
{
"name": "Mercado Pago SMB",
"email": "[email protected]"
}
],
"minimum-stability": "stable"
"name": "mp-plugins/php-sdk",
"description": "Mercado Pago Plugins PHP-SDK",
"version": "1.9.0",
"type": "library",
"scripts": {
"lint": "./vendor/bin/phpcs -q --report=checkstyle --standard=PSR2 src",
"test": "./vendor/bin/phpunit --coverage-html coverage --coverage-clover clover.xml --coverage-text --testdox --colors=auto --testsuite pp-php-sdk-unit"
},
"autoload": {
"psr-4": {
"MercadoPago\\PP\\Sdk\\": [
"src"
]
}
},
"autoload-dev": {
"psr-4": {
"MercadoPago\\PP\\Sdk\\Tests\\Unit\\": [
"tests/unit"
],
"MercadoPago\\PP\\Sdk\\Tests\\Integration\\": [
"tests/integration"
]
}
},
"require": {
"php": ">=7",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "9.5.27",
"squizlabs/php_codesniffer": "3.7.2"
},
"license": "proprietary",
"authors": [
{
"name": "Mercado Pago SMB",
"email": "[email protected]"
}
],
"minimum-stability": "stable"
}
2 changes: 1 addition & 1 deletion packages/sdk/src/Common/AbstractCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function setEntity($entities)
/**
* @inheritDoc
*/
public function getIterator()
public function getIterator(): \Traversable
{
return new \ArrayIterator($this->collection);
}
Expand Down
28 changes: 26 additions & 2 deletions packages/sdk/src/Common/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace MercadoPago\PP\Sdk\Common;

use MercadoPago\PP\Sdk\Interfaces\EntityInterface;
use MercadoPago\PP\Sdk\Sdk;

/**
* Class AbstractEntity
Expand Down Expand Up @@ -166,7 +167,7 @@ public function read(array $params = [])

$uri = $this->manager->getEntityUri($entity, $method, $params);
$response = $this->manager->execute($entity, $uri, $method, $header);

$this->obfuscateAuthorizationHeader($header);
return $this->manager->handleResponse($response, $method, $entity);
}

Expand All @@ -185,7 +186,7 @@ public function save()

$uri = $this->manager->getEntityUri($this, $method);
$response = $this->manager->execute($this, $uri, $method, $header);

$this->obfuscateAuthorizationHeader($header);
return $this->manager->handleResponse($response, $method);
}

Expand All @@ -206,4 +207,27 @@ public function setExcludedProperties()
{
$this->excluded_properties = [];
}

/**
* Obfuscate Authorization Header.
*
* @return void
*/
public function obfuscateAuthorizationHeader(array $headers)
{
Sdk::$cache['last_headers'] = preg_replace('/(Authorization: Bearer) (.*)/i', '$1 xxx', $headers);
}

/**
* Get last Headers.
*
* @return array
*/
public function getLastHeaders(): array
{
if (isset(Sdk::$cache['last_headers'])) {
return Sdk::$cache['last_headers'];
}
return [];
}
}
5 changes: 5 additions & 0 deletions packages/sdk/src/Common/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ class Constants
{
const BASEURL_MP = 'https://api.mercadopago.com';
const BASEURL_ML = 'https://api.mercadolibre.com';
const THREE_DS_VALID_OPTIONS = array(self::THREE_DS_MODE_OPTIONAL,
self::THREE_DS_MODE_MANDATORY, self::THREE_DS_MODE_NOT_SUPPORTED);
const THREE_DS_MODE_OPTIONAL = 'optional';
const THREE_DS_MODE_MANDATORY = 'mandatory';
const THREE_DS_MODE_NOT_SUPPORTED = 'not_supported';
}
3 changes: 2 additions & 1 deletion packages/sdk/src/Common/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ public function handleResponse(Response $response, string $method, AbstractEntit
}
return $response->getData();
} elseif (intval($response->getStatus()) >= 400 && intval($response->getStatus()) < 500) {
throw new \Exception($response->getData()['message']);
$message = $response->getData()['message'] ?? 'No message for Multipayment scenario in v1!';
throw new \Exception($message);
} else {
throw new \Exception("Internal API Error");
}
Expand Down
91 changes: 73 additions & 18 deletions packages/sdk/src/Entity/Notification/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,36 @@
use MercadoPago\PP\Sdk\Interfaces\RequesterEntityInterface;

/**
* Class Notification
* Handles integration with the Asgard Notification service.
*
* Asgard Notification is responsible for handling notifications originating from plugins and platforms.
* When a payment is initiated that requires asynchronous approval, a notification is generated and processed
* by this class.
* This class streamlines the interaction with the Asgard Notification service, allowing the details of a
* specific notification to be fetched using its ID. It aims to simplify the complexity associated with
* managing and validating notifications, ensuring that only relevant information is forwarded to
* platforms and plugins.
*
* @property string $ip_address
* @property string $notification_id
* @property string $notification_url
* @property string $status
* @property string $external_reference
* @property float $transaction_id
* @property string $transaction_id
* @property string $transaction_type
* @property string $platform_id
* @property string $external_reference
* @property string $preference_id
* @property float $transaction_amount
* @property float $total_pending
* @property float $total_approved
* @property float $total_paid
* @property float $total_rejected
* @property float $total_approved
* @property float $total_pending
* @property float $total_refunded
* @property float $total_rejected
* @property float $total_cancelled
* @property float $total_charged_back
* @property string $multiple_payment_transaction_id
* @property array $payments_metadata
* @property PaymentDetails $payments_details
* @property PaymentDetailsList $payments_details
* @property RefundNotifyingList $refunds_notifying
*
* @package MercadoPago\PP\Sdk\Entity\Notification
*/
Expand All @@ -49,17 +60,27 @@ class Notification extends AbstractEntity implements RequesterEntityInterface
/**
* @var string
*/
protected $external_reference;
protected $transaction_id;

/**
* @var float
* @var string
*/
protected $transaction_id;
protected $transaction_type;

/**
* @var string
*/
protected $transaction_type;
protected $platform_id;

/**
* @var string
*/
protected $external_reference;

/**
* @var string
*/
protected $preference_id;

/**
* @var float
Expand All @@ -69,7 +90,7 @@ class Notification extends AbstractEntity implements RequesterEntityInterface
/**
* @var float
*/
protected $total_pending;
protected $total_paid;

/**
* @var float
Expand All @@ -79,17 +100,17 @@ class Notification extends AbstractEntity implements RequesterEntityInterface
/**
* @var float
*/
protected $total_paid;
protected $total_pending;

/**
* @var float
*/
protected $total_rejected;
protected $total_refunded;

/**
* @var float
*/
protected $total_refunded;
protected $total_rejected;

/**
* @var float
Expand All @@ -101,16 +122,26 @@ class Notification extends AbstractEntity implements RequesterEntityInterface
*/
protected $total_charged_back;

/**
* @var string
*/
protected $multiple_payment_transaction_id;

/**
* @var array
*/
protected $payments_metadata;

/**
* @var PaymentDetails
* @var PaymentDetailsList
*/
protected $payments_details;

/**
* @var RefundNotifyingList
*/
protected $refunds_notifying;

/**
* Notification constructor.
*
Expand All @@ -120,6 +151,7 @@ public function __construct($manager)
{
parent::__construct($manager);
$this->payments_details = new PaymentDetailsList($manager);
$this->refunds_notifying = new RefundNotifyingList($manager);
}

/**
Expand Down Expand Up @@ -153,7 +185,30 @@ public function getHeaders(): array
public function getUris(): array
{
return array(
'get' => '/v1/bifrost/notification/status/:id',
'get' => '/v1/asgard/notification/:id',
);
}

/**
* Retrieves a notification from the Asgard Transaction service.
*
* Upon invoking this method, a request is made to the Asgard Transaction service
* using the provided notification ID. Authentication is performed using
* the seller's access token, which should be previously configured in the default headers.
*
* Note: This method is inherited from the parent class but specialized for notifications.
*
* @param array $params Associative array containing the parameters for the read operation.
* It expects an "id" key with the notification ID as its value.
* Example: $notification->read(['id' => 'P-1316643861'])
*
* @return mixed The result of the read operation, typically an instance of
* this Notification class populated with the retrieved data.
*
* @throws \Exception Throws an exception if something goes wrong during the read operation.
*/
public function read(array $params = [])
{
return parent::read($params);
}
}
Loading

0 comments on commit 03a23d4

Please sign in to comment.