Advertisement
Guest User

Untitled

a guest
Jan 4th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 52.35 KB | None | 0 0
  1.             $module_cart = getModuleInfo('iCart');
  2.             if(!empty($_POST['payment_type']) && ($_POST['payment_type'] == 2 || $_POST['payment_type'] == 5))
  3.             {
  4.                 $shipFields = [
  5.                     // Shipping address
  6.                     "first_name" => "",
  7.                     "last_name" => "",
  8.                     "city" => "",
  9.                     "country" => "",
  10.                     "state_prefix" => "",
  11.                     "address1" => "",
  12.                     "address2" => "",
  13.                     "zip" => "",
  14.                     "email" => "",
  15.                     "phone1" => "",
  16.                 ];
  17.             }
  18.             else
  19.             {
  20.                 $shipFields = [
  21.                     // Shipping address
  22.                     "first_name" => "",
  23.                     "last_name" => "",
  24.                     "city" => "",
  25.                     "country" => "",
  26.                     "state_prefix" => "",
  27.                     "address1" => "",
  28.                     "address2" => "",
  29.                     "zip" => "",
  30.                     "email" => "",
  31.                     "phone1" => "",
  32.                 ];
  33.             }
  34.             $billFields = [
  35.                 // Billing address
  36.                 "first_name" => "",
  37.                 "last_name" => "",
  38.                 "country" => "",
  39.                 "city" => "",
  40.                 "state_prefix" => "",
  41.                 "address1" => "",
  42.                 "address2" => "",
  43.                 "zip" => "",
  44.                 // Payment Information
  45.                 "card_number" => "",
  46.                 "month" => "",
  47.                 "year" => "",
  48.                 "security_id" => "",
  49.                 "phone1" => "",
  50.                 "email" => "",
  51.             ];
  52.             if(!empty($_SESSION['post']['s']))
  53.                 $_POST['post']['s'] = $_SESSION['post']['s'];
  54.             if(empty($_POST['post']['s']) and !empty($_POST['post']['b']))
  55.             {
  56.                 $_POST['post']['s']['email'] = $_POST['post']['b']['email'];
  57.                 $_POST['post']['s']['phone1'] = $_POST['post']['b']['phone1'];
  58.             }
  59.             if(isset($_POST['post']['s']) && isset($_POST['post']['b']))
  60.             {
  61.                 //$payment_type = ( isset( $_POST['payment_type'] ) ? $_POST['payment_type'] == 1 ? 1 : $_POST['payment_type'] == 2 ? 2 : 3 : 2 );
  62.                 $payment_type = (!empty($_POST['payment_type'])) ? $_POST['payment_type'] : 2;
  63.                 foreach($_POST['post']['s'] as $key => $val)
  64.                 {
  65.                     if(is_string($val))
  66.                     {
  67.                         if(ini_get('magic_quotes_gpc') == 1)
  68.                         {
  69.                             $_POST['post']['s'][$key] = trim(stripslashes($val));
  70.                         }
  71.                         else
  72.                         {
  73.                             $_POST['post']['s'][$key] = trim($val);
  74.                         }
  75.                     }
  76.                 }
  77.                 foreach($_POST['post']['b'] as $key => $val)
  78.                 {
  79.                     if(is_string($val))
  80.                     {
  81.                         if(ini_get('magic_quotes_gpc') == 1)
  82.                         {
  83.                             $_POST['post']['b'][$key] = trim(stripslashes($val));
  84.                         }
  85.                         else
  86.                         {
  87.                             $_POST['post']['b'][$key] = trim($val);
  88.                         }
  89.                     }
  90.                 }
  91.                 if(isset($_POST['post']['ship_as_bill_address']) && ($payment_type == 1 || $payment_type == 3 || $payment_type == 4))
  92.                 {
  93.                     foreach($billFields as $key => $val)
  94.                     {
  95.                         if(!empty($_POST['post']['s'][$key]))
  96.                             $_POST['post']['b'][$key] = $_POST['post']['s'][$key];
  97.                     }
  98.                 }
  99.                 $original_ship_fields_count = count($shipFields);
  100.                 $shipFields = array_merge($shipFields, $_POST['post']['s']);
  101.                 $original_bill_fields_count = count($billFields);
  102.                 $billFields = array_merge($billFields, $_POST['post']['b']);
  103.                 $out['p'] = [
  104.                     'ship' => $shipFields,
  105.                     'bill' => $billFields
  106.                 ];
  107.                 if($original_ship_fields_count == count(
  108.                         $shipFields
  109.                     ) && $original_bill_fields_count == count($billFields)
  110.                 )
  111.                 {
  112.                     $is_abon_c = 0;
  113.                     $other_items_c_2 = 0;
  114.                     foreach($_SESSION['cart']['items'] as $item_num => $item_value)
  115.                     {
  116.                         $abon = exec_sql2array(
  117.                             //"SELECT * FROM `" . PREFIX . "product_info` WHERE `product_type_id`='4' and `id`='$item_num'"
  118.                             "SELECT * FROM `" . PREFIX . "product_info` WHERE `physical`='0' and `id`='$item_num'"
  119.                         );
  120.                         if(!empty($abon))
  121.                         {
  122.                             $is_abon_c++;
  123.                         }
  124.                         $other_items = exec_sql2array(
  125.                             "SELECT * FROM `" . PREFIX . "product_info` WHERE `physical`='1' and `id`='$item_num'"
  126.                         );
  127.                         if(!empty($other_items))
  128.                         {
  129.                             $other_items_c_2++;
  130.                         }
  131.                     }
  132.                     if($is_abon_c > 0 && $other_items_c_2 == 0)
  133.                     {
  134.                         if(!empty($_POST['payment_type']) && ($_POST['payment_type'] == 2 || $_POST['payment_type'] == 5))
  135.                         {
  136.                             $shipTestFields = [
  137.                                 "phone1" => [
  138.                                     "!is_fill()" => trans("This entry is required"),
  139.                                 ],
  140.                                 "email" => [
  141.                                     "!is_fill()" => trans("This entry is required"),
  142.                                     "!testEmail()" => trans(
  143.                                         "Not correctly specified E-mail"
  144.                                     ),
  145.                                 ],
  146.                             ];
  147.                         }
  148.                         else
  149.                         {
  150.                             $shipTestFields = [
  151.                                 "email" => [
  152.                                     "!is_fill()" => trans("This entry is required"),
  153.                                     "!testEmail()" => trans(
  154.                                         "Not correctly specified E-mail"
  155.                                     ),
  156.                                 ],
  157.                             ];
  158.                         }
  159.                     }
  160.                     else
  161.                     {
  162.                         if(!empty($_POST['payment_type']) && ($_POST['payment_type'] == 2 || $_POST['payment_type'] == 5))
  163.                         {
  164.                             $shipTestFields = [
  165.                                 "first_name" => [
  166.                                     "!is_fill()" => trans("This entry is required"),
  167.                                 ],
  168.                                 "last_name" => [
  169.                                     "!is_fill()" => trans("This entry is required"),
  170.                                 ],
  171.                                 "city" => [
  172.                                     "!is_fill()" => trans("This entry is required"),
  173.                                 ],
  174.                                 "state_prefix" => [
  175.                                 ],
  176.                                 "address1" => [
  177.                                     "!is_fill()" => trans("This entry is required"),
  178.                                 ],
  179.                                 "address2" => [
  180.                                 ],
  181.                                 "zip" => [
  182.                                 ],
  183.                                 "phone1" => [
  184.                                     "!is_fill()" => trans("This entry is required"),
  185.                                 ],
  186.                                 "email" => [
  187.                                     "!is_fill()" => trans("This entry is required"),
  188.                                     "!testEmail()" => trans(
  189.                                         "Not correctly specified E-mail"
  190.                                     ),
  191.                                 ],
  192.                             ];
  193.                         }
  194.                         else
  195.                         {
  196.                             $shipTestFields = [
  197.                                 "first_name" => [
  198.                                     "!is_fill()" => trans("This entry is required"),
  199.                                 ],
  200.                                 "last_name" => [
  201.                                     "!is_fill()" => trans("This entry is required"),
  202.                                 ],
  203.                                 "city" => [
  204.                                     "!is_fill()" => trans("This entry is required"),
  205.                                 ],
  206.                                 "state_prefix" => [
  207.                                 ],
  208.                                 "address1" => [
  209.                                     "!is_fill()" => trans("This entry is required"),
  210.                                 ],
  211.                                 "address2" => [
  212.                                 ],
  213.                                 "zip" => [
  214.                                 ],
  215.                                 "email" => [
  216.                                     "!is_fill()" => trans("This entry is required"),
  217.                                     "!testEmail()" => trans(
  218.                                         "Not correctly specified E-mail"
  219.                                     ),
  220.                                 ],
  221.                             ];
  222.                         }
  223.                     }
  224.                     $billTestFields = [
  225.                         "first_name" => [
  226.                             "!is_fill()" => trans("This entry is required"),
  227.                         ],
  228.                         "last_name" => [
  229.                             "!is_fill()" => trans("This entry is required"),
  230.                         ],
  231.                         "city" => [
  232.                             "!is_fill()" => trans("This entry is required"),
  233.                         ],
  234.                         "state_prefix" => [
  235.                         ],
  236.                         "address1" => [
  237.                             "!is_fill()" => trans("This entry is required"),
  238.                         ],
  239.                         "address2" => [
  240.                         ],
  241.                         "zip" => [
  242.                         ],
  243.                         "card_number" => [
  244.                             "!is_fill()" => trans("This entry is required"),
  245.                         ],
  246.                         "month" => [
  247.                             "!is_fill()" => trans("This entry is required"),
  248.                         ],
  249.                         "year" => [
  250.                         ],
  251.                         "security_id" => [
  252.                             "!is_fill()" => trans("This entry is required"),
  253.                         ],
  254.                         "phone1" => [
  255.                             "!is_fill()" => "",
  256.                         ],
  257.                         "email" => [
  258.                             "!is_fill()" => trans("This entry is required"),
  259.                             "!testEmail()" => trans("Not correctly specified E-mail"),
  260.                         ],
  261.                     ];
  262.                     if(!empty($billFields))
  263.                     {
  264.                         if($billFields['city'] == 'New York')
  265.                         {
  266.                             $group = '2';
  267.                         }
  268.                         else if($billFields['city'] == 'Brooklyn')
  269.                         {
  270.                             $group = '1';
  271.                         }
  272.                         else
  273.                         {
  274.                             $group = '';
  275.                         }
  276.                         $fields_2 = [
  277.                             "`email`",
  278.                             "`groups`",
  279.                             "`location`",
  280.                             "`subscribe`",
  281.                             "`new`",
  282.                         ];
  283.                         $values_2 = [
  284.                             "'" . $billFields['email'] . "'",
  285.                             "'" . $group . "'",
  286.                             "'" . $billFields['city'] . "'",
  287.                             "'1'",
  288.                             "'0'",
  289.                         ];
  290.                         if(!empty($billFields['email']))
  291.                         {
  292.                             $is_subscribers = exec_sql2array(
  293.                                 "SELECT * FROM `dd_subscrib_emails` WHERE `email`='" . $billFields['email'] . "'"
  294.                             );
  295.                             if(empty($is_subscribers))
  296.                             {
  297.                                 exec_sql(
  298.                                     "INSERT INTO `dd_subscrib_emails` (" . implode(
  299.                                         ",",
  300.                                         $fields_2
  301.                                     ) . ") VALUES (" . implode(
  302.                                         ",",
  303.                                         $values_2
  304.                                     ) . ");"
  305.                                 );
  306.                             }
  307.                         }
  308.                         if(!empty($shipFields))
  309.                         {
  310.                             if($shipFields['city'] == 'New York')
  311.                             {
  312.                                 $group = '2';
  313.                             }
  314.                             else if($shipFields['city'] == 'Brooklyn')
  315.                             {
  316.                                 $group = '1';
  317.                             }
  318.                             else
  319.                             {
  320.                                 $group = '';
  321.                             }
  322.                             $fields_3 = [
  323.                                 "`email`",
  324.                                 "`groups`",
  325.                                 "`location`",
  326.                                 "`subscribe`",
  327.                                 "`new`",
  328.                             ];
  329.                             $values_3 = [
  330.                                 "'" . $shipFields['email'] . "'",
  331.                                 "'" . $group . "'",
  332.                                 "'" . $shipFields['city'] . "'",
  333.                                 "'1'",
  334.                                 "'0'",
  335.                             ];
  336.                             $is_subscribers_2 = exec_sql2array(
  337.                                 "SELECT * FROM `dd_subscrib_emails` WHERE `email`='" . $shipFields['email'] . "'"
  338.                             );
  339.                             if(empty($is_subscribers_2))
  340.                             {
  341.                                 exec_sql(
  342.                                     "INSERT INTO `dd_subscrib_emails` (" . implode(
  343.                                         ",",
  344.                                         $fields_3
  345.                                     ) . ") VALUES (" . implode(
  346.                                         ",",
  347.                                         $values_3
  348.                                     ) . ");"
  349.                                 );
  350.                             }
  351.                         }
  352.                     }
  353.                     if($payment_type == 1 || $payment_type == 3 || $payment_type == 4)
  354.                     {
  355.                         $shipFields['email'] = $billFields['email'];
  356.                     }
  357.                     if($payment_type == 2 || $payment_type == 5)
  358.                     {
  359.                         $billFields['phone1'] = $shipFields['phone1'];
  360.                     }
  361.                     $shipErrors = [];
  362.                     foreach($shipTestFields as $key => $value)
  363.                     {
  364.                         if(($error = testField($shipFields[$key], $value)) !== true)
  365.                         {
  366.                             if(!empty($error))
  367.                             {
  368.                                 $shipErrors[$key] = $error;
  369.                             }
  370.                         }
  371.                     }
  372.                     $billErrors = [];
  373.                     if($payment_type == 1 || $payment_type == 3)
  374.                     {
  375.                         foreach($billTestFields as $key => $value)
  376.                         {
  377.                             if(($error = testField($billFields[$key], $value)) !== true)
  378.                             {
  379.                                 if(!empty($error))
  380.                                 {
  381.                                     $billErrors[$key] = $error;
  382.                                 }
  383.                             }
  384.                         }
  385.                     }
  386.                     if(count($shipErrors) == 0 && count($billErrors) == 0)
  387.                     {
  388.                         $shipFields['state'] = get_field(
  389.                             $zip_table,
  390.                             "`state_name`",
  391.                             "WHERE `state_prefix`='" . $shipFields['state_prefix'] . "'"
  392.                         );
  393.                         $billFields['state'] = get_field(
  394.                             $zip_table,
  395.                             "`state_name`",
  396.                             "WHERE `state_prefix`='" . $billFields['state_prefix'] . "'"
  397.                         );
  398.                         /*if ( !empty( $shipFields['zip'] ) ) {
  399.                             $zip_data = get_fields( $zip_table, "WHERE `zip_code`='".$shipFields['zip']."';" );
  400.                             if ( count( $zip_data ) > 0 ) {
  401.                                 $shipFields['city'] = $zip_data['city'];
  402.                                 $shipFields['state_prefix'] = $zip_data['state_prefix'];
  403.                                 $shipFields['state'] = $zip_data['state_name'];
  404.                             }
  405.                         }
  406.                         if ( !empty( $billFields['zip'] ) ) {
  407.                             $zip_data = get_fields( $zip_table, "WHERE `zip_code`='".$billFields['zip']."';" );
  408.                             if ( count( $zip_data ) > 0 ) {
  409.                                 $billFields['city'] = $zip_data['city'];
  410.                                 $billFields['state_prefix'] = $zip_data['state_prefix'];
  411.                                 $billFields['state'] = $zip_data['state_name'];
  412.                             }
  413.                         }*/
  414.                         $total_price = calcAllPrice();
  415.                         $cart_total = $total_price['total_price'];
  416.                         $shipFields['orders_count'] = 0;
  417.                         $shipFields['phone1'] = $billFields['phone1'];
  418.                         $shipFields['phone2'] = "";
  419.                         $service = [];
  420.                         $service['user'] = $shipFields;
  421.                         $service['bill'] = $billFields;
  422.                         $service['cart'] = $_SESSION['cart'];
  423.                         if($payment_type == 3)
  424.                         {
  425.                             $service['layaway'] = [
  426.                                 "count" => $total_price['layaway_count'],
  427.                                 "total" => $total_price['layaway_total'],
  428.                             ];
  429.                         }
  430.                         if(!empty($_SESSION['login']) && !empty($_SESSION['user']['id']))
  431.                         {
  432.                             $user_id = $_SESSION['user']['id'];
  433.                         }
  434.                         else
  435.                         {
  436.                             $user_id = '0';
  437.                         }
  438.                         $currency = 'USD';
  439.                         if($is_us == '1')
  440.                         {
  441.                             $currency_todb = 'USD';
  442.                         }
  443.                         else
  444.                         {
  445.                             $currency_todb = 'EUR';
  446.                         }
  447.                         $is_russia = '1';
  448.                         if($is_us == '1')
  449.                         {
  450.                             $is_russia = '0';
  451.                             if($is_canada == '1')
  452.                             {
  453.                                 $order_country = 'Canada';
  454.                             }
  455.                             else
  456.                             {
  457.                                 $order_country = 'USA';
  458.                             }
  459.                         }
  460.                         else
  461.                         {
  462.                             $order_country = 'Rest';
  463.                         }
  464.                         if(isset($_SESSION['cart']['shipping_country']))
  465.                         {
  466.                             if($_SESSION['cart']['shipping_country'] == 'USA')
  467.                             {
  468.                                 $order_country = 'USA';
  469.                             }
  470.                             else
  471.                             {
  472.                                 $order_country = 'Canada';
  473.                             }
  474.                         }
  475.                         $fields = [
  476.                             "user_id",
  477.                             "_create",
  478.                             "services",
  479.                             "status",
  480.                             "mc_gross",
  481.                             "mc_currency",
  482.                             "txn_id",
  483.                             "country",
  484.                             "country_by_ip",
  485.                             "europe"
  486.                         ];
  487.  
  488.                         //$is_europe = (isset($is_europe) && strlen($is_europe) ? $is_europe : '0');
  489.  
  490.                         $values = [
  491.                             "'" . $user_id . "'",
  492.                             "NOW()",
  493.                             "'" . mysql_real_escape_string(serialize($service)) . "'",
  494.                             "'0'",
  495.                             "'" . $cart_total . "'",
  496.                             "'" . $currency_todb . "'",
  497.                             "''",
  498.                             "'" . $order_country . "'",
  499.                             "'" . $ip . "'",
  500.                             "'" . $is_europe . "'"
  501.                         ];
  502.  
  503.                         exec_sql(
  504.                             "INSERT INTO " . $accounts_table . " (" . implode(",", $fields) . ") VALUES (" . implode(",", $values) . ");"
  505.                         );
  506.                         // Order number here
  507.                         $account_id = mysql_insert_id();
  508.                         $_SESSION['expect_order'] = $account_id;
  509.                         if($payment_type == 1 || $payment_type == 4)
  510.                         {
  511.                             // Card Payment
  512.                             $what_user = exec_sql2array(
  513.                                 "SELECT * FROM `" . PREFIX . "users` WHERE `id`='" . $user_id . "'"
  514.                             );
  515.                             if(!empty($what_user))
  516.                             {
  517.                                 $what_user = $what_user[0];
  518.                                 if(empty($what_user['card_number']) && empty($what_user['b_name']) && empty($what_user['l_name']))
  519.                                 {
  520.                                     if(!empty($billFields['card_number']))
  521.                                     {
  522.                                         $b_card_number = htmlspecialchars(
  523.                                             $billFields['card_number']
  524.                                         );
  525.                                         $_SESSION['payment']['card_number'] = $b_card_number;
  526.                                     }
  527.                                     else
  528.                                     {
  529.                                         $b_card_number = '';
  530.                                         $_SESSION['payment']['card_number'] = '';
  531.                                     }
  532.                                     if(!empty($billFields['month']))
  533.                                     {
  534.                                         $b_month = htmlspecialchars(
  535.                                             $billFields['month']
  536.                                         );
  537.                                         $_SESSION['payment']['month'] = $b_month;
  538.                                     }
  539.                                     else
  540.                                     {
  541.                                         $b_month = '';
  542.                                         $_SESSION['payment']['month'] = '';
  543.                                     }
  544.                                     if(!empty($billFields['year']))
  545.                                     {
  546.                                         $b_year = htmlspecialchars(
  547.                                             $billFields['year']
  548.                                         );
  549.                                         $_SESSION['payment']['year'] = $b_year;
  550.                                     }
  551.                                     else
  552.                                     {
  553.                                         $b_year = '';
  554.                                         $_SESSION['payment']['year'] = '';
  555.                                     }
  556.                                     if(!empty($billFields['security_id']))
  557.                                     {
  558.                                         $b_card_id = htmlspecialchars(
  559.                                             $billFields['security_id']
  560.                                         );
  561.                                         $_SESSION['payment']['card_id'] = $b_card_id;
  562.                                     }
  563.                                     else
  564.                                     {
  565.                                         $b_card_id = '';
  566.                                         $_SESSION['payment']['card_id'] = '';
  567.                                     }
  568.                                     if(!empty($billFields['first_name']))
  569.                                     {
  570.                                         $nu_first_name = $billFields['first_name'];
  571.                                     }
  572.                                     else
  573.                                     {
  574.                                         $nu_first_name = '';
  575.                                     }
  576.                                     if(!empty($billFields['last_name']))
  577.                                     {
  578.                                         $nu_last_name = $billFields['last_name'];
  579.                                     }
  580.                                     else
  581.                                     {
  582.                                         $nu_last_name = '';
  583.                                     }
  584.                                     if(!empty($billFields['phone1']))
  585.                                     {
  586.                                         $nu_phone = $billFields['phone1'];
  587.                                     }
  588.                                     else
  589.                                     {
  590.                                         $nu_phone = '';
  591.                                     }
  592.                                     if(!empty($billFields['email']))
  593.                                     {
  594.                                         $nu_mail = $billFields['email'];
  595.                                     }
  596.                                     else
  597.                                     {
  598.                                         $nu_mail = '';
  599.                                     }
  600.                                     if(!empty($billFields['address1']))
  601.                                     {
  602.                                         $nu_address = $billFields['address1'];
  603.                                     }
  604.                                     else
  605.                                     {
  606.                                         $nu_address = '';
  607.                                     }
  608.                                     if(!empty($billFields['city']))
  609.                                     {
  610.                                         $nu_city = $billFields['city'];
  611.                                     }
  612.                                     else
  613.                                     {
  614.                                         $nu_city = '';
  615.                                     }
  616.                                     if(!empty($billFields['state']))
  617.                                     {
  618.                                         $nu_state = $billFields['state'];
  619.                                     }
  620.                                     else
  621.                                     {
  622.                                         $nu_state = '';
  623.                                     }
  624.                                     if(!empty($billFields['zip']))
  625.                                     {
  626.                                         $nu_zip = $billFields['zip'];
  627.                                     }
  628.                                     else
  629.                                     {
  630.                                         $nu_zip = '';
  631.                                     }
  632.                                     exec_sql(
  633.                                         "UPDATE `dd_users` SET `b_mail`='" . $nu_mail . "', `card_number`='**********" . substr(
  634.                                             $b_card_number,
  635.                                             -4,
  636.                                             4
  637.                                         ) . "', `card`='" . $b_card_number . "', `month`='" . $b_month . "', `year`='" . $b_year . "', `card_id`='" . $b_card_id . "',  `b_name`='" . $nu_first_name . "', `b_lname`='" . $nu_last_name . "', `b_phone`='" . $nu_phone . "', `b_address_1`='" . $nu_address . "', `b_city`='" . $nu_city . "', `b_state`='" . $nu_state . "' , `b_zip`='" . $nu_zip . "' WHERE `id`='" . $user_id . "';"
  638.                                     );
  639.                                     $_SESSION['payment']['phone'] = $nu_phone;
  640.                                 }
  641.                             }
  642.                             $price_for_subscribe = 0;
  643.                             $is_abon_subscribe = 0;
  644.                             $subscription_paid = 1;
  645.                             ######################### оплата подписки на абонемент
  646.                             $subscr_cart = prepareCart($_SESSION['cart']);
  647.                             foreach($subscr_cart['items'] as $record)
  648.                             {
  649.                                 $subsct_abon = exec_sql2array(
  650.                                     //"SELECT * FROM `" . PREFIX . "product_info` WHERE `product_type_id`='4' and `id`='" . $record['item']['id'] . "' and `issubscribe`='1'"
  651.                                     "SELECT * FROM `" . PREFIX . "product_info` WHERE `physical`='0' and `id`='" . $record['item']['id'] . "' and `issubscribe`='1'"
  652.                                 );
  653.                                 if(!empty($subsct_abon))
  654.                                 {
  655.                                     $is_abon_subscribe++;
  656.                                     $price_for_subscribe += $record['total_price'];        //цена подписки
  657.                                 }
  658.                             }
  659.                             if(!empty($is_abon_subscribe) && $is_abon_subscribe > 0)
  660.                             {
  661.                                 //$subscription_paid=0;
  662.                                 //include "subscription_create.php";
  663.                             }
  664.                             $cart_price_for_card = $cart_total - $price_for_subscribe; //цена без учета стоимости подписки
  665.                             ###############
  666.                             //if just subscribe abon
  667.  
  668.  
  669.                             // временно - в связи с изменениями у Kartina.tv, все заказы обрабатываем вручную
  670.                             //if(true)
  671.  
  672.                             // заказы из Европы проводятся вручную
  673.                             if((!$is_us && !$is_canada)) // || ($is_canada && $cart_price_for_card > 0) || ($is_canada && $is_abon_subscribe == 0))
  674.                             {
  675.                                 // ручная обработка заказов
  676.                                 $subscription_paid = 1;
  677.                                 $response_array[0] = 1;
  678.                             }
  679.  
  680.                             else
  681.                             {
  682.                                 if(!empty($is_abon_subscribe) && $is_abon_subscribe > 0 && $other_items_c_2 == 0)
  683.                                 {
  684.                                     $response_array[0] = 1;
  685.                                 }
  686.                                 else
  687.                                 {
  688.                                     if($cart_price_for_card > 0)
  689.                                     {
  690.                                         if($payment_type == 1)
  691.                                         {
  692.                                             $post_url = "https://secure.authorize.net/gateway/transact.dll";
  693.                                             $post_values = [
  694.                                                 "x_login" => $settings['auth_login'],
  695.                                                 "x_tran_key" => $settings['auth_key'],
  696.                                                 "x_version" => "3.1",
  697.                                                 "x_delim_data" => "TRUE",
  698.                                                 "x_delim_char" => "|",
  699.                                                 "x_relay_response" => "FALSE",
  700.                                                 "x_type" => "AUTH_CAPTURE",
  701.                                                 "x_method" => "CC",
  702.                                                 "x_currency_code" => $currency,
  703.                                                 "x_card_num" => $billFields['card_number'],
  704.                                                 "x_exp_date" => $billFields['month'] . $billFields['year'],
  705.                                                 "x_card_code" => $billFields['security_id'],
  706.                                                 "x_amount" => number_format(
  707.                                                     $cart_price_for_card,
  708.                                                     2,
  709.                                                     '.',
  710.                                                     ''
  711.                                                 ),
  712.                                                 "x_description" => "Payment for services on the site " . $uri['domain'],
  713.                                                 "x_first_name" => $billFields['first_name'],
  714.                                                 "x_last_name" => $billFields['last_name'],
  715.                                                 "x_city" => $billFields['city'],
  716.                                                 "x_address" => $billFields['address1'],
  717.                                                 "x_state" => $billFields['state']
  718.                                                 //"x_zip"               => $billFields['zip']
  719.                                             ];
  720.                                             $post_string = "";
  721.                                             foreach($post_values as $key => $value)
  722.                                             {
  723.                                                 $post_string .= (!empty($post_string) ? "&" : "") . $key . "=" . urlencode(
  724.                                                         $value
  725.                                                     );
  726.                                             }
  727.                                             $request = curl_init($post_url);
  728.                                             curl_setopt(
  729.                                                 $request,
  730.                                                 CURLOPT_HEADER,
  731.                                                 0
  732.                                             );
  733.                                             curl_setopt(
  734.                                                 $request,
  735.                                                 CURLOPT_RETURNTRANSFER,
  736.                                                 1
  737.                                             );
  738.                                             curl_setopt(
  739.                                                 $request,
  740.                                                 CURLOPT_POSTFIELDS,
  741.                                                 $post_string
  742.                                             );
  743.                                             curl_setopt(
  744.                                                 $request,
  745.                                                 CURLOPT_SSL_VERIFYPEER,
  746.                                                 false
  747.                                             );
  748.                                             $post_response = curl_exec(
  749.                                                 $request
  750.                                             );
  751.                                             curl_close($request);
  752.                                             $response_array = explode(
  753.                                                 $post_values["x_delim_char"],
  754.                                                 $post_response
  755.                                             );
  756.                                             $out['payment_type'] = $payment_type;
  757.                                         }
  758.                                         if($payment_type == 4)
  759.                                         {
  760.                                             // Card Payment
  761.                                             $sandbox = false;
  762.                                             $api_version = '85.0';
  763.                                             $api_endpoint = $sandbox ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
  764.                                             $api_username = $sandbox ? 'xander.monk-facilitator_api1.gmail.com' : $settings['pppro_username'];
  765.                                             $api_password = $sandbox ? '1397164939' : $settings['pppro_password'];
  766.                                             $api_signature = $sandbox ? 'AURHNsg1Fk3cAULW4uwMYSQHlV95APcQBFyukiiZVFZ3w9rSn9wwU2w0' : $settings['pppro_signature'];
  767.                                             $c_type = substr(
  768.                                                 $billFields['card_number'],
  769.                                                 0,
  770.                                                 1
  771.                                             );
  772.                                             switch($c_type)
  773.                                             {
  774.                                                 case '3':
  775.                                                     $card_type = 'AMEX';
  776.                                                     break;
  777.                                                 case '4':
  778.                                                     $card_type = 'Visa';
  779.                                                     break;
  780.                                                 case '5':
  781.                                                     $card_type = 'MasterCard';
  782.                                                     break;
  783.                                                 case '6':
  784.                                                     $card_type = 'Discover';
  785.                                                     break;
  786.                                             }
  787.                                             $request_params = [
  788.                                                 'METHOD' => 'DoDirectPayment',
  789.                                                 'USER' => $api_username,
  790.                                                 'PWD' => $api_password,
  791.                                                 'SIGNATURE' => $api_signature,
  792.                                                 'VERSION' => $api_version,
  793.                                                 'PAYMENTACTION' => 'Sale',
  794.                                                 'IPADDRESS' => $_SERVER['REMOTE_ADDR'],
  795.                                                 'CREDITCARDTYPE' => $card_type,
  796.                                                 'ACCT' => $billFields['card_number'],
  797.                                                 'EXPDATE' => $billFields['month'] . $billFields['year'],
  798.                                                 'CVV2' => $billFields['security_id'],
  799.                                                 'FIRSTNAME' => $billFields['first_name'],
  800.                                                 'LASTNAME' => $billFields['last_name'],
  801.                                                 'STREET' => $billFields['address1'],
  802.                                                 'CITY' => $billFields['city'],
  803.                                                 'STATE' => $billFields['state'],
  804.                                                 'COUNTRYCODE' => $billFields['country'],
  805.                                                 //'ZIP' => $billFields['zip'],
  806.                                                 'AMT' => number_format(
  807.                                                     $cart_price_for_card,
  808.                                                     2,
  809.                                                     '.',
  810.                                                     ''
  811.                                                 ),
  812.                                                 'CURRENCYCODE' => 'EUR',
  813.                                                 'DESC' => 'Order ' . $account_id
  814.                                             ];
  815.                                             $nvp_string = '';
  816.                                             foreach($request_params as $var => $val)
  817.                                             {
  818.                                                 $nvp_string .= '&' . $var . '=' . urlencode(
  819.                                                         $val
  820.                                                     );
  821.                                             }
  822.                                             //echo $nvp_string;
  823.                                             $curl = curl_init();
  824.                                             curl_setopt(
  825.                                                 $curl,
  826.                                                 CURLOPT_VERBOSE,
  827.                                                 1
  828.                                             );
  829.                                             curl_setopt(
  830.                                                 $curl,
  831.                                                 CURLOPT_SSL_VERIFYPEER,
  832.                                                 false
  833.                                             );
  834.                                             curl_setopt(
  835.                                                 $curl,
  836.                                                 CURLOPT_TIMEOUT,
  837.                                                 30
  838.                                             );
  839.                                             curl_setopt(
  840.                                                 $curl,
  841.                                                 CURLOPT_URL,
  842.                                                 $api_endpoint
  843.                                             );
  844.                                             curl_setopt(
  845.                                                 $curl,
  846.                                                 CURLOPT_RETURNTRANSFER,
  847.                                                 1
  848.                                             );
  849.                                             curl_setopt(
  850.                                                 $curl,
  851.                                                 CURLOPT_POSTFIELDS,
  852.                                                 $nvp_string
  853.                                             );
  854.                                             $result = curl_exec($curl);
  855.                                             if(curl_errno($curl))
  856.                                             {
  857.                                                 //echo "cURL error number:" .curl_errno($ch)." / cURL error:" . curl_error($ch);
  858.                                                 curl_close($curl);
  859.                                             }
  860.                                             else
  861.                                             {
  862.                                                 curl_close($curl);
  863.                                             }
  864.                                             //echo $result;
  865.                                             $NVPString = $result;
  866.                                             $nvp_response_array = parse_str(
  867.                                                 $result
  868.                                             );
  869.                                             $payment_result = [];
  870.                                             while(strlen($NVPString))
  871.                                             {
  872.                                                 $keypos = strpos(
  873.                                                     $NVPString,
  874.                                                     '='
  875.                                                 );
  876.                                                 $keyval = substr(
  877.                                                     $NVPString,
  878.                                                     0,
  879.                                                     $keypos
  880.                                                 );
  881.                                                 $valuepos = strpos(
  882.                                                     $NVPString,
  883.                                                     '&'
  884.                                                 ) ? strpos(
  885.                                                     $NVPString,
  886.                                                     '&'
  887.                                                 ) : strlen($NVPString);
  888.                                                 $valval = substr(
  889.                                                     $NVPString,
  890.                                                     $keypos + 1,
  891.                                                     $valuepos - $keypos - 1
  892.                                                 );
  893.                                                 $payment_result[$keyval] = urldecode(
  894.                                                     $valval
  895.                                                 );
  896.                                                 $NVPString = substr(
  897.                                                     $NVPString,
  898.                                                     $valuepos + 1,
  899.                                                     strlen(
  900.                                                         $NVPString
  901.                                                     )
  902.                                                 );
  903.                                             }
  904.                                             switch($payment_result['ACK'])
  905.                                             {
  906.                                                 case 'Success':
  907.                                                     $response_array[0] = 1;
  908.                                                     break;
  909.                                                 case 'Failure':
  910.                                                     $response_array[0] = 2;
  911.                                                     break;
  912.                                                 case 'SuccessWithWarning':
  913.                                                     $response_array[0] = 3;
  914.                                                     break;
  915.                                                 case 'FailureWithWarning':
  916.                                                     $response_array[0] = 4;
  917.                                                     break;
  918.                                             }
  919.                                             $response_array[3] = $payment_result['ACK'];
  920.                                         }
  921.                                     }
  922.                                     else
  923.                                     {
  924.                                         $response_array[0] = 1;
  925.                                     }
  926.                                 }
  927.                             }
  928.                             //$response_array[ 0 ]=1;
  929.                             if($response_array[0] == 1)
  930.                             {
  931.                                 // successfuly paid
  932.                                 if($subscription_paid == 1)
  933.                                 {
  934.                                     $account = get_fields(
  935.                                         $accounts_table,
  936.                                         " WHERE `id`='" . $account_id . "';"
  937.                                     );
  938.                                     $account['status'] = $account['status'] | 2;
  939.                                     if(exec_sql(
  940.                                         "UPDATE `" . $accounts_table . "` SET `status`='" . $account['status'] . "' WHERE `id`='" . $account_id . "';"
  941.                                     ))
  942.                                     {
  943.                                         include "chek.php";
  944.                                         ######################### проверка номеров абонементов
  945.                                         include "ticket_send.php";
  946.                                         ###############
  947.                                         if(empty($tickets_numbers))
  948.                                         {
  949.                                             if(!empty($shipFields['email']))
  950.                                             {
  951.                                                 $subject = preg_replace(
  952.                                                     [
  953.                                                         '/\[order\]/i',
  954.                                                         '/\[name\]/i',
  955.                                                         '/\[domain\]/i',
  956.                                                         '/\[sum\]/i',
  957.                                                     ],
  958.                                                     [
  959.                                                         $account_id,
  960.                                                         $shipFields['last_name'] . ' ' . $shipFields['first_name'],
  961.                                                         $uri['domain'],
  962.                                                         number_format(
  963.                                                             $account['mc_gross'],
  964.                                                             2,
  965.                                                             '.',
  966.                                                             ' '
  967.                                                         ),
  968.                                                     ],
  969.                                                     $settings['order_subject']
  970.                                                 );
  971.                                                 $letter = preg_replace(
  972.                                                         [
  973.                                                             '/\[order\]/i',
  974.                                                             '/\[name\]/i',
  975.                                                             '/\[domain\]/i',
  976.                                                             '/\[sum\]/i',
  977.                                                             '/\[check\]/i',
  978.                                                         ],
  979.                                                         [
  980.                                                             $account_id,
  981.                                                             $shipFields['last_name'] . ' ' . $shipFields['first_name'],
  982.                                                             $uri['domain'],
  983.                                                             number_format(
  984.                                                                 $account['mc_gross'],
  985.                                                                 2,
  986.                                                                 '.',
  987.                                                                 ' '
  988.                                                             ),
  989.                                                             $check,
  990.                                                         ],
  991.                                                         nl2br(
  992.                                                             $settings['order_text']
  993.                                                         )
  994.                                                     ) . "\r\n";
  995.                                                 $headers = 'MIME-Version: 1.0' . "\r\n";
  996.                                                 $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
  997.                                                 //$headers .= "From: Kartina-tv <no-reply@kartinatv.ru>\r\n";
  998.                                                 $headers .= "From: no-reply@kartinatv.ru\r\n";
  999.                                                 //$headers .= "From: no-reply@".$uri['domain']."\r\n";
  1000.                                                 //$headers .= "Reply-To: info@".$uri['domain']."\r\n";
  1001.                                                 $headers .= "X-Mailer: PHP/" . phpversion(
  1002.                                                     );
  1003.                                                 if(@mail(
  1004.                                                     $shipFields['email'],
  1005.                                                     $subject,
  1006.                                                     $letter,
  1007.                                                     $headers
  1008.                                                 )
  1009.                                                 )
  1010.                                                 {
  1011.                                                 }
  1012.                                             }
  1013.                                         }
  1014.                                         if(!empty($settings['administratorEmail']))
  1015.                                         {
  1016.                                             if(empty($shipFields['address2']))
  1017.                                                 $shipFields['address2'] = '';
  1018.                                             $f = htmlspecialchars(
  1019.                                                 $shipFields['last_name']
  1020.                                             );
  1021.                                             $i = htmlspecialchars(
  1022.                                                 $shipFields['first_name']
  1023.                                             );
  1024.                                             $street1 = htmlspecialchars(
  1025.                                                 $shipFields['address1']
  1026.                                             );
  1027.                                             $street2 = htmlspecialchars(
  1028.                                                 $shipFields['address2']
  1029.                                             );
  1030.                                             $city = htmlspecialchars(
  1031.                                                 $shipFields['city']
  1032.                                             );
  1033.                                             $state = htmlspecialchars(
  1034.                                                 $shipFields['state']
  1035.                                             );
  1036.                                             $email = htmlspecialchars(
  1037.                                                 $shipFields['email']
  1038.                                             );
  1039.                                             $address = htmlspecialchars(
  1040.                                                 $shipFields['city'] . ' ' . (!empty($shipFields['state_prefix']) ? $shipFields['state_prefix'] : $shipFields['state']) . ', ' . $shipFields['zip']
  1041.                                             );
  1042.                                             $phone = htmlspecialchars(
  1043.                                                 $shipFields['phone1']
  1044.                                             );
  1045.                                             // админу
  1046.                                             $subject = "New order on site (" . $uri['domain'] . ")";
  1047.                                             $letter = "<br>";
  1048.                                             $letter .= "<h2>New order on site (" . $uri['domain'] . ")</h2>\r\n";
  1049.                                             $letter .= "<h2>Paid with the card</h2>\r\n";
  1050.                                             $letter .= "<h2>Order #" . $account_id . "</h2>\r\n";
  1051.                                             $letter .= "<p><b>First name</b>: " . $i . "</p>\r\n";
  1052.                                             $letter .= "<p><b>Last name</b>: " . $f . "</p>\r\n";
  1053.                                             $letter .= "<p><b>Street</b>: " . $street1 . "</p>\r\n";
  1054.                                             $letter .= "<p><b>Street2</b>: " . $street2 . "</p>\r\n";
  1055.                                             $letter .= "<p><b>City</b>: " . $city . "</p>\r\n";
  1056.                                             $letter .= "<p><b>State</b>: " . $state . "</p>\r\n";
  1057.                                             $letter .= "<p><b>Address</b>: " . $address . "</p>\r\n";
  1058.                                             $letter .= "<p><b>Phone</b>: " . $phone . "</p>\r\n";
  1059.                                             $letter .= "<br>----\r\n";
  1060.                                             $headers = 'MIME-Version: 1.0' . "\r\n";
  1061.                                             $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
  1062.                                             //$headers .= "From: Kartina-tv <no-reply@kartinatv.ru>\r\n";
  1063.                                             $headers .= "From: no-reply@kartinatv.ru\r\n";
  1064.                                             //$headers .= "From: no-reply@".$uri['domain']."\r\n";
  1065.                                             //$headers .= "Reply-To: info@".$uri['domain']."\r\n";
  1066.                                             $headers .= "X-Mailer: PHP/" . phpversion(
  1067.                                                 );
  1068.                                             if(@mail(
  1069.                                                 $settings['administratorEmail'],
  1070.                                                 $subject,
  1071.                                                 $letter,
  1072.                                                 $headers
  1073.                                             )
  1074.                                             )
  1075.                                             {
  1076.                                             }
  1077.                                         }
  1078.                                         if(!empty($is_abon_subscribe) && $is_abon_subscribe > 0)
  1079.                                         {
  1080.                                             exec_sql(
  1081.                                                 "UPDATE `" . $accounts_table . "` SET `subscribe`='1' WHERE `id`='" . $account_id . "';"
  1082.                                             );
  1083.                                             //send admin message about new subscription!!!
  1084.                                             if(!empty($settings['administratorEmail']))
  1085.                                             {
  1086.                                                 $subject = "New subscription order on site (" . $uri['domain'] . ")";
  1087.                                                 $letter = "<br>";
  1088.                                                 $letter .= "<h2>New order on site (" . $uri['domain'] . ")</h2>\r\n";
  1089.                                                 $letter .= "<h2>Subscription!!!</h2>\r\n";
  1090.                                                 $letter .= "<h2>Order #" . $account_id . "</h2>\r\n";
  1091.                                                 $letter .= "<br>----\r\n";
  1092.                                                 $headers = 'MIME-Version: 1.0' . "\r\n";
  1093.                                                 $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
  1094.                                                 //$headers .= "From: Kartina-tv <no-reply@kartinatv.ru>\r\n";
  1095.                                                 $headers .= "From: no-reply@kartinatv.ru\r\n";
  1096.                                                 $headers .= "X-Mailer: PHP/" . phpversion(
  1097.                                                     );
  1098.                                                 if(@mail(
  1099.                                                     $settings['administratorEmail'],
  1100.                                                     $subject,
  1101.                                                     $letter,
  1102.                                                     $headers
  1103.                                                 )
  1104.                                                 )
  1105.                                                 {
  1106.                                                 }
  1107.                                             }
  1108.                                         }
  1109.                                         // Чистим корзину
  1110.                                         $_SESSION['cart'] = [];
  1111.                                         $_SESSION['post'] = [];
  1112.                                         $_SESSION['order_details'] = $account_id;
  1113.                                         if(empty($tickets_numbers))
  1114.                                         {
  1115.                                             $out['payment_type'] = $payment_type;
  1116.                                             $out['html'] = '<form name="PaymentOkForm" action="" method="post"><input type="hidden" name="paymentOk" value="' . $account_id . '" /></form>';
  1117.                                             $out['form_name'] = 'PaymentOkForm';
  1118.                                             $out['error'] = 0;
  1119.                                         }
  1120.                                         else
  1121.                                         {
  1122.                                             $out['payment_type'] = $payment_type;
  1123.                                             $out['html'] = '<form name="PaymentOkForm" action="" method="post"><input type="hidden" name="paymentOkTicket" value="' . $tickets_number_mail . '" /></form>';
  1124.                                             $out['form_name'] = 'PaymentOkForm';
  1125.                                             $out['error'] = 0;
  1126.                                         }
  1127.                                     }
  1128.                                 }
  1129.                                 else
  1130.                                 {
  1131.                                     if(!empty($settings['administratorEmail']))
  1132.                                     {
  1133.                                         if(empty($shipFields['address2']))
  1134.                                             $shipFields['address2'] = '';
  1135.                                         $f = htmlspecialchars(
  1136.                                             $shipFields['last_name']
  1137.                                         );
  1138.                                         $i = htmlspecialchars(
  1139.                                             $shipFields['first_name']
  1140.                                         );
  1141.                                         $street1 = htmlspecialchars(
  1142.                                             $shipFields['address1']
  1143.                                         );
  1144.                                         $street2 = htmlspecialchars(
  1145.                                             $shipFields['address2']
  1146.                                         );
  1147.                                         $city = htmlspecialchars(
  1148.                                             $shipFields['city']
  1149.                                         );
  1150.                                         $state = htmlspecialchars(
  1151.                                             $shipFields['state']
  1152.                                         );
  1153.                                         $email = htmlspecialchars(
  1154.                                             $shipFields['email']
  1155.                                         );
  1156.                                         $address = htmlspecialchars(
  1157.                                             $shipFields['city'] . ' ' . (!empty($shipFields['state_prefix']) ? $shipFields['state_prefix'] : $shipFields['state']) . ', ' . $shipFields['zip']
  1158.                                         );
  1159.                                         $phone = htmlspecialchars(
  1160.                                             $shipFields['phone1']
  1161.                                         );
  1162.                                         // админу
  1163.                                         $subject = "New order on site - not paid (" . $uri['domain'] . ")";
  1164.                                         $letter = "<br>";
  1165.                                         $letter .= "<h2>New order on site - not paid (" . $uri['domain'] . ")</h2>\r\n";
  1166.                                         $letter .= "<h2>Order #" . $account_id . "</h2>\r\n";
  1167.                                         $letter .= "<p><b>First name</b>: " . $i . "</p>\r\n";
  1168.                                         $letter .= "<p><b>Last name</b>: " . $f . "</p>\r\n";
  1169.                                         $letter .= "<p><b>Street</b>: " . $street1 . "</p>\r\n";
  1170.                                         $letter .= "<p><b>Street2</b>: " . $street2 . "</p>\r\n";
  1171.                                         $letter .= "<p><b>City</b>: " . $city . "</p>\r\n";
  1172.                                         $letter .= "<p><b>State</b>: " . $state . "</p>\r\n";
  1173.                                         $letter .= "<p><b>Address</b>: " . $address . "</p>\r\n";
  1174.                                         $letter .= "<p><b>Phone</b>: " . $phone . "</p>\r\n";
  1175.                                         $letter .= "<br>----\r\n";
  1176.                                         $headers = 'MIME-Version: 1.0' . "\r\n";
  1177.                                         $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
  1178.                                         //$headers .= "From: Kartina-tv <no-reply@kartinatv.ru>\r\n";
  1179.                                         $headers .= "From: no-reply@kartinatv.ru\r\n";
  1180.                                         //$headers .= "From: no-reply@".$uri['domain']."\r\n";
  1181.                                         //$headers .= "Reply-To: info@".$uri['domain']."\r\n";
  1182.                                         $headers .= "X-Mailer: PHP/" . phpversion(
  1183.                                             );
  1184.                                         if(@mail(
  1185.                                             $settings['administratorEmail'],
  1186.                                             $subject,
  1187.                                             $letter,
  1188.                                             $headers
  1189.                                         )
  1190.                                         )
  1191.                                         {
  1192.                                         }
  1193.                                     }
  1194.                                     $out['errorString'] = 'Error';
  1195.                                     $out['error'] = 3;
  1196.                                     $_SESSION['cart_error'] = 1;
  1197.                                 }
  1198.                             }
  1199.                             else if($response_array[0] == 2)
  1200.                             {
  1201.                                 // no payed this order
  1202.                                 if(!empty($settings['administratorEmail']))
  1203.                                 {
  1204.                                     if(empty($shipFields['address2']))
  1205.                                         $shipFields['address2'] = '';
  1206.                                     $f = htmlspecialchars($shipFields['last_name']);
  1207.                                     $i = htmlspecialchars(
  1208.                                         $shipFields['first_name']
  1209.                                     );
  1210.                                     $street1 = htmlspecialchars(
  1211.                                         $shipFields['address1']
  1212.                                     );
  1213.                                     $street2 = htmlspecialchars(
  1214.                                         $shipFields['address2']
  1215.                                     );
  1216.                                     $city = htmlspecialchars($shipFields['city']);
  1217.                                     $state = htmlspecialchars($shipFields['state']);
  1218.                                     $email = htmlspecialchars($shipFields['email']);
  1219.                                     $address = htmlspecialchars(
  1220.                                         $shipFields['city'] . ' ' . (!empty($shipFields['state_prefix']) ? $shipFields['state_prefix'] : $shipFields['state']) . ', ' . $shipFields['zip']
  1221.                                     );
  1222.                                     $phone = htmlspecialchars(
  1223.                                         $shipFields['phone1']
  1224.                                     );
  1225.                                     // админу
  1226.                                     $subject = "New order on site - not paid (" . $uri['domain'] . ")";
  1227.                                     $letter = "<br>";
  1228.                                     $letter .= "<h2>New order on site - not paid (" . $uri['domain'] . ")</h2>\r\n";
  1229.                                     $letter .= "<h2>Order #" . $account_id . "</h2>\r\n";
  1230.                                     $letter .= "<p><b>First name</b>: " . $i . "</p>\r\n";
  1231.                                     $letter .= "<p><b>Last name</b>: " . $f . "</p>\r\n";
  1232.                                     $letter .= "<p><b>Street</b>: " . $street1 . "</p>\r\n";
  1233.                                     $letter .= "<p><b>Street2</b>: " . $street2 . "</p>\r\n";
  1234.                                     $letter .= "<p><b>City</b>: " . $city . "</p>\r\n";
  1235.                                     $letter .= "<p><b>State</b>: " . $state . "</p>\r\n";
  1236.                                     $letter .= "<p><b>Address</b>: " . $address . "</p>\r\n";
  1237.                                     $letter .= "<p><b>Phone</b>: " . $phone . "</p>\r\n";
  1238.                                     $letter .= "<br>----\r\n";
  1239.                                     $headers = 'MIME-Version: 1.0' . "\r\n";
  1240.                                     $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
  1241.                                     //$headers .= "From: Kartina-tv <no-reply@kartinatv.ru>\r\n";
  1242.                                     $headers .= "From: no-reply@kartinatv.ru\r\n";
  1243.                                     //$headers .= "From: no-reply@".$uri['domain']."\r\n";
  1244.                                     //$headers .= "Reply-To: info@".$uri['domain']."\r\n";
  1245.                                     $headers .= "X-Mailer: PHP/" . phpversion();
  1246.                                     if(@mail(
  1247.                                         $settings['administratorEmail'],
  1248.                                         $subject,
  1249.                                         $letter,
  1250.                                         $headers
  1251.                                     )
  1252.                                     )
  1253.                                     {
  1254.                                     }
  1255.                                 }
  1256.                                 $out['error'] = 2;
  1257.                                 $_SESSION['cart_error'] = 1;
  1258.                             }
  1259.                             else if($response_array[0] == 3)
  1260.                             {
  1261.                                 // error generated
  1262.                                 if(!empty($settings['administratorEmail']))
  1263.                                 {
  1264.                                     if(empty($shipFields['address2']))
  1265.                                         $shipFields['address2'] = '';
  1266.                                     $f = htmlspecialchars($shipFields['last_name']);
  1267.                                     $i = htmlspecialchars(
  1268.                                         $shipFields['first_name']
  1269.                                     );
  1270.                                     $street1 = htmlspecialchars(
  1271.                                         $shipFields['address1']
  1272.                                     );
  1273.                                     $street2 = htmlspecialchars(
  1274.                                         $shipFields['address2']
  1275.                                     );
  1276.                                     $city = htmlspecialchars($shipFields['city']);
  1277.                                     $state = htmlspecialchars($shipFields['state']);
  1278.                                     $email = htmlspecialchars($shipFields['email']);
  1279.                                     $address = htmlspecialchars(
  1280.                                         $shipFields['city'] . ' ' . (!empty($shipFields['state_prefix']) ? $shipFields['state_prefix'] : $shipFields['state']) . ', ' . $shipFields['zip']
  1281.                                     );
  1282.                                     $phone = htmlspecialchars(
  1283.                                         $shipFields['phone1']
  1284.                                     );
  1285.                                     // админу
  1286.                                     $subject = "New order on site - not paid (" . $uri['domain'] . ")";
  1287.                                     $letter = "<br>";
  1288.                                     $letter .= "<h2>New order on site - not paid (" . $uri['domain'] . ")</h2>\r\n";
  1289.                                     $letter .= "<h2>Order #" . $account_id . "</h2>\r\n";
  1290.                                     $letter .= "<p><b>First name</b>: " . $i . "</p>\r\n";
  1291.                                     $letter .= "<p><b>Last name</b>: " . $f . "</p>\r\n";
  1292.                                     $letter .= "<p><b>Street</b>: " . $street1 . "</p>\r\n";
  1293.                                     $letter .= "<p><b>Street2</b>: " . $street2 . "</p>\r\n";
  1294.                                     $letter .= "<p><b>City</b>: " . $city . "</p>\r\n";
  1295.                                     $letter .= "<p><b>State</b>: " . $state . "</p>\r\n";
  1296.                                     $letter .= "<p><b>Address</b>: " . $address . "</p>\r\n";
  1297.                                     $letter .= "<p><b>Phone</b>: " . $phone . "</p>\r\n";
  1298.                                     $letter .= "<br>----\r\n";
  1299.                                     $headers = 'MIME-Version: 1.0' . "\r\n";
  1300.                                     $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
  1301.                                     //$headers .= "From: Kartina-tv <no-reply@kartinatv.ru>\r\n";
  1302.                                     $headers .= "From: no-reply@kartinatv.ru\r\n";
  1303.                                     //$headers .= "From: no-reply@".$uri['domain']."\r\n";
  1304.                                     //$headers .= "Reply-To: info@".$uri['domain']."\r\n";
  1305.                                     $headers .= "X-Mailer: PHP/" . phpversion();
  1306.                                     if(@mail(
  1307.                                         $settings['administratorEmail'],
  1308.                                         $subject,
  1309.                                         $letter,
  1310.                                         $headers
  1311.                                     )
  1312.                                     )
  1313.                                     {
  1314.                                     }
  1315.                                 }
  1316.                                 $out['errorString'] = $response_array[3];
  1317.                                 $out['error'] = 3;
  1318.                                 $_SESSION['cart_error'] = 1;
  1319.                             }
  1320.                             else
  1321.                             {
  1322.                                 // unknown return error code
  1323.                                 if(!empty($settings['administratorEmail']))
  1324.                                 {
  1325.                                     if(empty($shipFields['address2']))
  1326.                                         $shipFields['address2'] = '';
  1327.                                     $f = htmlspecialchars($shipFields['last_name']);
  1328.                                     $i = htmlspecialchars(
  1329.                                         $shipFields['first_name']
  1330.                                     );
  1331.                                     $street1 = htmlspecialchars(
  1332.                                         $shipFields['address1']
  1333.                                     );
  1334.                                     $street2 = htmlspecialchars(
  1335.                                         $shipFields['address2']
  1336.                                     );
  1337.                                     $city = htmlspecialchars($shipFields['city']);
  1338.                                     $state = htmlspecialchars($shipFields['state']);
  1339.                                     $email = htmlspecialchars($shipFields['email']);
  1340.                                     $address = htmlspecialchars(
  1341.                                         $shipFields['city'] . ' ' . (!empty($shipFields['state_prefix']) ? $shipFields['state_prefix'] : $shipFields['state']) . ', ' . $shipFields['zip']
  1342.                                     );
  1343.                                     $phone = htmlspecialchars(
  1344.                                         $shipFields['phone1']
  1345.                                     );
  1346.                                     // админу
  1347.                                     $subject = "New order on site - not paid (" . $uri['domain'] . ")";
  1348.                                     $letter = "<br>";
  1349.                                     $letter .= "<h2>New order on site - not paid (" . $uri['domain'] . ")</h2>\r\n";
  1350.                                     $letter .= "<h2>Order #" . $account_id . "</h2>\r\n";
  1351.                                     $letter .= "<p><b>First name</b>: " . $i . "</p>\r\n";
  1352.                                     $letter .= "<p><b>Last name</b>: " . $f . "</p>\r\n";
  1353.                                     $letter .= "<p><b>Street</b>: " . $street1 . "</p>\r\n";
  1354.                                     $letter .= "<p><b>Street2</b>: " . $street2 . "</p>\r\n";
  1355.                                     $letter .= "<p><b>City</b>: " . $city . "</p>\r\n";
  1356.                                     $letter .= "<p><b>State</b>: " . $state . "</p>\r\n";
  1357.                                     $letter .= "<p><b>Address</b>: " . $address . "</p>\r\n";
  1358.                                     $letter .= "<p><b>Phone</b>: " . $phone . "</p>\r\n";
  1359.                                     $letter .= "<br>----\r\n";
  1360.                                     $headers = 'MIME-Version: 1.0' . "\r\n";
  1361.                                     $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
  1362.                                     //$headers .= "From: Kartina-tv <no-reply@kartinatv.ru>\r\n";
  1363.                                     $headers .= "From: no-reply@kartinatv.ru\r\n";
  1364.                                     //$headers .= "From: no-reply@".$uri['domain']."\r\n";
  1365.                                     //$headers .= "Reply-To: info@".$uri['domain']."\r\n";
  1366.                                     $headers .= "X-Mailer: PHP/" . phpversion();
  1367.                                     if(@mail(
  1368.                                         $settings['administratorEmail'],
  1369.                                         $subject,
  1370.                                         $letter,
  1371.                                         $headers
  1372.                                     )
  1373.                                     )
  1374.                                     {
  1375.                                     }
  1376.                                 }
  1377.                                 $out['error'] = 4;
  1378.                                 $_SESSION['cart_error'] = 1;
  1379.                             }
  1380.                         }
  1381.                         else if($payment_type == 2)
  1382.                         {
  1383.                             // PayPal Payment
  1384.                             // Генерим имя хоста для ответного запроса
  1385.                             $host = $uri['protocol'] . '://' . ((!empty($uri['language']['current']['urlname'])) ? $uri['language']['current']['urlname'] . '.' : '') . $uri['domain'];
  1386.                             // In this project, do not use the phone
  1387.                             $phone_array = [];
  1388.                             $phone = str_pad(
  1389.                                 preg_replace('#[^0-9]+#i', '', $shipFields['phone1']),
  1390.                                 10,
  1391.                                 " ",
  1392.                                 STR_PAD_LEFT
  1393.                             );
  1394.                             for($i = 0; $i < 3; $i++)
  1395.                             {
  1396.                                 $phone_array[] = trim(
  1397.                                     substr(
  1398.                                         $phone,
  1399.                                         -1 - ((3 - $i) * 3),
  1400.                                         $i == 2 ? 4 : 3
  1401.                                     )
  1402.                                 );
  1403.                             }
  1404.                             ////////!!!!!!!!!!!!!!!!!!!!!!/////
  1405.                             $_SESSION['not_paid_paypal_s'] = '1'; //add this for listing
  1406.                             $_SESSION['paypal_notpaid_order'] = $account_id;
  1407.                             if(empty($shipFields['address2']))
  1408.                                 $shipFields['address2'] = '';
  1409.                             $_SESSION['not_paid_paypal']['f'] = $shipFields['last_name'];
  1410.                             $_SESSION['not_paid_paypal']['i'] = $shipFields['first_name'];
  1411.                             $_SESSION['not_paid_paypal']['street_1'] = $shipFields['address1'];
  1412.                             $_SESSION['not_paid_paypal']['street_2'] = $shipFields['address2'];
  1413.                             $_SESSION['not_paid_paypal']['city'] = $shipFields['city'];
  1414.                             $_SESSION['not_paid_paypal']['state'] = $shipFields['state_prefix'];
  1415.                             $_SESSION['not_paid_paypal']['mail'] = $shipFields['email'];
  1416.                             ////////!!!!!!!!!!!!!!!!!!!!!!/////
  1417.                             $paypalFields = [
  1418.                                 "cmd" => "_xclick",
  1419.                                 "business" => $settings["pp_account_email"],
  1420.                                 // Receiver
  1421.                                 "lc" => "US",
  1422.                                 "button_subtype" => "services",
  1423.                                 "no_note" => 1,
  1424.                                 "no_shipping" => 1,
  1425.                                 "rm" => 2,
  1426.                                 "return" => $host . '/payapl_ok',
  1427.                                 "cancel_return" => $host . $module_cart['url'] . "?ro=" . $account_id,
  1428.                                 "notify_url" => $host . "/ajax/paypal.php",
  1429.                                 // сюда PayPal сделает запрос о подтвержении оплаты
  1430.                                 "currency_code" => $currency_todb,
  1431.                                 "item_name" => "Payment for services on the site " . $uri['domain'],
  1432.                                 "item_number" => $account_id,
  1433.                                 "amount" => number_format($cart_total, 2, '.', ''),
  1434.                                 // Сумму обязательно указываем именно в таком формате
  1435.                                 "first_name" => $shipFields['first_name'],
  1436.                                 "last_name" => $shipFields['last_name'],
  1437.                                 "address1" => $shipFields['address1'],
  1438.                                 "address2" => $shipFields['address2'],
  1439.                                 "city" => $shipFields['city'],
  1440.                                 "state" => $shipFields['state_prefix'],
  1441.                                 "zip" => $shipFields['zip'],
  1442.                                 "email" => "",
  1443.                                 "night_phone_a" => $phone_array[0],
  1444.                                 "night_phone_b" => $phone_array[1],
  1445.                                 "night_phone_c" => $phone_array[2],
  1446.                                 //"cpp_headerback_color" => "E5E5E5",
  1447.                                 //"cpp_headerborder_color" => "E5E5E5",
  1448.                                 //"cpp_payflow_color" => "E5E5E5",
  1449.                             ];
  1450.                             // Чистим корзину
  1451.                             $_SESSION['cart'] = [];
  1452.                             $_SESSION['post'] = [];
  1453.                             $postData = '<form name="PayPalForm" action="' . $settings['pp_redirect_ssl_url'] . '" method="post">' . "\r\n";
  1454.                             foreach($paypalFields as $field => $value)
  1455.                             {
  1456.                                 $postData .= '<input type="hidden" name="' . $field . '" value="' . htmlspecialchars(
  1457.                                         $value
  1458.                                     ) . '" />' . "\r\n";
  1459.                             }
  1460.                             $postData .= '</form>';
  1461.                             $out['payment_type'] = $payment_type;
  1462.                             $out['html'] = $postData;
  1463.                             $out['form_name'] = 'PayPalForm';
  1464.                             $out['error'] = 0;
  1465.                         }
  1466.                         else if($payment_type == 5)
  1467.                         {
  1468.                             $price = $cart_total;
  1469.                             $count = 1;
  1470.                             // Мыльники отправим тогда когда получим от Yandex подтверждение об оплате см. /ajax/yandex.php
  1471.                             $cart_total_y = number_format(($price * $count), 2, '.', '');
  1472.                             $yandex_total = number_format(
  1473.                                 ($cart_total_y * $settings['rur_course_yandex'] + (($cart_total_y * $settings['rur_course_yandex']) * 0.005)),
  1474.                                 2,
  1475.                                 ".",
  1476.                                 ""
  1477.                             );
  1478.                             //print number_format( ( $price * $count ), 2, '.', '' );
  1479.                             $postFields = [
  1480.                                 "receiver" => $settings['yd_key'],
  1481.                                 "formcomment" => "Пополнение счета Kartina-Tv",
  1482.                                 "short-dest" => "Kartina-Tv",
  1483.                                 "writable-targets" => "false",
  1484.                                 "quickpay-form" => "shop",
  1485.                                 "targets" => "Пополнение счета Kartina-Tv",
  1486.                                 "label" => $account_id,
  1487.                                 "sum" => $yandex_total,
  1488.                                 // Сумму обязательно указываем именно в таком формате
  1489.                             ];
  1490.                             $_SESSION['cart'] = [];
  1491.                             $_SESSION['post'] = [];
  1492.                             $postData = '<form name="YandexForm" action="https://money.yandex.ru/quickpay/confirm.xml" method="post">' . "\r\n";
  1493.                             foreach($postFields as $field => $value)
  1494.                             {
  1495.                                 $postData .= '<input type="hidden" name="' . $field . '" value="' . htmlspecialchars(
  1496.                                         $value
  1497.                                     ) . '" />' . "\r\n";
  1498.                             }
  1499.                             $postData .= '</form>';
  1500.                             $out['payment_type'] = $payment_type;
  1501.                             $out['html'] = $postData;
  1502.                             $out['form_name'] = 'YandexForm';
  1503.                             $out['error'] = 0;
  1504.                         }
  1505.                         else
  1506.                         {
  1507.                             $account = get_fields(
  1508.                                 $accounts_table,
  1509.                                 " WHERE `id`='" . $account_id . "';"
  1510.                             );
  1511.                             $account['status'] = $account['status'] | 3;
  1512.                             exec_sql(
  1513.                                 "UPDATE `" . $accounts_table . "` SET `status`='" . $account['status'] . "' WHERE `id`='" . $account_id . "';"
  1514.                             );
  1515.                             if(!empty($settings['administratorEmail']))
  1516.                             {
  1517.                                 if(empty($shipFields['address2']))
  1518.                                     $shipFields['address2'] = '';
  1519.                                 $f = htmlspecialchars($shipFields['last_name']);
  1520.                                 $i = htmlspecialchars($shipFields['first_name']);
  1521.                                 $street1 = htmlspecialchars($shipFields['address1']);
  1522.                                 $street2 = htmlspecialchars($shipFields['address2']);
  1523.                                 $city = htmlspecialchars($shipFields['city']);
  1524.                                 $state = htmlspecialchars($shipFields['state']);
  1525.                                 $email = htmlspecialchars($shipFields['email']);
  1526.                                 $address = htmlspecialchars(
  1527.                                     $shipFields['city'] . ' ' . (!empty($shipFields['state_prefix']) ? $shipFields['state_prefix'] : $shipFields['state']) . ', ' . $shipFields['zip']
  1528.                                 );
  1529.                                 $phone = htmlspecialchars($shipFields['phone1']);
  1530.                                 // админу
  1531.                                 $subject = "New order on site (" . $uri['domain'] . ")";
  1532.                                 $letter = "<br>";
  1533.                                 $letter .= "<h2>New order on site (" . $uri['domain'] . ")</h2>\r\n";
  1534.                                 $letter .= "<h2>Paid with the card</h2>\r\n";
  1535.                                 $letter .= "<h2>Order #" . $account_id . "</h2>\r\n";
  1536.                                 $letter .= "<p><b>First name</b>: " . $i . "</p>\r\n";
  1537.                                 $letter .= "<p><b>Last name</b>: " . $f . "</p>\r\n";
  1538.                                 $letter .= "<p><b>Street</b>: " . $street1 . "</p>\r\n";
  1539.                                 $letter .= "<p><b>Street2</b>: " . $street2 . "</p>\r\n";
  1540.                                 $letter .= "<p><b>City</b>: " . $city . "</p>\r\n";
  1541.                                 $letter .= "<p><b>State</b>: " . $state . "</p>\r\n";
  1542.                                 $letter .= "<p><b>Address</b>: " . $address . "</p>\r\n";
  1543.                                 $letter .= "<p><b>Phone</b>: " . $phone . "</p>\r\n";
  1544.                                 $letter .= "<br>----\r\n";
  1545.                                 $headers = 'MIME-Version: 1.0' . "\r\n";
  1546.                                 $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
  1547.                                 //$headers .= "From: Kartina-tv <no-reply@kartinatv.ru>\r\n";
  1548.                                 $headers .= "From: no-reply@kartinatv.ru\r\n";
  1549.                                 //$headers .= "From: no-reply@".$uri['domain']."\r\n";
  1550.                                 //$headers .= "Reply-To: info@".$uri['domain']."\r\n";
  1551.                                 $headers .= "X-Mailer: PHP/" . phpversion();
  1552.                                 if(@mail(
  1553.                                     $settings['administratorEmail'],
  1554.                                     $subject,
  1555.                                     $letter,
  1556.                                     $headers
  1557.                                 )
  1558.                                 )
  1559.                                 {
  1560.                                 }
  1561.                             }
  1562.                             // Чистим корзину
  1563.                             $_SESSION['cart'] = [];
  1564.                             $_SESSION['post'] = [];
  1565.                             $out['html'] = '<form name="PaymentOkForm" action="" method="post"><input type="hidden" name="paymentOk" value="' . $account_id . '" /><input type="hidden" name="paymentOklayaway" value="1" /></form>';
  1566.                             $out['form_name'] = 'PaymentOkForm';
  1567.                             $out['error'] = 0;
  1568.                         }
  1569.                     }
  1570.                     else
  1571.                     {
  1572.                         $out['shipFields'] = $shipFields;
  1573.                         $out['shipErrors'] = $shipErrors;
  1574.                         $out['billFields'] = $billFields;
  1575.                         $out['billErrors'] = $billErrors;
  1576.                         $out['error'] = 1;
  1577.                     }
  1578.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement