post() public static méthode

Static method to send a POST request
public static post ( string $url, array $params = [] ) : object
$url string
$params array
Résultat object Response
Exemple #1
0
 /**
  * Perform an api request, return an array with result details
  *
  * @param  string $endpoint
  * @param  array  $params
  * @throws Openbuildings\Emp\Exception If errors in request, api response or the card is declined
  * @return array
  */
 public function request($endpoint, array $params)
 {
     $params = array_merge($this->auth_params($endpoint), $params);
     $url = $url = $this->_gateway_url . $endpoint;
     $options = $this->_options;
     if ($this->proxy()) {
         $options[CURLOPT_PROXY] = $this->proxy();
     }
     $response = Remote::post($url, $params, $options);
     $xml_response = new \SimpleXMLElement($response);
     $trans_id = (string) ($xml_response->transaction->trans_id ?: $xml_response->trans_id);
     $response_code = (string) ($xml_response->transaction->response ?: $xml_response->response);
     if ($xml_response->errors and $error = $xml_response->errors[0]->error) {
         throw new Exception(':error (:code)', array(':error' => (string) $error->text, ':code' => (string) $error->code));
     } elseif ((string) $response_code === 'D') {
         throw new Exception('Transaction declined: :errors', array(':errors' => (string) $xml_response->transaction->response_text));
     }
     return array('order_id' => (string) $xml_response->order_id, 'order_status' => (string) $xml_response->order_status, 'transaction_response' => $response_code, 'transaction_id' => $trans_id, 'raw' => json_decode(json_encode($xml_response), TRUE));
 }