PHP code example of sipay / php-sdk

1. Go to this page and download the library: Download sipay/php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sipay / php-sdk example snippets


$path_autoload = "<directorio_de_descarga_de_php-sdk>/src/autoload.php";

$path_autoload = "vendor/autoload.php";

  
  $config = array(
      'logger' => array(
          'path' => 'logs',  // Nombre del directorio donde se crearan los logs (Nota: si la ruta es relativa se creará en el directorio del paquete)
          'level' => 'warning',  // Nivel mínimo de trazas [debug, info, warning, error, critical]
          'prefix' => 'logger',  // Prefijo del nombre del archivo
          'extension' => 'log',  // Extensión del archivo
          'date_format' => 'd/m/Y H:i:s',  // Formato de fecha de las trazas de log
          'backup_file_rotation' => 5  // Número de ficheros de backup
      ),
      'credentials' => array(
          'key' => 'api-key',  // Key del cliente
          'secret' => 'api-secret',  // Secret del cliente
          'resource' => 'resource' // Recurso al que se quiere acceder
      ),
      'api' => array(
          'environment' => 'sandbox',  // Entorno al que se deben enviar las peticiones ['sandbox', 'staging', 'live']
          'version' => 'v1',  // Versión de la api a usar actualmente solo existe v1
          'mode' => 'sha256'  // Modo de encriptacion de la firma, [sha256, sha512]
      ),
      'connection' => array(
          'timeout' => 30  // Tiempo máximo de respuesta de la petición.
      )
  );


  
   string
  $amount = new \Sipay\Amount('1.56', 'EUR');

  print($amount."\n")
  // Imprime 1.56EUR
  print($amount->get_amount()."\n")
  // Imprime 156
  print($amount->get_currency()."\n")
  // Imprime EUR

  // Con unidad indivisible
  $amount = new \Sipay\Amount(156, 'EUR');

  print($amount."\n")
  // Imprime 1.56EUR
  print($amount->get_amount()."\n")
  // Imprime 156
  print($amount->get_currency()."\n")
  // Imprime EUR

  // Con string en unidad indivisible
  $amount = new \Sipay\Amount('156', 'EUR');

  print($amount."\n")
  // Imprime 1.56EUR
  print($amount->get_amount()."\n")
  // Imprime 156
  print($amount->get_currency()."\n")
  // Imprime EUR

  
  = new \Sipay\Paymethods\Card('4242424242424242', 2018, 12);

  
  = new \Sipay\Paymethods\StoredCard('token-card');

  
  = new \Sipay\Paymethods\FastPay('token-fast-pay');

  
  erce = \Sipay\Ecommerce('etc/config.ini');

  $amount = \Sipay\Amount(100, 'EUR'); // 1€
  $card = \Sipay\Paymethods\Card('4242424242424242', 2050, 2);

  $auth = $ecommerce->authorization($card, $amount);

   $amount = \Sipay\Amount(100, 'EUR'); // 1€
   $fp = \Sipay\Paymethods\FastPay('830dc0b45f8945fab229000347646ca5');

   $auth = $ecommerce->authorization($fp, $amount);

  $auth = $ecommerce->authentication($card, $amount, $options);
  $auth1 = $ecommerce->confirm(array('request_id' => $auth->request_id));

  $cancel = $ecommerce->cancellation('transaction_id');

  $amount = \Sipay\Amount(100, 'EUR'); // 1€
  $card = \Sipay\Paymethods\StoredCard('bd6613acc6bd4ac7b6aa96fb92b2572a');
  $refund = $ecommerce->refund($card, $amount);

  $amount = \Sipay\Amount(100, 'EUR'); // 1€

  $refund = $ecommerce->refund('transaction_id', $amount);

  $query = array('transaction_id' => 'transaction_id');
  $query = $ecommerce->query($query);

    $card = \Sipay\Paymethods\Card('4242424242424242', 2050, 2);

    $masked_card = $ecommerce->register($card, 'newtoken');
  

   $masked_card = $ecommerce->card('newtoken');

  $unregister = $ecommerce->unregister('newtoken');
bash
  $ git clone https://github.com/sipay/php-sdk
  $ echo '
  
  gurar el archivo de configuración como se indica en la sección Ecommerce
  $amount = new \Sipay\Amount(100, "EUR");
  $card = new \Sipay\Paymethods\Card("4242424242424242", 2050, 12);
  $options = array(
    "order" => "order-test",
    "reference" => "1234",
    "token" => "new-token"
  );
  $auth = $ecommerce->authorization($card, $amount, $options);
  if($auth->code == 0){
    print("Autorización aceptada, el pago ha sido completado!\n");
  }else{
    print("Error: ".$auth->description."\n");
  }
  ' > quickstart.php
  $ php quickstart.php
bash
    $ git clone https://github.com/sipay/php-sdk.git
  
bash
$ composer