示例#1
0
 public static function fromJson($json)
 {
     if (!isset($json->item) && !isset($json->checkout)) {
         throw new \Exception('both checkout and item are null');
     }
     if (isset($json->item) && isset($json->checkout)) {
         throw new \Exception('both checkout and item are non-null, only expected one of checkout or item');
     }
     $r = new Transaction();
     $r->setId($json->id);
     $r->setExternalId(isset($json->external_id) ? $json->external_id : null);
     $r->setCreated($json->created);
     $r->setState($json->state);
     $r->setRevisionNumber($json->revision_number);
     $r->setProject($json->project);
     $r->setItem(isset($json->item) ? Item::fromJson($json->item) : null);
     $r->setCheckout(isset($json->checkout) ? Checkout::fromJson($json->checkout) : null);
     $r->setCustomer(Customer::fromJson($json->customer));
     $r->setPrice(Price::fromJson($json->price));
     $r->setPaymentMethod($json->payment_method);
     $r->setTest(isset($json->test) ? $json->test : false);
     return $r;
 }
 public function testRollback_NoTransactionCapability_ThrowsException()
 {
     $this->client = $this->getMock('Everyman\\Neo4j\\Client', array('hasCapability'), array($this->transport));
     $this->client->expects($this->any())->method('hasCapability')->will($this->returnValue(false));
     $transaction = new Transaction($this->client);
     $transaction->setId(321);
     $this->transport->expects($this->never())->method('delete');
     $this->setExpectedException('\\Everyman\\Neo4j\\Exception');
     $this->client->rollbackTransaction($transaction);
 }
示例#3
0
 /**
  * Verifica se uma notificação IPN é válida, fazendo a autenticação
  * da mensagem segundo o protocolo de segurança do serviço.
  *
  * @param array $message Um array contendo a notificação recebida.
  * @return boolean TRUE se a notificação for autência, ou FALSE se não for.
  *
  */
 function handleIpn(array $message)
 {
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $this->endpoint);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curl, CURLOPT_POST, true);
     curl_setopt($curl, CURLOPT_SSLVERSION, 6);
     //curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
     //curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
     curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($message));
     $response = curl_exec($curl);
     $error = curl_error($curl);
     $errno = curl_errno($curl);
     curl_close($curl);
     if (!empty($error) || $errno > 0 || $response != 'VERIFIED') {
         return array('error' => 'Not verified', 'errors' => $error);
     }
     if ($_POST['receiver_email'] != $this->getReceiverEmail()) {
         return array('error' => 'Receiver mail is different', 'errors' => array('expected' => $this->receiverEmail, 'returned' => $_POST['receiver_email']));
     }
     $arr = array_merge(array('txn_id' => null, 'txn_type' => null, 'payment_status' => null, 'pending_reason' => null, 'reason_code' => null, 'custom' => null, 'invoice' => null, 'address_country' => null, 'address_city' => null, 'address_country_code' => null, 'address_name' => null, 'address_state' => null, 'address_status' => null, 'address_street' => null, 'address_zip' => null, 'contact_phone' => null, 'first_name' => null, 'last_name' => null, 'business_name' => null, 'payer_email' => null, 'payer_id' => null, 'mc_currency' => null, 'mc_gross' => null, 'mc_fee' => null, 'mc_handling' => null, 'mc_shipping' => null, 'tax' => null), $message);
     //$this->ipnLog("....");
     //$this->ipnLog(json_encode($arr));
     $notification = new Notification();
     $notification->setTxnId($arr['txn_id']);
     $notification->setTxnType($arr['txn_type']);
     $notification->setReceiverEmail($arr['receiver_email']);
     $notification->setPaymentStatus($arr['payment_status']);
     $notification->setPendingReason($arr['pending_reason']);
     $notification->setReasonCode($arr['reason_code']);
     $notification->setCustom($arr['custom']);
     $notification->setInvoice($arr['invoice']);
     $customer = new Customer();
     $customer->setAddressCountry($arr['address_country']);
     $customer->setAddressCity($arr['address_city']);
     $customer->setAddressCountryCode($arr['address_country_code']);
     $customer->setAddressName($arr['address_name']);
     $customer->setAddressState($arr['address_state']);
     $customer->setAddressStatus($arr['address_status']);
     $customer->setAddressStreet($arr['address_street']);
     $customer->setAddressZip($arr['address_zip']);
     $customer->setContactPhone($arr['contact_phone']);
     $customer->setFirstName($arr['first_name']);
     $customer->setLastName($arr['last_name']);
     $customer->setBusinessName($arr['business_name']);
     $customer->setEmail($arr['payer_email']);
     $customer->setPaypalId($arr['payer_id']);
     $transaction = new Transaction();
     $transaction->setId(null);
     $transaction->setTxnId($arr['txn_id']);
     $transaction->setTxnType($arr['txn_type']);
     $transaction->setPaymentStatus($arr['payment_status']);
     $transaction->setPendingReason($arr['pending_reason']);
     $transaction->setReasonCode($arr['reason_code']);
     $transaction->setCustom($arr['custom']);
     $transaction->setInvoice($arr['invoice']);
     $transaction->setPayerId($arr['payer_id']);
     $transaction->setCurrency($arr['mc_currency']);
     $transaction->setGross($arr['mc_gross']);
     $transaction->setFee($arr['mc_fee']);
     $transaction->setHandling($arr['mc_handling']);
     $transaction->setShipping($arr['mc_shipping']);
     $transaction->setTax($arr['tax']);
     return array('notification' => $notification, 'customer' => $customer, 'transaction' => $transaction);
 }
  static public function retrieveByClient($status, $client_id = null)
  {
//echo $status;
    $types= array('all','sell','purchase','switch');
    $statuses= array('all','pending','completed','cancelled');    
    if(!in_array($status,$statuses))
    if(!in_array($status,$types))    
      die('Wrong status when getting tranaction collection!');
    $IsTypeOriented = in_array($status,$statuses) ? false: true;
    if(!$client_id)
      die('Should add case for all clients!');


    $transactions= array();
    if($IsTypeOriented)
      $addition = ($status!= 'all') ? " AND types = '$status'" : "";
    else
      $addition = ($status!= 'all') ? " AND status = '$status'" : "";
      
    $query = " SELECT t.id, t.created_at, t.comment_user, t.comment_admin, a.name aname, i.fund_name name,
    i.ISIN code, t.status, t.types, t.amount1  FROM transactions t, custody_ac a, fund i
    WHERE t.id_client = '$client_id' AND a.id = t.id_account AND i.id = t.id_isin1 $addition ";
    
//echo $query;

    $qres=mysql_query($query) or die(mysql_error());
    while($row=mysql_fetch_assoc($qres))
    {
      if(trim($row['id_isin2']))
      {
        $query = " SELECT name, code FROM isin WHERE id = '".trim($row['id_isin2'])."' LIMIT 1";
        //die($query);
        $qres1=mysql_query($query);
        $crow=mysql_fetch_assoc($qres1);
      }


      $transaction = new Transaction();
      $transaction->setId($row['id']);
      $transaction->setStatus($row['status']);
      $transaction->setType($row['types']);
      $transaction->setCommentUser($row['comment_user']);
      $transaction->setCommentAdmin($row['comment_admin']);
      $transaction->setSecurity1($row['name']);
      $transaction->setAmount1($row['amount1']);
      $transaction->setSecurity2($crow['name']?$crow['name']:0);
      $transaction->setAmount2($row['amount2']);
      $transaction->setIsin($row['code']);
      $transaction->setIsin2($crow['code']);
      $transaction->setAccount($row['aname']);
      $transaction->setDatetime($row['created_at']);
      $transactions[] = $transaction;

    }

    return $transactions;
  }