{"id":19545129,"url":"https://github.com/mercadopago/sdk-php","last_synced_at":"2026-06-11T03:01:27.359Z","repository":{"id":37447846,"uuid":"63957163","full_name":"mercadopago/sdk-php","owner":"mercadopago","description":"Mercado Pago's Official PHP SDK","archived":false,"fork":false,"pushed_at":"2026-06-05T18:03:54.000Z","size":19380,"stargazers_count":420,"open_issues_count":3,"forks_count":217,"subscribers_count":57,"default_branch":"master","last_synced_at":"2026-06-07T14:05:03.002Z","etag":null,"topics":["backend-sdk","mercadopago","php","sdk"],"latest_commit_sha":null,"homepage":"https://developers.mercadopago.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mercadopago.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"SUPPORT.md","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2016-07-22T13:53:01.000Z","updated_at":"2026-06-05T20:04:24.000Z","dependencies_parsed_at":"2024-01-15T14:45:27.824Z","dependency_job_id":"3860f3ee-b845-4fbb-bcb7-350e920cae5a","html_url":"https://github.com/mercadopago/sdk-php","commit_stats":{"total_commits":508,"total_committers":38,"mean_commits":"13.368421052631579","dds":0.7814960629921259,"last_synced_commit":"b03c3c789c7d4fedfcf7d54cf57993e77c95aabb"},"previous_names":[],"tags_count":88,"template":false,"template_full_name":null,"purl":"pkg:github/mercadopago/sdk-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mercadopago%2Fsdk-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mercadopago%2Fsdk-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mercadopago%2Fsdk-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mercadopago%2Fsdk-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mercadopago","download_url":"https://codeload.github.com/mercadopago/sdk-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mercadopago%2Fsdk-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34180147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend-sdk","mercadopago","php","sdk"],"created_at":"2024-11-11T03:35:03.798Z","updated_at":"2026-06-11T03:01:27.352Z","avatar_url":"https://github.com/mercadopago.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![image](https://github.com/mercadopago/sdk-php/assets/86324641/46001c9c-b28a-44cb-9fc3-211712be5022)\n\n# Mercado Pago SDK for PHP\n\n[![Latest Stable Version](https://poser.pugx.org/mercadopago/dx-php/v/stable)](https://packagist.org/packages/mercadopago/dx-php) [![Total Downloads](https://poser.pugx.org/mercadopago/dx-php/downloads)](https://packagist.org/packages/mercadopago/dx-php) [![License](https://poser.pugx.org/mercadopago/dx-php/license)](https://packagist.org/packages/mercadopago/dx-php)\n\nThis library provides developers with a simple set of bindings to help you integrate Mercado Pago API to a website and start receiving payments.\n\n## 💡 Requirements\n\nThe SDK Supports PHP version 8.2 or higher.\n\n## 💻 Installation\n\nIf you already use another version of MercadoPago PHP SDK, take a look at our [migration guide](MIGRATION_GUIDE.md) from version 2 to version 3.\n\nFirst time using Mercado Pago? Create your [Mercado Pago account](https://www.mercadopago.com), if you don’t have one already.\n\n1. Download [Composer](https://getcomposer.org/doc/00-intro.md) if not already installed.\n\n2. Install PHP SDK for MercadoPago running in command line:\n\n```\ncomposer require \"mercadopago/dx-php:3.11.2\"\n```\n\n\u003e You can also run _composer require \"mercadopago/dx-php:2.6.2\"_ for PHP7.1 or _composer require \"mercadopago/dx-php:1.12.6\"_ for PHP5.6.\n\n3. Copy the access_token in the [credentials](https://www.mercadopago.com/developers/en/docs/your-integrations/credentials) section of the page and replace YOUR_ACCESS_TOKEN with it.\n\nThat's it! Mercado Pago SDK has been successfully installed.\n\n## Useful links\n\n- [SDK Docs](https://www.mercadopago.com.br/developers/pt/docs/sdks-library/server-side)\n- [REST API (consumed by the SDK)](https://www.mercadopago.com.br/developers/en/reference)\n- [CHANGELOG](./CHANGELOG.md)\n\nHere you can check eg. data structures for each parameter used by the SDK for each class.\n\n## 🌟 Getting Started with payment via your own website forms\n\nSimple usage looks like:\n\n```php\n\u003c?php\n    // Step 1: Require the library from your Composer vendor folder\n    require_once 'vendor/autoload.php';\n\n    use MercadoPago\\Client\\Common\\RequestOptions;\n    use MercadoPago\\Client\\Order\\OrderClient;\n    use MercadoPago\\Exceptions\\MPApiException;\n    use MercadoPago\\MercadoPagoConfig;\n\n    // Step 2: Set production or sandbox access token\n    MercadoPagoConfig::setAccessToken(\"\u003cACCESS_TOKEN\u003e\");\n    // Step 2.1 (optional - default is SERVER): Set your runtime enviroment from MercadoPagoConfig::RUNTIME_ENVIROMENTS\n    // In case you want to test in your local machine first, set runtime enviroment to LOCAL\n    MercadoPagoConfig::setRuntimeEnviroment(MercadoPagoConfig::LOCAL);\n\n    // Step 3: Initialize the API client\n    $client = new OrderClient();\n\n    try {\n\n        // Step 4: Create the request array\n        $request = [\n            \"type\" =\u003e \"online\",\n            \"processing_mode\" =\u003e \"automatic\",\n            \"total_amount\" =\u003e \"1000.00\",\n            \"external_reference\" =\u003e \"ext_ref_1234\",\n            \"capture_mode\" =\u003e \"automatic_async\",\n            \"payer\" =\u003e [\n                \"email\" =\u003e \"\u003cPAYER_EMAIL\u003e\",\n            ],\n            \"transactions\" =\u003e [\n                \"payments\" =\u003e [\n                    [\n                        \"amount\" =\u003e \"1000.00\",\n                        \"payment_method\" =\u003e [\n                            \"id\" =\u003e \"master\",\n                            \"type\" =\u003e \"credit_card\",\n                            \"token\" =\u003e \"\u003cCARD_TOKEN\u003e\",\n                            \"installments\" =\u003e 1,\n                            \"statement_descriptor\" =\u003e \"Store name\",\n                        ]\n                    ]\n                ]\n            ]\n        ];\n\n        // Step 5: Create the request options, setting X-Idempotency-Key\n        $request_options = new RequestOptions();\n        $request_options-\u003esetCustomHeaders([\"X-Idempotency-Key: \u003cSOME_UNIQUE_VALUE\u003e\"]);\n\n        // Step 6: Make the request\n        $order = $client-\u003ecreate($request, $request_options);\n        echo \"Order ID:\" . $order-\u003eid;\n\n    // Step 7: Handle exceptions\n    } catch (MPApiException $e) {\n        echo \"Status code: \" . $e-\u003egetApiResponse()-\u003egetStatusCode() . \"\\n\";\n        echo \"Content: \";\n        var_dump($e-\u003egetApiResponse()-\u003egetContent());\n        echo \"\\n\";\n    } catch (\\Exception $e) {\n        echo $e-\u003egetMessage();\n    }\n```\n\n### Step 1: Require the library from your Composer vendor folder\n\n```php\nrequire_once 'vendor/autoload.php';\n\nuse MercadoPago\\Client\\Common\\RequestOptions;\nuse MercadoPago\\Client\\Order\\OrderClient;\nuse MercadoPago\\Exceptions\\MPApiException;\nuse MercadoPago\\MercadoPagoConfig;\n```\n\n### Step 2: Set production or sandbox access token\n\n```php\nMercadoPagoConfig::setAccessToken(\"\u003cACCESS_TOKEN\u003e\");\n```\n\nYou can also set another properties as quantity of retries, tracking headers, timeouts and a custom http client.\n\n### Step 3: Initialize the API client\n\n```php\n$client = new OrderClient();\n```\n\n### Step 4: Create the request array\n\n```php\n$request = [\n    \"type\" =\u003e \"online\",\n    \"processing_mode\" =\u003e \"automatic\",\n    \"total_amount\" =\u003e \"1000.00\",\n    \"external_reference\" =\u003e \"ext_ref_1234\",\n    \"capture_mode\" =\u003e \"automatic_async\",\n    \"payer\" =\u003e [\n        \"email\" =\u003e \"\u003cPAYER_EMAIL\u003e\",\n    ],\n    \"transactions\" =\u003e [\n        \"payments\" =\u003e [\n            [\n                \"amount\" =\u003e \"1000.00\",\n                \"payment_method\" =\u003e [\n                    \"id\" =\u003e \"master\",\n                    \"type\" =\u003e \"credit_card\",\n                    \"token\" =\u003e \"\u003cCARD_TOKEN\u003e\",\n                    \"installments\" =\u003e 1,\n                    \"statement_descriptor\" =\u003e \"Store name\",\n                ]\n            ]\n        ]\n    ]\n];\n```\n\n### Step 5: Create the request options, setting X-Idempotency-Key\n\n```php\n$request_options = new RequestOptions();\n$request_options-\u003esetCustomHeaders([\"X-Idempotency-Key: \u003cSOME_UNIQUE_VALUE\u003e\"]);\n```\n\n### Step 6: Make the request\n\n```php\n$order = $client-\u003ecreate($request, $request_options);\n```\n\n### Step 7: Handle exceptions\n\n```php\ntry{\n    // Do your stuff here\n} catch (MPApiException $e) {\n    // Handle API exceptions\n    echo \"Status code: \" . $e-\u003egetApiResponse()-\u003egetStatusCode() . \"\\n\";\n    echo \"Content: \";\n    var_dump($e-\u003egetApiResponse()-\u003egetContent());\n    echo \"\\n\";\n} catch (\\Exception $e) {\n    // Handle all other exceptions\n    echo $e-\u003egetMessage();\n}\n```\n\n## 🌟 Getting started with payment via Checkout Pro\n\n### Step 1: Require the libraries\n\n```php\nuse MercadoPago\\MercadoPagoConfig;\nuse MercadoPago\\Client\\Preference\\PreferenceClient;\nuse MercadoPago\\Exceptions\\MPApiException;\n```\n\n### Step 2: Create an authentication function\n\n```php\nprotected function authenticate()\n{\n    // Getting the access token from .env file (create your own function)\n    $mpAccessToken = getVariableFromEnv('mercado_pago_access_token');\n    // Set the token the SDK's config\n    MercadoPagoConfig::setAccessToken($mpAccessToken);\n    // (Optional) Set the runtime enviroment to LOCAL if you want to test on localhost\n    // Default value is set to SERVER\n    MercadoPagoConfig::setRuntimeEnviroment(MercadoPagoConfig::LOCAL);\n}\n```\n\n### Step 3: Create customer's preference before proceeding to Checkout Pro page\n\n```php\n// Function that will return a request object to be sent to Mercado Pago API\nfunction createPreferenceRequest($items, $payer): array\n{\n    $paymentMethods = [\n        \"excluded_payment_methods\" =\u003e [],\n        \"installments\" =\u003e 12,\n        \"default_installments\" =\u003e 1\n    ];\n\n    $backUrls = array(\n        'success' =\u003e route('mercadopago.success'),\n        'failure' =\u003e route('mercadopago.failed')\n    );\n\n    $request = [\n        \"items\" =\u003e $items,\n        \"payer\" =\u003e $payer,\n        \"payment_methods\" =\u003e $paymentMethods,\n        \"back_urls\" =\u003e $backUrls,\n        \"statement_descriptor\" =\u003e \"NAME_DISPLAYED_IN_USER_BILLING\",\n        \"external_reference\" =\u003e \"1234567890\",\n        \"expires\" =\u003e false,\n        \"auto_return\" =\u003e 'approved',\n    ];\n\n    return $request;\n}\n```\n\n### Step 4: Create the preference on Mercado Pago ([DOCS](https://www.mercadopago.com.br/developers/pt/docs/sdks-library/server-side/php/preferences))\n\n```php\npublic function createPaymentPreference(): ?Preference\n{\n    // Fill the data about the product(s) being purchased\n    $product1 = array(\n        \"id\" =\u003e \"1234567890\",\n        \"title\" =\u003e \"Product 1 Title\",\n        \"description\" =\u003e \"Product 1 Description\",\n        \"currency_id\" =\u003e \"BRL\",\n        \"quantity\" =\u003e 12,\n        \"unit_price\" =\u003e 9.90\n    );\n\n    $product2 = array(\n        \"id\" =\u003e \"9012345678\",\n        \"title\" =\u003e \"Product 2 Title\",\n        \"description\" =\u003e \"Product 2 Description\",\n        \"currency_id\" =\u003e \"BRL\",\n        \"quantity\" =\u003e 5,\n        \"unit_price\" =\u003e 19.90\n    );\n\n    // Mount the array of products that will integrate the purchase amount\n    $items = array($product1, $product2);\n\n    // Retrieve information about the user (use your own function)\n    $user = getSessionUser();\n\n    $payer = array(\n        \"name\" =\u003e $user-\u003ename,\n        \"surname\" =\u003e $user-\u003esurname,\n        \"email\" =\u003e $user-\u003eemail,\n    );\n\n    // Create the request object to be sent to the API when the preference is created\n    $request = createPreferenceRequest($item, $payer);\n\n    // Instantiate a new Preference Client\n    $client = new PreferenceClient();\n\n    try {\n        // Send the request that will create the new preference for user's checkout flow\n        $preference = $client-\u003ecreate($request);\n\n        // Useful props you could use from this object is 'init_point' (URL to Checkout Pro) or the 'id'\n        return $preference;\n    } catch (MPApiException $error) {\n        // Here you might return whatever your app needs.\n        // We are returning null here as an example.\n        return null;\n    }\n}\n```\n\nIn case you need to retrieve the preference by ID:\n\n```php\n    $client = new PreferenceClient();\n    $client-\u003eget(\"123456789\");\n```\n\n## 📚 Documentation\n\nSee our documentation for more details.\n\n- Mercado Pago reference API. [Portuguese](https://www.mercadopago.com/developers/pt/reference) / [English](https://www.mercadopago.com/developers/en/reference) / [Spanish](https://www.mercadopago.com/developers/es/reference)\n\n## 🤝 Contributing\n\nAll contributions are welcome, ranging from people wanting to triage issues, others wanting to write documentation, to people wanting to contribute code.\n\nPlease read and follow our [contribution guidelines](CONTRIBUTING.md). Contributions not following these guidelines will\nbe disregarded. The guidelines are in place to make all of our lives easier and make contribution a consistent process for everyone.\n\n### Patches to version 2.x.x\n\nSince the release of version 3.0.0, version 2 is deprecated and will not be receiving new features, only bug fixes. If you need to submit PRs for that version, please do so by using [master-v2](https://github.com/mercadopago/sdk-php/tree/master-v2) as your base branch.\n\n## ❤️ Support\n\nIf you require technical support, please contact our support team at our developers site: [English](https://www.mercadopago.com/developers/en/support/center/contact) / [Portuguese](https://www.mercadopago.com/developers/pt/support/center/contact) / [Spanish](https://www.mercadopago.com/developers/es/support/center/contact)\n\n## 🏻 License\n\n```\nMIT license. Copyright (c) 2023 - Mercado Pago / Mercado Libre\nFor more information, see the LICENSE file.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmercadopago%2Fsdk-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmercadopago%2Fsdk-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmercadopago%2Fsdk-php/lists"}