Skip to content

Commit e95422f

Browse files
[Feature] Payment Industry Data (#548)
* feat: add payer * feat: add preference payer * Revert "feat: add payer" This reverts commit e58db0a. * Revert "feat: add preference payer" This reverts commit 6709143. * feat: Add exemple PF Payment * fix: language change
1 parent 84a30e5 commit e95422f

File tree

5 files changed

+169
-0
lines changed

5 files changed

+169
-0
lines changed

examples/Payment/Create.php

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<?php
2+
3+
namespace Examples\Payment;
4+
5+
// Step 1: Require the Composer library
6+
require_once '../../vendor/autoload.php';
7+
8+
use MercadoPago\Client\Common\RequestOptions;
9+
use MercadoPago\Client\Payment\PaymentClient;
10+
use MercadoPago\Exceptions\MPApiException;
11+
use MercadoPago\MercadoPagoConfig;
12+
13+
// Step 2: Set the production or sandbox access token
14+
MercadoPagoConfig::setAccessToken('<ACCESS_TOKEN>');
15+
// Step 2.1 (optional - default is SERVER): Set your runtime enviroment from MercadoPagoConfig::RUNTIME_ENVIROMENTS
16+
// In case you want to test in your local machine first, set runtime enviroment to LOCAL
17+
MercadoPagoConfig::setRuntimeEnviroment(MercadoPagoConfig::LOCAL);
18+
19+
// Step 3: Initialize the API client
20+
$client = new PaymentClient();
21+
22+
try {
23+
// Step 4: Create the request array
24+
$request = [
25+
"transaction_amount" => 1000,
26+
"description" => "Product title",
27+
"payment_method_id" => "master",
28+
"token" => "{{CARD_TOKEN}}",
29+
"installments" => 1,
30+
"application_fee" => null,
31+
"binary_mode" => true,
32+
"capture" => true,
33+
"external_reference" => "Pedido01",
34+
"metadata" => new \stdClass(),
35+
"notification_url" => "https://www.mercadopago.com",
36+
"sponsor_id" => null,
37+
"statement_descriptor" => "LOJA 123",
38+
"payer" => [
39+
"first_name" => "Name",
40+
"last_name" => "Surname",
41+
"email" => "{{EMAIL}}",
42+
"identification" => [
43+
"number" => "{{DOCUMENT_NUMBER}}",
44+
"type" => "CPF"
45+
],
46+
"phone" => [
47+
"area_code" => "11",
48+
"number" => "{{PHONE_NUMBER}}"
49+
],
50+
"address" => [
51+
"street_name" => "Av. das Nações Unidas",
52+
"street_number" => "3003",
53+
"zip_code" => "206233-2002"
54+
]
55+
],
56+
"forward_data" => [
57+
"sub_merchant" => [
58+
"sub_merchant_id" => "1234183712",
59+
"mcc" => "5462",
60+
"country" => "BRA",
61+
"address_door_number"=> 123,
62+
"zip" => "2222222",
63+
"document_number" => "222222222222222",
64+
"city" => "SÃO PAULO",
65+
"address_street" => "RUA A",
66+
"legal_name" => "LOJINHA DO ZÉ",
67+
"region_code_iso" => "BR-MG",
68+
"region_code" => "BR",
69+
"document_type" => "CNPJ",
70+
"phone" => "{{PHONE}}",
71+
"url" => "www.mercadopago.com"
72+
]
73+
],
74+
"additional_info" => [
75+
"items" => [
76+
[
77+
"id" => "1941",
78+
"title" => "25/08/2022 | Pista Inteira5 lote - GREEN VALLEY GRAMADO 2022",
79+
"description" => "25/08/2022 | Pista Inteira5 lote - GREEN VALLEY GRAMADO 2022",
80+
"category_id" => "Tickets",
81+
"quantity" => 1,
82+
"unit_price" => 1000.00,
83+
"event_date" => "2019-12-25T19:30:00.000-03:00",
84+
"picture_url" => "{{IMAGE_URL}}",
85+
"type" => "my_items_type",
86+
"warranty" => true,
87+
"category_descriptor" => [
88+
"passenger" => [
89+
"first_name" => "Guest name",
90+
"last_name" => "Guest surname",
91+
"identification"=> [
92+
"type" => "DNI",
93+
"number" => "{{DOCUMENT}}"
94+
]
95+
],
96+
"route" => [
97+
"arrival_date_time" => "2022-03-14T12:58:41.425-04:00",
98+
"company" => "Companhia",
99+
"departure" => "Osasco",
100+
"departure_date_time" => "2022-03-12T12:58:41.425-04:00",
101+
"destination" => "Sao Paulo"
102+
]
103+
]
104+
]
105+
],
106+
"payer" => [
107+
"first_name" => "Name",
108+
"last_name" => "Surname",
109+
"is_prime_user" => true,
110+
"is_first_purchase_online" => true,
111+
"last_purchase" => "2019-10-25T19:30:00.000-03:00",
112+
"phone" => [
113+
"area_code" => "11",
114+
"number" => "{{PHONE_NUMBER}}"
115+
],
116+
"address" => [
117+
"street_name" => "Av. das Nações Unidas",
118+
"street_number" => "3003",
119+
"zip_code" => "206233-2002"
120+
],
121+
"registration_date" => "2020-08-06T09:25:04.000-03:00",
122+
"authentication_type" => "Gmail"
123+
],
124+
"shipments" => [
125+
"local_pickup" => "1",
126+
"express_shipment" => true,
127+
"receiver_address" => [
128+
"zip_code" => "306233-2003",
129+
"street_name" => "Av. das Nações Unidas",
130+
"street_number"=> "3003",
131+
"floor" => "5",
132+
"apartment" => "502",
133+
"state_name" => "DF",
134+
"city_name" => "Bogota"
135+
]
136+
]
137+
],
138+
];
139+
140+
// Step 5: Create the request options, setting X-Idempotency-Key
141+
$request_options = new RequestOptions();
142+
$request_options->setCustomHeaders(["X-Idempotency-Key: <SOME_UNIQUE_VALUE>"]);
143+
144+
// Step 6: Make the request
145+
$payment = $client->create($request, $request_options);
146+
echo "Payment ID: " . $payment->id . "\n";
147+
echo "Status: " . $payment->status . "\n";
148+
149+
// Step 7: Handle exceptions
150+
} catch (MPApiException $e) {
151+
echo "Status code: " . $e->getApiResponse()->getStatusCode() . "\n";
152+
echo "Content: ";
153+
var_dump($e->getApiResponse()->getContent());
154+
echo "\n";
155+
} catch (\Exception $e) {
156+
echo $e->getMessage();
157+
}

src/MercadoPago/Resources/Payment.php

+3
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ class Payment extends MPResource
185185
/** Coupon code. */
186186
public ?string $coupon_code;
187187

188+
/** Release Info. */
189+
public ?string $release_info;
190+
188191
/** Marketplace owner. */
189192
public ?string $marketplace_owner;
190193

src/MercadoPago/Resources/Payment/AdditionalInfo.php

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class AdditionalInfo
1313
/** IP from where the request comes from (only for bank transfers). */
1414
public ?string $ip_address;
1515

16+
/** The ID of tracking. */
17+
public ?string $tracking_id;
18+
1619
/** List of items to be paid. */
1720
public ?array $items;
1821

src/MercadoPago/Resources/Payment/Card.php

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class Card
3131
/** Last update of data from the card. */
3232
public ?string $date_last_updated;
3333

34+
/** Country Card. */
35+
public ?string $country;
36+
3437
/** Card's owner data. */
3538
public array|object|null $cardholder;
3639

src/MercadoPago/Resources/Payment/ReceiverAddress.php

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ class ReceiverAddress extends Address
1010
/** Street name. */
1111
public ?string $street_name;
1212

13+
/** State name. */
14+
public ?string $state_name;
15+
1316
/** Apartment. */
1417
public ?string $apartment;
1518

0 commit comments

Comments
 (0)