Jump to content

problem connecting a cms to gateway


omidas

Recommended Posts

hi,
i`m trying to connect a cms to a gateway but in my  country i cant use paypal or any other known gateways so i use a local bank for payments .
i want to change cms`s paypal gateway to the local one these are the sample codes they gave me
:  sender.php

  
<?php     function send($url,$api,$amount,$redirect){         $ch = curl_init();         curl_setopt($ch,CURLOPT_URL,$url);         curl_setopt($ch,CURLOPT_POSTFIELDS,"api=$api&amount=$amount&redirect=$redirect");         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);         curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);         $res = curl_exec($ch);         curl_close($ch);         return $res;     }     function get($url,$api,$trans_id,$id_get){         $ch = curl_init();         curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_POSTFIELDS,"api=$api&id_get=$id_get&trans_id=$trans_id");         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);         curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);         $res = curl_exec($ch);         curl_close($ch);         return $res;     } ?>   


:   send.php

<?php     include_once("sender.php");     $url = 'http://payline.ir/payment/gateway-send';     $api = ' Your-API ';     $amount = 1000;     $redirect = 'REDIRECT-PAGE';     $result = send($url,$api,$amount,$redirect);     if($result > 0 && is_numeric($result)){         $go = "http://payline.ir/payment/gateway-$result";         header("Location: $go");     } ?>  
[php]
:  get.php


<?php     include_once("sender.php");     $url = 'http://payline.ir/payment/gateway-result-second';     $api = ' Your-API';     $trans_id = $_POST['trans_id'];     $id_get = $_POST['id_get'];     $result = get($url,$api,$trans_id,$id_get); ?> [/php]

and this one is for cms `s paypal gate way

  define("_VALID_PHP", true);
  define("_PIPN", true);


  ini_set('log_errors', true);
  ini_set('error_log', dirname(__file__) . '/ipn_errors.log');

  if (isset($_POST['payment_status'])) {
      require_once ("../../init.php");
      require_once (BASEPATH . "lib/class_pp.php");

      $pp = Core::getRow(Membership::gTable, "name", "paypal");

      $listener = new IpnListener();
      $listener->use_live = $pp->live;
      $listener->use_ssl = true;
      $listener->use_curl = false;

      try {
          $listener->requirePostMethod();
          $ppver = $listener->processIpn();
      }
      catch (exception $e) {
          error_log($e->getMessage(), 3, "pp_errorlog.log");
          exit(0);
      }

      $payment_status = $_POST['payment_status'];
      $receiver_email = $_POST['business'];
      $mc_currency = $_POST['mc_currency'];
      list($membership_id, $user_id) = explode("_", $_POST['item_number']);
      $mc_gross = $_POST['mc_gross'];
      $txn_id = $_POST['txn_id'];

      $getxn_id = Core::verifyTxnId($txn_id);
      $price = getValueById("price", Membership::mTable, intval($membership_id));
      $v1 = compareFloatNumbers($mc_gross, $price, "=");

      if ($ppver) {
          if ($_POST['payment_status'] == 'Completed') {
              if ($receiver_email == $pp->extra && $v1 == true && $getxn_id == true) {
                  $sql = "SELECT * FROM " . Membership::mTable . " WHERE id=" . (int)$membership_id;
                  $row = $db->first($sql);

                  $username = getValueById("username", Users::uTable, (int)$user_id);

                  $data = array(
                      'txn_id' => $txn_id,
                      'membership_id' => $row->id,
                      'user_id' => (int)$user_id,
                      'rate_amount' => (float)$mc_gross,
                      'ip' => $_SERVER['REMOTE_ADDR'],
                      'date' => "NOW()",
                      'pp' => "PayPal",
                      'currency' => sanitize($mc_currency),
                      'status' => 1);

                  $db->insert(Membership::pTable, $data);

                  $udata = array(
                      'membership_id' => $row->id,
                      'mem_expire' => $user->calculateDays($row->id),
                      'trial_used' => ($row->trial == 1) ? 1 : 0,
                      'memused' => 1);

                  $db->update(Users::uTable, $udata, "id=" . (int)$user_id);

                  /* == Notify Administrator == */
                  require_once (BASEPATH . "lib/class_mailer.php");
                  $row2 = Core::getRowById(Content::eTable, 5);

                  $body = str_replace(array(
                      '[uSERNAME]',
                      '[iTEMNAME]',
                      '[PRICE]',
                      '[sTATUS]',
                      '[PP]',
                      '[iP]'), array(
                      $username,
                      $row->{'title' . Lang::$lang},
                      $core->formatMoney($mc_gross),
                      "Completed",
                      "PayPal",
                      $_SERVER['REMOTE_ADDR']), $row2->{'body' . Lang::$lang}
                      );

                  $newbody = cleanOut($body);

                  $mailer = Mailer::sendMail();
                  $message = Swift_Message::newInstance()
                            ->setSubject($row2->{'subject' . Lang::$lang})
                            ->setTo(array($core->site_email => $core->site_name))
                            ->setFrom(array($core->site_email => $core->site_name))
                            ->setBody($newbody, 'text/html');

                  $mailer->send($message);
                  Security::writeLog($username . ' ' . Lang::$word->_LG_PAYMENT_OK . ' ' . $row->{'title' . Lang::$lang}, "", "yes", "payment");
              }

          } else {
              /* == Failed Transaction= = */
              require_once (BASEPATH . "lib/class_mailer.php");
              $row2 = Core::getRowById(Content::eTable, 6);
              $itemname = getValueById("title" . Lang::$lang, Membership::mTable, $membership_id);
              $username = getValueById("username", Users::uTable, (int)$user_id);

              $body = str_replace(array(
                  '[uSERNAME]',
                  '[iTEMNAME]',
                  '[PRICE]',
                  '[sTATUS]',
                  '[PP]',
                  '[iP]'), array(
                  $username,
                  $itemname,
                  $core->formatMoney($mc_gross),
                  "Failed",
                  "PayPal",
                  $_SERVER['REMOTE_ADDR']), $row2->{'body' . Lang::$lang}
                  );

              $newbody = cleanOut($body);

              $mailer = $mail->sendMail();
              $message = Swift_Message::newInstance()
                        ->setSubject($row2->{'subject' . Lang::$lang})
                        ->setTo(array($core->site_email => $core->site_name))
                        ->setFrom(array($core->site_email => $core->site_name))
                        ->setBody($newbody, 'text/html');

              $mailer->send($message);

              Security::writeLog(Lang::$word->_LG_PAYMENT_ERR . $username, "", "yes", "payment");

          }
      }
  }
?>


i`ll be grateful if you help me on this

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.