/**
  * Register the service provider.
  * @return void
  */
 public function register()
 {
     $this->app->bind('pagseguro', function () {
         $platform = new Laravel5();
         Config::usePlatform($platform);
         $facade = new PagSeguroFacade();
         return $facade;
     });
 }
Ejemplo n.º 2
0
 /**
  * @param string $key
  * @param mixed $value
  * @return mixed
  */
 public static function set($key, $value)
 {
     $platform = self::getPlatform();
     $default = static::get($key);
     if ($default != $value) {
         static::$data[$key] = $value;
         if ($platform->hasPersonalConfig()) {
             $key = implode('.', (array) $key);
             \Config::set('laravelpagseguro.' . $key, $value);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Build Http Adapter by Application Config
  * @return AdapterInterface
  * @throws \RuntimeException
  */
 public static function buildHttpAdapter()
 {
     $http = Config::get('http');
     $adapterConfig = $http['adapter'];
     $adapter = null;
     if (is_array($adapterConfig)) {
         $adapter = self::adapterArrayFactory($adapterConfig);
     } elseif ($adapterConfig instanceof \Closure) {
         $adapter = $adapterConfig();
     }
     if (!$adapter instanceof AdapterInterface) {
         throw new \RuntimeException('Invalid adapter object');
     }
     return $adapter;
 }
 /**
  * Notification Action
  */
 public function notification()
 {
     \App::make('pagseguro');
     // Register PagSeguro
     $platform = Config::getPlatform();
     $params = array_merge(['notificationCode' => null, 'notificationType' => null], $platform->getUrlParameters());
     $code = $params['notificationCode'];
     $type = $params['notificationType'];
     if (empty($code) || empty($type)) {
         $platform->abort();
         return;
     }
     $credential = $this->getCredentialsTo($code);
     $notification = new Notification($code, $type);
     $info = $notification->check($credential);
     $this->notify($info);
 }
Ejemplo n.º 5
0
 /**
  * Route URL
  * @param array $routeConfig [route-name: string]
  * @return string
  */
 private function getRouterURL($routeConfig)
 {
     $platform = Config::getPlatform();
     if (!$platform->hasRouter()) {
         throw new \RuntimeException('Undefined platform router');
     }
     if (!array_key_exists('route-name', $routeConfig)) {
         throw new \RuntimeException('Undefined key route-name');
     }
     $routeName = $routeConfig['route-name'];
     if (empty($routeName)) {
         return null;
     }
     return $platform->getUrlByRoute($routeName);
 }
 /**
  * Get Default Credentials
  * @return Credentials
  */
 public function get()
 {
     $data = Config::get('credentials');
     return $this->create($data['token'], $data['email']);
 }
<?php

require '_prevent-access.php';
require_once __DIR__ . '/../vendor/autoload.php';
ini_set('display_errors', 'On');
error_reporting(E_ALL);
/**
 * Change Credentials to your SandBox
 */
$sandBoxCredentials = (include '_sandbox-credentials.php');
$credentialEmail = $sandBoxCredentials['email'];
// Email
$credentialKey = $sandBoxCredentials['key'];
// Public Key
$senderEmail = '*****@*****.**';
// Sender-Email
use laravel\pagseguro\Config\Config;
use laravel\pagseguro\Credentials\Credentials;
use laravel\pagseguro\Checkout\Facade\CheckoutFacade;
$data = ['items' => [['id' => 18, 'description' => 'Laravel PS Simple Checkout', 'quantity' => 1, 'shippingCost' => 3.5, 'width' => 50, 'weight' => 45, 'height' => 45, 'length' => 60, 'amount' => 1.15]], 'shipping' => ['address' => ['postalCode' => '06410030', 'street' => 'Rua da Selva', 'number' => '12', 'district' => 'Jardim dos Camargos', 'city' => 'Barueri', 'state' => 'SP', 'country' => 'BRA'], 'type' => 2, 'cost' => 30.4], 'sender' => ['email' => $senderEmail, 'name' => 'Isaque de Souza Barbosa', 'documents' => [['number' => '80808080822', 'type' => 'CPF']], 'phone' => '11985445522', 'bornDate' => '1988-03-25']];
try {
    Config::set('use-sandbox', true);
    $facade = new CheckoutFacade();
    $credentials = new Credentials($credentialKey, $credentialEmail);
    $checkout = $facade->createFromArray($data);
    $information = $checkout->send($credentials);
    printf('<pre>%s</pre>', print_r($information, 1));
    printf('<a href="%s">Clique para pagar</a>', $information->getLink());
} catch (\Exception $e) {
    printf('<pre>%s</pre>', print_r((string) $e, 1));
}