PHP code example of mp-plugins / php-sdk

1. Go to this page and download the library: Download mp-plugins/php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mp-plugins / php-sdk example snippets



    $sdk = new Sdk('accessToken', 'platformId', 'productId', 'integratorId', 'publicKey');



    $sdk = new Sdk('accessToken', 'platformId', 'productId', 'integratorId', 'publicKey');
    
    $payment = $sdk->getPaymentInstance();
    
    $payment->token = "card_token";
    $payment->transaction_amount = 230;
    $payment->description = "Ergonomic Silk Shirt";
    $payment->installments = 1;
    $payment->payment_method_id = "master";
    $payment->payer->email = "[email protected]";
    .
    .
    .
    
    $payment->save();



    $sdk = new Sdk('accessToken', 'platformId', 'productId', 'integratorId', 'publicKey');
    
    $payment = $sdk->getPaymentInstance();
    
    $payment->read(array("id" => 'payment_id'));


    $sdk = new Sdk('accessToken', 'platformId', 'productId', 'integratorId', 'publicKey');
    
    $preference = $sdk->getPreferenceInstance();
    
    $items = ["items" =>  
                [
                    "title" => "Dummy Title",
                    "description" => "Dummy description",
                    "picture_url" => "http://www.myapp.com/myimage.jpg",
                    "category_id" => "car_electronics",
                    "quantity" => 1,
                    "currency_id" => "BRL",
                    "unit_price" => 10.5
                ]
            ];
    
    $preference->items = $items;
    $preference->notification_url = "notification_url";
    $preference->external_reference = "external_reference";
    
    $preference->save();



    $sdk = new Sdk('accessToken', 'platformId', 'productId', 'integratorId', 'publicKey');
    
    $notification = $sdk->getNotificationInstance();
    
    $notification->read(array("id" => "P-1316643861"));



    $sdk = new Sdk('accessToken', 'platformId', 'productId', 'integratorId', 'publicKey');
    
    $datadogEvent = $sdk->getDatadogEventInstance();
    
    $details = [
        "payment_id" => "123456"
    ];
    
    $datadogEvent->value = "success";
    $datadogEvent->message = "mensagem vinda do teste de integração da SDK de PHP";
    $datadogEvent->plugin_version = "1.0.0";
    $datadogEvent->platform->name = "core";
    $datadogEvent->platform->version = "1.2.0";
    $datadogEvent->platform->uri = "/integration_test";
    $datadogEvent->platform->url = "https://...";
    $datadogEvent->details = $details;
       
    $datadogEvent->register(array("team" => "core", "event_type"=> "unit_test"));
    


    $sdk = new Sdk('accessToken', 'platformId', 'productId', 'integratorId', 'publicKey');
    
    $registerErrorLog = $sdk->getRegisterErrorLogInstance();
    
    $registerErrorLog->message = 'Sample error message';
    $registerErrorLog->stacktrace = 'monitoring_regiter_log.php';
    $registerErrorLog->location = 'registerErrorLog';
    $registerErrorLog->platform_version = phpversion();
    $registerErrorLog->module_version = "1.0.0";
    $registerErrorLog->user_agent = 'PHP SDK';
    $registerErrorLog->flow = 'sample-php-sdk';
    $registerErrorLog->runtime_version = phpversion();
    $registerErrorLog->os_version = "10";
    $registerErrorLog->browser_version = "Chrome";
    $registerErrorLog->uri = 'http://localhost';
    $registerErrorLog->url = 'http://localhost';
    $registerErrorLog->details = [
        'payment_id' => '123456789',
    ];
    
    $registerErrorLog->save();
    


    $sdk = new Sdk('accessToken', 'platformId', 'productId', 'integratorId', 'publicKey');
    
    $paymentMethods = $sdk->getPaymentMethodsInstance();
    
    $paymentMethods->getPaymentMethodsByGroupBy('id');
    


    $sdk = new Sdk('accessToken', 'platformId', 'productId', 'integratorId', 'publicKey');
    
    $paymentMethods = $sdk->getPaymentMethodsInstance();
    
    $paymentMethods->getPaymentMethodsByGroupBy('id');
    


    use MercadoPago\PP\Sdk\Sdk;

    "<pre>";
        print_r($value);
        echo "</pre>";
    }

    $sdk = new Sdk( 'accessToken', 'platformId', 'productId', 'integratorId', 'publicKey' );

    $merchantOrder = $sdk->getMerchantOrderInstance();

    debug(json_encode($merchantOrder->getMerchantOrders()));
    



    use MercadoPago\PP\Sdk\Sdk;
    
    <pre>";
        print_r($value);
        echo "</pre>";
    }
    
    $sdk = new Sdk( 'accessToken', 'platformId', 'productId', 'integratorId', 'publicKey' );
    
    $createSellerFunnelBase = $sdk->getCreateSellerFunnelBaseInstance();
    
    $createSellerFunnelBase->platform_id = "123";
    $createSellerFunnelBase->shop_url = "http://localhost";
    $createSellerFunnelBase->platform_version = "1.0.0";
    $createSellerFunnelBase->plugin_version = "1.0.0";
    $createSellerFunnelBase->site_id = "MLB";
    
    $response = $createSellerFunnelBase->save();
    
    $response->id
    $response->cpp_token
    



    use MercadoPago\PP\Sdk\Sdk;

    <pre>";
        print_r($value);
        echo "</pre>";
    }

    $sdk = new Sdk( 'accessToken', 'platformId', 'productId', 'integratorId', 'publicKey' );

    $updateSellerFunnelBase = $sdk->getUpdateSellerFunnelBaseInstance();

    $updateSellerFunnelBase->id = "id";
    $updateSellerFunnelBase->cpp_token = "token";
    $updateSellerFunnelBase->is_added_production_credential = true;
    $updateSellerFunnelBase->is_added_test_credential = true;
    $updateSellerFunnelBase->product_id = "4das56";
    $updateSellerFunnelBase->cust_id = "123";
    $updateSellerFunnelBase->application_id = "123";
    $updateSellerFunnelBase->plugin_mode = "prod";
    $updateSellerFunnelBase->is_deleted = false;
    $updateSellerFunnelBase->accepted_payments = ["bolbradesco", "pix"];
    $updateSellerFunnelBase->is_disabled = false;

    debug(json_encode($updateSellerFunnelBase->update()));


    $sdk = new Sdk('accessToken', 'platformId', 'productId', 'integratorId', 'publicKey');
    
    $exchange = $sdk->getExchangeInstance();
    
    $exchange->getExchangeRate("currency_id");


    $sdk = new Sdk( 
        'accessToken',
        'platformId',
        'productId',
        'integratorId',
        'publicKey'
    );

    $onboarding = $sdk->getOnboardingInstance();

    $onboarding->getOnboardingData("applicationId");