PHP code example of caydeesoft / card-sdk

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

    

caydeesoft / card-sdk example snippets


'providers' => [
    Caydeesoft\CardSdk\CardServiceProvider::class,
],

use Caydeesoft\CardSdk\Contracts\CardInterface;

class PaymentController
{
    public function store(CardInterface $cards)
    {
        $response = $cards->authorizePayment([
            'amount' => 1000,
            'currency' => 'USD',
            'card_number' => '4111111111111111',
            'expiry' => '12/26',
            'cvv' => '123',
        ]);

        return response()->json($response);
    }
}

authorizePayment(array $paymentData): array;
capturePayment(string $transactionId): array;
refundPayment(string $transactionId): array;

$response = $cards->capturePayment($transactionId);

$response = $cards->refundPayment($transactionId);

use Caydeesoft\CardSdk\CardValidator;

$cardType = CardValidator::getCardType('4111111111111111');

if (! CardValidator::isValidCardNumber('4111111111111111')) {
    return response()->json(['error' => 'Invalid card number'], 422);
}

if (! CardValidator::isValidExpiry('12', '2026')) {
    return response()->json(['error' => 'Expired card'], 422);
}

if (! CardValidator::isValidCVV('123', $cardType)) {
    return response()->json(['error' => 'Invalid CVV'], 422);
}

use Caydeesoft\CardSdk\StoredCardEncryptor;

class StoredPaymentMethodController
{
    public function store(StoredCardEncryptor $encryptor)
    {
        $encrypted = $encryptor->encrypt([
            'provider' => 'visa',
            'card_token' => 'tok_provider_generated_value',
            'last_four' => '1111',
            'card_type' => 'Visa',
            'expiry_month' => '12',
            'expiry_year' => '2028',
        ], request('password_or_pin'));

        auth()->user()->paymentMethods()->create([
            'encrypted_payload' => $encrypted,
        ]);
    }
}

use Caydeesoft\CardSdk\Contracts\CardInterface;
use Caydeesoft\CardSdk\StoredCardEncryptor;

class RepeatPaymentController
{
    public function store(CardInterface $cards, StoredCardEncryptor $encryptor)
    {
        $paymentMethod = auth()->user()->paymentMethods()->findOrFail(request('payment_method_id'));

        $stored = $encryptor->decrypt(
            $paymentMethod->encrypted_payload,
            request('password_or_pin')
        );

        $response = $cards->authorizePayment([
            'amount' => 1000,
            'currency' => 'USD',
            'card_token' => $stored['card_token'],
        ]);

        return response()->json($response);
    }
}
bash
php artisan vendor:publish --tag=card-config
bash
composer dump-autoload
php artisan package:discover