コード例 #1
0
<?php

/**
 * User: Hossein Moradgholi
 * Date: 10/25/15
 * Time: 12:01 AM
 */
error_reporting(E_ERROR);
use Fisharebest\ExtCalendar\GregorianCalendar;
use Fisharebest\ExtCalendar\PersianCalendar;
use Nikapps\BatchPayment\Paya\PayaCollection;
use Nikapps\BatchPayment\Paya\PayaPayment;
use Nikapps\BatchPayment\Paya\PayaPaymentInfo;
require "../vendor/autoload.php";
$payaCollection = new PayaCollection();
$payaPaymentInfo = new PayaPaymentInfo();
$persianCalendar = new PersianCalendar();
$gregorianCalendar = new GregorianCalendar();
$requestDateTime = implode('-', $persianCalendar->jdToYmd($gregorianCalendar->ymdToJd(date('Y'), date('m'), date('d')))) . "T" . date('H:i:s');
$payaPaymentInfo->setRequestDate($requestDateTime);
$payaPaymentInfo->setPayerIban('IR360560080133100002001001940612002');
$payaPaymentInfo->setPayerName('نام من');
$payaPayment = new PayaPayment();
$payaPayment->setAmount(2080000);
$payaPayment->setCreditorIban('IR020540110180001974695003');
$payaPayment->setCreditorName('امیرحسین صادقی');
$payaPayment->setDescription('تست سیستم');
$payaPaymentInfo->addPayment($payaPayment);
$payaCollection->setPayaPaymentInfo($payaPaymentInfo);
$payaCollection->exportXml();
コード例 #2
0
ファイル: BazaarPush.php プロジェクト: nikapps/bazaar-push
 /**
  * This will process a single account and checks for new sales.
  * @param $email
  * @param $password
  * @throws BazaarPushException
  */
 public function processAccountSale($email, $password)
 {
     $ch = curl_init($this->urls['loginPage']);
     // creating a temporary cookie file
     $cookiefile = tempnam("/tmp", "cookie");
     curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_TIMEOUT, 10);
     $resultOfLoginPage = curl_exec($ch);
     $cookieInfo = curl_getinfo($ch);
     if ($cookieInfo['http_code'] != 200) {
         throw new BazaarPushException("Could not reach bazaar login page.");
     }
     // fetching CSRF key from login page
     preg_match_all($this->patterns['csrfKey'], $resultOfLoginPage, $loginPageMatches);
     $fields = ['csrfmiddlewaretoken' => $loginPageMatches[1][0], 'email' => $email, 'password' => $password, 'login' => 1, 'newsletter' => 'newsletter', 'agree' => 'agree'];
     $headers = ['Referer: ' . $this->urls['loginPage'], 'Origin: ' . $this->urls['loginPage'], 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36'];
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_exec($ch);
     // disabling post flag
     curl_setopt($ch, CURLOPT_POST, 0);
     // going to pardakht section
     curl_setopt($ch, CURLOPT_URL, $this->urls['paymentPage']);
     curl_exec($ch);
     // fetching latest sales list
     curl_setopt($ch, CURLOPT_URL, $this->urls['paymentsList']);
     $sales = curl_exec($ch);
     preg_match_all($this->patterns['paymentList'], $sales, $salesMatches);
     // removing the headers, kind a lazy :)
     unset($salesMatches[1][0]);
     $newSalePrice = 0;
     $newSaleItems = [];
     $totalNewItems = 0;
     foreach ($salesMatches[1] as $row) {
         preg_match_all($this->patterns['paymentItem'], $row, $rowMatches);
         $date = $rowMatches[3][0];
         $date = $this->endigit($date);
         list($year, $month, $day) = explode("/", $date);
         $jalaliCalender = new PersianCalendar();
         list($gYear, $gMonth, $gDay) = $jalaliCalender->ymdToJd($year, $month, $day);
         $time = $rowMatches[4][0];
         $time = $this->endigit($time);
         list($hour, $minute, $second) = explode(":", $time);
         $token = $rowMatches[6][0];
         if (!count(BazaarSale::where('token', '=', $token)->get())) {
             $bazaarSale = new BazaarSale();
             $bazaarSale->email = $rowMatches[1][0];
             $bazaarSale->account = $email;
             $bazaarSale->package = $rowMatches[2][0];
             $bazaarSale->date = "{$gYear}-{$gMonth}-{$gDay} {$hour}:{$minute}:{$second}";
             $bazaarSale->price = intval($this->endigit(str_replace("٬", "", $rowMatches[5][0])));
             $bazaarSale->token = $token;
             $bazaarSale->save();
             if (!isset($newSaleItems[$bazaarSale->package])) {
                 $newSaleItems[$bazaarSale->package] = 0;
             }
             $newSaleItems[$bazaarSale->package]++;
             $newSalePrice += $bazaarSale->price;
             $totalNewItems++;
         }
     }
     if ($newSalePrice > 0) {
         $reportTemplates = $this->getReportTemplates();
         $reportAdapter = ["[[[--TOTAL-NEW-SALE--]]]" => number_format($newSalePrice), "[[[--TOTAL-NEW-ITEMS--]]]" => number_format($totalNewItems), "[[[--BAZAAR-ACCOUNT--]]]" => $email, "[[[--ITEMS-REPORT--]]]" => print_r($newSaleItems, 1)];
         $reportTitle = $reportTemplates['newSaleReport']['title'];
         $reportBody = $reportTemplates['newSaleReport']['body'];
         foreach ($reportAdapter as $key => $item) {
             $reportTitle = str_replace($key, $item, $reportTitle);
             $reportBody = str_replace($key, $item, $reportBody);
         }
         $this->pushReport($reportTitle, $reportBody, $email);
     }
 }