PHP code example of shieldgate / sdk-php

1. Go to this page and download the library: Download shieldgate/sdk-php 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/ */

    

shieldgate / sdk-php example snippets




ayment\Payment;

// First setup your credentials provided by ShieldGate
$applicationCode = "SOME_APP_CODE";
$applicationKey = "SOME_APP_KEY";

Payment::init($applicationCode, $applicationKey);



use Payment\Payment;
use Payment\Exceptions\PaymentErrorException;

Payment::init($applicationCode, $aplicationKey);

$card = Payment::card();

// Success response
$userId = "1";
$listOfUserCards = $card->getList($userId);

$totalSizeOfCardList = $listOfUserCards->result_size;
$listCards = $listOfUserCards->cards;

// Get all data of response
$response = $listOfUserCards->getData();

// Catch fail response
try {
	$listOfUserCards = $card->getList("someUID");
} catch (PaymentErrorException $error) {
	// Details of exception
	echo $error->getMessage();
	// You can see the logs for complete information
}



use Payment\Payment;
use Payment\Exceptions\PaymentErrorException;

// Card token
$cardToken = "myAwesomeTokenCard";

$charge = Payment::charge();

$userDetails = [
    'id' => "1", // Field , // Field rmation
    // Access to HTTP code from gateway service
    $code = $error->getCode();
    $message = $error->getMessage();
}

// Get transaction status
$status = $created->transaction->status;
// Get transaction ID
$transactionId = $created->transaction->id;
// Get authorization code
$authCode = $created->transaction->authorization_code;



use Payment\Payment;
use Payment\Exceptions\PaymentErrorException;

// Card token
$cardToken = "myAwesomeTokenCard";

$charge = Payment::charge();

$userDetails = [
    'id' => "1", // Field , // Field lete information
    // Access to HTTP code from gateway service
    $code = $error->getCode();
    $message = $error->getMessage();
}

// Get transaction status
$status = $authorization->transaction->status;
// Get transaction ID
$transactionId = $authorization->transaction->id;
// Get authorization code
$authCode = $authorization->transaction->authorization_code;



use Payment\Payment;
use Payment\Exceptions\PaymentErrorException;

$charge = Payment::charge();

$authorization = $charge->authorize($cardToken, $orderDetails, $userDetails);
$transactionId = $authorization->transaction->id;

try {
    $capture = $charge->capture($transactionId);
} catch (PaymentErrorException $error) {
    // See the console output for complete information
    // Access to HTTP code from gwateway service
    $code = $error->getCode();
    $message = $error->getMessage();
}

// Get transaction status
$status = $capture->transaction->status;

// Make a capture with different amount
$newAmountForCapture = 1000.46;
$capture = $charge->capture($transactionId, $newAmountForCapture);



use Payment\Payment;
use Payment\Exceptions\PaymentErrorException;

$charge = Payment::charge();

$created = $charge->create($cardToken, $orderDetails, $userDetails);
$transactionId = $created->transaction->id;

try {
    $refund = $charge->refund($transactionId);
} catch (PaymentErrorException $error) {
    // See the console output for complete information
    // Access to HTTP code from gateway service
    $code = $error->getCode();
    $message = $error->getMessage();
}

// Get status of refund
$status = $refund->status;
$detail = $refund->detail;

// Make a partial refund
$partialAmountToRefund = 10;
$refund = $charge->refund($transactionId, $partialAmountToRefund);



use Payment\Payment;
use Payment\Exceptions\PaymentErrorException;

$cash = Payment::cash();

$carrierDetails = [
    'id' => 'oxxo', // Field      'last_name' => "Perez"
        ]
    ]
];

$userDetails = [
   'id' => "1", // Field ield 
    // Access to HTTP code from gateway service
    $code = $error->getCode();
    $message = $error->getMessage();
}

// Get reference code
$referenceCode = $order->transaction->reference;
// Get expiration date
$expirationData = $order->transaction->expiration_date;
// Get order status
$status = $order->transaction->status;



ayment\Payment;

// Primero configura las credenciales otorgadas por ShieldGate
$applicationCode = "SOME_APP_CODE";
$applicationKey = "SOME_APP_KEY";

Payment::init($applicationCode, $applicationKey);



use Payment\Payment;
use Payment\Exceptions\PaymentErrorException;

Payment::init($applicationCode, $aplicationKey);

$card = Payment::card();

// Respuesta exitosa
$userId = "1";
$listOfUserCards = $card->getList($userId);

$totalSizeOfCardList = $listOfUserCards->result_size;
$listCards = $listOfUserCards->cards;

// Obtener los datos de la respuesta
$response = $listOfUserCards->getData();

// Manejo de errores en la respuesta
try {
	$listOfUserCards = $card->getList("someUID");
} catch (PaymentErrorException $error) {
	// Detalles de la excepción
	echo $error->getMessage();
	// Puedes ver los logs para información completa
}



use Payment\Payment;
use Payment\Exceptions\PaymentErrorException;

// Token de tarjeta
$cardToken = "myAwesomeTokenCard";

$charge = Payment::charge();

$userDetails = [
    'id' => "1", // Campo requerido
    'email' => "[email protected]" // Campo requerido
];

$orderDetails = [
    'amount' => 100.00, // Campo requerido
    'description' => "XXXXXX", // Campo requerido
    'dev_reference' => "XXXXXX", // Campo requerido
    'vat' => 0.00 // Campo requerido 
];

try {
    $created = $charge->create($cardToken, $orderDetails, $userDetails);
} catch (PaymentErrorException $error) {
    // Revisa la salida en consola para más información    
    // Acceso al código HTTP y el mensaje de error del servicio de la pasarela
    $code = $error->getCode();
    $message = $error->getMessage();
}

// Obtiene el estado de la transacción
$status = $created->transaction->status;
// Obtiene el ID de la transacción
$transactionId = $created->transaction->id;
// Obtiene el código de autorización de la transacción
$authCode = $created->transaction->authorization_code;



use Payment\Payment;
use Payment\Exceptions\PaymentErrorException;

// Token de tarjeta
$cardToken = "myAwesomeTokenCard";

$charge = Payment::charge();

$userDetails = [
    'id' => "1", // Campo requerido
    'email' => "[email protected]" // Campo requerido
];

$orderDetails = [
    'amount' => 100.00, // Campo requerido
    'description' => "XXXXXX", // Campo requerido
    'dev_reference' => "XXXXXX", // Campo requerido
    'vat' => 0.00 // Campo requerido 
];

try {
    $authorization = $charge->authorize($cardToken, $orderDetails, $userDetails);
} catch (PaymentErrorException $error) {
    // Revisa la salida en consola para más información    
    // Acceso al código HTTP y el mensaje de error del servicio de la pasarela
    $code = $error->getCode();
    $message = $error->getMessage();
}

// Obtiene el estado de la transacción
$status = $authorization->transaction->status;
// Obtiene el ID de la transacción
$transactionId = $authorization->transaction->id;
// Obtiene el código de autorización de la transacción
$authCode = $authorization->transaction->authorization_code;



use Payment\Payment;
use Payment\Exceptions\PaymentErrorException;

$charge = Payment::charge();

$authorization = $charge->authorize($cardToken, $orderDetails, $userDetails);
$transactionId = $authorization->transaction->id;

try {
    $capture = $charge->capture($transactionId);
} catch (PaymentErrorException $error) {
    // Revisa la salida en consola para más información    
    // Acceso al código HTTP y el mensaje de error del servicio de la pasarela
    $code = $error->getCode();
    $message = $error->getMessage();
}

// Obtiene el estado de la transacción
$status = $capture->transaction->status;

// Realiza la captura con un monto diferente (Consulta con el equipo de integraciones sobre las limitaciones de cada operador)
$newAmountForCapture = 1000.46;
$capture = $charge->capture($transactionId, $newAmountForCapture);



use Payment\Payment;
use Payment\Exceptions\PaymentErrorException;

$charge = Payment::charge();

$created = $charge->create($cardToken, $orderDetails, $userDetails);
$transactionId = $created->transaction->id;

try {
    $refund = $charge->refund($transactionId);
} catch (PaymentErrorException $error) {
    // Revisa la salida en consola para más información    
    // Acceso al código HTTP y el mensaje de error del servicio de la pasarela
    $code = $error->getCode();
    $message = $error->getMessage();
}

// Obtiene el estado del reembolso
$status = $refund->status;
$detail = $refund->detail;

// Realiza un refund parcial (Consulta con el equipo de integraciones sobre las limitaciones de cada operador)
$partialAmountToRefund = 10;
$refund = $charge->refund($transactionId, $partialAmountToRefund);



use Payment\Payment;
use Payment\Exceptions\PaymentErrorException;

$cash = Payment::cash();

$carrierDetails = [
    'id' => 'oxxo', // Campo requerido
    'extra_params' => [ // Depends of carrier, for oxxo is po requerido
];

$orderDetails = [
    'dev_reference' => "XXXXXXX", // Campo requerido 
    'amount' => 100, // Campo requerido
    'expiration_days' => 1, // Campo requerido
    'recurrent' => false, // Campo requerido
    'description' => "XXXXXX" // Campo requerido
];

try {
    $order = $cash->generateOrder($carrierDetails, 
    $userDetails, 
    $orderDetails);
} catch (PaymentErrorException $error) {
    // Revisa la salida en consola para más información    
    // Acceso al código HTTP y el mensaje de error del servicio de la pasarela
    $code = $error->getCode();
    $message = $error->getMessage();
}

// Obtiene el código / referencia de pago
$referenceCode = $order->transaction->reference;
// Obtiene la fecha de expiración
$expirationData = $order->transaction->expiration_date;
// Obtiene el estado de la orden
$status = $order->transaction->status;