-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #449 from mercadopago/feature/implementation-point
Point implementation
- Loading branch information
Showing
23 changed files
with
893 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
<?php | ||
|
||
namespace MercadoPago\Client\Point; | ||
|
||
use MercadoPago\Client\MercadoPagoClient; | ||
use MercadoPago\Core\MPRequestOptions; | ||
use MercadoPago\MercadoPagoConfig; | ||
use MercadoPago\Net\HttpMethod; | ||
use MercadoPago\Net\MPSearchRequest; | ||
use MercadoPago\Resources\PaymentIntent; | ||
use MercadoPago\Resources\PaymentIntentCancel; | ||
use MercadoPago\Resources\PaymentIntentList; | ||
use MercadoPago\Resources\PaymentIntentStatus; | ||
use MercadoPago\Resources\PointDeviceOperatingMode; | ||
use MercadoPago\Resources\PointDevices; | ||
use MercadoPago\Serialization\Serializer; | ||
|
||
/** Client responsible for performing preference actions. */ | ||
final class PointClient extends MercadoPagoClient | ||
{ | ||
private const PAYMENT_INTENT_URL = "/point/integration-api/devices/%s/payment-intents"; | ||
|
||
private const PAYMENT_INTENT_SEARCH_URL = "/point/integration-api/payment-intents/%s"; | ||
|
||
private const PAYMENT_INTENT_LIST_URL = "/point/integration-api/payment-intents/events"; | ||
|
||
private const PAYMENT_INTENT_DELETE_URL = "/point/integration-api/devices/%s/payment-intents/%s"; | ||
|
||
private const PAYMENT_INTENT_STATUS_URL = "/point/integration-api/payment-intents/%s/events"; | ||
|
||
private const DEVICES_URL = "/point/integration-api/devices"; | ||
|
||
private const DEVICE_WITH_ID_URL = "/point/integration-api/devices/%s"; | ||
|
||
/** Default constructor. Uses the default http client used by the SDK. */ | ||
public function __construct() | ||
{ | ||
parent::__construct(MercadoPagoConfig::getHttpClient()); | ||
} | ||
|
||
/** | ||
* Method responsible for creating a payment intent. | ||
* @param string $device_id device id. | ||
* @param array $request payment intent data. | ||
* @param mixed $request_options request options to be sent. | ||
* @return \MercadoPago\Resources\PaymentIntent payment intent created. | ||
* @throws \MercadoPago\Exceptions\MPApiException if the request fails. | ||
* @throws \Exception if the request fails. | ||
*/ | ||
public function createPaymentIntent(string $device_id, array $request, ?MPRequestOptions $request_options = null): PaymentIntent | ||
{ | ||
$response = parent::send(sprintf(self::PAYMENT_INTENT_URL, $device_id), HttpMethod::POST, json_encode($request), null, $request_options); | ||
$result = Serializer::deserializeFromJson(PaymentIntent::class, $response->getContent()); | ||
$result->setResponse($response); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Method responsible for searching a payment intent. | ||
* @param string $payment_intent_id payment intent id. | ||
* @param mixed $request_options request options to be sent. | ||
* @return \MercadoPago\Resources\PaymentIntent payment intent found. | ||
* @throws \MercadoPago\Exceptions\MPApiException if the request fails. | ||
* @throws \Exception if the request fails. | ||
*/ | ||
public function searchPaymentIntent(string $payment_intent_id, ?MPRequestOptions $request_options = null): PaymentIntent | ||
{ | ||
$response = parent::send(sprintf(self::PAYMENT_INTENT_SEARCH_URL, $payment_intent_id), HttpMethod::GET, null, null, $request_options); | ||
$result = Serializer::deserializeFromJson(PaymentIntent::class, $response->getContent()); | ||
$result->setResponse($response); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Method responsible for canceling a payment intent. | ||
* @param string $device_id device id. | ||
* @param string $payment_intent_id payment intent id. | ||
* @param mixed $request_options request options to be sent. | ||
* @return \MercadoPago\Resources\PaymentIntentCancel payment intent canceled. | ||
* @throws \MercadoPago\Exceptions\MPApiException if the request fails. | ||
* @throws \Exception if the request fails. | ||
*/ | ||
public function cancelPaymentIntent(string $device_id, string $payment_intent_id, ?MPRequestOptions $request_options = null): PaymentIntentCancel | ||
{ | ||
$response = parent::send(sprintf(self::PAYMENT_INTENT_DELETE_URL, $device_id, $payment_intent_id), HttpMethod::DELETE, null, null, $request_options); | ||
$result = Serializer::deserializeFromJson(PaymentIntentCancel::class, $response->getContent()); | ||
$result->setResponse($response); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Method responsible for getting payment intent list. | ||
* @param \MercadoPago\Client\Point\PointPaymentIntentListRequest $request payment intent list request. | ||
* @param mixed $request_options request options to be sent. | ||
* @return \MercadoPago\Resources\PaymentIntentList payment intent list. | ||
* @throws \MercadoPago\Exceptions\MPApiException if the request fails. | ||
* @throws \Exception if the request fails. | ||
*/ | ||
public function getPaymentIntentList(PointPaymentIntentListRequest $request, ?MPRequestOptions $request_options = null): PaymentIntentList | ||
{ | ||
$response = parent::send(self::PAYMENT_INTENT_LIST_URL, HttpMethod::GET, null, $request->getParameters(), $request_options); | ||
$result = Serializer::deserializeFromJson(PaymentIntentList::class, $response->getContent()); | ||
$result->setResponse($response); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Method responsible for getting payment intent status. | ||
* @param string $payment_intent_id payment intent id. | ||
* @param mixed $request_options request options to be sent. | ||
* @return \MercadoPago\Resources\PaymentIntentStatus payment intent status. | ||
* @throws \MercadoPago\Exceptions\MPApiException if the request fails. | ||
* @throws \Exception if the request fails. | ||
*/ | ||
public function getPaymentIntentStatus(string $payment_intent_id, ?MPRequestOptions $request_options = null): PaymentIntentStatus | ||
{ | ||
$response = parent::send(sprintf(self::PAYMENT_INTENT_STATUS_URL, $payment_intent_id), HttpMethod::GET, null, null, $request_options); | ||
$result = Serializer::deserializeFromJson(PaymentIntentStatus::class, $response->getContent()); | ||
$result->setResponse($response); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Method responsible for getting devices. | ||
* @param \MercadoPago\Net\MPSearchRequest $request search request. | ||
* @param mixed $request_options request options to be sent. | ||
* @return \MercadoPago\Resources\PointDevices devices found. | ||
* @throws \MercadoPago\Exceptions\MPApiException if the request fails. | ||
* @throws \Exception if the request fails. | ||
*/ | ||
public function getDevices(MPSearchRequest $request, ?MPRequestOptions $request_options = null): PointDevices | ||
{ | ||
$query_params = isset($request) ? $request->getParameters() : null; | ||
$response = parent::send(self::DEVICES_URL, HttpMethod::GET, null, $query_params, $request_options); | ||
$result = Serializer::deserializeFromJson(PointDevices::class, $response->getContent()); | ||
$result->setResponse($response); | ||
return $result; | ||
} | ||
|
||
/** | ||
* Method responsible for changing the device operating mode. | ||
* @param string $device_id device id. | ||
* @param mixed $request_options request options to be sent. | ||
* @return \MercadoPago\Resources\PointDeviceOperatingMode device operating mode. | ||
* @throws \MercadoPago\Exceptions\MPApiException if the request fails. | ||
* @throws \Exception if the request fails. | ||
*/ | ||
public function changeDeviceOperatingMode(string $device_id, PointDeviceOperatingModeRequest $request, ?MPRequestOptions $request_options = null): PointDeviceOperatingMode | ||
{ | ||
$response = parent::send(sprintf(self::DEVICE_WITH_ID_URL, $device_id), HttpMethod::PATCH, json_encode($request), null, $request_options); | ||
$result = Serializer::deserializeFromJson(PointDeviceOperatingMode::class, $response->getContent()); | ||
$result->setResponse($response); | ||
return $result; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/MercadoPago/Client/Point/PointDeviceOperatingModeRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace MercadoPago\Client\Point; | ||
|
||
/** PointDeviceOperatingModeRequest class. */ | ||
class PointDeviceOperatingModeRequest | ||
{ | ||
/** Operating mode. */ | ||
public string $operating_mode; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/MercadoPago/Client/Point/PointPaymentIntentListRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace MercadoPago\Client\Point; | ||
|
||
/** PointPaymentIntentListRequest class. */ | ||
class PointPaymentIntentListRequest | ||
{ | ||
/** Start date. */ | ||
public string $start_date; | ||
|
||
/** End date. */ | ||
public string $end_date; | ||
|
||
public function getParameters(): array | ||
{ | ||
return [ | ||
"startDate" => $this->start_date, | ||
"endDate" => $this->end_date, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace MercadoPago\Resources; | ||
|
||
use MercadoPago\Net\MPResource; | ||
use MercadoPago\Serialization\Mapper; | ||
|
||
/** PaymentIntent class. */ | ||
class PaymentIntent extends MPResource | ||
{ | ||
/** Class mapper. */ | ||
use Mapper; | ||
|
||
/** Additional info of the payment intent.*/ | ||
public array|object|null $additional_info; | ||
|
||
/** Amount of the payment intent.*/ | ||
public ?float $amount; | ||
|
||
/** Description of the payment intent.*/ | ||
public ?string $description; | ||
|
||
/** Device id for the payment intent.*/ | ||
public ?string $device_id; | ||
|
||
/** ID of the payment intent.*/ | ||
public ?string $id; | ||
|
||
/** Payment intent details.*/ | ||
public array|object|null $payment; | ||
|
||
/** Payment intent mode.*/ | ||
public ?string $payment_mode; | ||
|
||
/** State of the payment intent.*/ | ||
public ?string $state; | ||
|
||
public $map = [ | ||
"additional_info" => "MercadoPago\Resources\Point\PaymentIntentAdditionalInfo", | ||
"payment" => "MercadoPago\Resources\Point\PaymentIntentPayment", | ||
]; | ||
|
||
/** | ||
* Method responsible for getting map of entities. | ||
*/ | ||
public function getMap(): array | ||
{ | ||
return $this->map; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace MercadoPago\Resources; | ||
|
||
use MercadoPago\Net\MPResource; | ||
|
||
/** PaymentIntentCancel class. */ | ||
class PaymentIntentCancel extends MPResource | ||
{ | ||
/** ID of the payment intent.*/ | ||
public ?string $id; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace MercadoPago\Resources; | ||
|
||
use MercadoPago\Net\MPResource; | ||
|
||
/** PaymentIntentList class. */ | ||
class PaymentIntentList extends MPResource | ||
{ | ||
/** Events. */ | ||
public array $events; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace MercadoPago\Resources; | ||
|
||
use MercadoPago\Net\MPResource; | ||
|
||
/** PaymentIntentStatus class. */ | ||
class PaymentIntentStatus extends MPResource | ||
{ | ||
/** Status of payment intent. */ | ||
public ?string $status; | ||
|
||
/** Date created. */ | ||
public ?string $created_on; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/MercadoPago/Resources/Point/PaymentIntentAdditionalInfo.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace MercadoPago\Resources\Point; | ||
|
||
/** PaymentIntentAdditionalInfo class. */ | ||
class PaymentIntentAdditionalInfo | ||
{ | ||
/** External reference of the payment. */ | ||
public ?string $external_reference; | ||
|
||
/** Print on terminal flag. */ | ||
public ?bool $print_on_terminal; | ||
} |
Oops, something went wrong.