Author: Nick Sagona, III (nick@popphp.org)
Exemple #1
0
 /**
  * Send transaction
  *
  * @param  boolean $verifyPeer
  * @return void
  */
 public function send($verifyPeer = true)
 {
     $this->buildRateRequest();
     $options = array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => $this->accessRequest . $this->rateRequest, CURLOPT_HEADER => false);
     if (!$verifyPeer) {
         $options[CURLOPT_SSL_VERIFYPEER] = false;
     }
     $curl = new Curl($this->url, $options);
     $curl->execute();
     $this->response = simplexml_load_string($curl->getBody());
     $this->responseCode = (int) $this->response->Response->ResponseStatusCode;
     if ($this->responseCode == 1) {
         $this->responseMessage = (string) $this->response->Response->ResponseStatusDescription;
         foreach ($this->response->RatedShipment as $rate) {
             $this->rates[self::$services[(string) $rate->Service->Code]] = (string) $rate->TotalCharges->MonetaryValue;
         }
     } else {
         $this->responseCode = (string) $this->response->Response->Error->ErrorCode;
         $this->responseMessage = (string) $this->response->Response->Error->ErrorDescription;
     }
 }
Exemple #2
0
 /**
  * Send transaction
  *
  * @param  boolean $verifyPeer
  * @throws Exception
  * @return void
  */
 public function send($verifyPeer = true)
 {
     if (!$this->validate()) {
         throw new Exception('The required transaction data has not been set.');
     }
     $url = $this->test ? $this->testUrl : $this->liveUrl;
     $url .= '?' . $this->buildQueryString();
     $options = array(CURLOPT_HEADER => false);
     if (!$verifyPeer) {
         $options[CURLOPT_SSL_VERIFYPEER] = false;
     }
     $curl = new Curl($url, $options);
     $this->response = $curl->execute();
     $this->responseCodes = $this->parseResponseCodes();
     $this->responseCode = $this->responseCodes['Result'];
     $this->message = $this->responseCodes['RespMSG'];
     switch ($this->message) {
         case 'Approved':
             $this->approved = true;
             break;
         case 'Declined':
             $this->declined = true;
             break;
     }
     if ($this->responseCode > 0) {
         $this->error = true;
     }
 }
 /**
  * Send transaction
  *
  * @param  boolean $verifyPeer
  * @throws Exception
  * @return void
  */
 public function send($verifyPeer = true)
 {
     if (!$this->validate()) {
         throw new Exception('The required transaction data has not been set.');
     }
     $url = $this->test ? $this->testUrl : $this->liveUrl;
     $options = array(CURLOPT_HEADER => false, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $this->buildPostString());
     if (!$verifyPeer) {
         $options[CURLOPT_SSL_VERIFYPEER] = false;
     }
     $curl = new Curl($url, $options);
     $this->response = $curl->execute();
     $this->responseCodes = $this->parseResponseCodes();
     $this->responseCode = $this->responseCodes['UMerrorcode'];
     $this->message = $this->responseCodes['UMerror'];
     switch ($this->responseCodes['UMstatus']) {
         case 'Approved':
             $this->approved = true;
             break;
         case 'Declined':
             $this->declined = true;
             break;
         case 'Error':
             $this->error = true;
             break;
     }
 }
Exemple #4
0
 /**
  * Send transaction
  *
  * @param  boolean $verifyPeer
  * @throws Exception
  * @return void
  */
 public function send($verifyPeer = true)
 {
     if (null === $this->transaction['IPADDRESS']) {
         $this->transaction['IPADDRESS'] = $_SERVER['REMOTE_ADDR'];
     }
     if (!$this->validate()) {
         throw new Exception('The required transaction data has not been set.');
     }
     $url = $this->test ? $this->testUrl : $this->liveUrl;
     $options = array(CURLOPT_HEADER => false, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $this->buildPostString());
     if (!$verifyPeer) {
         $options[CURLOPT_SSL_VERIFYPEER] = false;
     }
     $curl = new Curl($url, $options);
     $this->response = $curl->execute();
     $this->responseCodes = $this->parseResponseCodes();
     if (stripos($this->responseCodes['ACK'], 'Success') !== false) {
         $this->approved = true;
         $this->message = 'The transaction has been approved.';
     } else {
         if (isset($this->responseCodes['L_SHORTMESSAGE0']) && stripos($this->responseCodes['L_SHORTMESSAGE0'], 'Decline') !== false) {
             $this->declined = true;
         }
         if (isset($this->responseCodes['L_SEVERITYCODE0']) && stripos($this->responseCodes['L_SEVERITYCODE0'], 'Error') !== false) {
             $this->error = true;
         }
         if (isset($this->responseCodes['L_LONGMESSAGE0'])) {
             $this->message = $this->responseCodes['L_LONGMESSAGE0'];
         }
     }
 }
Exemple #5
0
<?php

require_once '../../bootstrap.php';
use Pop\Curl\Curl;
try {
    $curl = new Curl('http://pop.localhost/examples/curl/curl-process.php');
    $curl->setPost(true);
    $curl->setFields(array('name' => 'Bubba', 'email' => '*****@*****.**'));
    $curl->execute();
    echo $curl->getBody();
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
Exemple #6
0
 /**
  * Send transaction
  *
  * @param  boolean $verifyPeer
  * @return void
  */
 public function send($verifyPeer = true)
 {
     $this->buildRequest();
     $url = ($this->testMode ? $this->testUrl : $this->liveUrl) . rawurlencode($this->request);
     $options = array(CURLOPT_HEADER => false);
     if (!$verifyPeer) {
         $options[CURLOPT_SSL_VERIFYPEER] = false;
     }
     $curl = new Curl($url, $options);
     $curl->execute();
     $this->response = simplexml_load_string($curl->getBody());
     if (isset($this->response->Package)) {
         $this->responseCode = 1;
         foreach ($this->response->Package->Postage as $rate) {
             $this->rates[str_replace(array('&lt;', '&gt;'), array('<', '>'), (string) $rate->MailService)] = (string) $rate->Rate;
         }
         $this->rates = array_reverse($this->rates, true);
     } else {
         if (isset($this->response->Number)) {
             $this->responseCode = (string) $this->response->Number;
             $this->responseMessage = (string) $this->response->Description;
         } else {
             $this->responseCode = 0;
         }
     }
 }
Exemple #7
0
 public function testCurlError()
 {
     $c = new Curl('http://badurl/', array(CURLOPT_RETURNTRANSFER => false));
     $this->setExpectedException('Pop\\Curl\\Exception');
     $c->execute();
 }
Exemple #8
0
 /**
  * Send transaction
  *
  * @param  boolean $verifyPeer
  * @throws Exception
  * @return void
  */
 public function send($verifyPeer = true)
 {
     if (!$this->validate()) {
         throw new Exception('The required transaction data has not been set.');
     }
     $this->transaction['demo'] = $this->test ? 'y' : 'n';
     $options = array(CURLOPT_HEADER => false, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $this->buildPostString());
     if (!$verifyPeer) {
         $options[CURLOPT_SSL_VERIFYPEER] = false;
     }
     $curl = new Curl($this->url, $options);
     $this->response = $curl->execute();
     $this->responseCodes = $this->parseResponseCodes();
     $this->responseCode = isset($this->responseCodes['transid']) ? $this->responseCodes['transid'] : null;
     $this->message = $this->responseCodes['status'];
     switch ($this->responseCodes['status']) {
         case 'approved':
             $this->approved = true;
             break;
         case 'decline':
             $this->declined = true;
             break;
         case 'error':
             $this->error = true;
             break;
     }
 }
Exemple #9
0
<?php

require_once '../../bootstrap.php';
use Pop\Curl\Curl;
try {
    $total = 0;
    $curl = new Curl('http://www.popphp.org/license');
    $curl->setOption(CURLOPT_WRITEFUNCTION, function ($curl, $data) {
        global $total;
        $len = strlen($data);
        $total += $len;
        echo $len . ' (' . $total . ')<br />' . PHP_EOL;
        return $len;
    });
    $curl->execute();
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
 /**
  * Send transaction
  *
  * @param  boolean $verifyPeer
  * @throws Exception
  * @return void
  */
 public function send($verifyPeer = true)
 {
     if (!$this->validate()) {
         throw new Exception('The required transaction data has not been set.');
     }
     $url = $this->test ? $this->testUrl : $this->liveUrl;
     $options = array(CURLOPT_HEADER => false, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $this->buildPostString());
     if (!$verifyPeer) {
         $options[CURLOPT_SSL_VERIFYPEER] = false;
     }
     $curl = new Curl($url, $options);
     $this->response = $curl->execute();
     $this->responseCodes = explode('|', $this->response);
     $this->responseCode = $this->responseCodes[0];
     $this->responseSubcode = $this->responseCodes[1];
     $this->reasonCode = $this->responseCodes[2];
     $this->message = $this->responseCodes[3];
     switch ($this->responseCode) {
         case 1:
             $this->approved = true;
             break;
         case 2:
             $this->declined = true;
             break;
         case 3:
             $this->error = true;
             break;
     }
 }
Exemple #11
0
<?php

require_once '../../bootstrap.php';
use Pop\Curl\Curl;
try {
    $curl = new Curl('http://www.popphp.org/license');
    $curl->execute();
    header('Content-Type: ' . $curl->getHeader('Content-Type'));
    echo $curl->getBody();
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}