Exemple #1
0
 /**
  * Execute a http request. If payload == null no body will be sent. Empty body ('{}') is supported by sending a
  * empty stdClass.
  *
  * @param string     $path
  * @param string     $method
  * @param mixed|null $payload
  *
  * @throws Exceptions\ValidationException  if the API returns a 4xx http status code. Usually means invalid data was sent.
  * @throws Exceptions\UnautorizedException if the API returns a 401 http status code. Check API token and key.
  * @throws Exceptions\UnexpectedException  if the API returns a 500 http status code or something unexpected happens (ie.: Network error).
  *
  * @return stdClass
  */
 protected function httpRequest($path, $method, $payload = null)
 {
     $http_sess = $this->moip->getSession();
     $headers = [];
     $body = null;
     if ($payload !== null) {
         $body = json_encode($payload, JSON_UNESCAPED_SLASHES);
         if ($body) {
             // if it's json serializable
             $headers['Content-Type'] = 'application/json';
         } else {
             $body = null;
         }
     }
     try {
         $http_response = $http_sess->request($path, $headers, $body, $method);
     } catch (Requests_Exception $e) {
         throw new Exceptions\UnexpectedException($e);
     }
     $code = $http_response->status_code;
     $response_body = $http_response->body;
     if ($code >= 200 && $code < 300) {
         return json_decode($response_body);
     } elseif ($code == 401) {
         throw new Exceptions\UnautorizedException();
     } elseif ($code >= 400 && $code <= 499) {
         $errors = Exceptions\Error::parseErrors($response_body);
         throw new Exceptions\ValidationException($code, $errors);
     }
     throw new Exceptions\UnexpectedException();
 }
Exemple #2
0
 /**
  * Creates an order.
  *
  * @return Orders
  */
 public function createOrder()
 {
     if ($this->sandbox_mock == self::SANDBOX) {
         $this->last_ord_id = uniqid('ORD-');
     } else {
         $this->last_ord_id = 'meu_id_pedido';
     }
     $order = $this->moip->orders()->setCustomer($this->createCustomer())->addItem('Nome do produto', 1, 'Mais info...', 100000)->addItem('abacaxi', 2, 'Abacaxi de terra de areia', 990)->setDiscount(1000)->setShippingAmount(1490)->setOwnId($this->last_ord_id);
     return $order;
 }
Exemple #3
0
function exampleFull()
{
    $moip = new Moip();
    $moip->setEnvironment('test');
    $moip->setCredential(array('key' => 'ABABABABABABABABABABABABABABABABABABABAB', 'token' => '01010101010101010101010101010101'));
    $moip->setUniqueID(false);
    $moip->setValue('100.00');
    $moip->setReason('Teste do Moip-PHP');
    $moip->setPayer(array('name' => 'Nome Sobrenome', 'email' => '*****@*****.**', 'payerId' => 'id_usuario', 'billingAddress' => array('address' => 'Rua do Zézinho Coração', 'number' => '45', 'complement' => 'z', 'city' => 'São Paulo', 'neighborhood' => 'Palhaço Jão', 'state' => 'SP', 'country' => 'BRA', 'zipCode' => '01230-000', 'phone' => '(11)8888-8888')));
    $moip->validate('Identification');
    $moip->setReceiver('*****@*****.**');
    $moip->addParcel('2', '4');
    $moip->addParcel('5', '7', '1.00');
    $moip->addParcel('8', '12', null, true);
    $moip->addComission('Razão do Split', 'recebedor_secundario', '5.00');
    $moip->addComission('Razão do Split', 'recebedor_secundario', '2.00', true);
    $moip->addComission('Razão do Split', 'recebedor_secundario_2', '12.00', true, 'recebedor_secundario_3');
    $moip->addPaymentWay('creditCard');
    $moip->addPaymentWay('billet');
    $moip->addPaymentWay('financing');
    $moip->addPaymentWay('debit');
    $moip->addPaymentWay('debitCard');
    $moip->setBilletConf("2011-04-06", true, array("Primeira linha", "Segunda linha", "Terceira linha"), "http://seusite.com.br/logo.gif");
    print_r($moip->getXML());
}
 /**
  * Create a new connecttion.
  * 
  * @return \Moip\Http\HTTPConnection
  */
 protected function createConnection()
 {
     return $this->moip->createConnection();
 }
Exemple #5
0
 /**
  * Create a new Multiorders instance.
  *
  * @return \Moip\Resource\Multiorders
  */
 public function multiorders()
 {
     return $this->moip->multiorders();
 }
Exemple #6
0
<?php

phpinfo();
ini_set('display_errors', 1);
require 'vendor/autoload.php';
/**
 include_once 'examples.php';

 exampleBasicInstructions();
 exampleFull();
 exampleQueryParcels();
*
*/
use Moip\Moip;
$moip = new Moip();
$moip->setEnvironment('test');
$moip->setCredential(array('key' => '8UUKVUTBRLBGDGISZUY7UY7Y22SHZO3OIKBW6RMJ', 'token' => '6YA2TFYGRIWA5LPPTUJRJ88VPBNMKLF1'));
$moip->setUniqueID(false);
$moip->setValue('100.00');
$moip->setReason('Teste do Moip-PHP');
$moip->validate('Basic');
$moip->send();
print_r($moip->getAnswer());