Skip to content

Commit 03a23d4

Browse files
committed
chore: updating sdk
1 parent 8d07bd5 commit 03a23d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1878
-320
lines changed

packages/sdk/composer.json

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
11
{
2-
"name": "mp-plugins/php-sdk",
3-
"description": "Mercado Pago Plugins PHP-SDK",
4-
"type": "library",
5-
"scripts": {
6-
"lint": "./vendor/bin/phpcs -q --report=checkstyle --standard=PSR2 src",
7-
"test": "./vendor/bin/phpunit --coverage-html coverage --coverage-clover clover.xml --coverage-text --testdox --colors=auto"
8-
},
9-
"autoload": {
10-
"psr-4": {
11-
"MercadoPago\\PP\\Sdk\\": [
12-
"src"
13-
]
14-
}
15-
},
16-
"autoload-dev": {
17-
"psr-4": {
18-
"MercadoPago\\PP\\Sdk\\Tests\\": [
19-
"tests"
20-
]
21-
}
22-
},
23-
"require": {
24-
"php": ">=7",
25-
"ext-json": "*"
26-
},
27-
"require-dev": {
28-
"phpunit/phpunit": ">=7.2",
29-
"squizlabs/php_codesniffer": ">=3"
30-
},
31-
"license": "proprietary",
32-
"authors": [
33-
{
34-
"name": "Mercado Pago SMB",
35-
"email": "[email protected]"
36-
}
37-
],
38-
"minimum-stability": "stable"
2+
"name": "mp-plugins/php-sdk",
3+
"description": "Mercado Pago Plugins PHP-SDK",
4+
"version": "1.9.0",
5+
"type": "library",
6+
"scripts": {
7+
"lint": "./vendor/bin/phpcs -q --report=checkstyle --standard=PSR2 src",
8+
"test": "./vendor/bin/phpunit --coverage-html coverage --coverage-clover clover.xml --coverage-text --testdox --colors=auto --testsuite pp-php-sdk-unit"
9+
},
10+
"autoload": {
11+
"psr-4": {
12+
"MercadoPago\\PP\\Sdk\\": [
13+
"src"
14+
]
15+
}
16+
},
17+
"autoload-dev": {
18+
"psr-4": {
19+
"MercadoPago\\PP\\Sdk\\Tests\\Unit\\": [
20+
"tests/unit"
21+
],
22+
"MercadoPago\\PP\\Sdk\\Tests\\Integration\\": [
23+
"tests/integration"
24+
]
25+
}
26+
},
27+
"require": {
28+
"php": ">=7",
29+
"ext-json": "*"
30+
},
31+
"require-dev": {
32+
"phpunit/phpunit": "9.5.27",
33+
"squizlabs/php_codesniffer": "3.7.2"
34+
},
35+
"license": "proprietary",
36+
"authors": [
37+
{
38+
"name": "Mercado Pago SMB",
39+
"email": "[email protected]"
40+
}
41+
],
42+
"minimum-stability": "stable"
3943
}

packages/sdk/src/Common/AbstractCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function setEntity($entities)
6161
/**
6262
* @inheritDoc
6363
*/
64-
public function getIterator()
64+
public function getIterator(): \Traversable
6565
{
6666
return new \ArrayIterator($this->collection);
6767
}

packages/sdk/src/Common/AbstractEntity.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace MercadoPago\PP\Sdk\Common;
44

55
use MercadoPago\PP\Sdk\Interfaces\EntityInterface;
6+
use MercadoPago\PP\Sdk\Sdk;
67

78
/**
89
* Class AbstractEntity
@@ -166,7 +167,7 @@ public function read(array $params = [])
166167

167168
$uri = $this->manager->getEntityUri($entity, $method, $params);
168169
$response = $this->manager->execute($entity, $uri, $method, $header);
169-
170+
$this->obfuscateAuthorizationHeader($header);
170171
return $this->manager->handleResponse($response, $method, $entity);
171172
}
172173

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

186187
$uri = $this->manager->getEntityUri($this, $method);
187188
$response = $this->manager->execute($this, $uri, $method, $header);
188-
189+
$this->obfuscateAuthorizationHeader($header);
189190
return $this->manager->handleResponse($response, $method);
190191
}
191192

@@ -206,4 +207,27 @@ public function setExcludedProperties()
206207
{
207208
$this->excluded_properties = [];
208209
}
210+
211+
/**
212+
* Obfuscate Authorization Header.
213+
*
214+
* @return void
215+
*/
216+
public function obfuscateAuthorizationHeader(array $headers)
217+
{
218+
Sdk::$cache['last_headers'] = preg_replace('/(Authorization: Bearer) (.*)/i', '$1 xxx', $headers);
219+
}
220+
221+
/**
222+
* Get last Headers.
223+
*
224+
* @return array
225+
*/
226+
public function getLastHeaders(): array
227+
{
228+
if (isset(Sdk::$cache['last_headers'])) {
229+
return Sdk::$cache['last_headers'];
230+
}
231+
return [];
232+
}
209233
}

packages/sdk/src/Common/Constants.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ class Constants
1111
{
1212
const BASEURL_MP = 'https://api.mercadopago.com';
1313
const BASEURL_ML = 'https://api.mercadolibre.com';
14+
const THREE_DS_VALID_OPTIONS = array(self::THREE_DS_MODE_OPTIONAL,
15+
self::THREE_DS_MODE_MANDATORY, self::THREE_DS_MODE_NOT_SUPPORTED);
16+
const THREE_DS_MODE_OPTIONAL = 'optional';
17+
const THREE_DS_MODE_MANDATORY = 'mandatory';
18+
const THREE_DS_MODE_NOT_SUPPORTED = 'not_supported';
1419
}

packages/sdk/src/Common/Manager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ public function handleResponse(Response $response, string $method, AbstractEntit
135135
}
136136
return $response->getData();
137137
} elseif (intval($response->getStatus()) >= 400 && intval($response->getStatus()) < 500) {
138-
throw new \Exception($response->getData()['message']);
138+
$message = $response->getData()['message'] ?? 'No message for Multipayment scenario in v1!';
139+
throw new \Exception($message);
139140
} else {
140141
throw new \Exception("Internal API Error");
141142
}

packages/sdk/src/Entity/Notification/Notification.php

Lines changed: 73 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,36 @@
77
use MercadoPago\PP\Sdk\Interfaces\RequesterEntityInterface;
88

99
/**
10-
* Class Notification
10+
* Handles integration with the Asgard Notification service.
11+
*
12+
* Asgard Notification is responsible for handling notifications originating from plugins and platforms.
13+
* When a payment is initiated that requires asynchronous approval, a notification is generated and processed
14+
* by this class.
15+
* This class streamlines the interaction with the Asgard Notification service, allowing the details of a
16+
* specific notification to be fetched using its ID. It aims to simplify the complexity associated with
17+
* managing and validating notifications, ensuring that only relevant information is forwarded to
18+
* platforms and plugins.
1119
*
12-
* @property string $ip_address
1320
* @property string $notification_id
1421
* @property string $notification_url
1522
* @property string $status
16-
* @property string $external_reference
17-
* @property float $transaction_id
23+
* @property string $transaction_id
1824
* @property string $transaction_type
25+
* @property string $platform_id
26+
* @property string $external_reference
27+
* @property string $preference_id
1928
* @property float $transaction_amount
20-
* @property float $total_pending
21-
* @property float $total_approved
2229
* @property float $total_paid
23-
* @property float $total_rejected
30+
* @property float $total_approved
31+
* @property float $total_pending
2432
* @property float $total_refunded
33+
* @property float $total_rejected
2534
* @property float $total_cancelled
2635
* @property float $total_charged_back
36+
* @property string $multiple_payment_transaction_id
2737
* @property array $payments_metadata
28-
* @property PaymentDetails $payments_details
38+
* @property PaymentDetailsList $payments_details
39+
* @property RefundNotifyingList $refunds_notifying
2940
*
3041
* @package MercadoPago\PP\Sdk\Entity\Notification
3142
*/
@@ -49,17 +60,27 @@ class Notification extends AbstractEntity implements RequesterEntityInterface
4960
/**
5061
* @var string
5162
*/
52-
protected $external_reference;
63+
protected $transaction_id;
5364

5465
/**
55-
* @var float
66+
* @var string
5667
*/
57-
protected $transaction_id;
68+
protected $transaction_type;
5869

5970
/**
6071
* @var string
6172
*/
62-
protected $transaction_type;
73+
protected $platform_id;
74+
75+
/**
76+
* @var string
77+
*/
78+
protected $external_reference;
79+
80+
/**
81+
* @var string
82+
*/
83+
protected $preference_id;
6384

6485
/**
6586
* @var float
@@ -69,7 +90,7 @@ class Notification extends AbstractEntity implements RequesterEntityInterface
6990
/**
7091
* @var float
7192
*/
72-
protected $total_pending;
93+
protected $total_paid;
7394

7495
/**
7596
* @var float
@@ -79,17 +100,17 @@ class Notification extends AbstractEntity implements RequesterEntityInterface
79100
/**
80101
* @var float
81102
*/
82-
protected $total_paid;
103+
protected $total_pending;
83104

84105
/**
85106
* @var float
86107
*/
87-
protected $total_rejected;
108+
protected $total_refunded;
88109

89110
/**
90111
* @var float
91112
*/
92-
protected $total_refunded;
113+
protected $total_rejected;
93114

94115
/**
95116
* @var float
@@ -101,16 +122,26 @@ class Notification extends AbstractEntity implements RequesterEntityInterface
101122
*/
102123
protected $total_charged_back;
103124

125+
/**
126+
* @var string
127+
*/
128+
protected $multiple_payment_transaction_id;
129+
104130
/**
105131
* @var array
106132
*/
107133
protected $payments_metadata;
108134

109135
/**
110-
* @var PaymentDetails
136+
* @var PaymentDetailsList
111137
*/
112138
protected $payments_details;
113139

140+
/**
141+
* @var RefundNotifyingList
142+
*/
143+
protected $refunds_notifying;
144+
114145
/**
115146
* Notification constructor.
116147
*
@@ -120,6 +151,7 @@ public function __construct($manager)
120151
{
121152
parent::__construct($manager);
122153
$this->payments_details = new PaymentDetailsList($manager);
154+
$this->refunds_notifying = new RefundNotifyingList($manager);
123155
}
124156

125157
/**
@@ -153,7 +185,30 @@ public function getHeaders(): array
153185
public function getUris(): array
154186
{
155187
return array(
156-
'get' => '/v1/bifrost/notification/status/:id',
188+
'get' => '/v1/asgard/notification/:id',
157189
);
158190
}
191+
192+
/**
193+
* Retrieves a notification from the Asgard Transaction service.
194+
*
195+
* Upon invoking this method, a request is made to the Asgard Transaction service
196+
* using the provided notification ID. Authentication is performed using
197+
* the seller's access token, which should be previously configured in the default headers.
198+
*
199+
* Note: This method is inherited from the parent class but specialized for notifications.
200+
*
201+
* @param array $params Associative array containing the parameters for the read operation.
202+
* It expects an "id" key with the notification ID as its value.
203+
* Example: $notification->read(['id' => 'P-1316643861'])
204+
*
205+
* @return mixed The result of the read operation, typically an instance of
206+
* this Notification class populated with the retrieved data.
207+
*
208+
* @throws \Exception Throws an exception if something goes wrong during the read operation.
209+
*/
210+
public function read(array $params = [])
211+
{
212+
return parent::read($params);
213+
}
159214
}

0 commit comments

Comments
 (0)