User Tools

Site Tools


The example of the implementation of the payment form (PHP)

// Getting information about the product with a form sent to buy goods
$url            = '';
$merchant        = 'XXX'; // Your partner ID / Seller received at registration (integer)
$shop_hash        = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // The secret key to generate a signature request (32 characters). Available after registration in the office of a partner/seller (string)
$sign            = sha1(md5($merchant.$shop_hash)); // Creating a Signature request (64 characters), (string)
$good            = 'XXX'; // Good ID (integer)
$data        = array(
                    'merchant'    => $merchant,    // Your unique ID of the merchant (ID of the seller/partner) (integer)
                    'signature'    => $sign,        // The signature request (string)
                    'good'        => $good,        // Unique ID of the product (integer)
                    'currency'    => 'usd',        // In what currency to deduce the value of the goods. Available Currency: uah,usd,rub,eur. Default: usd (string)
                    'language'    => 'ru',        // What language output (ru - Russian, en - English). Default: en (string).
                    'format'    => 'json',        // The format in which you receive a response to the request (xml / json). Default: xml (string)
function get_xml_or_json($url,$data){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$request = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<request api_version="1.0">
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_HTTPHEADER,     array('Content-Type: application/'.$data['format'].'; charset=utf-8','Content-Length: '.strlen($request)));
$response = curl_exec($ch);
return $response;
$x = get_xml_or_json($url,$data);
//print_r(json_decode($x,1));     // Output data в JSON (массив)
//print_r($x);             // Output RAW-data в XML/JSON
// Reception and output data in XML format
//xml = simplexml_load_string($x);
// Reception and output data in XML format
// An example of an XML data access
//echo $xml->status['status_descr']; // XML. Output with the tag "status" attribute value "status_descr" and obtain a description of the status of
//echo $xml->cnt; // XML. Output with the tag "cnt" number of all goods seller
############ FORM PAYMENT GOOD ###############

$data = json_decode($x,1); // Получаем данные по товару
//print_r($data); // а посмотреть
<!DOCTYPE html>
<html lang="ru"><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Test form of payment for the API / Тестовая форма оплаты API для</title>
    <body style="padding:20px 20px 20px 20px;">
hr{border-bottom:5px solid #E4E4E4;}
#pay_form > input.axe-input{font-size:18px;}
#pay_form > select.axe-input{font-size:18px;}
.hide {
    display: none;
function ChoiceCurrency()
var val    = new Array;
var txt    = new Array;
<?php for ($i = 0; $i <= count($data['gateways'])-1; $i++) {
        $price        = $data['gateways'][$i]['price'];
        $txt        = strtoupper($data['gateways'][$i]['currency']);
// Add price visible
val[<?php echo $i; ?>] = <?php echo $price; ?>;
txt[<?php echo $i; ?>] = "<?php echo $txt; ?>";
<?php } ?>
var myselect = document.all("select_gateway_id").options;
for (var i=0; i< myselect.length; i++){
    if (myselect[i].selected==true){
        document.all("price").value = val[i-1];
        document.all("curr").value = txt[i-1];
        document.all("pay").disabled = '';
        <h1>Payment for goods: <?=$data['good']['title'];?></h1>
        <form action="" method="post" name="pay_form" id="pay_form">
            <input type="hidden" name="merchant" value="<?php echo $merchant; ?>">
            <input type="hidden" name="signature" value="<?php echo $sign; ?>">
            <input type="hidden" name="good_id" value="<?php echo $good; ?>">
            <h3>Cost of goods</h3>
            <input class="axe-input" type="text" name="price" id="price" size="11" value="<?php echo $data['good']['price']; ?>" readonly>
            <input class="axe-input" type="text" name="curr" id="curr" size="5" value="<?php echo strtoupper($data['good']['currency']); ?>" readonly><br />
            <?php if($data['good']['type']==2 || $data['good']['type']==3) { ?>
            <input type="text" class="axe-input" name="quantity" value="1"> <label><strong>Available: <?php echo $data['good']['good_num']; ?> pcs.</strong></label>
            <?php }else{ ?>
            <input type="hidden" name="quantity" value="1">
            <?php } ?>
            <h3>Select a Payment Method</h3>
            <select class="axe-input" name="select_gateway_id" id="select_gateway_id" onChange="ChoiceCurrency()">
                <option>Please, choose...</option>
                <?php for ($i = 0; $i <= count($data['gateways'])-1; $i++) {
                         $id     = $data['gateways'][$i]['id'];
                        $title    = $data['gateways'][$i]['title'];
                        $price    = $data['gateways'][$i]['price'];
                        $curr    = $data['gateways'][$i]['currency'];
                    <option value="<?php echo $id; ?>"><?php echo $title; ?> [<?php echo strtoupper($curr); ?>]</option>
                <?php } ?>
            <h3>Email a buyer</h3>
                <input class="axe-input" name="email_payer" id="email_payer" type="email" placeholder="Enter your email"><br /><br />
                <span><i>Please <strong>carefully</strong> enter your valid email, since it will be sent goods</i></span><br />
                <input class="axe-input" id="pay" name="pay" value="Pay" type="submit">
en/api_solutions/api_page_good_with_payment_form/example_page_with_form_of_payment.txt · Last modified: 2016/03/08 09:36 by root