PHP code example of asciisd / cybersource-laravel

1. Go to this page and download the library: Download asciisd/cybersource-laravel 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/ */

    

asciisd / cybersource-laravel example snippets


use Asciisd\CyberSource\Facades\CyberSource;

// For authorization only (no capture)
$transaction = CyberSource::authorize([
    'reference' => 'order-123',
    'amount' => '100.00',
    'currency' => 'USD',
    'card' => [
        'number' => '4111111111111111', // Visa card number
        'expiration_month' => '12',
        'expiration_year' => '2025',
        'security_code' => '123'
    ],
    'billing' => [
        'first_name' => 'John',
        'last_name' => 'Doe',
        'address' => '1 Market St',
        'city' => 'San Francisco',
        'state' => 'CA',
        'postal_code' => '94105',
        'country' => 'US',
        'email' => '[email protected]',
        'phone' => '4158880000'
    ]
]);

// Check if the transaction was successful
if ($transaction->isSuccessful()) {
    // Get the transaction ID
    $transactionId = $transaction->getId();
    
    // Get the transaction status
    $status = $transaction->getStatus();
    
    // Store the transaction ID for future operations
    // ...
}

// For authorization with immediate capture (sale)
$transaction = CyberSource::charge([
    'reference' => 'order-123',
    'amount' => '100.00',
    'currency' => 'USD',
    'card' => [
        'number' => '4111111111111111', // Visa card number
        'expiration_month' => '12',
        'expiration_year' => '2025',
        'security_code' => '123'
    ],
    'billing' => [
        'first_name' => 'John',
        'last_name' => 'Doe',
        'address' => '1 Market St',
        'city' => 'San Francisco',
        'state' => 'CA',
        'postal_code' => '94105',
        'country' => 'US',
        'email' => '[email protected]',
        'phone' => '4158880000'
    ]
]);

$transaction = CyberSource::capture('transaction-id', 100.00, [
    'reference' => 'capture-123',
    'currency' => 'USD'
]);

$transaction = CyberSource::void('transaction-id', [
    'reference' => 'void-123'
]);

$transaction = CyberSource::refund('transaction-id', 100.00, [
    'reference' => 'refund-123',
    'currency' => 'USD'
]);

$transaction = CyberSource::retrieveTransaction('transaction-id');

use Asciisd\CyberSource\Exceptions\CyberSourceException;
use Asciisd\CyberSource\Facades\CyberSource;

try {
    $transaction = CyberSource::charge([
        // Payment details...
    ]);
    
    // Process successful transaction
    
} catch (CyberSourceException $e) {
    // Handle the error
    $errorMessage = $e->getMessage();
    $errorCode = $e->getCode();
    $errorData = $e->getErrorData();
    
    // Log the error or display a message to the user
}
bash
php artisan cybersource:install
bash
php artisan migrate