Skip to content

Commit

Permalink
Merge pull request #449 from mercadopago/feature/implementation-point
Browse files Browse the repository at this point in the history
Point implementation
  • Loading branch information
rhames07 authored Sep 15, 2023
2 parents 958e9b7 + bc0a73b commit 927811a
Show file tree
Hide file tree
Showing 23 changed files with 893 additions and 13 deletions.
26 changes: 13 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<exclude>./tests/MercadoPago/Client/Customer/CustomerCardClientITTest.php</exclude>
<exclude>./tests/MercadoPago/Client/User/UserClientITTest.php</exclude>
<exclude>./tests/MercadoPago/Client/IdentificationType/IdentificationTypeClientITTest.php</exclude>
<exclude>./tests/MercadoPago/Client/Point/PointClientITTest.php</exclude>
<exclude>./tests/MercadoPago/Client/MerchantOrder/MerchantOrderClientITTest.php</exclude>
</testsuite>
</testsuites>
Expand Down
155 changes: 155 additions & 0 deletions src/MercadoPago/Client/Point/PointClient.php
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 src/MercadoPago/Client/Point/PointDeviceOperatingModeRequest.php
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 src/MercadoPago/Client/Point/PointPaymentIntentListRequest.php
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,
];
}
}
1 change: 1 addition & 0 deletions src/MercadoPago/Net/HttpMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ class HttpMethod
public const GET = "GET";
public const POST = "POST";
public const PUT = "PUT";
public const PATCH = "PATCH";
public const DELETE = "DELETE";
}
50 changes: 50 additions & 0 deletions src/MercadoPago/Resources/PaymentIntent.php
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;
}
}
12 changes: 12 additions & 0 deletions src/MercadoPago/Resources/PaymentIntentCancel.php
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;
}
12 changes: 12 additions & 0 deletions src/MercadoPago/Resources/PaymentIntentList.php
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;
}
15 changes: 15 additions & 0 deletions src/MercadoPago/Resources/PaymentIntentStatus.php
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 src/MercadoPago/Resources/Point/PaymentIntentAdditionalInfo.php
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;
}
Loading

0 comments on commit 927811a

Please sign in to comment.