该包已被废弃,不再维护。未建议替代包。
该包最新版本(v0.5.6)没有可用的许可证信息。

MercadoPago支付集成SDK模块。

v0.5.6 2019-04-15 14:29 UTC

This package is auto-updated.

Last update: 2021-03-05 15:24:52 UTC


README

警告:我们建议您尝试使用我们新的SDK dx-php

MercadoPago SDK

安装

使用Composer

从命令行

composer require mercadopago/sdk:0.5.3

作为项目composer.json中的依赖项

{
    "require": {
        "mercadopago/sdk": "0.5.3"
    }
}

通过下载

  1. 克隆/下载此存储库
  2. lib/mercadopago.php 复制到您项目所需的文件夹。

基本结账

配置您的凭证

require_once ('mercadopago.php');

$mp = new MP ("CLIENT_ID", "CLIENT_SECRET");

首选项

获取现有的结账首选项

$preference = $mp->get_preference("PREFERENCE_ID");

print_r ($preference);

创建结账首选项

$preference_data = array (
    "items" => array (
        array (
            "title" => "Test",
            "quantity" => 1,
            "currency_id" => "USD",
            "unit_price" => 10.4
        )
    )
);

$preference = $mp->create_preference($preference_data);

print_r ($preference);

更新现有的结账首选项

$preference_data = array (
    "items" => array (
        array (
            "title" => "Test Modified",
            "quantity" => 1,
            "currency_id" => "USD",
            "unit_price" => 20.4
        )
    )
);

$preference = $mp->update_preference("PREFERENCE_ID", $preference_data);

print_r ($preference);

支付/收款

搜索支付

$filters = array (
        "id"=>null,
        "external_reference"=>null
    );

$searchResult = $mp->search_payment ($filters);

print_r ($searchResult);

获取支付数据

require_once ('mercadopago.php');

$mp = new MP ("CLIENT_ID", "CLIENT_SECRET");
$paymentInfo = $mp->get_payment ("PAYMENT_ID");

print_r ($paymentInfo);

取消(仅限挂起支付)

$result = $mp->cancel_payment("PAYMENT_ID");

print_r ($result);

退款(仅限授权支付)

$result = $mp->refund_payment("PAYMENT_ID");

print_r ($result);

自定义结账

配置您的凭证

require_once ('mercadopago.php');

$mp = new MP ("ACCESS_TOKEN");

创建支付

$mp->post (
    array(
        "uri" => "/v1/payments",
        "data" => [payment_data]
    )
);

创建客户

$mp->post (
    array(
        "uri" => "/v1/customers",
        "data" => array(
            "email" => "email@test.com"
        )
    )
);

获取客户

$mp->get (
    array(
        "uri" => "/v1/customers/CUSTOMER_ID"
    )
);

通用方法

您可以使用通用方法从 MercadoPago API 访问任何资源。基本结构为

$mp->[method]($request)

其中 request 可以是

array(
    "uri" => "The resource URI, relative to https://api.mercadopago.com",
    "params" => "Optional. Key=>Value array with parameters to be appended to the URL",
    "data" => "Optional. Object or String to be sent in POST and PUT requests",
    "headers" => "Optional. Key => Value array with custom headers, like content-type: application/x-www-form-urlencoded",
    "authenticate" => "Optional. Boolean to specify if the GET method has to authenticate with credentials before request. Set it to false when accessing public APIs"
)

示例

// Get a resource, with optional URL params. Also you can disable authentication for public APIs
$mp->get (
    array(
        "uri" => "/resource/uri",
        "params" => array(
            "param" => "value"
        ),
        "headers" => array(
            "header" => "value"
        ),
        "authenticate" => true
    )
);

// Create a resource with "data" and optional URL params.
$mp->post (
    array(
        "uri" => "/resource/uri",
        "params" => array(
            "param" => "value"
        ),
        "headers" => array(
            "header" => "value"
        ),
        "data" => [data]
    )
);

// Update a resource with "data" and optional URL params.
$mp->put (
    array(
        "uri" => "/resource/uri",
        "params" => array(
            "param" => "value"
        ),
        "headers" => array(
            "header" => "value"
        ),
        "data" => [data]
    )
);

// Delete a resource with optional URL params.
$mp->delete (
    array(
        "uri" => "/resource/uri",
        "params" => array(
            "param" => "value"
        ),
        "headers" => array(
            "header" => "value"
        )
    )
);