Skip to content
Open
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
Binary file added .DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.0.0] - 2024-11-25

### Changed
- pablorsk/dx-php to mercadopago/dx-php 3.

## [1.1.4] - 2023-02-15

### Changed
Expand Down
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,8 @@ $order = $pos->createAnOrder();
$result = $order->sendData($order_data);
```

This generates a qr code like that:
### Images

![mercadopago-qr](https://github.com/reyesoft/mercadopago/blob/master/tests/image/mercadopago-qr-code.png?raw=true "Mercadopago QR generated with MercadoPagoQr library")

## Support us
Reyesoft is a software industry based in San Rafael, Argentina. You'll find an overview of all our projects on our [website](http://reyesoft.com/).

## PHP 7.4

> docker run -it --rm --name php74 -e PHP_EXTENSIONS="gd" -v "$PWD":/usr/src/app thecodingmachine/php:7.4-v4-cli bash
```bash
docker run -it --rm --name php82 -e PHP_EXTENSIONS="" -v "$PWD":/usr/src/app pablorsk/laravel-json-api:8.2 bash
```
13 changes: 5 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "reyesoft/mercadopago",
"description": "This library helps to make payments through MercadoPago, even with QR",
"type": "library",
"version": "1.1.4",
"version": "3.0.0",
"keywords": ["qrcode", "payments", "mercadopago api", "reyesoft"],
"homepage": "https://github.com/reyesoft/mercadopago",
"license": "MIT",
Expand All @@ -16,15 +16,12 @@
}
],
"require": {
"php": ">=7.2",
"endroid/qr-code": "^3.2",
"ext-gd": "*",
"pablorsk/dx-php": "2.2.8"
"php": ">=8.2",
"mercadopago/dx-php": "3.0.8"
},
"require-dev": {
"reyesoft/ci": "1.2.0",
"phpunit/phpunit": "^7",
"codedungeon/phpunit-result-printer": "0.19.10"
"reyesoft/ci": "^2.0",
"phpunit/phpunit": "^10.2"
},
"autoload": {
"classmap": [
Expand Down
46 changes: 46 additions & 0 deletions src/Clients/InstoreOrderV2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Copyright (C) 1997-2020 Reyesoft <info@reyesoft.com>.
*
* This file is part of CryptoQr. CryptoQr can not be copied and/or
* distributed without the express permission of Reyesoft
*/

declare(strict_types=1);

namespace MercadoPagoQr\Clients;

use MercadoPago\Client\Common\RequestOptions;
use MercadoPago\Client\MercadoPagoClient;
use MercadoPago\MercadoPagoConfig;
use MercadoPago\Net\HttpMethod;
use MercadoPago\Net\MPHttpClient;
use MercadoPago\Serialization\Serializer;
use MercadoPagoQr\Resources\Pos;

final class InstoreOrderV2 extends MercadoPagoClient
{
private const URL = '/pos';
private const URL_CREATE = '/instore/qr/seller/collectors/%s/stores/%s/pos/%s/orders';

public function __construct(?MPHttpClient $MPHttpClient = null)
{
parent::__construct($MPHttpClient ?: MercadoPagoConfig::getHttpClient());
}

/**
* @see https://www.mercadopago.com.ar/developers/en/reference/instore_orders_v2/_instore_qr_seller_collectors_user_id_stores_external_store_id_pos_external_pos_id_orders/put
*/
public function create(int $user_id, string $external_store_id, string $external_pos_id, array $payload, ?RequestOptions $request_options = null): bool
{
// no response
$response = parent::send(sprintf(self::URL_CREATE, $user_id, $external_store_id, $external_pos_id), HttpMethod::PUT, json_encode($payload), null, $request_options);

return $response->getStatusCode() === 200;
/*
$result = Serializer::deserializeFromJson(PosX::class, $response->getContent());
$result->setResponse($response);
return $result;
*/
}
}
42 changes: 42 additions & 0 deletions src/Clients/InstoreQrTramma.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Copyright (C) 1997-2020 Reyesoft <info@reyesoft.com>.
*
* This file is part of CryptoQr. CryptoQr can not be copied and/or
* distributed without the express permission of Reyesoft
*/

declare(strict_types=1);

namespace MercadoPagoQr\Clients;

use MercadoPago\Client\Common\RequestOptions;
use MercadoPago\Client\MercadoPagoClient;
use MercadoPago\MercadoPagoConfig;
use MercadoPago\Net\HttpMethod;
use MercadoPago\Net\MPHttpClient;
use MercadoPago\Serialization\Serializer;
use MercadoPagoQr\Resources\Pos;
use MercadoPagoQr\Resources\QrTramma;

final class InstoreQrTramma extends MercadoPagoClient
{
private const URL_CREATE = '/instore/orders/qr/seller/collectors/%s/pos/%s/qrs';

public function __construct(?MPHttpClient $MPHttpClient = null)
{
parent::__construct($MPHttpClient ?: MercadoPagoConfig::getHttpClient());
}

/**
* @see https://www.mercadopago.com.ar/developers/en/reference/qr-dynamic/_instore_orders_qr_seller_collectors_user_id_pos_external_pos_id_qrs/post
*/
public function create(int $user_id, string $external_pos_id, array $payload, ?RequestOptions $request_options = null): QrTramma
{
$response = parent::send(sprintf(self::URL_CREATE, $user_id, $external_pos_id), HttpMethod::POST, json_encode($payload), null, $request_options);
$result = Serializer::deserializeFromJson(QrTramma::class, $response->getContent());
$result->setResponse($response);

return $result;
}
}
51 changes: 51 additions & 0 deletions src/Clients/PosClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Copyright (C) 1997-2020 Reyesoft <info@reyesoft.com>.
*
* This file is part of CryptoQr. CryptoQr can not be copied and/or
* distributed without the express permission of Reyesoft
*/

declare(strict_types=1);

namespace MercadoPagoQr\Clients;

use MercadoPago\Client\Common\RequestOptions;
use MercadoPago\Client\MercadoPagoClient;
use MercadoPago\Exceptions\MPApiException;
use MercadoPago\MercadoPagoConfig;
use MercadoPago\Net\HttpMethod;
use MercadoPago\Net\MPHttpClient;
use MercadoPago\Serialization\Serializer;
use MercadoPagoQr\Resources\Pos;

final class PosClient extends MercadoPagoClient
{
private const URL = '/pos';

public function __construct(?MPHttpClient $MPHttpClient = null)
{
parent::__construct($MPHttpClient ?: MercadoPagoConfig::getHttpClient());
}

/**
* Method responsible for creating card token.
*
* @param array $request card token data
* @param RequestOptions request options to be sent
*
* @throws MPApiException if the request fails
* @throws \Exception if the request fails
*
* @return Pos card token created
*/
public function create(array $request, ?RequestOptions $request_options = null): Pos
{
$response = parent::send(self::URL, HttpMethod::POST, json_encode($request), null, $request_options);
$result = Serializer::deserializeFromJson(Pos::class, $response->getContent());
$result->setResponse($response);

// @phpstan-ignore-next-line
return $result;
}
}
92 changes: 24 additions & 68 deletions src/MercadoPagoOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,78 +10,34 @@

namespace MercadoPagoQr;

use MercadoPagoQr\Clients\InstoreOrderV2;

use MercadoPago\Entities\InstoreOrder;

/**
* @see https://www.mercadopago.com.ar/developers/en/guides/instore-payments/qr-payments/qr-pos/ "Order object"
*/
class MercadoPagoOrder
{
use HasMpTrait;

/** @var MercadoPagoPos */
protected $pos;

/** @var InstoreOrder */
protected $order;

public function __construct(MercadoPagoPos $pos)
{
$this->pos = $pos;
$this->order = new InstoreOrder();
}

public function setExternalReference(string $value): void
{
$this->order->external_reference = $value;
}

public function setNotificationUrl(string $value): void
{
$this->order->notification_url = $value;
}

/**
* @param array<mixed> $value
* @see https://www.mercadopago.com.ar/developers/en/reference/instore_orders_v2/_instore_qr_seller_collectors_user_id_stores_external_store_id_pos_external_pos_id_orders/put
*/
public function setItems(array $value): void
{
$this->order->items = $value;
}

/**
* @return array<mixed>
*/
public function getResponse(): array
{
return $this->order->getAttributes();
}

/**
* @param array<string,mixed> $data
* @param null $collector_id
*
* @throws \Exception
*
* @return array<mixed>
*/
public function sendData(array $data, $collector_id = null): array
{
if (isset($data['external_reference'])) {
$this->setExternalReference($data['external_reference']);
}
if (isset($data['notification_url'])) {
$this->setNotificationUrl($data['notification_url']);
}
if (isset($data['items'])) {
$this->setItems($data['items']);
}

$this->order->external_id = $this->pos->getPosData()->getExternalId();

$this->order->save();

return $this->getResponse();
public static function createOrFail(
int $user_id,
string $external_store_id,
string $external_pos_id,
?string $external_reference= null,
?string $notification_url= null,
?array $payeer= null,
?array $items= null,
?string $preference_id = null,
): bool {
return (new InstoreOrderV2())->create(
$user_id,
$external_store_id,
$external_pos_id,
array_filter([
'external_reference' => $external_reference,
'notification_url' => $notification_url,
'payeer' => $payeer,
'items' => $items,
'preference_id' => $preference_id,
])
);
}
}
Loading