Link API Create

You can create payment links for your Service / Product or Invoice / Current collections by using the Link Create Service.

1- The token data is generated with the information below that must be sent
2-A request is made to the create service ( https://www.paytr.com/odeme/api/link/create ) along with the generated token and the fields that must be sent..

Required parameters for token creation

Field name / Type Description Mandatory Limitations & Notes
name (string) Product or Service Name Yes Description of the product or service. (Minimum 4 and maximum 200 characters required)
price (string) Payment Amount Yes For example, 3456 should be sent for 34.56 (34.56 * 100 = 3456)
currency (string) Currency Yes TL, EUR, USD, GBP, RUB ((If the value is null, TL is accepted))
max_installment (string) Maximum number of installments: Specifies the maximum number of installments to be displayed (example usage: up to 4 installments is allowed for jewellery expenditures) Yes It can be sent between 2 and 12. If 1 is sent, individual cards cannot be used for installments
link_type(integer) Link Type Yes For product sale: product For invoice / current collection: collection
lang(string) Language to be used on the pages during the payment process Yes tr for Turkish or en for English (If it is sent null, tr will be valid)
merchant_salt A value specific to your store, which you can access through the PayTR Merchant Panel > Information page. Yes -
merchant_key A value specific to your store, which you can access through the PayTR Merchant Panel > Information page. Yes -


* Values to be sent in POST REQUEST content:

Field name / Type Description Mandatory Limitations & Notes
merchant_id (integer) Merchant number: Merchant number given to you by PayTR Yes -
name (string) Product or Service Name Yes Description of the product or service. (Minimum 4 and maximum 200 characters required)
price (string) Payment Amount Yes For example, 3456 should be sent for 34.56 (34.56 * 100 = 3456)
currency (string) Currency Yes TL, EUR, USD, GBP, RUB ((If the value is null, TL is accepted))
max_installment (string) Maximum number of installments: Specifies the maximum number of installments to be displayed (example usage: up to 4 installments is allowed for jewellery expenditures) Yes It can be sent between 2 and 12. If 1 is sent, individual cards cannot be used for installments
link_type(integer) Link Type Yes For product sale: product For invoice / current collection: collection
lang(string) Language to be used on the pages during the payment process Yes tr for Turkish or en for English (If it is sent null, tr will be valid)
get_qr QR code returns in base64 format, it needs to be converted to image format and used. No 1 or 0 can be sent. 1 must be sent to receive a QR code response.
paytr_token(string) paytr_token: This value is the one you need to create to make sure the request is coming from you and that the values it contains have not changed Yes Please check the sample codes for calculation
min_count (integer) Minimum quantity limit.(it is required if link type is product) No It can be at least 1
email(string) E-mail address (it is required if link type is collection) No It can contain up to 100 characters.
max_count(integer) Stock quantity (It can only be used in product type. It set the stock quantity of Link and if it is not sent, the stock limit is not applied. When the payment is made as much as the stock number, the link is closed No It can be at least 1.
pft (integer) Installment Cash Price setting (optional).All installment options up to the highest number sent are set as Installments to Cash Price. ATTENTION: Installment commissions will be deducted from you in all payment No It can be sent ​​between 2-12.
expiry_date Link expiration date No Link's expiration date. If not sent, it remains open until deleted. Example format: 2021-05-31 17:00:00
callback_link The URL where the result of the link payment will be sent No Must start with http: // or https: //, not contain localhost and port.
callback_id Notification ID to return in notification. This field is required when the callback_link is sent. No It can be alphanumeric and up to 64 characters.
debug_on Error message (Be sure to send 1 to detect errors during the integration and testing process). No 0 or 1



2) RESPONS

Description Field name / Type Values
Response status (string) success, error or failed
Unique link id id (string) Example: NB2Zlz3
Link status (string) Example: https://www.paytr.com/link/NB2Zlz3
Request description (in case of error) reason (string) Example: Required field value is invalid or not sent (Link API - create): price


<?php

    $merchant_id    = 'AAAAAA';
    $merchant_key   = 'XXXXXXXXXXXXXXXX';
    $merchant_salt  = 'XXXXXXXXXXXXXXXX';

    $name            = "Örnek Ürün / Hizmet Adı";

    $price           = 1445;

    $currency        = "TL";

    $max_installment = "12";

    $link_type       = "product";

    $lang            = "tr";

    $get_qr          = 1;

    $required        = $name.$price.$currency.$max_installment.$link_type.$lang;

    if($link_type == "product"){
        $min_count     = "1";

        $required     .= $min_count;
    }elseif($link_type == "collection"){
        $email         = time()."@example.com";

        $required     .= $email;
    }

    $expiry_date        = "2020-03-23 17:00:00";

    $max_count          = "1";

    $pft             = "0"; 

    $callback_link      = "";

    $callback_id        = "";

    $debug_on           = 1;

    $paytr_token=base64_encode(hash_hmac('sha256', $required.$merchant_salt, $merchant_key, true));
    $post_vals=array(
        'merchant_id'       => $merchant_id,
        'name'              => $name,
        'price'             => $price,
        'currency'          => $currency,
        'max_installment'   => $max_installment,
        'link_type'         => $link_type,
        'lang'              => $lang,
        'min_count'         => $min_count,
        'email'             => $email,
        'expiry_date'       => $expiry_date,
        'max_count'         => $max_count,
        'callback_link'     => $callback_link,
        'callback_id'       => $callback_id,
        'debug_on'          => $debug_on,
        'get_qr'            => $get_qr,
        'paytr_token'       => $paytr_token
    );

    $ch=curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://www.paytr.com/odeme/api/link/create");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1) ;
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_vals);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    $result = @curl_exec($ch);

    if(curl_errno($ch))
        die("PAYTR LINK CREATE API request timeout. err:".curl_error($ch));

    curl_close($ch);

    $result=json_decode($result,1);

    if($result['status']=='error')
        die($result['err_msg']);
    elseif($result['status']=='failed')
        print_r($result);
    else
        print_r($result);

For Link API Create service sample codes. Click to download